Skip to content

Commit 7c6aea1

Browse files
committed
Make CallerFrameAccess#execute() return a MaterializedFrame
* All usages of CallerFrameAccess materialize anyway.
1 parent ea4ac38 commit 7c6aea1

File tree

7 files changed

+17
-56
lines changed

7 files changed

+17
-56
lines changed

src/main/java/org/truffleruby/builtins/CallerFrameAccess.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public abstract static class InstanceEvalNode extends CoreMethodArrayArgumentsNo
266266
public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject string, DynamicObject fileName, int line, NotProvided block,
267267
@Cached("create()") ReadCallerFrameNode callerFrameNode,
268268
@Cached("create()") IndirectCallNode callNode) {
269-
final MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
269+
final MaterializedFrame callerFrame = callerFrameNode.execute(frame);
270270

271271
return instanceEvalHelper(callerFrame, receiver, string, fileName, line, callNode);
272272
}
@@ -275,7 +275,7 @@ public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject st
275275
public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject string, DynamicObject fileName, NotProvided line, NotProvided block,
276276
@Cached("create()") ReadCallerFrameNode callerFrameNode,
277277
@Cached("create()") IndirectCallNode callNode) {
278-
final MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
278+
final MaterializedFrame callerFrame = callerFrameNode.execute(frame);
279279

280280
return instanceEvalHelper(callerFrame, receiver, string, fileName, 1, callNode);
281281
}
@@ -284,7 +284,7 @@ public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject st
284284
public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject string, NotProvided fileName, NotProvided line, NotProvided block,
285285
@Cached("create()") ReadCallerFrameNode callerFrameNode,
286286
@Cached("create()") IndirectCallNode callNode) {
287-
final MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
287+
final MaterializedFrame callerFrame = callerFrameNode.execute(frame);
288288

289289
return instanceEvalHelper(callerFrame, receiver, string, coreStrings().EVAL_FILENAME_STRING.createInstance(), 1, callNode);
290290
}

