Skip to content

Commit d12d0d0

Browse files
committed
Convert remaining single context assumptions usages to isSingleContext
1 parent 73ff20b commit d12d0d0

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@
219219
import com.oracle.graal.python.util.CharsetMapping;
220220
import com.oracle.graal.python.util.PythonUtils;
221221
import com.oracle.graal.python.util.Supplier;
222-
import com.oracle.truffle.api.Assumption;
223222
import com.oracle.truffle.api.CallTarget;
224223
import com.oracle.truffle.api.CompilerAsserts;
225224
import com.oracle.truffle.api.CompilerDirectives;
@@ -1766,7 +1765,6 @@ public abstract static class PrintNode extends PythonBuiltinNode {
17661765
private static final String DEFAULT_END = "\n";
17671766
private static final String DEFAULT_SEPARATOR = " ";
17681767
@Child private ReadAttributeFromObjectNode readStdout;
1769-
@CompilationFinal private Assumption singleContextAssumption;
17701768
@CompilationFinal private PythonModule cachedSys;
17711769

17721770
@Specialization
@@ -1844,12 +1842,8 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
18441842
}
18451843

18461844
private Object getStdout() {
1847-
if (singleContextAssumption == null) {
1848-
CompilerDirectives.transferToInterpreterAndInvalidate();
1849-
singleContextAssumption = singleContextAssumption();
1850-
}
18511845
PythonModule sys;
1852-
if (singleContextAssumption.isValid()) {
1846+
if (getLanguage().isSingleContext()) {
18531847
if (cachedSys == null) {
18541848
CompilerDirectives.transferToInterpreterAndInvalidate();
18551849
cachedSys = getContext().lookupBuiltinModule("sys");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.TransformExceptionToNativeNodeGen;
9797
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.VoidPtrToJavaNodeGen;
9898
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
99+
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.PythonObjectNativeWrapper;
99100
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.WriteNativeMemberNode;
100101
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.DefaultCheckFunctionResultNode;
101102
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes.MethKeywordsRoot;
@@ -106,7 +107,6 @@
106107
import com.oracle.graal.python.builtins.objects.cext.capi.NativeReferenceCache.ResolveNativeReferenceNode;
107108
import com.oracle.graal.python.builtins.objects.cext.capi.PGetDynamicTypeNode.GetSulongTypeNode;
108109
import com.oracle.graal.python.builtins.objects.cext.capi.PyTruffleObjectFree.FreeNode;
109-
import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper.PythonObjectNativeWrapper;
110110
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CArrayWrapper;
111111
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CByteArrayWrapper;
112112
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CStringWrapper;
@@ -2643,7 +2643,7 @@ public abstract static class IsPointerNode extends com.oracle.graal.python.nodes
26432643

26442644
public abstract boolean execute(PythonNativeWrapper obj);
26452645

2646-
@Specialization(assumptions = {"singleContextAssumption()", "nativeObjectsAllManagedAssumption()"})
2646+
@Specialization(guards = "isSingleContext()", assumptions = "nativeObjectsAllManagedAssumption()")
26472647
static boolean doFalse(@SuppressWarnings("unused") PythonNativeWrapper obj) {
26482648
return false;
26492649
}
@@ -2686,9 +2686,9 @@ public abstract static class GetTypeMemberNode extends PNodeWithContext {
26862686
* native context, so we can be sure that the "nativeClassStableAssumption" (which is
26872687
* per-context) is from the context in which this native object was created.
26882688
*/
2689-
@Specialization(guards = {"lib.isIdentical(cachedObj, obj, lib)", "memberName == cachedMemberName"}, //
2689+
@Specialization(guards = {"isSingleContext()", "lib.isIdentical(cachedObj, obj, lib)", "memberName == cachedMemberName"}, //
26902690
limit = "1", //
2691-
assumptions = {"getNativeClassStableAssumption(cachedObj)", "singleContextAssumption()"})
2691+
assumptions = {"getNativeClassStableAssumption(cachedObj)"})
26922692
public Object doCachedObj(@SuppressWarnings("unused") PythonAbstractNativeObject obj, @SuppressWarnings("unused") NativeMember memberName,
26932693
@Cached("obj") @SuppressWarnings("unused") PythonAbstractNativeObject cachedObj,
26942694
@CachedLibrary(limit = "2") @SuppressWarnings("unused") InteropLibrary lib,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/InvalidateNativeObjectsAllManagedNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public abstract class InvalidateNativeObjectsAllManagedNode extends PNodeWithCon
5353

5454
public abstract void execute();
5555

56-
@Specialization(assumptions = {"singleContextAssumption()", "nativeObjectsAllManagedAssumption"})
56+
@Specialization(guards = "isSingleContext()", assumptions = "nativeObjectsAllManagedAssumption")
5757
@TruffleBoundary
5858
static void doValid(
5959
@Cached("nativeObjectsAllManagedAssumption()") Assumption nativeObjectsAllManagedAssumption) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ protected static boolean isLongLivedObject(DynamicObject object) {
8484
@SuppressWarnings("unused")
8585
@Specialization(limit = "1", //
8686
guards = {
87+
"isSingleContext()",
8788
"dynamicObject == cachedObject",
8889
"isLongLivedObject(cachedObject)",
8990
"key == cachedKey",
9091
"dynamicObject.getShape() == cachedShape",
9192
"loc != null",
9293
"loc.isAssumedFinal()"
9394
}, //
94-
assumptions = {"singleContextAssumption()", "cachedShape.getValidAssumption()", "loc.getFinalAssumption()"})
95+
assumptions = {"cachedShape.getValidAssumption()", "loc.getFinalAssumption()"})
9596
protected Object readFinalAttr(DynamicObject dynamicObject, String key,
9697
@Cached("key") String cachedKey,
9798
@Cached(value = "dynamicObject", weak = true) DynamicObject cachedObject,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/FunctionNodes.java

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

43-
import com.oracle.graal.python.builtins.objects.code.PCode;
4443
import com.oracle.graal.python.builtins.objects.code.CodeNodes;
44+
import com.oracle.graal.python.builtins.objects.code.PCode;
4545
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4646
import com.oracle.graal.python.builtins.objects.function.PFunction;
4747
import com.oracle.graal.python.builtins.objects.function.PKeyword;
@@ -50,10 +50,10 @@
5050
import com.oracle.graal.python.builtins.objects.method.PMethod;
5151
import com.oracle.graal.python.nodes.PGuards;
5252
import com.oracle.graal.python.nodes.PNodeWithContext;
53+
import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetCallTargetNodeGen;
5354
import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetDefaultsNodeGen;
5455
import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetKeywordDefaultsNodeGen;
5556
import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetSignatureNodeGen;
56-
import com.oracle.graal.python.nodes.builtins.FunctionNodesFactory.GetCallTargetNodeGen;
5757
import com.oracle.truffle.api.Assumption;
5858
import com.oracle.truffle.api.RootCallTarget;
5959
import com.oracle.truffle.api.dsl.Bind;
@@ -70,7 +70,7 @@ public abstract static class GetFunctionDefaultsNode extends PNodeWithContext {
7070

7171
public abstract Object[] execute(PFunction function);
7272

73-
@Specialization(guards = {"self == cachedSelf"}, assumptions = {"singleContextAssumption()", "defaultsStableAssumption"})
73+
@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = "defaultsStableAssumption")
7474
static Object[] getDefaultsCached(@SuppressWarnings("unused") PFunction self,
7575
@SuppressWarnings("unused") @Cached("self") PFunction cachedSelf,
7676
@Cached(value = "self.getDefaults()", dimensions = 1) Object[] cachedDefaults,
@@ -129,7 +129,7 @@ public abstract static class GetFunctionKeywordDefaultsNode extends PNodeWithCon
129129

130130
public abstract PKeyword[] execute(PFunction function);
131131

132-
@Specialization(guards = {"self == cachedSelf"}, assumptions = {"singleContextAssumption()", "defaultsStableAssumption"})
132+
@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = "defaultsStableAssumption")
133133
static PKeyword[] getKwDefaultsCached(@SuppressWarnings("unused") PFunction self,
134134
@SuppressWarnings("unused") @Cached("self") PFunction cachedSelf,
135135
@Cached(value = "self.getKwDefaults()", dimensions = 1) PKeyword[] cachedKeywordDefaults,
@@ -188,7 +188,7 @@ public abstract static class GetFunctionCodeNode extends PNodeWithContext {
188188

189189
public abstract PCode execute(PFunction function);
190190

191-
@Specialization(guards = {"self == cachedSelf"}, assumptions = {"singleContextAssumption()", "codeStableAssumption"})
191+
@Specialization(guards = {"isSingleContext()", "self == cachedSelf"}, assumptions = "codeStableAssumption")
192192
static PCode getCodeCached(@SuppressWarnings("unused") PFunction self,
193193
@SuppressWarnings("unused") @Cached("self") PFunction cachedSelf,
194194
@Cached("self.getCode()") PCode cachedCode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/cell/WriteLocalCellNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ abstract static class WriteToCellNode extends PNodeWithContext {
8686

8787
public abstract void execute(PCell cell, Object value);
8888

89-
@Specialization(guards = "cell == cachedCell", limit = "getAttributeAccessInlineCacheMaxDepth()", assumptions = "singleContextAssumption")
89+
@Specialization(guards = {"isSingleContext()", "cell == cachedCell"}, limit = "getAttributeAccessInlineCacheMaxDepth()")
9090
void doWriteCached(@SuppressWarnings("unused") PCell cell, Object value,
91-
@SuppressWarnings("unused") @Cached("singleContextAssumption()") Assumption singleContextAssumption,
9291
@Cached("cell") PCell cachedCell) {
9392
if (value == NO_VALUE) {
9493
cachedCell.clearRef(cachedCell.isEffectivelyFinalAssumption());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/IsSubtypeNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ boolean isVariableSubtypeOfConstantTypeCachedMultiContext(Object derived, @Suppr
181181
}
182182

183183
@Specialization(guards = {
184+
"isSingleContext()",
184185
"isTypeDerived.execute(derived)", "isTypeCls.execute(cls)",
185186
"isSameType(isSameDerivedNode, derived, cachedDerived)",
186187
"isSameType(isSameClsNode, cls, cachedCls)",
@@ -189,7 +190,6 @@ boolean isVariableSubtypeOfConstantTypeCachedMultiContext(Object derived, @Suppr
189190
"isVariableSubtypeOfConstantTypeCachedMultiContext",
190191
}, assumptions = {
191192
"mro.getLookupStableAssumption()",
192-
"singleContextAssumption()"
193193
})
194194
@SuppressWarnings("unused")
195195
boolean isSubtypeOfCached(Object derived, Object cls,
@@ -207,6 +207,7 @@ boolean isSubtypeOfCached(Object derived, Object cls,
207207
}
208208

209209
@Specialization(guards = {
210+
"isSingleContext()",
210211
"isTypeDerived.execute(derived)", "isTypeCls.execute(cls)",
211212
"isSameType(isSameDerivedNode, derived, cachedDerived)",
212213
"mro.getInternalClassArray().length < 32"
@@ -215,8 +216,7 @@ boolean isSubtypeOfCached(Object derived, Object cls,
215216
"isVariableSubtypeOfConstantTypeCachedMultiContext",
216217
"isSubtypeOfCached"
217218
}, assumptions = {
218-
"mro.getLookupStableAssumption()",
219-
"singleContextAssumption()"
219+
"mro.getLookupStableAssumption()"
220220
})
221221
boolean isSubtypeOfVariableTypeCached(@SuppressWarnings("unused") Object derived, Object cls,
222222
@Cached("derived") @SuppressWarnings("unused") Object cachedDerived,
@@ -231,6 +231,7 @@ boolean isSubtypeOfVariableTypeCached(@SuppressWarnings("unused") Object derived
231231
}
232232

233233
@Specialization(guards = {
234+
"isSingleContext()",
234235
"isKindOfBuiltinClass(derived)", // see assertion in isSubMro
235236
"isKindOfBuiltinClass(cls)", // see assertion in isSubMro
236237
"mroAry.length == derivedMroLen",
@@ -242,8 +243,7 @@ boolean isSubtypeOfVariableTypeCached(@SuppressWarnings("unused") Object derived
242243
"isSubtypeOfCached",
243244
"isSubtypeOfVariableTypeCached",
244245
}, assumptions = {
245-
"baseMro.getLookupStableAssumption()",
246-
"singleContextAssumption()"
246+
"baseMro.getLookupStableAssumption()"
247247
})
248248
boolean isVariableSubtypeOfConstantTypeCached(Object derived, @SuppressWarnings("unused") Object cls,
249249
@Cached("cls") @SuppressWarnings("unused") Object cachedCls,

0 commit comments

Comments
 (0)