Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rely on the scope's refinement flag instead of per-clone OR-ing
The initial implementation OR-ed `ii.isRefinementsClone()` into the
`potentiallyRefined` argument of ~14 call-bearing instruction clone()
methods so that a Proc#with_refinements clone would rebuild each call as
a refined call site.  That pattern was scattered and fragile: any
call-bearing instruction whose clone() forgot the OR (e.g. MatchInstr,
ArrayDerefInstr) would silently lose refinements, with no compile-time
error.

It was also redundant.  CallBase's constructor already derives refinement
from the call's scope:

    boolean effectivelyRefined =
        potentiallyRefined || (scope != null && scope.maybeUsingRefinements());

cloneForInlining sets setIsMaybeUsingRefinements() on the clone's scope
before its instructions are cloned, and every cloned call instruction is
built with that scope, so the scope check alone already marks them
refined -- which is exactly how MatchInstr/ArrayDerefInstr (which never
had the OR) already worked.

So drop the per-clone OR and let the single CallBase choke point handle
all instruction types uniformly, including any that were missed or are
added later.  The Fixnum/Float fast-path clones keep their explicit
downgrade to a generic refined call: that changes instruction selection
(the primitive path bypasses the call site), not just the call-site
flavor, so it cannot be centralized into CallBase.

Verified: a probe covering plain/operator/===/[]=/block/varargs/nested/
super refined calls is unchanged before and after; feature suite (17)
and MRI test_proc/test_refinement/test_method (284) pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
  • Loading branch information