src/main/java/org/truffleruby/core/binding/BindingNodes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.jcodings.specific.UTF8Encoding;
1616
import org.truffleruby.Layouts;
1717
import org.truffleruby.RubyContext;
18-
import org.truffleruby.builtins.CallerFrameAccess;
1918
import org.truffleruby.builtins.CoreClass;
2019
import org.truffleruby.builtins.CoreMethod;
2120
import org.truffleruby.builtins.CoreMethodNode;
@@ -388,11 +387,11 @@ public DynamicObject allocate(DynamicObject rubyClass) {
388387
@Primitive(name = "caller_binding", needsSelf = false)
389388
public abstract static class CallerBindingNode extends PrimitiveArrayArgumentsNode {
390389

391-
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode(CallerFrameAccess.MATERIALIZE);
390+
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode();
392391

393392
@Specialization
394393
public DynamicObject binding(VirtualFrame frame) {
395-
final MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
394+
final MaterializedFrame callerFrame = callerFrameNode.execute(frame);
396395

397396
return BindingNodes.createBinding(getContext(), callerFrame);
398397
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.jcodings.specific.UTF8Encoding;
4040
import org.truffleruby.Layouts;
4141
import org.truffleruby.RubyContext;
42-
import org.truffleruby.builtins.CallerFrameAccess;
4342
import org.truffleruby.builtins.CoreClass;
4443
import org.truffleruby.builtins.CoreMethod;
4544
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -262,11 +261,11 @@ public Object compare(VirtualFrame frame, Object self, Object other) {
262261
@CoreMethod(names = "binding", isModuleFunction = true)
263262
public abstract static class BindingNode extends CoreMethodArrayArgumentsNode {
264263

265-
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode(CallerFrameAccess.MATERIALIZE);
264+
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode();
266265

267266
@Specialization
268267
protected DynamicObject bindingUncached(VirtualFrame frame) {
269-
final MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
268+
final MaterializedFrame callerFrame = callerFrameNode.execute(frame);
270269
final SourceSection sourceSection = getCallerSourceSection();
271270

272271
return BindingNodes.createBinding(getContext(), callerFrame, sourceSection);
@@ -283,13 +282,13 @@ protected SourceSection getCallerSourceSection() {
283282
@CoreMethod(names = "block_given?", isModuleFunction = true)
284283
public abstract static class BlockGivenNode extends CoreMethodArrayArgumentsNode {
285284

286-
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode(CallerFrameAccess.MATERIALIZE);
285+
@Child ReadCallerFrameNode callerFrameNode = new ReadCallerFrameNode();
287286

288287
@Specialization
289288
public boolean blockGiven(VirtualFrame frame,
290289
@Cached("create(nil())") FindAndReadDeclarationVariableNode readNode,
291290
@Cached("createBinaryProfile()") ConditionProfile blockProfile) {
292-
MaterializedFrame callerFrame = callerFrameNode.execute(frame).materialize();
291+
MaterializedFrame callerFrame = callerFrameNode.execute(frame);
293292
return blockProfile.profile(readNode.execute(callerFrame, TranslatorEnvironment.METHOD_BLOCK_NAME) != nil());
294293
}
295294
}

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public Object sliceCapture(
631631
@Cached("create()") ReadCallerFrameNode readCallerNode) {
632632
final Object matchStrPair = callNode.call(string, "subpattern", regexp, capture);
633633

634-
final DynamicObject binding = BindingNodes.createBinding(getContext(), readCallerNode.execute(frame).materialize());
634+
final DynamicObject binding = BindingNodes.createBinding(getContext(), readCallerNode.execute(frame));
635635
if (matchStrPair == nil()) {
636636
setLastMatchNode.call(coreLibrary().getTruffleRegexpOperationsModule(), "set_last_match", nil(), binding);
637637
return nil();

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
*/
1010
package org.truffleruby.language.arguments;
1111

12-
import org.truffleruby.builtins.CallerFrameAccess;
12+
import com.oracle.truffle.api.frame.FrameInstance;
1313
import org.truffleruby.language.RubyBaseNode;
1414
import org.truffleruby.language.dispatch.CachedDispatchNode;
1515

1616
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
17-
import com.oracle.truffle.api.frame.Frame;
1817
import com.oracle.truffle.api.frame.MaterializedFrame;
1918
import com.oracle.truffle.api.frame.VirtualFrame;
2019
import com.oracle.truffle.api.nodes.DirectCallNode;
@@ -25,17 +24,11 @@ public class ReadCallerFrameNode extends RubyBaseNode {
2524

2625
private final ConditionProfile callerFrameProfile = ConditionProfile.createBinaryProfile();
2726

28-
private final CallerFrameAccess accessMode;
29-
3027
public static ReadCallerFrameNode create() {
31-
return new ReadCallerFrameNode(CallerFrameAccess.MATERIALIZE);
32-
}
33-
34-
public ReadCallerFrameNode(CallerFrameAccess callerFrameAccess) {
35-
this.accessMode = callerFrameAccess;
28+
return new ReadCallerFrameNode();
3629
}
3730

38-
public Frame execute(VirtualFrame frame) {
31+
public MaterializedFrame execute(VirtualFrame frame) {
3932
final MaterializedFrame callerFrame = RubyArguments.getCallerFrame(frame);
4033

4134
if (callerFrameProfile.profile(callerFrame != null)) {
@@ -56,9 +49,9 @@ private void replaceDispatchNode() {
5649
}
5750

5851
@TruffleBoundary
59-
private Frame getCallerFrame() {
52+
private MaterializedFrame getCallerFrame() {
6053
replaceDispatchNode();
61-
return getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(accessMode.getFrameAccess());
54+
return getContext().getCallStack().getCallerFrameIgnoringSend().getFrame(FrameInstance.FrameAccess.MATERIALIZE).materialize();
6255
}
6356

6457
}

src/main/java/org/truffleruby/language/dispatch/CachedDispatchNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.truffleruby.language.dispatch;
1111

1212
import org.truffleruby.RubyContext;
13-
import org.truffleruby.builtins.CallerFrameAccess;
1413
import org.truffleruby.core.rope.RopeNodes;
1514
import org.truffleruby.core.string.StringOperations;
1615
import org.truffleruby.language.RubyGuards;
@@ -98,7 +97,7 @@ private synchronized void startSendingFrame(SendsFrame frameToSend) {
9897
assert needsCallerAssumption != AlwaysValidAssumption.INSTANCE;
9998
this.sendsFrame = frameToSend;
10099
if (frameToSend == SendsFrame.CALLER_FRAME) {
101-
this.readCaller = insert(new ReadCallerFrameNode(CallerFrameAccess.MATERIALIZE));
100+
this.readCaller = insert(new ReadCallerFrameNode());
102101
}
103102
Node root = getRootNode();
104103
if (root instanceof RubyRootNode) {
@@ -195,7 +194,7 @@ private MaterializedFrame getFrameIfRequired(VirtualFrame frame) {
195194
case MY_FRAME:
196195
return frame.materialize();
197196
case CALLER_FRAME:
198-
return readCaller.execute(frame).materialize();
197+
return readCaller.execute(frame);
199198
default:
200199
return null;
201200
}

0 commit comments

Comments
 (0)