Skip to content

Commit ba9583f

Browse files
authored
Merge pull request #5358 from headius/toplevel_visibility_in_jit
Fix toplevel method visibility in jit/fullint script scopes.
2 parents 15ae912 + fbecf3e commit ba9583f

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

core/src/main/java/org/jruby/ir/instructions/PushMethodFrameInstr.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,34 @@
66
import org.jruby.ir.persistence.IRReaderDecoder;
77
import org.jruby.ir.transformations.inlining.CloneInfo;
88
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
9+
import org.jruby.runtime.Visibility;
910

1011
public class PushMethodFrameInstr extends NoOperandInstr implements FixedArityInstr {
1112
private final RubySymbol frameName;
13+
private final Visibility visibility;
1214

13-
public PushMethodFrameInstr(RubySymbol frameName) {
15+
public PushMethodFrameInstr(RubySymbol frameName, Visibility visibility) {
1416
super(Operation.PUSH_METHOD_FRAME);
1517

1618
this.frameName = frameName;
19+
this.visibility = visibility;
1720
}
1821

1922
public RubySymbol getFrameName() {
2023
return frameName;
2124
}
2225

26+
public Visibility getVisibility() {
27+
return visibility;
28+
}
29+
2330
@Override
2431
public Instr clone(CloneInfo ii) {
2532
return ii instanceof SimpleCloneInfo ? this : NopInstr.NOP; // FIXME: Is this correct?
2633
}
2734

2835
public static PushMethodFrameInstr decode(IRReaderDecoder d) {
29-
return new PushMethodFrameInstr(d.decodeSymbol());
36+
return new PushMethodFrameInstr(d.decodeSymbol(), Visibility.values()[d.decodeByte()]);
3037
}
3138

3239
@Override

core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.jruby.ir.instructions.NonlocalReturnInstr;
1717
import org.jruby.ir.instructions.PopBlockFrameInstr;
1818
import org.jruby.ir.instructions.PushBlockFrameInstr;
19+
import org.jruby.ir.instructions.PushMethodFrameInstr;
1920
import org.jruby.ir.instructions.ReceiveArgBase;
2021
import org.jruby.ir.instructions.ReceivePostReqdArgInstr;
2122
import org.jruby.ir.instructions.ReceivePreReqdArgInstr;
@@ -383,10 +384,7 @@ protected static void processBookKeepingOp(ThreadContext context, Block block, I
383384
break;
384385
case PUSH_METHOD_FRAME:
385386
context.preMethodFrameOnly(implClass, name, self, blockArg);
386-
// Only the top-level script scope has PRIVATE visibility.
387-
// This is already handled as part of Interpreter.execute above.
388-
// Everything else is PUBLIC by default.
389-
context.setCurrentVisibility(Visibility.PUBLIC);
387+
context.setCurrentVisibility(((PushMethodFrameInstr) instr).getVisibility());
390388
break;
391389
case PUSH_BACKREF_FRAME:
392390
context.preBackrefMethod();

core/src/main/java/org/jruby/ir/passes/AddCallProtocolInstructions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jruby.ir.operands.Variable;
1212
import org.jruby.ir.representations.BasicBlock;
1313
import org.jruby.ir.representations.CFG;
14+
import org.jruby.runtime.Visibility;
1415

1516
import java.util.ListIterator;
1617

@@ -135,7 +136,9 @@ public Object execute(IRScope scope, Object... data) {
135136
if (scope.needsOnlyBackref()) {
136137
entryBB.addInstr(new PushBackrefFrameInstr());
137138
} else {
138-
entryBB.addInstr(new PushMethodFrameInstr(scope.getName()));
139+
entryBB.addInstr(new PushMethodFrameInstr(
140+
scope.getName(),
141+
scope.isScriptScope() ? Visibility.PRIVATE : Visibility.PUBLIC));
139142
}
140143
}
141144
if (requireBinding) entryBB.addInstr(new PushMethodBindingInstr());

core/src/main/java/org/jruby/ir/targets/JVMVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ public void PushMethodFrameInstr(PushMethodFrameInstr pushframeinstr) {
17701770
// FIXME: this should be part of explicit call protocol only when needed, optimizable, and correct for the scope
17711771
// See also CompiledIRMethod.call
17721772
jvmMethod().loadContext();
1773-
jvmAdapter().getstatic(p(Visibility.class), "PUBLIC", ci(Visibility.class));
1773+
jvmAdapter().getstatic(p(Visibility.class), pushframeinstr.getVisibility().name(), ci(Visibility.class));
17741774
jvmAdapter().invokevirtual(p(ThreadContext.class), "setCurrentVisibility", sig(void.class, Visibility.class));
17751775
}
17761776

0 commit comments

Comments
 (0)