Skip to content

Commit b9f8634

Browse files
committed
GraalHPyHandle, CodeNodes, GetAttributeNode, DeleteGlobalNode, FunctionDefinitionNode, GeneratorFunctionDefinitionNode use PythonLanguage#isSingleContext()
1 parent f8bf654 commit b9f8634

File tree

6 files changed

+18
-39
lines changed

6 files changed

+18
-39
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyHandle.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4747
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapperLibrary;
4848
import com.oracle.graal.python.runtime.PythonContext;
49-
import com.oracle.truffle.api.Assumption;
5049
import com.oracle.truffle.api.CompilerDirectives;
5150
import com.oracle.truffle.api.dsl.Cached;
5251
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -174,11 +173,10 @@ boolean hasNativeType() {
174173
@ExportMessage
175174
static class GetNativeType {
176175

177-
@Specialization(assumptions = "singleContextAssumption")
176+
@Specialization(guards = "isSingleContext(lib)")
178177
@SuppressWarnings("unused")
179178
static Object doSingleContext(GraalHPyHandle handle,
180179
@CachedLibrary("handle") InteropLibrary lib,
181-
@Cached("singleContextAssumption(lib)") Assumption singleContextAssumption,
182180
@Cached("getHPyNativeType(lib)") Object hpyNativeType) {
183181
return hpyNativeType;
184182
}
@@ -193,8 +191,8 @@ static Object getHPyNativeType(Node node) {
193191
return PythonContext.get(node).getHPyContext().getHPyNativeType();
194192
}
195193

196-
static Assumption singleContextAssumption(Node node) {
197-
return PythonLanguage.get(node).singleContextAssumption;
194+
static boolean isSingleContext(Node node) {
195+
return PythonLanguage.get(node).isSingleContext();
198196
}
199197
}
200198

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static PCode createCode(PythonContext context, int flags, byte[] codedata
139139
PythonLanguage language = context.getLanguage();
140140
Supplier<CallTarget> createCode = () -> {
141141
ByteSequence bytes = ByteSequence.create(codedata);
142-
Source source = Source.newBuilder(PythonLanguage.ID, bytes, filename).mimeType(PythonLanguage.MIME_TYPE_BYTECODE).cached(!language.singleContextAssumption.isValid()).build();
142+
Source source = Source.newBuilder(PythonLanguage.ID, bytes, filename).mimeType(PythonLanguage.MIME_TYPE_BYTECODE).cached(!language.isSingleContext()).build();
143143
return context.getEnv().parsePublic(source);
144144
};
145145

@@ -172,7 +172,6 @@ public static final class GetCodeCallTargetNode extends Node {
172172
private static final GetCodeCallTargetNode UNCACHED = new GetCodeCallTargetNode(false);
173173

174174
private final boolean isAdoptable;
175-
@CompilationFinal private Assumption singleContextAssumption;
176175
@CompilationFinal private ConditionProfile hasCtProfile;
177176
@CompilationFinal private PCode cachedCode1;
178177
@CompilationFinal private PCode cachedCode2;
@@ -185,12 +184,8 @@ private GetCodeCallTargetNode(boolean isAdoptable) {
185184

186185
public final RootCallTarget execute(PCode code) {
187186
if (isAdoptable) {
188-
if (singleContextAssumption == null) {
189-
CompilerDirectives.transferToInterpreterAndInvalidate();
190-
singleContextAssumption = PythonLanguage.get(this).singleContextAssumption;
191-
}
192187
if (hasCtProfile == null) {
193-
if (singleContextAssumption.isValid()) {
188+
if (PythonLanguage.get(this).isSingleContext()) {
194189
if (cachedCode1 == null) {
195190
CompilerDirectives.transferToInterpreterAndInvalidate();
196191
cachedCode1 = code;
@@ -239,17 +234,12 @@ public static GetCodeCallTargetNode getUncached() {
239234
}
240235

241236
@GenerateUncached
242-
public abstract static class GetCodeSignatureNode extends Node {
237+
public abstract static class GetCodeSignatureNode extends PNodeWithContext {
243238
public abstract Signature execute(PCode code);
244239

245-
protected static final Assumption getSingleContextAssumption() {
246-
return PythonLanguage.get(null).singleContextAssumption;
247-
}
248-
249240
@SuppressWarnings("unused")
250-
@Specialization(guards = "cachedCode == code", limit = "2", assumptions = "singleContextAssumption")
241+
@Specialization(guards = {"isSingleContext()", "cachedCode == code"}, limit = "2")
251242
protected static Signature doCached(PCode code,
252-
@Cached("getSingleContextAssumption()") Assumption singleContextAssumption,
253243
@Cached("code") PCode cachedCode,
254244
@Cached("code.initializeCallTarget()") RootCallTarget ct,
255245
@Cached("code.initializeSignature(ct)") Signature signature) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/GetAttributeNode.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
4444

45-
import com.oracle.graal.python.PythonLanguage;
4645
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4746
import com.oracle.graal.python.builtins.objects.PNone;
4847
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
@@ -52,6 +51,7 @@
5251
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
5352
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
5453
import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
54+
import com.oracle.graal.python.nodes.PNodeWithContext;
5555
import com.oracle.graal.python.nodes.attributes.GetAttributeNodeFactory.GetFixedAttributeNodeGen;
5656
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
5757
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -62,13 +62,11 @@
6262
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6363
import com.oracle.graal.python.nodes.statement.StatementNode;
6464
import com.oracle.graal.python.runtime.exception.PException;
65-
import com.oracle.truffle.api.Assumption;
6665
import com.oracle.truffle.api.CompilerDirectives;
6766
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
6867
import com.oracle.truffle.api.dsl.Cached;
6968
import com.oracle.truffle.api.dsl.Specialization;
7069
import com.oracle.truffle.api.frame.VirtualFrame;
71-
import com.oracle.truffle.api.nodes.Node;
7270
import com.oracle.truffle.api.profiles.ConditionProfile;
7371

7472
public final class GetAttributeNode extends ExpressionNode implements ReadNode {
@@ -111,7 +109,7 @@ public ExpressionNode getObject() {
111109
return objectExpression;
112110
}
113111

114-
abstract static class GetAttributeBaseNode extends Node {
112+
abstract static class GetAttributeBaseNode extends PNodeWithContext {
115113

116114
@Child protected LookupAndCallBinaryNode dispatchNode = LookupAndCallBinaryNode.create(SpecialMethodSlot.GetAttribute);
117115
@Child private IsBuiltinClassProfile isBuiltinClassProfile;
@@ -175,10 +173,6 @@ protected Object getPythonClass(Object object) {
175173
return getClassNode.execute(object);
176174
}
177175

178-
Assumption singleContextAssumption() {
179-
return PythonLanguage.get(this).singleContextAssumption;
180-
}
181-
182176
protected IsBuiltinClassProfile getErrorProfile() {
183177
if (isBuiltinClassProfile == null) {
184178
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -235,7 +229,7 @@ protected static boolean isTypeGetAttribute(Object lazyClass) {
235229
* it in single context mode.
236230
*/
237231

238-
@Specialization(assumptions = "singleContextAssumption()")
232+
@Specialization(guards = "isSingleContext()")
239233
final Object doSingleContext(VirtualFrame frame, Object object) {
240234
try {
241235
return dispatchNode.executeObject(frame, object, key);
@@ -245,7 +239,7 @@ final Object doSingleContext(VirtualFrame frame, Object object) {
245239
}
246240
}
247241

248-
@Specialization(replaces = "doSingleContext", guards = "isObjectGetAttribute(getPythonClass(object))")
242+
@Specialization(guards = {"!isSingleContext()", "isObjectGetAttribute(getPythonClass(object))"})
249243
final Object doBuiltinObject(VirtualFrame frame, Object object,
250244
@Cached ObjectBuiltins.GetAttributeNode getAttributeNode) {
251245
try {
@@ -256,7 +250,7 @@ final Object doBuiltinObject(VirtualFrame frame, Object object,
256250
}
257251
}
258252

259-
@Specialization(replaces = "doSingleContext", guards = "isTypeGetAttribute(getPythonClass(object))")
253+
@Specialization(guards = {"!isSingleContext()", "isTypeGetAttribute(getPythonClass(object))"})
260254
final Object doBuiltinType(VirtualFrame frame, Object object,
261255
@Cached TypeBuiltins.GetattributeNode getAttributeNode) {
262256
try {
@@ -267,7 +261,7 @@ final Object doBuiltinType(VirtualFrame frame, Object object,
267261
}
268262
}
269263

270-
@Specialization(replaces = "doSingleContext", guards = "isModuleGetAttribute(getPythonClass(object))")
264+
@Specialization(guards = {"!isSingleContext()", "isModuleGetAttribute(getPythonClass(object))"})
271265
final Object doBuiltinModule(VirtualFrame frame, Object object,
272266
@Cached ModuleBuiltins.ModuleGetattritbuteNode getAttributeNode) {
273267
try {
@@ -278,7 +272,7 @@ final Object doBuiltinModule(VirtualFrame frame, Object object,
278272
}
279273
}
280274

281-
@Specialization(replaces = {"doBuiltinObject", "doBuiltinType", "doBuiltinModule"})
275+
@Specialization(guards = "!isSingleContext()", replaces = {"doBuiltinObject", "doBuiltinType", "doBuiltinModule"})
282276
final Object doGeneric(VirtualFrame frame, Object object) {
283277
try {
284278
return dispatchNode.executeObject(frame, object, key);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DeleteGlobalNode.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,18 @@
4040
*/
4141
package com.oracle.graal.python.nodes.frame;
4242

43-
import com.oracle.graal.python.PythonLanguage;
4443
import com.oracle.graal.python.builtins.objects.PNone;
4544
import com.oracle.graal.python.builtins.objects.dict.PDict;
4645
import com.oracle.graal.python.builtins.objects.module.PythonModule;
4746
import com.oracle.graal.python.nodes.attributes.DeleteAttributeNode;
4847
import com.oracle.graal.python.nodes.statement.StatementNode;
4948
import com.oracle.graal.python.nodes.subscript.DeleteItemNode;
50-
import com.oracle.truffle.api.Assumption;
5149
import com.oracle.truffle.api.dsl.Cached;
5250
import com.oracle.truffle.api.dsl.Specialization;
5351
import com.oracle.truffle.api.frame.VirtualFrame;
5452

5553
public abstract class DeleteGlobalNode extends StatementNode implements GlobalNode {
5654
private final String attributeId;
57-
protected final Assumption singleContextAssumption = PythonLanguage.get(this).singleContextAssumption;
5855

5956
DeleteGlobalNode(String attributeId) {
6057
this.attributeId = attributeId;
@@ -71,7 +68,7 @@ public final void executeVoid(VirtualFrame frame) {
7168

7269
public abstract Object executeWithGlobals(VirtualFrame frame, Object globals);
7370

74-
@Specialization(guards = {"globals == cachedGlobals"}, assumptions = "singleContextAssumption", limit = "1")
71+
@Specialization(guards = {"isSingleContext()", "globals == cachedGlobals"}, limit = "1")
7572
Object deleteDictCached(VirtualFrame frame, @SuppressWarnings("unused") PDict globals,
7673
@Cached(value = "globals", weak = true) PDict cachedGlobals,
7774
@Cached DeleteItemNode deleteNode) {
@@ -86,7 +83,7 @@ Object deleteDict(VirtualFrame frame, PDict globals,
8683
return PNone.NONE;
8784
}
8885

89-
@Specialization(guards = {"globals == cachedGlobals"}, assumptions = "singleContextAssumption", limit = "1")
86+
@Specialization(guards = {"isSingleContext()", "globals == cachedGlobals"}, limit = "1")
9087
Object deleteModuleCached(VirtualFrame frame, @SuppressWarnings("unused") PythonModule globals,
9188
@Cached(value = "globals", weak = true) PythonModule cachedGlobals,
9289
@Cached DeleteAttributeNode storeNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public Object execute(VirtualFrame frame) {
129129
PythonLanguage lang = PythonLanguage.get(this);
130130
CompilerAsserts.partialEvaluationConstant(lang);
131131
PCode code;
132-
if (lang.singleContextAssumption.isValid()) {
132+
if (lang.isSingleContext()) {
133133
if (cachedCode == null) {
134134
CompilerDirectives.transferToInterpreterAndInvalidate();
135135
cachedCode = factory().createCode(callTarget);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/GeneratorFunctionDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected PCode getGeneratorCode() {
106106
generatorCallTarget = PythonUtils.getOrCreateCallTarget(getGeneratorFunctionRootNode(lang));
107107
}
108108
CompilerAsserts.partialEvaluationConstant(lang);
109-
if (lang.singleContextAssumption.isValid()) {
109+
if (lang.isSingleContext()) {
110110
if (generatorCode == null) {
111111
CompilerDirectives.transferToInterpreterAndInvalidate();
112112
generatorCode = factory().createCode(generatorCallTarget);

0 commit comments

Comments
 (0)