Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COMPILER] Compiling array within a hash #2015

Closed
jemmaissroff opened this issue Dec 7, 2023 · 4 comments · Fixed by #2016 or #2055
Closed

[COMPILER] Compiling array within a hash #2015

jemmaissroff opened this issue Dec 7, 2023 · 4 comments · Fixed by #2016 or #2055
Assignees
Labels
Milestone

Comments

@jemmaissroff
Copy link
Collaborator

Minimal repro:

{[] => 1}

leads to method hash' called on hidden T_ARRAY object`

Found from: RUBY_ISEQ_DUMP_DEBUG=prism make test/coverage/test_coverage.rb

@jemmaissroff jemmaissroff changed the title [COMPILER] Compiling array within a hash breaks [COMPILER] Compiling array within a hash Dec 7, 2023
tenderlove added a commit to tenderlove/yarp that referenced this issue Dec 8, 2023
If a hash has children that are not "basic" types of objects, then we
can't consider the hash to be a static literal.

Fixes: ruby#2015
@tenderlove tenderlove self-assigned this Dec 8, 2023
@jemmaissroff jemmaissroff reopened this Dec 12, 2023
@jemmaissroff
Copy link
Collaborator Author

@tenderlove @kddnewton , this is still a bug on the latest master. I don't think #2016 fixed it.

@kddnewton kddnewton added this to the Ruby 3.3.0 milestone Dec 12, 2023
@paracycle
Copy link
Collaborator

There is a similar problem that exhibits itself with a similar message, which can be reproduced by:

RubyVM::InstructionSequence.compile_prism(<<~RUBY).eval
  def foo a: [], b: []
    p a
    p b
  end
  foo(a: [Symbol])
RUBY

and it outputs:

[Symbol]
<compiled>:2:in `p': method `inspect' called on hidden T_ARRAY object (0x00000001033d4de0 flags=0xa00002807) (NotImplementedError)
        from <compiled>:2:in `foo'
        from <compiled>:4:in `<compiled>'
        from ../test.rb:39:in `eval'
        from ../test.rb:39:in `<main>'

Note that since the second optional param is not passed, it causes an error on the p b line, so this version of the error looks like a default parameter bug.

I found this by isolating it from the failure of RUBY_ISEQ_DUMP_DEBUG=prism make ../test/ostruct/test_ostruct.rb

@paracycle
Copy link
Collaborator

Oh I think I know what's wrong with #2016. The PR checks if element is any of the types PM_NODE_ARRAY, PM_NODE_HASH and PM_NODE_RANGE, but the element won't be any of those types for a hash, it will be PM_NODE_ASSOC.

Now, PM_NODE_ASSOC also has a static literal check of its own, but that only checks to see if the value (not the key) is an array, hash or range.

So, none of our code actually makes the PM_HASH_NODE in the above example to not be a static literal.

@paracycle
Copy link
Collaborator

OK, I have what I think is a fix here: #2055 and a test that passes on ruby/ruby with that change here: ruby/ruby#9215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants