Skip to content

Commit 3876d18

Browse files
committed
[GR-69504][GR-72574] Remove FrameInfo#getYieldFrom, fix more tracing tests.
PullRequest: graalpython/4172
2 parents af773aa + 622354c commit 3876d18

8 files changed

Lines changed: 320 additions & 184 deletions

File tree

graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py

Lines changed: 283 additions & 159 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public Object getYieldFrom() {
350350
}
351351
return getContinuationBytecodeNode().getLocalValue(0, getGeneratorFrame(), rootNode.yieldFromGeneratorIndex);
352352
} else {
353-
return frameInfo.getYieldFrom(frame, getBci(), getBytecodeState().getCurrentRootNode().getResumeStackTop());
353+
return ((BytecodeFrameInfo) frameInfo).getYieldFrom(frame, getBci(), getBytecodeState().getCurrentRootNode().getResumeStackTop());
354354
}
355355

356356
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,9 @@ private void visitArguments(ExprTy func, ExprTy[] args, int numArgs) {
19651965
for (int i = 0; i < numArgs - 1; i++) {
19661966
args[i].accept(this);
19671967
}
1968-
b.beginTraceLineWithArgument();
1968+
beginTraceLineChecked(b);
19691969
args[numArgs - 1].accept(this);
1970-
b.endTraceLineWithArgument(func.getSourceRange().startLine);
1970+
endTraceLineChecked(func, b);
19711971
}
19721972
}
19731973

@@ -5481,9 +5481,12 @@ public Void visit(StmtTy.Try node) {
54815481
* }
54825482
*/
54835483
b.beginTryCatchOtherwise(() -> {
5484+
int saveLastTracedLine = lastTracedLine;
5485+
lastTracedLine = -1;
54845486
b.beginBlock(); // finally
54855487
visitSequence(node.finalBody);
54865488
b.endBlock();
5489+
lastTracedLine = saveLastTracedLine;
54875490
});
54885491

54895492
emitTryExceptElse(node); // try-except-else
@@ -6111,9 +6114,12 @@ public Void visit(StmtTy.TryStar node) {
61116114
* }
61126115
*/
61136116
b.beginTryCatchOtherwise(() -> {
6117+
int saveLastTracedLine = lastTracedLine;
6118+
lastTracedLine = -1;
61146119
b.beginBlock(); // finally
61156120
visitSequence(node.finalBody);
61166121
b.endBlock();
6122+
lastTracedLine = saveLastTracedLine;
61176123
});
61186124

