Skip to content

Commit a490186

Browse files
committed
Better assertion message in MaterializeFrameNode, use BytecodeDescriptor, replace beginTryCatchOtherwise(()->{}) with just beingTryCatch
1 parent 20b02c0 commit a490186

File tree

6 files changed

+14
-26
lines changed

6 files changed

+14
-26
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.runtime.object.PFactory;
4545
import com.oracle.truffle.api.CompilerDirectives;
4646
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
47-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4847
import com.oracle.truffle.api.RootCallTarget;
4948
import com.oracle.truffle.api.TruffleStackTraceElement;
5049
import com.oracle.truffle.api.bytecode.BytecodeLocation;
@@ -238,10 +237,6 @@ public static Frame unwrapDSLGeneratorFrame(TruffleStackTraceElement element) {
238237
return element.getFrame();
239238
}
240239

241-
public static Frame getDSLGeneratorFrame(Object[] continuationCallArguments) {
242-
return (Frame) continuationCallArguments[0];
243-
}
244-
245240
public static RootNode unwrapContinuationRoot(RootNode rootNode) {
246241
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER &&
247242
rootNode instanceof ContinuationRootNode continuationRoot) {
@@ -251,20 +246,7 @@ public static RootNode unwrapContinuationRoot(RootNode rootNode) {
251246
}
252247

253248
public static PBytecodeDSLRootNode unwrapContinuationRoot(ContinuationRootNode continuationRoot) {
254-
if (CompilerDirectives.isPartialEvaluationConstant(continuationRoot)) {
255-
return (PBytecodeDSLRootNode) continuationRoot.getSourceRootNode();
256-
} else {
257-
/*
258-
* TODO We know that the continuation root node is always the same type, but we can't
259-
* cast to it because it's not public. So we end up with a virtual call.
260-
*/
261-
return unwrapContinuationRootBoundary(continuationRoot);
262-
}
263-
}
264-
265-
@TruffleBoundary
266-
private static PBytecodeDSLRootNode unwrapContinuationRootBoundary(ContinuationRootNode continuationRoot) {
267-
return (PBytecodeDSLRootNode) continuationRoot.getSourceRootNode();
249+
return PBytecodeDSLRootNode.cast(continuationRoot);
268250
}
269251

270252
public static boolean isGeneratorFrame(Frame frame) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5703,12 +5703,12 @@ private void emitTryExceptElse(StmtTy.TryStar node) {
57035703
b.emitLoadLocal(matchedExceptions);
57045704
b.endSetCurrentException();
57055705

5706-
b.beginTryCatchOtherwise(() -> { });
5706+
b.beginTryCatch();
57075707
b.beginThrow(); // "try"
57085708
b.emitLoadException(); // handler_i_ex (exception thrown in this handler)
57095709
b.endThrow();
57105710

5711-
b.beginBlock(); // catch and insert into exception groups group
5711+
b.beginBlock(); // catch and insert into exception group
57125712
b.beginStoreLocal(exceptionAcc);
57135713
b.beginHandleExceptionsInHandler();
57145714
b.emitLoadException();
@@ -5718,7 +5718,7 @@ private void emitTryExceptElse(StmtTy.TryStar node) {
57185718
b.endHandleExceptionsInHandler();
57195719
b.endStoreLocal();
57205720
b.endBlock();
5721-
b.endTryCatchOtherwise();
5721+
b.endTryCatch();
57225722

57235723
b.beginSetCurrentException();
57245724
b.emitLoadLocal(exceptionOrig);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
import com.oracle.truffle.api.nodes.DirectCallNode;
289289
import com.oracle.truffle.api.nodes.ExplodeLoop;
290290
import com.oracle.truffle.api.nodes.Node;
291+
import com.oracle.truffle.api.nodes.RootNode;
291292
import com.oracle.truffle.api.nodes.UnexpectedResultException;
292293
import com.oracle.truffle.api.object.DynamicObject;
293294
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@@ -396,6 +397,10 @@ protected PBytecodeDSLRootNode(PythonLanguage language, FrameDescriptor.Builder
396397
((BytecodeDSLFrameInfo) getFrameDescriptor().getInfo()).setRootNode(this);
397398
}
398399

400+
public static PBytecodeDSLRootNode cast(RootNode root) {
401+
return PBytecodeDSLRootNodeGen.BYTECODE.cast(root);
402+
}
403+
399404
public final PythonLanguage getLanguage() {
400405
return getLanguage(PythonLanguage.class);
401406
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
224224
pyFrame.setBci(bytecodeNode.getBytecodeIndex(frameToMaterialize));
225225
pyFrame.setLocation(bytecodeNode);
226226
} else {
227-
assert location == PythonLanguage.get(null).unavailableSafepointLocation : String.format("%s, root: %s", location, location != null ? location.getRootNode() : "null");
227+
assert location == PythonLanguage.get(null).unavailableSafepointLocation : String.format("(%s) %s, root: %s",
228+
location != null ? location.getClass().getSimpleName() : "null",
229+
location, location != null ? location.getRootNode() : "null");
228230
pyFrame.setBci(-1);
229231
pyFrame.setLocation(location);
230232
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ public static class AllPythonFramesSelector implements FrameSelector {
111111
@Override
112112
public boolean skip(RootNode rootNode) {
113113
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
114-
// TODO check for specific continuation root
115-
return !(rootNode instanceof PBytecodeDSLRootNode || rootNode instanceof ContinuationRootNode);
114+
return PBytecodeDSLRootNode.cast(rootNode) == null;
116115
} else {
117116
return !(rootNode instanceof PBytecodeRootNode || rootNode instanceof PBytecodeGeneratorRootNode);
118117
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public final void execute(PythonContext context, Access access) {
173173
// the frame. Otherwise, we were woken-up in middle of Python frame code, we
174174
// will have to do a stack walk if caller frame is needed, but we still need
175175
// the "call" location
176-
if (location instanceof PBytecodeDSLRootNode) {
176+
if (location instanceof RootNode root && PBytecodeDSLRootNode.cast(root) != null) {
177177
// PBytecodeDSLRootNode is not usable as a location. To resolve the BCI
178178
// stored in the frame, we need the currently executing BytecodeNode,
179179
// using PBytecodeRootNode.getBytecodeNode() is not correct. We use the

0 commit comments

Comments
 (0)