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

Kernel.require should not try to load lazy rubygems #3224

Closed
eregon opened this issue Aug 22, 2023 · 0 comments
Closed

Kernel.require should not try to load lazy rubygems #3224

eregon opened this issue Aug 22, 2023 · 0 comments
Assignees
Labels

Comments

@eregon
Copy link
Member

eregon commented Aug 22, 2023

Reported by @nirvdrum.
With zeitwerk we can end up in a stack overflow that looks like:

.../truffleruby-dev/gems/zeitwerk-2.6.9/lib/zeitwerk/kernel.rb:38:in `require'
<internal:core> core/unbound_method.rb:18:in `bind_call'
<internal:core> core/kernel.rb:272:in `require'
.../truffleruby-dev/gems/zeitwerk-2.6.9/lib/zeitwerk/kernel.rb:38:in `require'
<internal:core> core/unbound_method.rb:18:in `bind_call'
<internal:core> core/kernel.rb:272:in `require'

So the issue is RubyGems redefines Kernel#require but not Kernel.require. The original Kernel#require is a module_function, so after RubyGems we have: Kernel#require -> RubyGems require; Kernel.require -> the initial core require with lazy-rubygems handling (line 243).
And indeed, on CRuby:

$ ruby -e 'p method(:require)'
#<Method: Object(Kernel)#require(path) <internal:/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:36>
$ ruby -e 'p Kernel.method(:require)'
#<Method: Kernel.require(_)>

And on TruffleRuby:

jt -q ruby -e 'p Gem; p method(:require); p Kernel.method(:require)'
Gem
#<Method: #<Class:#<Object:0x8>>(Kernel)#require(path) <internal:/home/eregon/code/truffleruby-ws/graal/sdk/mxbuild/linux-amd64/GRAALVM_3555B82685_JAVA21/graalvm-3555b82685-java21-23.1.0-dev/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb>:36>
#<Method: Kernel.require(feature) <internal:core> core/kernel.rb:243>

But Kernel.require should be the one without lazy-rubygems behavior, i.e., gem_original_require in core/kernel.rb.

@eregon eregon added the bug label Aug 22, 2023
@eregon eregon self-assigned this Aug 22, 2023
eregon referenced this issue in fxn/zeitwerk Aug 22, 2023
module_function does not act on the alias.

Thanks to @rafaelfranca for alerting about the warning this was issuing,
and to @matthewd for helping understand the root cause.
mtortonesi pushed a commit to mtortonesi/truffleruby that referenced this issue Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant