Skip to content

Commit 412791a

Browse files
committed
Fix: PGenerator.getBytecodeNode should check running flag not isStarted
1 parent 4e00fb3 commit 412791a

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.oracle.graal.python.nodes.bytecode.FrameInfo;
7373
import com.oracle.graal.python.nodes.bytecode.GeneratorReturnException;
7474
import com.oracle.graal.python.nodes.bytecode.GeneratorYieldResult;
75+
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
7576
import com.oracle.graal.python.nodes.call.CallDispatchers;
7677
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
7778
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -398,7 +399,7 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object
398399
Node location;
399400
RootNode rootNode = self.getCurrentCallTarget().getRootNode();
400401
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
401-
location = self.getBytecodeNode();
402+
location = ((PBytecodeDSLRootNode) self.getRootNode()).getBytecodeNode();
402403
} else {
403404
location = rootNode;
404405
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public Object handleResult(PythonLanguage language, GeneratorYieldResult result)
121121
public static class BytecodeDSLState {
122122
private final PBytecodeDSLRootNode rootNode;
123123
private final Object[] arguments;
124+
private ContinuationRootNode prevContinuationRootNode;
124125
private ContinuationRootNode continuationRootNode;
125126
private boolean isStarted;
126127

@@ -133,6 +134,9 @@ public BytecodeDSLState(PBytecodeDSLRootNode rootNode, Object[] arguments, Conti
133134
public Object handleResult(PGenerator generator, ContinuationResult result) {
134135
assert result.getContinuationRootNode() == null || result.getContinuationRootNode().getFrameDescriptor() == generator.frame.getFrameDescriptor();
135136
isStarted = true;
137+
// We must keep the previous root so that we can load its BytecodeNode to resolve BCI to
138+
// location, the next continuation node may have different BytecodeNode
139+
prevContinuationRootNode = continuationRootNode;
136140
continuationRootNode = result.getContinuationRootNode();
137141
return result.getResult();
138142
}
@@ -301,12 +305,11 @@ public RootCallTarget getCurrentCallTarget() {
301305

302306
public BytecodeNode getBytecodeNode() {
303307
assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER;
308+
assert !running; // When it is running, we must use stack walking to get the location
304309
BytecodeDSLState state = getBytecodeDSLState();
305310
if (state.isStarted) {
306-
return state.continuationRootNode.getLocation().getBytecodeNode();
311+
return state.prevContinuationRootNode.getLocation().getBytecodeNode();
307312
} else {
308-
// Loading the BytecodeNode from the RootNode field is, in general, not correct, but can
309-
// be used if we know that the generator function is currently not on stack.
310313
return state.rootNode.getBytecodeNode();
311314
}
312315
}

0 commit comments

Comments
 (0)