Skip to content

Commit 41bbd27

Browse files
committed
fix crashing traceback tests; assert materialize frame location is valid Node
1 parent 6614978 commit 41bbd27

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public int getLasti() {
309309
@TruffleBoundary
310310
public static int bciToLasti(int bci, Node location) {
311311
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
312-
if (location instanceof BytecodeNode bytecodeNode) {
312+
if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) {
313313
// Emulate CPython's fixed 2-word instructions.
314314
return bytecodeNode.findInstructionIndex(bci) * 2;
315315
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
6868
import com.oracle.graal.python.nodes.bytecode.GeneratorReturnException;
6969
import com.oracle.graal.python.nodes.bytecode.GeneratorYieldResult;
70+
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
7071
import com.oracle.graal.python.nodes.call.CallTargetInvokeNode;
7172
import com.oracle.graal.python.nodes.call.GenericInvokeNode;
7273
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
@@ -404,7 +405,7 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
404405
PTraceback newTraceback = factory.get(inliningTarget).createTraceback(pFrame, pFrame.getLine(),
405406
(existingTracebackObj instanceof PTraceback existingTraceback) ? existingTraceback : null);
406407
setTracebackNode.execute(inliningTarget, instance, newTraceback);
407-
throw PException.fromObject(instance, location, PythonOptions.isPExceptionWithJavaStacktrace(language));
408+
throw PException.fromObject(instance, inliningTarget, PythonOptions.isPExceptionWithJavaStacktrace(language));
408409
}
409410
}
410411
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ public static void doEnter(VirtualFrame frame,
319319
public static final class ExitCalleeContext {
320320
@Specialization
321321
public static Object doExit(VirtualFrame frame, Object returnValue,
322-
@Bind("$root") PBytecodeDSLRootNode root) {
323-
root.calleeContext.exit(frame, root);
322+
@Bind("$root") PBytecodeDSLRootNode root,
323+
@Bind("this") Node location) {
324+
root.calleeContext.exit(frame, root, location);
324325
return returnValue;
325326
}
326327
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5151
import com.oracle.graal.python.util.PythonUtils;
5252
import com.oracle.truffle.api.Truffle;
53+
import com.oracle.truffle.api.bytecode.BytecodeLocation;
5354
import com.oracle.truffle.api.bytecode.BytecodeNode;
5455
import com.oracle.truffle.api.dsl.Bind;
5556
import com.oracle.truffle.api.dsl.Cached;
@@ -181,8 +182,13 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
181182
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
182183
BytecodeDSLFrameInfo bytecodeDSLFrameInfo = (BytecodeDSLFrameInfo) info;
183184
PBytecodeDSLRootNode rootNode = bytecodeDSLFrameInfo.getRootNode();
185+
if (location instanceof PBytecodeDSLRootNode) {
186+
throw new AssertionError("The root node was passed as a location, but the root node is insufficient for identifying a bytecode location.");
187+
} else if (location.getRootNode() != rootNode) {
188+
throw new AssertionError("A node that did not belong to this root node was passed as a location.");
189+
}
184190
BytecodeNode bytecodeNode = BytecodeNode.get(location);
185-
pyFrame.setBci(rootNode.readBciFromFrame(frameToMaterialize));
191+
pyFrame.setBci(bytecodeNode.getBytecodeLocation(frameToMaterialize, location).getBytecodeIndex());
186192
pyFrame.setLocation(bytecodeNode);
187193
} else {
188194
BytecodeFrameInfo bytecodeFrameInfo = (BytecodeFrameInfo) info;

0 commit comments

Comments
 (0)