Skip to content

Commit 73ff20b

Browse files
committed
Semiautomated conversion of single ctx assumption to a field
1 parent 862edd4 commit 73ff20b

File tree

18 files changed

+50
-51
lines changed

18 files changed

+50
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public abstract static class GetMagic extends PythonBuiltinNode {
168168
@Child private IntBuiltins.ToBytesNode toBytesNode = IntBuiltins.ToBytesNode.create();
169169
@Child private PythonBufferAccessLibrary bufferLib = PythonBufferAccessLibrary.getFactory().createDispatched(1);
170170

171-
@Specialization(assumptions = "singleContextAssumption()")
171+
@Specialization(guards = "isSingleContext()")
172172
public PBytes runCachedSingleContext(@SuppressWarnings("unused") VirtualFrame frame,
173173
@Cached(value = "getMagicNumberPBytes(frame)", weak = true) PBytes magicBytes) {
174174
return magicBytes;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ static PyCFunctionDecorator decorate(Object fun0, Object fun1) {
20742074
@ImportStatic(PythonOptions.class)
20752075
abstract static class PyType_IsSubtype extends PythonBinaryBuiltinNode {
20762076

2077-
@Specialization(guards = {"a == cachedA", "b == cachedB"}, assumptions = "singleContextAssumption()")
2077+
@Specialization(guards = {"isSingleContext()", "a == cachedA", "b == cachedB"})
20782078
static int doCached(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") PythonNativeWrapper a, @SuppressWarnings("unused") PythonNativeWrapper b,
20792079
@Cached(value = "a", weak = true) @SuppressWarnings("unused") PythonNativeWrapper cachedA,
20802080
@Cached(value = "b", weak = true) @SuppressWarnings("unused") PythonNativeWrapper cachedB,
@@ -2743,7 +2743,7 @@ static Object doGeneric(String key) {
27432743
abstract static class PyTruffleTraceMallocTrack extends PythonBuiltinNode {
27442744
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(PyTruffleTraceMallocTrack.class);
27452745

2746-
@Specialization(guards = {"domain == cachedDomain"}, limit = "3", assumptions = "singleContextAssumption()")
2746+
@Specialization(guards = {"isSingleContext()", "domain == cachedDomain"}, limit = "3")
27472747
int doCachedDomainIdx(VirtualFrame frame, @SuppressWarnings("unused") long domain, Object pointerObject, long size,
27482748
@Cached GetThreadStateNode getThreadStateNode,
27492749
@Cached("domain") @SuppressWarnings("unused") long cachedDomain,
@@ -2775,7 +2775,7 @@ int lookupDomain(long domain) {
27752775
abstract static class PyTruffleTraceMallocUntrack extends PythonBinaryBuiltinNode {
27762776
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(PyTruffleTraceMallocUntrack.class);
27772777

2778-
@Specialization(guards = {"domain == cachedDomain"}, limit = "3", assumptions = "singleContextAssumption()")
2778+
@Specialization(guards = {"isSingleContext()", "domain == cachedDomain"}, limit = "3")
27792779
int doCachedDomainIdx(@SuppressWarnings("unused") long domain, Object pointerObject,
27802780
@Cached("domain") @SuppressWarnings("unused") long cachedDomain,
27812781
@Cached("lookupDomain(domain)") int cachedDomainIdx) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Object doSingleton(CExtContext cextContext, PythonAbstractObject object) {
474474
return doSingleton(cextContext, object, getContext());
475475
}
476476

477-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
477+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
478478
static Object doPythonClass(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonManagedClass object,
479479
@SuppressWarnings("unused") @Cached(value = "object", weak = true) PythonManagedClass cachedObject,
480480
@Cached(value = "wrapNativeClass(object)", weak = true) PythonClassNativeWrapper wrapper) {
@@ -487,7 +487,7 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
487487
return PythonClassNativeWrapper.wrap(object, getNameNode.execute(object));
488488
}
489489

490-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
490+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
491491
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
492492
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
493493
@Cached("wrapNativeClassFast(object, getContext())") PythonClassNativeWrapper wrapper) {
@@ -737,7 +737,7 @@ Object doSingleton(CExtContext cextContext, PythonAbstractObject object) {
737737
return doSingleton(cextContext, object, getContext());
738738
}
739739

740-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
740+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
741741
static Object doPythonClass(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonManagedClass object,
742742
@SuppressWarnings("unused") @Cached(value = "object", weak = true) PythonManagedClass cachedObject,
743743
@Cached(value = "wrapNativeClass(object)", weak = true) PythonClassNativeWrapper wrapper) {
@@ -751,7 +751,7 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
751751
return PythonClassNativeWrapper.wrapNewRef(object, getNameNode.execute(object));
752752
}
753753

754-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
754+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
755755
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
756756
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
757757
@Cached("wrapNativeClassFast(getContext(), object)") PythonClassNativeWrapper wrapper) {
@@ -912,7 +912,7 @@ Object doSingleton(CExtContext cextContext, PythonAbstractObject object) {
912912
return ToNewRefNode.doSingleton(cextContext, object, getContext());
913913
}
914914

915-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
915+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
916916
static Object doPythonClass(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonManagedClass object,
917917
@SuppressWarnings("unused") @Cached(value = "object", weak = true) PythonManagedClass cachedObject,
918918
@Cached(value = "wrapNativeClass(object)", weak = true) PythonClassNativeWrapper wrapper) {
@@ -926,7 +926,7 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
926926
return PythonClassNativeWrapper.wrapNewRef(object, getNameNode.execute(object));
927927
}
928928

929-
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
929+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "3")
930930
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
931931
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
932932
@Cached("wrapNativeClassFast(getContext(), object)") PythonClassNativeWrapper wrapper) {
@@ -1588,7 +1588,7 @@ public static Object run(Object object,
15881588
public abstract static class GetNativeClassNode extends PNodeWithContext {
15891589
public abstract Object execute(PythonAbstractNativeObject object);
15901590

1591-
@Specialization(guards = "object == cachedObject", limit = "1", assumptions = "singleContextAssumption()")
1591+
@Specialization(guards = {"isSingleContext()", "object == cachedObject"}, limit = "1")
15921592
@SuppressWarnings("unused")
15931593
static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
15941594
@Cached(value = "object", weak = true) PythonAbstractNativeObject cachedObject,
@@ -1600,7 +1600,7 @@ static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
16001600
return cachedClass;
16011601
}
16021602

1603-
@Specialization(guards = "isSame(lib, cachedObject, object)", assumptions = "singleContextAssumption()")
1603+
@Specialization(guards = {"isSingleContext()", "isSame(lib, cachedObject, object)"})
16041604
@SuppressWarnings("unused")
16051605
static Object getNativeClassCached(PythonAbstractNativeObject object,
16061606
@Cached(value = "object", weak = true) PythonAbstractNativeObject cachedObject,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ abstract class PGetDynamicTypeNode extends PNodeWithContext {
6666

6767
public abstract Object execute(PythonNativeWrapper obj);
6868

69-
@Specialization(guards = "obj.isIntLike()", assumptions = "singleContextAssumption()")
69+
@Specialization(guards = {"isSingleContext()", "obj.isIntLike()"})
7070
static Object doIntLikeSingleContext(@SuppressWarnings("unused") DynamicObjectNativeWrapper.PrimitiveNativeWrapper obj,
7171
@Cached(value = "getLongobjectType()", allowUncached = true) Object cachedSulongType) {
7272
return cachedSulongType;
7373
}
7474

75-
@Specialization(guards = "obj.isBool()", assumptions = "singleContextAssumption()")
75+
@Specialization(guards = {"isSingleContext()", "obj.isBool()"})
7676
static Object doBoolSingleContext(@SuppressWarnings("unused") DynamicObjectNativeWrapper.PrimitiveNativeWrapper obj,
7777
@Cached(value = "getBoolobjectType()", allowUncached = true) Object cachedSulongType) {
7878
return cachedSulongType;
7979
}
8080

81-
@Specialization(guards = "obj.isDouble()", assumptions = "singleContextAssumption()")
81+
@Specialization(guards = {"isSingleContext()", "obj.isDouble()"})
8282
static Object doDoubleSingleContext(@SuppressWarnings("unused") DynamicObjectNativeWrapper.PrimitiveNativeWrapper obj,
8383
@Cached(value = "getFloatobjectType()", allowUncached = true) Object cachedSulongType) {
8484
return cachedSulongType;
@@ -127,14 +127,14 @@ abstract static class GetSulongTypeNode extends PNodeWithContext {
127127

128128
public abstract Object execute(Object clazz);
129129

130-
@Specialization(guards = "clazz == cachedClass", limit = "10", assumptions = "singleContextAssumption()")
130+
@Specialization(guards = {"isSingleContext()", "clazz == cachedClass"}, limit = "10")
131131
static Object doBuiltinCachedResult(@SuppressWarnings("unused") PythonBuiltinClassType clazz,
132132
@Cached("clazz") @SuppressWarnings("unused") PythonBuiltinClassType cachedClass,
133133
@Cached("getLLVMTypeForBuiltinClass(clazz, getContext())") Object llvmType) {
134134
return llvmType;
135135
}
136136

137-
@Specialization(guards = "clazz == cachedClass", limit = "1")
137+
@Specialization(guards = {"isSingleContext()", "clazz == cachedClass"}, limit = "1")
138138
Object doBuiltinCached(@SuppressWarnings("unused") PythonBuiltinClassType clazz,
139139
@Cached("clazz") @SuppressWarnings("unused") PythonBuiltinClassType cachedClass) {
140140
return getLLVMTypeForBuiltinClass(cachedClass, getContext());
@@ -145,7 +145,7 @@ Object doBuiltinGeneric(PythonBuiltinClassType clazz) {
145145
return getLLVMTypeForBuiltinClass(clazz, getContext());
146146
}
147147

148-
@Specialization(assumptions = "singleContextAssumption()", guards = "clazz == cachedClass")
148+
@Specialization(guards = {"isSingleContext()", "clazz == cachedClass"})
149149
static Object doManagedClassCached(@SuppressWarnings("unused") PythonManagedClass clazz,
150150
@Cached("clazz") @SuppressWarnings("unused") PythonManagedClass cachedClass,
151151
@Cached("getLLVMTypeForClass(clazz)") Object llvmType) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,15 @@ public abstract static class ImportCExtSymbolNode extends PNodeWithContext {
154154

155155
public abstract Object execute(CExtContext nativeContext, NativeCExtSymbol symbol);
156156

157-
@Specialization(guards = "cachedSymbol == symbol", limit = "1", assumptions = "singleContextAssumption()")
157+
@Specialization(guards = {"isSingleContext()", "cachedSymbol == symbol"}, limit = "1")
158158
static Object doSymbolCached(@SuppressWarnings("unused") CExtContext nativeContext, @SuppressWarnings("unused") NativeCExtSymbol symbol,
159159
@Cached("symbol") @SuppressWarnings("unused") NativeCExtSymbol cachedSymbol,
160160
@Cached("importCAPISymbolUncached(nativeContext, symbol)") Object llvmSymbol) {
161161
return llvmSymbol;
162162
}
163163

164164
// n.b. if 'singleContextAssumption' is valid, we may also cache the native context
165-
@Specialization(guards = "nativeContext == cachedNativeContext", limit = "1", //
166-
assumptions = "singleContextAssumption()", //
165+
@Specialization(guards = {"isSingleContext()", "nativeContext == cachedNativeContext"}, limit = "1", //
167166
replaces = "doSymbolCached")
168167
Object doWithSymbolCacheSingleContext(@SuppressWarnings("unused") CExtContext nativeContext, NativeCExtSymbol symbol,
169168
@Cached("nativeContext") CExtContext cachedNativeContext,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ public static HPyAttachFunctionTypeNode getUncached() {
22082208
public abstract static class HPyAttachNFIFunctionTypeNode extends HPyAttachFunctionTypeNode {
22092209
public static final String NFI_LANGUAGE = "nfi";
22102210

2211-
@Specialization(guards = "llvmFunctionType == cachedType", limit = "3", assumptions = "singleContextAssumption()")
2211+
@Specialization(guards = {"isSingleContext()", "llvmFunctionType == cachedType"}, limit = "3")
22122212
static Object doCachedSingleContext(@SuppressWarnings("unused") GraalHPyContext hpyContext, Object pointerObject, @SuppressWarnings("unused") LLVMType llvmFunctionType,
22132213
@Cached("llvmFunctionType") @SuppressWarnings("unused") LLVMType cachedType,
22142214
@Cached("getNFISignature(hpyContext, llvmFunctionType)") Object nfiSignature,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ abstract static class GetNode extends PythonTernaryBuiltinNode {
9292
* {@code null}. So if it ever was not null and we cached that, it is being held alive by
9393
* the {@code self} argument now and there cannot be a race.
9494
*/
95-
@Specialization(guards = {"isNoValue(type)", "cachedSelf == self"}, assumptions = "singleContextAssumption()")
95+
@Specialization(guards = {"isSingleContext()", "isNoValue(type)", "cachedSelf == self"})
9696
Object getCached(@SuppressWarnings("unused") PDecoratedMethod self, Object obj, @SuppressWarnings("unused") Object type,
9797
@SuppressWarnings("unused") @Cached(value = "self", weak = true) PDecoratedMethod cachedSelf,
9898
@SuppressWarnings("unused") @Cached(value = "self.getCallable()", weak = true) Object cachedCallable,
@@ -110,7 +110,7 @@ Object get(PDecoratedMethod self, Object obj, @SuppressWarnings("unused") Object
110110
/**
111111
* @see #getCached
112112
*/
113-
@Specialization(guards = {"!isNoValue(type)", "cachedSelf == self"}, assumptions = "singleContextAssumption()")
113+
@Specialization(guards = {"isSingleContext()", "!isNoValue(type)", "cachedSelf == self"})
114114
Object getTypeCached(@SuppressWarnings("unused") PDecoratedMethod self, @SuppressWarnings("unused") Object obj, Object type,
115115
@SuppressWarnings("unused") @Cached(value = "self", weak = true) PDecoratedMethod cachedSelf,
116116
@SuppressWarnings("unused") @Cached(value = "self.getCallable()", weak = true) Object cachedCallable) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract static class GetNode extends PythonTernaryBuiltinNode {
7373
/**
7474
* @see ClassmethodBuiltins.GetNode#getCached
7575
*/
76-
@Specialization(guards = {"cachedSelf == self"}, assumptions = "singleContextAssumption()")
76+
@Specialization(guards = {"isSingleContext()", "cachedSelf == self"})
7777
protected static Object getCached(@SuppressWarnings("unused") PDecoratedMethod self, @SuppressWarnings("unused") Object obj, @SuppressWarnings("unused") Object type,
7878
@SuppressWarnings("unused") @Cached(value = "self", weak = true) PDecoratedMethod cachedSelf,
7979
@SuppressWarnings("unused") @Cached(value = "self.getCallable()", weak = true) Object cachedCallable) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ protected abstract static class CallNodeHelper extends PNodeWithRaise {
418418

419419
abstract Object execute(VirtualFrame frame, Object self, Object[] args, PKeyword[] keywords, boolean doCreateArgs);
420420

421-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"self == cachedSelf"}, assumptions = "singleContextAssumption()")
421+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"isSingleContext()", "self == cachedSelf"})
422422
protected Object doIt0BuiltinSingle(VirtualFrame frame, @SuppressWarnings("unused") PythonBuiltinClass self, Object[] arguments, PKeyword[] keywords, boolean doCreateArgs,
423423
@Cached("self") PythonBuiltinClass cachedSelf) {
424424
PythonBuiltinClassType type = cachedSelf.getType();
@@ -428,8 +428,8 @@ protected Object doIt0BuiltinSingle(VirtualFrame frame, @SuppressWarnings("unuse
428428
return op(frame, type, arguments, keywords, doCreateArgs);
429429
}
430430

431-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"self == cachedSelf", "isPythonClass(cachedSelf)",
432-
"!isPythonBuiltinClass(cachedSelf)"}, assumptions = "singleContextAssumption()")
431+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"isSingleContext()", "self == cachedSelf", "isPythonClass(cachedSelf)",
432+
"!isPythonBuiltinClass(cachedSelf)"})
433433
protected Object doIt0User(VirtualFrame frame, @SuppressWarnings("unused") Object self, Object[] arguments, PKeyword[] keywords, boolean doCreateArgs,
434434
@Cached(value = "self", weak = true) Object cachedSelf) {
435435
return op(frame, cachedSelf, arguments, keywords, doCreateArgs);
@@ -470,7 +470,7 @@ protected Object doItIndirect0User(VirtualFrame frame, PythonAbstractClass self,
470470
}
471471

472472
/* self is native */
473-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"self == cachedSelf"}, assumptions = "singleContextAssumption()")
473+
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()", guards = {"isSingleContext()", "self == cachedSelf"})
474474
protected Object doIt1(VirtualFrame frame, @SuppressWarnings("unused") PythonNativeObject self, Object[] arguments, PKeyword[] keywords, boolean doCreateArgs,
475475
@Cached("self") PythonNativeObject cachedSelf) {
476476
return op(frame, PythonNativeClass.cast(cachedSelf), arguments, keywords, doCreateArgs);

0 commit comments

Comments
 (0)