Repository navigation
Share refinements with methods defined in a refine block - #10217
Open
evaniainbrooks wants to merge 1 commit into
Open
evaniainbrooks wants to merge 1 commit into
evaniainbrooks wants to merge 1 commit into
Conversation
A method or block copied its parent's refinements when it was defined. A method defined in a refine block then missed refinements added later in the same module, so a refined existing method such as String#upcase fell back to the original. CRuby shares the refinements with the new cref and copies them only when a later using changes them (vm_cref_new0 and rb_using_refinement). Do the same, using the existing SHARED_MODULE flag, which was checked but never set. Fixes jruby#10207
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.
Fixes #10207.
A method defined in a
refineblock got a copy of the refinements that existed when it was defined. Refinements added later in the same module were missing, so refining an existing method (likeString#upcase) fell back to the original method. Smaller repro:In the issue, the JIT hid the bug: the compiled refined
instance_evaldoes not push a scope, so the eval used the scope ofevaluate, which has all refinements.CRuby shares the refinements with the new cref and marks both as shared (vm.c, vm_cref_new0). A later
usingcopies them first (eval.c, rb_using_refinement). JRuby already checkedSHARED_MODULEinusingRefinementbut never set it. NowcaptureParentRefinementsshares the map and sets the flag, and the copy happens ingetRefinementsForWrite(), soimport_methodscopies too.Testing:
spec/ruby/core/module/refine_spec.rb. It fails without the fix and passes with it in interpreter, JIT and-X-Cmode, and on CRuby 4.0.1 and 3.4.8.spec/ruby/core/{module,basicobject,kernel,refinement,main},spec/ruby/languageandspec/compilerpass in interpreter and JIT mode.test/mri/ruby/test_refinement.rb: onlytest_import_methodsfails, and it fails without this change too.