shugo and claude committed Jun 10, 2026
commit 14f02881e073c7d803c1c18ee296f4573e821646
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AttrAssignInstr(IRScope scope, Operand obj, RubySymbol attr, Operand[] ar
@Override
public Instr clone(CloneInfo ii) {
return new AttrAssignInstr(ii.getScope(), getCallType(), getName(), getReceiver().cloneForInlining(ii),
cloneCallArgs(ii), getFlags(), isPotentiallyRefined() || ii.isRefinementsClone());
cloneCallArgs(ii), getFlags(), isPotentiallyRefined());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Instr clone(CloneInfo ii) {
return new CallInstr(ii.getScope(), getOperation(), getCallType(), ii.getRenamedVariable(result), getName(),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
getClosureArg().cloneForInlining(ii),
getFlags(), isPotentiallyRefined() || ii.isRefinementsClone()
getFlags(), isPotentiallyRefined()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean computeScopeFlags(IRScope scope, EnumSet<IRFlags> flags) {
public Instr clone(CloneInfo ii) {
return new ClassSuperInstr(ii.getScope(), ii.getRenamedVariable(getResult()), getDefiningModule().cloneForInlining(ii),
name, cloneCallArgs(ii), getClosureArg().cloneForInlining(ii),
getFlags(), isPotentiallyRefined() || ii.isRefinementsClone());
getFlags(), isPotentiallyRefined());
}

public static ClassSuperInstr decode(IRReaderDecoder d) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/instructions/EQQInstr.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean isPattern() {
@Override
public Instr clone(CloneInfo ii) {
return new EQQInstr(ii.getScope(), ii.getRenamedVariable(result), getReceiver().cloneForInlining(ii),
getArg1().cloneForInlining(ii), isSplattedValue(), isPattern(), isPotentiallyRefined() || ii.isRefinementsClone());
getArg1().cloneForInlining(ii), isSplattedValue(), isPattern(), isPotentiallyRefined());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Instr clone(CloneInfo ii) {
return new InstanceSuperInstr(ii.getScope(), ii.getRenamedVariable(getResult()),
getDefiningModule().cloneForInlining(ii), getName(), cloneCallArgs(ii),
getClosureArg().cloneForInlining(ii), getFlags(),
isPotentiallyRefined() || ii.isRefinementsClone());
isPotentiallyRefined());
}

public static InstanceSuperInstr decode(IRReaderDecoder d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Instr clone(CloneInfo ii) {
return new NoResultCallInstr(ii.getScope(), getOperation(), getCallType(), getName(),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
getClosureArg().cloneForInlining(ii), getFlags(),
isPotentiallyRefined() || ii.isRefinementsClone());
isPotentiallyRefined());
}

public static NoResultCallInstr decode(IRReaderDecoder d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Instr clone(CloneInfo ii) {
return new UnresolvedSuperInstr(ii.getScope(), Operation.UNRESOLVED_SUPER, ii.getRenamedVariable(getResult()),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
getClosureArg().cloneForInlining(ii), getFlags(),
isPotentiallyRefined() || ii.isRefinementsClone());
isPotentiallyRefined());
}

public static UnresolvedSuperInstr decode(IRReaderDecoder d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean computeScopeFlags(IRScope scope, EnumSet<IRFlags> flags) {
public Instr clone(CloneInfo ii) {
return new ZSuperInstr(ii.getScope(), ii.getRenamedVariable(getResult()), getReceiver().cloneForInlining(ii),
cloneCallArgs(ii), getClosureArg().cloneForInlining(ii), getFlags(),
isPotentiallyRefined() || ii.isRefinementsClone());
isPotentiallyRefined());
}

public static ZSuperInstr decode(IRReaderDecoder d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public OneArgOperandAttrAssignInstr(IRScope scope, Operand obj, RubySymbol attr,
@Override
public Instr clone(CloneInfo ii) {
return new OneArgOperandAttrAssignInstr(ii.getScope(), getCallType(), getName(), getReceiver().cloneForInlining(ii),
cloneCallArgs(ii), getFlags(), isPotentiallyRefined() || ii.isRefinementsClone());
cloneCallArgs(ii), getFlags(), isPotentiallyRefined());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public OneOperandArgBlockCallInstr(IRScope scope, CallType callType, Variable re
public Instr clone(CloneInfo ii) {
return new OneOperandArgBlockCallInstr(ii.getScope(), getCallType(), ii.getRenamedVariable(result), getName(),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
getClosureArg().cloneForInlining(ii), getFlags(), isPotentiallyRefined() || ii.isRefinementsClone()
getClosureArg().cloneForInlining(ii), getFlags(), isPotentiallyRefined()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public OneOperandArgNoBlockCallInstr(IRScope scope, Operation op, CallType callT
public Instr clone(CloneInfo ii) {
return new OneOperandArgNoBlockCallInstr(ii.getScope(), Operation.CALL_1O, getCallType(),
ii.getRenamedVariable(result), getName(), getReceiver().cloneForInlining(ii), cloneCallArgs(ii),
getFlags(), isPotentiallyRefined() || ii.isRefinementsClone());
getFlags(), isPotentiallyRefined());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public OneOperandArgNoBlockNoResultCallInstr(IRScope scope, CallType callType, R
public Instr clone(CloneInfo ii) {
return new OneOperandArgNoBlockNoResultCallInstr(ii.getScope(), getCallType(), getName(), getReceiver().cloneForInlining(ii),
cloneCallArgs(ii), getClosureArg().cloneForInlining(ii), getFlags(),
isPotentiallyRefined() || ii.isRefinementsClone());
isPotentiallyRefined());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TwoOperandArgNoBlockCallInstr(IRScope scope, CallType callType, Variable
@Override
public Instr clone(CloneInfo ii) {
return new TwoOperandArgNoBlockCallInstr(ii.getScope(), getCallType(), ii.getRenamedVariable(result), getName(),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii), getFlags(), isPotentiallyRefined() || ii.isRefinementsClone()
getReceiver().cloneForInlining(ii), cloneCallArgs(ii), getFlags(), isPotentiallyRefined()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ZeroOperandArgNoBlockCallInstr(IRScope scope, CallType callType, Variable
@Override
public Instr clone(CloneInfo ii) {
return new ZeroOperandArgNoBlockCallInstr(ii.getScope(), getOperation(), getCallType(), ii.getRenamedVariable(result), getName(),
getReceiver().cloneForInlining(ii), cloneCallArgs(ii), getFlags(), isPotentiallyRefined() || ii.isRefinementsClone());
getReceiver().cloneForInlining(ii), cloneCallArgs(ii), getFlags(), isPotentiallyRefined());
}

@Override
Expand Down
Loading