Skip to content

Commit 6609034

Browse files
committed
Workaround wrong f-string locations
1 parent 63b1617 commit 6609034

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,24 @@ public final class InstrumentationSupport extends Node {
7272
*/
7373
@CompilationFinal(dimensions = 1) public Node[] bciToHelperNode;
7474

75+
final int startLine;
76+
7577
public InstrumentationSupport(PBytecodeRootNode rootNode) {
7678
assert rootNode.getSource() != null && rootNode.getSource().hasCharacters();
7779
code = rootNode.getCodeUnit();
78-
statements = new InstrumentedBytecodeStatement[code.endLine - code.startLine + 1];
80+
/*
81+
* TODO GR-40896 this search for min/max line shouldn't be necessary, but the parser doesn't
82+
* provide the correct location for f-strings (may be outside of the range of the function's
83+
* location).
84+
*/
85+
int minLine = code.startLine;
86+
int maxLine = code.endLine;
87+
for (int bci = 0; bci < code.code.length; bci++) {
88+
minLine = Math.min(minLine, code.bciToLine(bci));
89+
maxLine = Math.max(maxLine, code.bciToLine(bci));
90+
}
91+
startLine = minLine;
92+
statements = new InstrumentedBytecodeStatement[maxLine - minLine + 1];
7993
bciToHelperNode = new Node[code.code.length];
8094
boolean[] loadedBreakpoint = new boolean[1];
8195
code.iterateBytecode((bci, op, oparg, followingArgs) -> {
@@ -113,7 +127,7 @@ private void setStatement(int line, InstrumentedBytecodeStatement statement) {
113127
}
114128

115129
private int getStatementIndex(int line) {
116-
return line - code.startLine;
130+
return line - startLine;
117131
}
118132

119133
private InstrumentableNode.WrapperNode getWrapperAtLine(int line) {

0 commit comments

Comments
 (0)