Repository navigation
Conversation
The IR copy propagation pass could replace one use of a local variable with the literal it was assigned. The JIT compiles each literal operand to its own site, so for Regexp, Range, Bignum, Complex and Rational literals the two uses of the local became different objects: `r = /a/; [r, r]` gave two Regexps, and MatchData#regexp did not return the Regexp used to match. These operands are no longer propagated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@headius I found this while looking at the The fix stops copy propagation for Regexp, Range, Bignum, Complex and Rational literals, so those literals are no longer substituted into later uses of the local. I don't think that loses much, but you know better whether any JIT optimization depends on it. The other option I see is to have the JIT share one site per literal operand, which would be a bigger change. |
zev
marked this pull request as ready for review
December 6, 2026 05:08
Integer#equal? compares values only inside CRuby's fixnum range, as in CRuby. Outside it, a copy-propagated Fixnum literal became a different object at each JIT site, so `i = 4_611_686_018_427_387_905; i.dup` was not equal? to i. Such literals are no longer propagated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
In compiled code, a literal assigned to a local variable could turn into two different objects:
The IR copy propagation pass replaces a use of a local with its value when
canCopyPropagate()is true.ImmutableLiteralreturns true, so one use ofrbecame theRegexpoperand itself, while the other kept readingr. The interpreter caches the object in the operand, so both uses still get the same object. The JIT compiles each literal operand to its own site, and each site makes its own object.This affects the literal operands that make a new object: Regexp, Range, Bignum, Complex and Rational. They now return false from
canCopyPropagate().It also affects Fixnum literals outside CRuby's fixnum range (±2**62). There
Integer#equal?compares identity, as for a Bignum in CRuby, soi = 4_611_686_018_427_387_905; i.dup.equal?(i)was false. The Fixnum operand now returns false fromcanCopyPropagate()for those values, usingRubyFixnum.fixnumable(now public), the same checkequal?uses. Smaller Fixnums, Float, Symbol, nil, booleans and frozen Strings are still propagated.This fixes
MatchData#regexp returns the same Regexp used to matchandInteger#dup returns self for large integersunder-X+C.Testing
spec/compiler/general_spec.rb: each of these literals (including4611686018427387905), assigned to a local at the top level and in a method, is the same object at both uses. It fails in the jit and aot modes without the change.spec/compiler: 510 examples, 0 failures.mspec cionlanguage,core/integer,core/matchdata,core/range,core/regexp: 0 failures interpreted, with-X+Cand with-Xjit.threshold=0. Oncore/complexandcore/rational: no new failures.test/mritest_regexp,test_range,test_rational,test_complex,test_bignum,test_integer,test_integer_comb,test_fixnum, interpreted and-X+C: 0 failures.-Xcompile.invokedynamic=trueandfalse.🤖 Generated with Claude Code