Skip to content

Commit 0b5c498

Browse files
committed
Bytecode DSL: fixes for the coverage package
* fix tracing: put all expressions into blocks * co_positions return None for unavailable positions, but always something for each non-tracing instruction
1 parent f1c9df7 commit 0b5c498

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ Object positions(PCode self) {
500500
// 1-based inclusive to 0-based exclusive (-1 + 1 = 0)
501501
section.getEndColumn()
502502
}));
503+
} else {
504+
lines.add(PFactory.createTuple(language, new Object[]{PNone.NONE, PNone.NONE, PNone.NONE, PNone.NONE}));
503505
}
504506
}
505507
} else {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ void beginTraceLineChecked(Builder b) {
648648
/**
649649
* Emits a "line" tracing if either no tracing was emitted before, or if line number was
650650
* updated.
651-
*
651+
*
652652
* @param b Builder for line tracing.
653653
*/
654654
void endTraceLineChecked(SSTNode node, Builder b) {
@@ -1881,6 +1881,7 @@ public void acceptBoolOpArgs(ExprTy.BoolOp node) {
18811881
@Override
18821882
public Void visit(ExprTy.BoolOp node) {
18831883
boolean newStatement = beginSourceSection(node, b);
1884+
b.beginBlock();
18841885
emitTraceLineChecked(node, b);
18851886

18861887
if (node.op == BoolOpTy.And) {
@@ -1897,6 +1898,7 @@ public Void visit(ExprTy.BoolOp node) {
18971898
b.endBoolOr();
18981899
}
18991900

1901+
b.endBlock();
19001902
endSourceSection(b, newStatement);
19011903
return null;
19021904
}
@@ -2053,9 +2055,11 @@ private void emitGetMethod(ExprTy func, BytecodeLocal receiver) {
20532055
@Override
20542056
public Void visit(ExprTy.Call node) {
20552057
boolean newStatement = beginSourceSection(node, b);
2058+
b.beginBlock();
20562059
emitTraceLineChecked(node, b);
20572060
checkCaller(ctx.errorCallback, node.func);
20582061
emitCall(node.func, node.args, node.keywords);
2062+
b.endBlock();
20592063
endSourceSection(b, newStatement);
20602064
return null;
20612065
}
@@ -2832,6 +2836,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer, BytecodeLocal r
28322836
* except Exception as e:
28332837
* # throw/close generator
28342838
* if generator returned a value:
2839+
* returnValue = e.value
28352840
* goto end
28362841
* else:
28372842
* continue (generator yielded a value)
@@ -2843,7 +2848,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer, BytecodeLocal r
28432848
* returnValue = e.value
28442849
* goto end
28452850
*
2846-
* end: # Step 4: resultValue local is assigned
2851+
* end: # Step 4: returnValue local is assigned
28472852
* @formatter:on
28482853
*/
28492854
BytecodeLocal generator = b.createLocal();
@@ -4383,6 +4388,7 @@ private void visitMatchCaseRecursively(MatchCaseTy[] cases, int index, PatternCo
43834388
*/
43844389
MatchCaseTy c = cases[index];
43854390
boolean newStatement = beginSourceSection(c, b);
4391+
b.beginBlock();
43864392
emitTraceLineChecked(cases[index], b);
43874393

43884394
if (index != cases.length - 1) {
@@ -4415,6 +4421,7 @@ private void visitMatchCaseRecursively(MatchCaseTy[] cases, int index, PatternCo
44154421
}
44164422
}
44174423

4424+
b.endBlock();
44184425
endSourceSection(b, newStatement);
44194426
}
44204427

@@ -4486,6 +4493,7 @@ private void emitPatternCondition(MatchCaseTy currentCase, PatternContext pc) {
44864493
*/
44874494
private void visitPattern(PatternTy pattern, PatternContext pc) {
44884495
boolean newStatement = beginSourceSection(pattern, b);
4496+
b.beginBlock();
44894497
emitTraceLineChecked(pattern, b);
44904498
if (pattern instanceof PatternTy.MatchAs matchAs) {
44914499
doVisitPattern(matchAs, pc);
@@ -4506,6 +4514,7 @@ private void visitPattern(PatternTy pattern, PatternContext pc) {
45064514
} else {
45074515
throw CompilerDirectives.shouldNotReachHere();
45084516
}
4517+
b.endBlock();
45094518
endSourceSection(b, newStatement);
45104519
}
45114520

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ private static int getLineno(Frame frame, Node location, FrameInstance frameInst
137137

138138
if (bytecodeNode != null) {
139139
int bci = bytecodeNode.getBytecodeIndex(frame);
140-
return bytecodeNode.getBytecodeLocation(bci).getSourceLocation().getStartLine();
140+
SourceSection sourceLocation = bytecodeNode.getBytecodeLocation(bci).getSourceLocation();
141+
if (sourceLocation != null) {
142+
return sourceLocation.getStartLine();
143+
}
141144
}
142145
} else {
143146
return ((BytecodeFrameInfo) frameInfo).getLine(frame);

0 commit comments

Comments
 (0)