Skip to content

Commit f131453

Browse files
committed
[GR-71951] Bytecode DSL: fixes for coverage.
PullRequest: graalpython/4146
2 parents 34886f6 + 0b5c498 commit f131453

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/grammar/AsyncTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class AsyncTests {
5050
@Test
5151
public void nativeCoroutine() {
5252
assumeFalse(IS_WINDOWS);
53-
assumeFalse("TODO: not implemented PGenerator.getYieldFrom(PGenerator.java:204)", Boolean.getBoolean("python.EnableBytecodeDSLInterpreter"));
5453
String source = "import asyncio\n" +
5554
"async def foo():\n" +
5655
" return 42\n" +
@@ -63,7 +62,6 @@ public void nativeCoroutine() {
6362
@Test
6463
public void asyncWith() {
6564
assumeFalse(IS_WINDOWS);
66-
assumeFalse("TODO: not implemented PGenerator.getYieldFrom(PGenerator.java:204)", Boolean.getBoolean("python.EnableBytecodeDSLInterpreter"));
6765
String source = "import asyncio\n" +
6866
"class AsyncContextManager:\n" +
6967
" async def __aenter__(self):\n" +
@@ -89,7 +87,6 @@ public void asyncWith() {
8987
@Test
9088
public void asyncWithExceptional() {
9189
assumeFalse(IS_WINDOWS);
92-
assumeFalse("TODO: not implemented PGenerator.getYieldFrom(PGenerator.java:204)", Boolean.getBoolean("python.EnableBytecodeDSLInterpreter"));
9390
String source = "import asyncio\n" +
9491
"class AsyncContextManager:\n" +
9592
" async def __aenter__(self):\n" +

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@
4040
*/
4141
package com.oracle.graal.python.test.integration.runtime;
4242

43+
import static com.oracle.graal.python.test.integration.PythonTests.eval;
44+
4345
import java.io.ByteArrayOutputStream;
4446
import java.io.PrintStream;
4547

48+
import org.graalvm.polyglot.Value;
4649
import org.junit.Assert;
4750
import org.junit.Assume;
4851
import org.junit.Test;
@@ -68,7 +71,9 @@ public void profileYield() {
6871

6972
@Test
7073
public void profileException() {
71-
Assume.assumeFalse("TODO: wrong stacktrace", Boolean.getBoolean("python.EnableBytecodeDSLInterpreter"));
74+
Value isBytecodeDLS = eval("__graalpython__.is_bytecode_dsl_interpreter");
75+
// GR-71916
76+
Assume.assumeFalse("TODO: wrong stacktrace", isBytecodeDLS.asBoolean());
7277
String source = "import sys\n" +
7378
"def f(frame, event, arg): print(frame, event, arg)\n" +
7479
"sys.setprofile(f)\n" +

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)