Skip to content

Commit 0c01508

Browse files
committed
We no longer need to filter out #__send__, #send and #public_send from the call stack
* Since they are always inlined and do not add an extra stack entry.
1 parent 8d8463c commit 0c01508

File tree

11 files changed

+33
-67
lines changed

11 files changed

+33
-67
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public abstract static class CallerFrameVisibilityNode extends CoreMethodArrayAr
742742
@TruffleBoundary
743743
@Specialization
744744
protected boolean checkCallerVisibility(RubySymbol visibility) {
745-
final Frame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
745+
final Frame callerFrame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
746746
final Visibility callerVisibility = DeclarationContext.findVisibility(callerFrame);
747747

748748
switch (visibility.getString()) {

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ public class CoreLibrary {
232232
private final Map<String, RubyClass> errnoClasses = new HashMap<>();
233233
private final Map<Integer, String> errnoValueToNames = new HashMap<>();
234234

235-
@CompilationFinal private SharedMethodInfo basicObjectSendInfo;
236-
@CompilationFinal private SharedMethodInfo kernelPublicSendInfo;
237235
@CompilationFinal private SharedMethodInfo truffleBootMainInfo;
238236

239237
@CompilationFinal private GlobalVariableReader loadPathReader;
@@ -613,8 +611,6 @@ public void loadCoreNodes() {
613611
final CoreMethodNodeManager coreMethodNodeManager = new CoreMethodNodeManager(context);
614612
coreMethodNodeManager.loadCoreMethodNodes();
615613

616-
basicObjectSendInfo = getMethod(basicObjectClass, "__send__").getSharedMethodInfo();
617-
kernelPublicSendInfo = getMethod(kernelModule, "public_send").getSharedMethodInfo();
618614
truffleBootMainInfo = getMethod(node.executeSingletonClass(truffleBootModule), "main").getSharedMethodInfo();
619615
}
620616

@@ -952,14 +948,6 @@ public boolean isLoaded() {
952948
return state == State.LOADED;
953949
}
954950

955-
public boolean isSend(InternalMethod method) {
956-
return isSend(method.getSharedMethodInfo());
957-
}
958-
959-
public boolean isSend(SharedMethodInfo sharedMethodInfo) {
960-
return sharedMethodInfo == basicObjectSendInfo || sharedMethodInfo == kernelPublicSendInfo;
961-
}
962-
963951
public boolean isTruffleBootMainMethod(SharedMethodInfo info) {
964952
return info == truffleBootMainInfo;
965953
}

src/main/java/org/truffleruby/core/MainNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected Object mainUsing(RubyModule refinementModule,
7474

7575
@TruffleBoundary
7676
private boolean isCalledFromTopLevel() {
77-
final Frame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
77+
final Frame callerFrame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
7878
final String name = RubyArguments.getMethod(callerFrame).getSharedMethodInfo().getBacktraceName();
7979
return name.equals("<main>") || name.startsWith("<top ");
8080
}

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ protected RubyString getCallerPath(Object feature,
302302
} else {
303303
final SourceSection sourceSection = getContext()
304304
.getCallStack()
305-
.getCallerNodeIgnoringSend()
305+
.getCallerNode()
306306
.getEncapsulatingSourceSection();
307307
if (!BacktraceFormatter.isAvailable(sourceSection)) {
308308
throw new RaiseException(
@@ -376,7 +376,7 @@ protected RubyBinding binding(VirtualFrame frame) {
376376

377377
@TruffleBoundary
378378
protected SourceSection getCallerSourceSection() {
379-
return getContext().getCallStack().getCallerNodeIgnoringSend().getEncapsulatingSourceSection();
379+
return getContext().getCallStack().getCallerNode().getEncapsulatingSourceSection();
380380
}
381381

382382
}
@@ -402,7 +402,7 @@ public abstract static class CalleeNameNode extends CoreMethodArrayArgumentsNode
402402
@Specialization
403403
protected RubySymbol calleeName() {
404404
// the "called name" of a method.
405-
return getSymbol(getContext().getCallStack().getCallingMethodIgnoringSend().getName());
405+
return getSymbol(getContext().getCallStack().getCallingMethod().getName());
406406
}
407407
}
408408

@@ -1278,7 +1278,7 @@ protected RubyProc lambdaFromExistingProc(RubyProc block) {
12781278

12791279
@TruffleBoundary
12801280
protected boolean isLiteralBlock(RubyProc block) {
1281-
Node callNode = getContext().getCallStack().getCallerNodeIgnoringSend();
1281+
Node callNode = getContext().getCallStack().getCallerNode();
12821282
RubyCallNode rubyCallNode = NodeUtil.findParent(callNode, RubyCallNode.class);
12831283
return rubyCallNode != null && rubyCallNode.hasLiteralBlock();
12841284
}
@@ -1290,7 +1290,7 @@ public abstract static class MethodNameNode extends CoreMethodArrayArgumentsNode
12901290
@Specialization
12911291
protected RubySymbol methodName() {
12921292
// the "original/definition name" of the method.
1293-
InternalMethod internalMethod = getContext().getCallStack().getCallingMethodIgnoringSend();
1293+
InternalMethod internalMethod = getContext().getCallStack().getCallingMethod();
12941294
return getSymbol(internalMethod.getSharedMethodInfo().getMethodNameForNotBlock());
12951295
}
12961296

src/main/java/org/truffleruby/core/kernel/TruffleKernelNodes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ protected Object storage() {
348348
if (rootNode instanceof RubyRootNode &&
349349
rootNode.getSourceSection().isAvailable() &&
350350
!rootNode.getSourceSection().getSource().getName().endsWith("cext.rb") &&
351-
!rootNode.getSourceSection().getSource().getName().endsWith("cext_ruby.rb") &&
352-
!getContext().getCoreLibrary().isSend(
353-
RubyArguments.tryGetMethod(frameInstance.getFrame(FrameAccess.READ_ONLY)))) {
351+
!rootNode.getSourceSection().getSource().getName().endsWith("cext_ruby.rb")) {
354352
return frameInstance.getFrame(FrameAccess.MATERIALIZE).materialize();
355353
}
356354
}

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ private void createAccessor(RubyModule module, String name, MaterializedFrame ca
405405
RubyLanguage language) {
406406
final SourceSection sourceSection = getContext()
407407
.getCallStack()
408-
.getCallerNodeIgnoringSend()
408+
.getCallerNode()
409409
.getEncapsulatingSourceSection();
410410
final Visibility visibility = DeclarationContext.findVisibility(callerFrame);
411411
final Arity arity = isGetter ? Arity.NO_ARGUMENTS : Arity.ONE_REQUIRED;
@@ -1559,7 +1559,7 @@ public abstract static class NestingNode extends CoreMethodArrayArgumentsNode {
15591559
protected RubyArray nesting() {
15601560
final List<RubyModule> modules = new ArrayList<>();
15611561

1562-
InternalMethod method = getContext().getCallStack().getCallingMethodIgnoringSend();
1562+
InternalMethod method = getContext().getCallStack().getCallingMethod();
15631563
LexicalScope lexicalScope = method == null ? null : method.getSharedMethodInfo().getLexicalScope();
15641564
RubyClass objectClass = coreLibrary().objectClass;
15651565

@@ -2049,7 +2049,7 @@ public abstract static class UsedModulesNode extends CoreMethodArrayArgumentsNod
20492049
@TruffleBoundary
20502050
@Specialization
20512051
protected RubyArray usedModules() {
2052-
final Frame frame = getContext().getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
2052+
final Frame frame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
20532053
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
20542054
final Set<RubyModule> refinementNamespaces = new HashSet<>();
20552055
for (RubyModule[] refinementModules : declarationContext.getRefinements().values()) {
@@ -2069,7 +2069,7 @@ public abstract static class UsedRefinementsNode extends CoreMethodArrayArgument
20692069
@TruffleBoundary
20702070
@Specialization
20712071
protected RubyArray usedRefinements() {
2072-
final Frame frame = getContext().getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
2072+
final Frame frame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
20732073
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
20742074
final Set<RubyModule> refinements = new HashSet<>();
20752075
for (RubyModule[] refinementModules : declarationContext.getRefinements().values()) {
@@ -2230,7 +2230,7 @@ public abstract static class ModuleUsingNode extends CoreMethodArrayArgumentsNod
22302230
@TruffleBoundary
22312231
@Specialization
22322232
protected RubyModule moduleUsing(RubyModule self, RubyModule refinementModule) {
2233-
final Frame callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
2233+
final Frame callerFrame = getContext().getCallStack().getCallerFrame(FrameAccess.READ_ONLY);
22342234
if (self != RubyArguments.getSelf(callerFrame)) {
22352235
throw new RaiseException(
22362236
getContext(),

src/main/java/org/truffleruby/language/CallStackManager.java

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ public Frame getCurrentFrame(FrameAccess frameAccess) {
5151
}
5252

5353
@TruffleBoundary
54-
public Frame getCallerFrameIgnoringSend(FrameAccess frameAccess) {
54+
public Frame getCallerFrame(FrameAccess frameAccess) {
5555
// System.err.printf("Getting a caller frame...\n");
5656
// new Error().printStackTrace();
57-
return getCallerFrameIgnoringSend(f -> isRubyFrameAndNotSend(f.getFrame(FrameAccess.READ_ONLY)), frameAccess);
57+
return getCallerFrame(f -> isRubyFrame(f.getFrame(FrameAccess.READ_ONLY)), frameAccess);
5858
}
5959

6060
@TruffleBoundary
6161
public Frame getCallerFrameNotInModules(FrameAccess frameAccess, Object[] modules) {
6262
final Memo<Boolean> skippedFirstFrameFound = new Memo<>(false);
6363

64-
return getCallerFrameIgnoringSend(frameInstance -> {
65-
final InternalMethod method = getMethod(frameInstance.getFrame(FrameAccess.READ_ONLY));
64+
return getCallerFrame(frameInstance -> {
65+
final InternalMethod method = tryGetMethod(frameInstance.getFrame(FrameAccess.READ_ONLY));
6666
if (method != null && !ArrayUtils.contains(modules, method.getDeclaringModule())) {
6767
if (skippedFirstFrameFound.get()) {
6868
return true;
@@ -76,15 +76,15 @@ public Frame getCallerFrameNotInModules(FrameAccess frameAccess, Object[] module
7676
// Node
7777

7878
@TruffleBoundary
79-
public Node getCallerNodeIgnoringSend() {
79+
public Node getCallerNode() {
8080
return getCallerNode(1, true);
8181
}
8282

8383
@TruffleBoundary
84-
public Node getCallerNode(int skip, boolean ignoreSend) {
84+
public Node getCallerNode(int skip, boolean onlyRubyFrames) {
8585
return iterateFrames(skip, frameInstance -> {
86-
if (ignoreSend) {
87-
return isRubyFrameAndNotSend(frameInstance.getFrame(FrameAccess.READ_ONLY));
86+
if (onlyRubyFrames) {
87+
return isRubyFrame(frameInstance.getFrame(FrameAccess.READ_ONLY));
8888
} else {
8989
return true;
9090
}
@@ -94,19 +94,12 @@ public Node getCallerNode(int skip, boolean ignoreSend) {
9494
// Method
9595

9696
@TruffleBoundary
97-
public InternalMethod getCallingMethodIgnoringSend() {
98-
return getMethod(getCallerFrameIgnoringSend(FrameAccess.READ_ONLY));
97+
public InternalMethod getCallingMethod() {
98+
return tryGetMethod(getCallerFrame(FrameAccess.READ_ONLY));
9999
}
100100

101-
@TruffleBoundary
102101
public boolean callerIsSend() {
103-
final Boolean isSend = iterateFrames(
104-
1,
105-
f -> true,
106-
frameInstance -> context
107-
.getCoreLibrary()
108-
.isSend(getMethod(frameInstance.getFrame(FrameAccess.READ_ONLY))));
109-
return isSend != null && isSend;
102+
return false; // TODO (eregon, 2 Feb 2021): simplify callers
110103
}
111104

112105
// SourceSection
@@ -139,7 +132,7 @@ public SourceSection getTopMostUserSourceSection() {
139132

140133
// Internals
141134

142-
private Frame getCallerFrameIgnoringSend(Predicate<FrameInstance> filter, FrameAccess frameAccess) {
135+
private Frame getCallerFrame(Predicate<FrameInstance> filter, FrameAccess frameAccess) {
143136
return iterateFrames(1, filter, f -> f.getFrame(frameAccess));
144137
}
145138

@@ -191,12 +184,11 @@ public R visitFrame(FrameInstance frameInstance) {
191184
}
192185
}
193186

194-
private boolean isRubyFrameAndNotSend(Frame frame) {
195-
final InternalMethod method = getMethod(frame);
196-
return method != null && !context.getCoreLibrary().isSend(method);
187+
private boolean isRubyFrame(Frame frame) {
188+
return tryGetMethod(frame) != null;
197189
}
198190

199-
private static InternalMethod getMethod(Frame frame) {
191+
private static InternalMethod tryGetMethod(Frame frame) {
200192
return RubyArguments.tryGetMethod(frame);
201193
}
202194

@@ -232,11 +224,6 @@ public boolean ignoreFrame(Node callNode, RootCallTarget callTarget) {
232224
if (rootNode instanceof RubyRootNode) {
233225
final SharedMethodInfo sharedMethodInfo = ((RubyRootNode) rootNode).getSharedMethodInfo();
234226

235-
// Ignore BasicObject#__send__, Kernel#send and Kernel#public_send like MRI
236-
if (context.getCoreLibrary().isSend(sharedMethodInfo)) {
237-
return true;
238-
}
239-
240227
// Ignore Truffle::Boot.main and its caller
241228
if (context.getCoreLibrary().isTruffleBootMainMethod(sharedMethodInfo)) {
242229
return true;

src/main/java/org/truffleruby/language/arguments/ReadCallerDataNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private Object getCallerData() {
4949
}
5050
MaterializedFrame callerFrame = getContext()
5151
.getCallStack()
52-
.getCallerFrameIgnoringSend(FrameAccess.MATERIALIZE)
52+
.getCallerFrame(FrameAccess.MATERIALIZE)
5353
.materialize();
5454
return getDataFromFrame(callerFrame);
5555
}

src/main/java/org/truffleruby/language/methods/DeclarationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static void changeVisibility(Frame frame, Visibility newVisibility) {
122122

123123
@TruffleBoundary
124124
public static void setCurrentVisibility(RubyContext context, Visibility visibility) {
125-
final Frame callerFrame = context.getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_WRITE);
125+
final Frame callerFrame = context.getCallStack().getCallerFrame(FrameAccess.READ_WRITE);
126126
changeVisibility(callerFrame, visibility);
127127
}
128128

src/main/java/org/truffleruby/language/methods/LookupMethodNode.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.oracle.truffle.api.dsl.ReportPolymorphism;
3131
import com.oracle.truffle.api.dsl.Specialization;
3232
import com.oracle.truffle.api.frame.Frame;
33-
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
3433
import com.oracle.truffle.api.profiles.ConditionProfile;
3534

3635
/** Caches {@link ModuleOperations#lookupMethodCached(RubyModule, String, DeclarationContext)} on an actual instance. */
@@ -135,11 +134,8 @@ protected InternalMethod lookupMethodUncached(
135134

136135
if (noCallerMethodProfile.profile(callerMethod == null)) {
137136
callerClass = context.getCoreLibrary().objectClass;
138-
} else if (!isSendProfile.profile(context.getCoreLibrary().isSend(callerMethod))) {
139-
callerClass = metaClassNode.execute(RubyArguments.getSelf(frame));
140137
} else {
141-
Frame callerFrame = context.getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
142-
callerClass = metaClassNode.execute(RubyArguments.getSelf(callerFrame));
138+
callerClass = metaClassNode.execute(RubyArguments.getSelf(frame));
143139
}
144140

145141
if (!isVisibleProfile.profile(method.isProtectedMethodVisibleTo(callerClass))) {
@@ -194,11 +190,8 @@ private static RubyClass getCallerClass(RubyContext context, Frame callingFrame)
194190
final InternalMethod callerMethod = RubyArguments.tryGetMethod(callingFrame);
195191
if (callerMethod == null) {
196192
return context.getCoreLibrary().objectClass;
197-
} else if (!context.getCoreLibrary().isSend(callerMethod)) {
198-
return MetaClassNode.getUncached().execute(RubyArguments.getSelf(callingFrame));
199193
} else {
200-
final Frame callerFrame = context.getCallStack().getCallerFrameIgnoringSend(FrameAccess.READ_ONLY);
201-
return MetaClassNode.getUncached().execute(RubyArguments.getSelf(callerFrame));
194+
return MetaClassNode.getUncached().execute(RubyArguments.getSelf(callingFrame));
202195
}
203196
}
204197

0 commit comments

Comments
 (0)