Truffleruby: Support ActiveSupport gem.

Created on 21 Jul 2018  ·  8Comments  ·  Source: oracle/truffleruby

👋 Hey folks! I wanted to flag a glitch that I'm seeing with Rails' ActiveSupport gem. I know you've designated the project not quite ready for production, so it's a low-urgency problem, but I can't seem to get past it. Running TruffleRuby RC3, installed through RVM on macOS 10.14, any attempt to run a Rails command throws the following error:

~ ❯❯❯ rvm use truffleruby
Using /usr/local/rvm/gems/truffleruby-1.0.0-rc3

~ ❯❯❯ cd Desktop

~/Desktop ❯❯❯ rails new shuffle
Possibly unsupported Ruby implementation
/usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:145:in `block (2 levels) in <top (required)>': undefined method `sum' for #<Module:0x120a> (NameError)
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:144:in `refine'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:144:in `block in <top (required)>'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:143:in `initialize'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:143:in `new'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/activesupport-5.2.0/lib/active_support/core_ext/enumerable.rb:143:in `<top (required)>'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `gem_original_require'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/railties-5.2.0/lib/rails/command.rb:5:in `<top (required)>'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `gem_original_require'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/railties-5.2.0/lib/rails/cli.rb:12:in `<top (required)>'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `gem_original_require'
    from /usr/local/rvm/rubies/truffleruby-1.0.0-rc3/lib/mri/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/gems/railties-5.2.0/exe/rails:10:in `<top (required)>'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/bin/rails:23:in `load'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/bin/rails:23:in `load'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/bin/rails:23:in `<top (required)>'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/bin/truffleruby_executable_hooks:24:in `eval'
    from /usr/local/rvm/gems/truffleruby-1.0.0-rc3/bin/truffleruby_executable_hooks:24:in `<main>'

It looks like the problem chunk of code (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/enumerable.rb#L151-L156) has been in ActiveSupport for some two years, so downgrading isn't really on the table. I can't quite reason out why TruffleRuby would be so confused about the scope of the refinement there, but maybe you have some insight.

Thanks in advance for your help, and good luck with what looks like a super exciting project!

bug

All 8 comments

Hello, and thank you for the report!

Here is the relevant line in ActiveSupport 5.2.0:
https://github.com/rails/rails/blob/v5.2.0/activesupport/lib/active_support/core_ext/enumerable.rb#L145
Looks like alias doesn't find Array#sum for some reason.

@aardvark179 Could you take a look? I think it's related to the refinement module having a superclass in MRI: https://bugs.ruby-lang.org/issues/14744

the same problem with activesupport (6.0.0.alpha)

$ rails s
Possibly unsupported Ruby implementation
/Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:154:in `block (2 levels) in <top (required)>': undefined method `sum' for #<Module:0x5e82> (NameError)
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:153:in `refine'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:153:in `block in <top (required)>'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:152:in `initialize'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:152:in `new'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/activesupport/lib/active_support/core_ext/enumerable.rb:152:in `<top (required)>'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/railties/lib/rails/command.rb:5:in `require'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/railties/lib/rails/command.rb:5:in `<top (required)>'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/railties/lib/rails/commands.rb:3:in `require'
  from /Users/User/.rvm/gems/truffleruby-1.0.0-rc3@project/bundler/gems/rails-a4398e412c04/railties/lib/rails/commands.rb:3:in `<top (required)>'
  from bin/rails:11:in `require'
  from bin/rails:11:in `<main>'

This appears to now be working in master. There have been some changes recently around both method and constant lookup which might have fixed this, but I'm not sure which commit solved this particular issue.

@aardvark179 Are you sure? I can reproduce the issue on master with just:

using Module.new {
  refine Array do
    p self
    p self.ancestors
    alias :orig_sum :sum
  end
}
MRI:
#<refinement:Array@#<Module:0x000055b2f5b982c0>>
[#<refinement:Array@#<Module:0x000055b2f5b982c0>>, Array, Enumerable, Object, Kernel, BasicObject]

TruffleRuby:
#<refinement:Array@#<Module:0x8e>>
[#<refinement:Array@#<Module:0x8e>>]
ref.rb:5:in `block (2 levels) in <main>': undefined method `sum' for #<Module:0x94> (NameError)

I think this is what we talked about, refinement modules have a "superclass" in MRI and that's why alias works above for MRI but not for us. I opened an issue and chatted about that with shugo and matz at RubyKaigi but there was no conclusion and I think it can't really change as now even Rails depends on this behavior.

You're right, the library can be required, but that particular file was hidden behind a couple of autoloads.

At the moment we special case method definition inside a refinement module, and we'd need to refactor things like alias to do something similar. Sorting out method lookup or changing the ancestors won't be enough however as include and prepend also add methods to the refined class in MRI, and will need considerably more work to sort out in order for method resolution to work properly.

A fix for this was merged in 6f1a4e94b9f568f4e3fcf5223956e4a9121e52b2.

How exciting, thanks for the update!

This is now fixed, and rails new myapp succeeds for rails 5.2.1.
bundle exec rails s doesn't work yet, but that is a different issue (currently concurrent-ruby fails to load, and I have another fix related to loading sass being reviewed).
Therefore I will close this issue. This fix will be in the next release.
Thank you for the report!

Was this page helpful?
0 / 5 - 0 ratings