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

Different behavior for Array#reject in required file #8225

Closed
Maumagnaguagno opened this issue May 5, 2024 · 5 comments · Fixed by #8252
Closed

Different behavior for Array#reject in required file #8225

Maumagnaguagno opened this issue May 5, 2024 · 5 comments · Fixed by #8252
Milestone

Comments

@Maumagnaguagno
Copy link

Maumagnaguagno commented May 5, 2024

A few days ago I noticed a behavior change related to Array#reject using GitHub Actions and jruby-head.
Today I was able to obtain the following minimal reproducible example using Linux and RVM with two files:

test_jruby.rb

puts RUBY_DESCRIPTION
puts 'test1'
[[1,2]].reject {|e,| p e}
require_relative 'test_jruby2'

test_jruby2.rb

puts 'test2'
[[1,2]].reject {|e,| p e}

The expected output contains the description strings and the first element, e, of each Array.

Output of Ruby MRI 3.3.1 (expected)

$ ruby test_jruby.rb 
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
test1
1
test2
1

Output of JRuby 9.4.7.0 (expected)

$ ruby test_jruby.rb 
jruby 9.4.7.0 (3.1.4) 2024-04-29 597ff08ac1 OpenJDK 64-Bit Server VM 25.402-b06 on 1.8.0_402-b06 +jit [x86_64-linux]
test1
1
test2
1

Output of JRuby head (unexpected output in test2)

$ ruby test_jruby.rb 
jruby 9.4.8.0-SNAPSHOT (3.1.4) 2024-05-05 d7358ea8c5 OpenJDK 64-Bit Server VM 25.402-b06 on 1.8.0_402-b06 +jit [x86_64-linux]
test1
1
test2
[1, 2]

Note that using underscore, [[1,2]].reject {|e,_| p e}, is enough to obtain the correct behavior.
This used to work without the underscore and the difference between main and required files is surprising.

@enebo enebo added this to the JRuby 9.4.8.0 milestone May 21, 2024
@enebo
Copy link
Member

enebo commented May 21, 2024

This can just be reduced to:

puts 'test2'
[[1,2]].reject {|e,| p e}

If run by default command-line we unconditionally compile the main file and if compiled this works as expected. If I run it with interpreter (jruby --dev reject1.rb) then we see the wrong binding.

@enebo
Copy link
Member

enebo commented May 21, 2024

So this is specific to how we dispatch from some enumerable methods (and possibly others) but only when calling into the interpreter. This partially explains why we didn't see this failing. If I just call a proc with |e,| from interp or JIT it works as expected.

@enebo
Copy link
Member

enebo commented May 22, 2024

In the end one proc parameter method was not updated for the arity "fix" for , procs.

@headius
Copy link
Member

headius commented May 22, 2024

Is there a test we can add for this somewhere? I know these JIT-Int-JIT transitions are hard to test. 🫤

@enebo
Copy link
Member

enebo commented May 22, 2024

@headius this is not a JIT-int-JIT thing but merely it did not work from native -> int for yieldSpecific. I added a regression test which will run as interp. Should be covered.

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

Successfully merging a pull request may close this issue.

3 participants