Skip to content

Commit 64cf870

Browse files
committed
add assertion and better error when executing unadopted nodes
1 parent 3503d74 commit 64cf870

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PNodeWithContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@
5151
import com.oracle.graal.python.runtime.exception.PythonErrorType;
5252
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5353
import com.oracle.truffle.api.Assumption;
54+
import com.oracle.truffle.api.CompilerAsserts;
5455
import com.oracle.truffle.api.CompilerDirectives;
5556
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5657
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5758
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
5859
import com.oracle.truffle.api.nodes.Node;
60+
import com.oracle.truffle.api.nodes.RootNode;
5961
import com.oracle.truffle.api.profiles.ConditionProfile;
6062

6163
public abstract class PNodeWithContext extends Node {
@@ -121,7 +123,14 @@ public final PythonContext getContext() {
121123
}
122124

123125
protected Assumption singleContextAssumption() {
124-
PythonLanguage language = getRootNode().getLanguage(PythonLanguage.class);
126+
CompilerAsserts.neverPartOfCompilation("the singleContextAssumption should only be retrieved in the interpreter");
127+
PythonLanguage language = null;
128+
RootNode rootNode = getRootNode();
129+
if (rootNode != null) {
130+
language = rootNode.getLanguage(PythonLanguage.class);
131+
} else {
132+
throw new IllegalStateException("a python node was executed without being adopted!");
133+
}
125134
if (language == null) {
126135
language = PythonLanguage.getCurrent();
127136
}

0 commit comments

Comments
 (0)