Use the real module for Kernel autoload#6749
Merged
headius merged 4 commits intojruby:masterfrom Jul 12, 2021
Merged
Conversation
This logic needs to walk up to the nearest non-singleton, non- include wrapper to find the "real" module, since constants do not live on those other "non-real" module types. Fixes jruby#6708
The frame class is frequently pointing at the include wrapper for a given module, in order to indicate where super should start from. However with the "real module" logic this causes the target of the autoload to not be on that included module, but on the superclas of the include wrapper. This led to breakage in the Kernel#autoload specs, since they require that Kernel.autoload and Kernel#autoload define the constant on the included module.
Closed
We do not have a concept of cbase in our codebase, but the cbase in CRuby is used as the target for class variables and other class-y things that can be done from within a method body. The logic in IRRuntimeHelpers.getModuleFromScope seems to find the appropriate location. We do not do class variable targeting exactly right (e.g. in cloned modules) so this logic is not quite matching CRuby, but it does pass the original case in jruby#6708. This still fails a regression test from "JRUBY-6570" but it appears that the original fix for that issue did not really fix the problem. It merely made the expected case pass by always using Object as the target, which is clearly not correct. In order to start using the language of CRuby I have introduced a new method getCurrentClassBase that should eventually be equivalent to CRuby's vm_get_cbase.
ffff32f to
06e13b6
Compare
headius
added a commit
to headius/spec
that referenced
this pull request
Jul 12, 2021
This behavior is peculiar but can be traced back at least as far as 1.9.3 (with 1.8.7 exhibiting different behavior). The target for a bare 'autoload' call in a method in a Class.new block should be the new class. This differs from constant lookup, which will skip the new class and use whatever "concrete" class scope is above it. This behavior was reported broken in JRuby many years ago and never completely fixed. The spec provided here happened to work until a recent fix for autoload scoping broke it (see jruby/jruby#6749). There are various problems with this behavior, the most obvious being that the autoload (used to define a lazy constant) does not go to the same place that constant lookup happens, and so this code likely does not do what anyone would want it to do. Nevertheless, this is current behavior of Ruby.
This spec defines current behavior of CRuby, but that behavior is rather questionable due to unexpectedly different targeting of autoload versus constant definition. We believe this regression spec was never truly fixed in JRuby and merely happened to pass, due to a naive fix that was still incorrect behavior but close enough to make the given test pass. In order to move forward with the fixes for jruby#6708 we are moving this spec into rubyspec via ruby/spec#839, so we can discuss whether this is really correct behavior or not.
eregon
pushed a commit
to ruby/spec
that referenced
this pull request
Jul 29, 2021
This behavior is peculiar but can be traced back at least as far as 1.9.3 (with 1.8.7 exhibiting different behavior). The target for a bare 'autoload' call in a method in a Class.new block should be the new class. This differs from constant lookup, which will skip the new class and use whatever "concrete" class scope is above it. This behavior was reported broken in JRuby many years ago and never completely fixed. The spec provided here happened to work until a recent fix for autoload scoping broke it (see jruby/jruby#6749). There are various problems with this behavior, the most obvious being that the autoload (used to define a lazy constant) does not go to the same place that constant lookup happens, and so this code likely does not do what anyone would want it to do. Nevertheless, this is current behavior of Ruby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This logic needs to walk up to the nearest non-singleton, non-
include wrapper to find the "real" module, since constants do not
live on those other "non-real" module types.
Fixes #6708