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

The behavior of Enumerable#each_with_index has changed in JRuby 9.1.9.0 #4610

Closed
koic opened this issue May 17, 2017 · 13 comments
Closed

The behavior of Enumerable#each_with_index has changed in JRuby 9.1.9.0 #4610

koic opened this issue May 17, 2017 · 13 comments

Comments

@koic
Copy link

koic commented May 17, 2017

Environment

  • jruby 9.1.9.0 (2.3.3) 2017-05-15 28aa830 Java HotSpot(TM) 64-Bit Server VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
  • Darwin Kernel Version 13.0.2: Sun Sep 29 19:38:57 PDT 2013; root:xnu-2422.75.4~1/RELEASE_X86_64 x86_64

Expected Behavior

This is behavior of JRuby 9.1.8.0 and MRI 2.4.1 and MRI 2.5.0dev (2017-05-16 trunk 58738) .

> %i(foo bar baz).each_with_index {|v| puts v.inspect }
:foo
:bar
:baz

Actual Behavior

This is behavior of JRuby 9.1.9.0.

> %i(foo bar baz).each_with_index {|v| puts v.inspect }
[:foo, 0]
[:bar, 1]
[:baz, 2]

JRuby 9.1.9.0 returns array object. Is this intentionally changed?

@headius
Copy link
Member

headius commented May 17, 2017

Huh, I wonder what changed.

@headius
Copy link
Member

headius commented May 17, 2017

I do not see any modifications to each_with_index directly, but there are some changes to the utility methods it uses in RubyEnumerable.

This code is unfortunately rather fragile. MRI seems to have strange rules (or else no rules at all) about which Enumerable methods will break up arguments this way and which will box them in array. We probably fixed it for one method and broke it for others.

@headius
Copy link
Member

headius commented May 17, 2017

It appears to be from e4adab3 which was part of clean-up efforts for our block protocol. It seems this one might have overreached a bit. cc @enebo

@PragTob
Copy link

PragTob commented May 17, 2017

Hello friends 👋

Just one "me too" for the simplecov gem (and I'm about to check if shoes4 is affected).

Honestly, I think I'd appreciate a patch level release.. but well, I can also do simplecov patch level release :)

PragTob added a commit to shoes/shoes4 that referenced this issue May 17, 2017
See if we run into the each_with_index problem outlined in jruby/jruby#4610
PragTob added a commit to simplecov-ruby/simplecov-html that referenced this issue May 17, 2017
@PragTob
Copy link

PragTob commented May 17, 2017

simplecov-html 0.10.1 released with a fix. Shoes4 otherwise unaffected :)

@koic
Copy link
Author

koic commented May 18, 2017

Thank you for the quick answer. I understood that it was an unexpected regression.

@aviflax
Copy link

aviflax commented May 19, 2017

I’m looking forward to a patch release that fixes this… I’m eager to upgrade to 9.1.9.x but this regression makes me nervous.

@ghost
Copy link

ghost commented May 23, 2017

Depending on if block arity is being checked, this could make sense; an arity of 1 could thus infer passing the array object produced by each_with_index(), wherein an arity of 2 would perform the expected splat of the values.

That might make sense for the change from call() to yieldSpecific(), which I believe I recall reading functions similar to what's described above.

Oddly enough, a quick check of both JRuby 9.1.9.0 and MRI 2.3.3 works for the following:

# convert array to Hash of index => value
Hash[ [:foo, :bar, :baz].each_with_index.map {|value, index| [index, value] }]

@enebo enebo modified the milestones: JRuby 9.2.0.0, JRuby 9.1.10.0 May 23, 2017
@enebo
Copy link
Member

enebo commented May 23, 2017

I reverted this in ad368ee. With the millions of specs/test asserts we do apparently this is not covered and I did not try/think of this permutation.

The original intent is that we are slowly cleaning up our internal call paths for blocks/closures such that we can replace them with our own IR instructions when we inline a block back through a method. Unfortunately, the Enumerable stuff is the most difficult to follow.

I will put out 9.1.10.0 this week with this fix and a second fix for become_java! (unrelated to users of this issue).

@koic
Copy link
Author

koic commented May 26, 2017

Thank you for the release of JRuby 9.1.10.0. I confirmed that this regression was resolved.

@mojavelinux
Copy link

@enebo
Copy link
Member

enebo commented Jul 26, 2017

@mojavelinux thanks for letting us know. Opened #4724 to track this second regression :(

@mojavelinux
Copy link

👍

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

No branches or pull requests

6 participants