61196125
emitTryExceptElse(node); // try-except-else
@@ -6267,7 +6273,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
62676273
if (async) {
62686274
finallyHandler = () -> emitAwait(() -> {
62696275
b.beginBlock();
6270-
emitTraceLineChecked(items[index], b);
6276+
b.emitTraceLine(items[index].getSourceRange().startLine);
62716277
b.beginAsyncContextManagerCallExit();
62726278
b.emitLoadConstant(PNone.NONE);
62736279
b.emitLoadLocal(exit);
@@ -6278,7 +6284,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
62786284
} else {
62796285
finallyHandler = () -> {
62806286
// call __exit__
6281-
emitTraceLineChecked(items[index], b);
6287+
b.emitTraceLine(items[index].getSourceRange().startLine);
62826288
b.beginContextManagerExit();
62836289
b.emitLoadConstant(PNone.NONE);
62846290
b.emitLoadLocal(exit);
@@ -6314,6 +6320,8 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
63146320
emitSaveCurrentException(savedException);
63156321
emitSetCurrentException();
63166322

6323+
b.beginBlock();
6324+
b.emitTraceLine(items[index].getSourceRange().startLine);
63176325
// @formatter:off
63186326
b.beginAsyncContextManagerExit();
63196327
b.emitLoadException();
@@ -6333,11 +6341,13 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
63336341
b.emitLoadLocal(tmp);
63346342
b.endBlock();
63356343
b.endAsyncContextManagerExit();
6344+
b.endBlock();
63366345
// @formatter:on
63376346

63386347
exitSaveExceptionBlock(prevPrevSaved);
63396348
} else {
63406349
// call __exit__
6350+
b.emitTraceLine(items[index].getSourceRange().startLine);
63416351
b.beginContextManagerExit();
63426352
b.emitLoadException();
63436353
b.emitLoadLocal(exit);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BytecodeFrameInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -78,7 +78,6 @@ public int getFirstLineNumber() {
7878
return rootNode.getFirstLineno();
7979
}
8080

81-
@Override
8281
public Object getYieldFrom(Frame generatorFrame, int bci, int stackTop) {
8382
/* Match the `yield from` bytecode pattern and get the object from stack */
8483
if (bci > 3 && bci < rootNode.bytecode.length && rootNode.bytecode[bci - 3] == OpCodesConstants.SEND && rootNode.bytecode[bci - 1] == OpCodesConstants.YIELD_VALUE &&

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/FrameInfo.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,7 +43,6 @@
4343
import com.oracle.graal.python.compiler.CodeUnit;
4444
import com.oracle.graal.python.nodes.PRootNode;
4545
import com.oracle.truffle.api.dsl.Idempotent;
46-
import com.oracle.truffle.api.frame.Frame;
4746
import com.oracle.truffle.api.frame.FrameDescriptor;
4847
import com.oracle.truffle.api.strings.TruffleString;
4948

@@ -58,8 +57,6 @@ public interface FrameInfo {
5857

5958
public int getFirstLineNumber();
6059

61-
public Object getYieldFrom(Frame generatorFrame, int bci, int stackTop);
62-
6360
public boolean includeInTraceback();
6461

6562
public CodeUnit getCodeUnit();

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,7 +43,6 @@
4343
import com.oracle.graal.python.compiler.CodeUnit;
4444
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
4545
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
46-
import com.oracle.truffle.api.frame.Frame;
4746

4847
public class BytecodeDSLFrameInfo implements FrameInfo {
4948
@CompilationFinal PBytecodeDSLRootNode rootNode;
@@ -66,12 +65,6 @@ public int getFirstLineNumber() {
6665
return rootNode.getFirstLineno();
6766
}
6867

69-
@Override
70-
public Object getYieldFrom(Frame generatorFrame, int bci, int stackTop) {
71-
// TODO implement
72-
throw new UnsupportedOperationException("not implemented");
73-
}
74-
7568
@Override
7669
public CodeUnit getCodeUnit() {
7770
return rootNode.getCodeUnit();

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -507,11 +507,15 @@ public static final class InstrumentationData {
507507
private final InstrumentationData previous;
508508
private final PBytecodeDSLRootNode rootNode;
509509
private int pastLine;
510+
// Sometimes, we need to use pastLine value after it has been cleared. Implicit returns in
511+
// combination with loops are one such scenario.
512+
private int nonClearingPastLine;
510513

511514
public InstrumentationData(PBytecodeDSLRootNode rootNode, InstrumentationData previous) {
512515
this.previous = previous;
513516
this.rootNode = rootNode;
514517
this.pastLine = -1;
518+
this.nonClearingPastLine = -1;
515519
}
516520

517521
public InstrumentationData getPrevious() {
@@ -533,6 +537,14 @@ void setPastLine(int pastLine) {
533537
void clearPastLine() {
534538
this.pastLine = -1;
535539
}
540+
541+
int getNonClearingPastLine() {
542+
return nonClearingPastLine;
543+
}
544+
545+
void setNonClearingPastLine(int value) {
546+
nonClearingPastLine = value;
547+
}
536548
}
537549

538550
@NonIdempotent
@@ -675,6 +687,7 @@ private void traceLine(VirtualFrame frame, BytecodeNode location, int line) {
675687
return;
676688
}
677689
instrumentationData.setPastLine(line);
690+
instrumentationData.setNonClearingPastLine(line);
678691

679692
PFrame pyFrame = ensurePyFrame(frame, location);
680693
if (pyFrame.getTraceLine()) {
@@ -692,6 +705,7 @@ private void traceLineAtLoopHeader(VirtualFrame frame, BytecodeNode location, in
692705
int pastLine = instrumentationData.getPastLine();
693706

694707
instrumentationData.setPastLine(line);
708+
instrumentationData.setNonClearingPastLine(line);
695709

696710
PFrame pyFrame = ensurePyFrame(frame, location);
697711
if (pyFrame.getTraceLine()) {
@@ -720,7 +734,7 @@ private void traceOrProfileReturn(VirtualFrame frame, BytecodeNode location, Obj
720734
PythonThreadState threadState = getThreadState();
721735
Object traceFun = threadState.getTraceFun();
722736
if (traceFun != null) {
723-
int pastLine = threadState.getInstrumentationData(this).getPastLine();
737+
int pastLine = threadState.getInstrumentationData(this).getNonClearingPastLine();
724738
invokeTraceFunction(frame, location, traceFun, threadState, TraceEvent.RETURN, value, pastLine);
725739
}
726740
Object profileFun = threadState.getProfileFun();
@@ -3092,7 +3106,9 @@ public static void doExceptional(VirtualFrame frame,
30923106
Object result = callExit.execute(frame, exit, contextManager, excType, pythonException, excTraceback);
30933107
if (!isTrue.execute(frame, result)) {
30943108
if (exception instanceof PException pException) {
3095-
throw pException.getExceptionForReraise(!rootNode.isInternal());
3109+
PException reraisedException = pException.getExceptionForReraise(!rootNode.isInternal());
3110+
reraisedException.dontTraceOnReraise();
3111+
throw reraisedException;
30963112
} else if (exception instanceof AbstractTruffleException ate) {
30973113
throw ate;
30983114
} else {

graalpython/lib-python/3/test/test_sys_settrace.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ def test_03_one_instr(self):
452452
self.run_test(one_instr_line)
453453
def test_04_no_pop_blocks(self):
454454
self.run_test(no_pop_blocks)
455-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Fix tracing of the return")
456455
def test_05_no_pop_tops(self):
457456
self.run_test(no_pop_tops)
458457
def test_06_call(self):
@@ -992,7 +991,6 @@ def func():
992991
(10, 'line'),
993992
(10, 'return')])
994993

995-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Fix tracing of the return")
996994
def test_break_to_continue1(self):
997995

998996
def func():
@@ -1016,7 +1014,6 @@ def func():
10161014
(3, 'line'),
10171015
(3, 'return')])
10181016

1019-
@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Fix tracing of the return")
10201017
def test_break_to_continue2(self):
10211018

10221019
def func():

0 commit comments

Comments
 (0)