Skip to content

Commit dff1cbc

Browse files
committed
PyLongDigitsWrapper, PySequenceArrayWrapper, PythonNativeWrapper use PythonLanguage#isSingleContext
1 parent 2a56795 commit dff1cbc

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
import com.oracle.graal.python.runtime.PythonOptions;
121121
import com.oracle.graal.python.runtime.exception.PException;
122122
import com.oracle.graal.python.util.PythonUtils;
123-
import com.oracle.truffle.api.Assumption;
124123
import com.oracle.truffle.api.CompilerDirectives;
125124
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
126125
import com.oracle.truffle.api.TruffleLanguage;
@@ -161,14 +160,6 @@ public abstract class PythonAbstractObject extends DynamicObject implements Truf
161160
protected static final SpecialMethodSlot Iter = SpecialMethodSlot.Iter;
162161
protected static final SpecialMethodSlot Next = SpecialMethodSlot.Next;
163162

164-
public static final Assumption singleContextAssumption() {
165-
return PythonLanguage.get(null).singleContextAssumption;
166-
}
167-
168-
public static final Assumption singleContextAssumption(Node node) {
169-
return PythonLanguage.get(node).singleContextAssumption;
170-
}
171-
172163
protected static final Shape ABSTRACT_SHAPE = Shape.newBuilder().build();
173164

174165
protected PythonAbstractObject(Shape shape) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.oracle.graal.python.runtime.GilNode;
5151
import com.oracle.graal.python.runtime.PythonContext;
5252
import com.oracle.graal.python.runtime.PythonOptions;
53-
import com.oracle.truffle.api.Assumption;
5453
import com.oracle.truffle.api.CompilerAsserts;
5554
import com.oracle.truffle.api.dsl.Cached;
5655
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -255,7 +254,7 @@ static Object callGetUInt32ArrayTypeIDUncached(@SuppressWarnings("unused") PyLon
255254
return PCallCapiFunction.getUncached().call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
256255
}
257256

258-
@Specialization(assumptions = "singleContextAssumption()")
257+
@Specialization(guards = "isSingleContext()")
259258
static Object doByteArray(@SuppressWarnings("unused") PyLongDigitsWrapper object,
260259
@Exclusive @Cached("callGetUInt32ArrayTypeIDUncached(object)") Object nativeType) {
261260
return nativeType;
@@ -267,8 +266,9 @@ static Object doByteArrayMultiCtx(@SuppressWarnings("unused") PyLongDigitsWrappe
267266
return callGetTypeIDNode.call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
268267
}
269268

270-
protected static Assumption singleContextAssumption() {
271-
return PythonLanguage.get(null).singleContextAssumption;
269+
protected static boolean isSingleContext() {
270+
CompilerAsserts.neverPartOfCompilation();
271+
return PythonLanguage.get(null).isSingleContext();
272272
}
273273
}
274274
}

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_GET_PTR_ARRAY_TYPE_ID;
4545
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_NATIVE_HANDLE_FOR_ARRAY;
4646

47-
import com.oracle.graal.python.PythonLanguage;
4847
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4948
import com.oracle.graal.python.builtins.objects.PythonAbstractObject.PInteropSubscriptAssignNode;
5049
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
@@ -62,6 +61,7 @@
6261
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6362
import com.oracle.graal.python.lib.PyLongAsLongNode;
6463
import com.oracle.graal.python.lib.PyObjectSizeNode;
64+
import com.oracle.graal.python.nodes.PNodeWithContext;
6565
import com.oracle.graal.python.nodes.SpecialMethodNames;
6666
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
6767
import com.oracle.graal.python.nodes.call.CallNode;
@@ -73,7 +73,6 @@
7373
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
7474
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
7575
import com.oracle.graal.python.util.PythonUtils;
76-
import com.oracle.truffle.api.Assumption;
7776
import com.oracle.truffle.api.CompilerAsserts;
7877
import com.oracle.truffle.api.CompilerDirectives;
7978
import com.oracle.truffle.api.dsl.Cached;
@@ -482,7 +481,7 @@ Object getNativeType(
482481

483482
@GenerateUncached
484483
@ImportStatic({SpecialMethodNames.class, PySequenceArrayWrapper.class})
485-
abstract static class GetTypeIDNode extends Node {
484+
abstract static class GetTypeIDNode extends PNodeWithContext {
486485

487486
public abstract Object execute(Object delegate);
488487

@@ -494,17 +493,15 @@ protected static Object callGetPtrArrayTypeIDUncached() {
494493
return PCallCapiFunction.getUncached().call(FUN_GET_PTR_ARRAY_TYPE_ID, 0);
495494
}
496495

497-
@Specialization(assumptions = "singleContextAssumption", guards = "hasByteArrayContent(object)")
496+
@Specialization(guards = {"isSingleContext()", "hasByteArrayContent(object)"})
498497
Object doByteArray(@SuppressWarnings("unused") Object object,
499-
@Shared("singleContextAssumption") @Cached("singleContextAssumption()") @SuppressWarnings("unused") Assumption singleContextAssumption,
500498
@Exclusive @Cached("callGetByteArrayTypeIDUncached()") Object nativeType) {
501499
// TODO(fa): use weak reference ?
502500
return nativeType;
503501
}
504502

505-
@Specialization(assumptions = "singleContextAssumption", guards = "!hasByteArrayContent(object)")
503+
@Specialization(guards = {"isSingleContext()", "!hasByteArrayContent(object)"})
506504
Object doPtrArray(@SuppressWarnings("unused") Object object,
507-
@Shared("singleContextAssumption") @Cached("singleContextAssumption()") @SuppressWarnings("unused") Assumption singleContextAssumption,
508505
@Exclusive @Cached("callGetPtrArrayTypeIDUncached()") Object nativeType) {
509506
// TODO(fa): use weak reference ?
510507
return nativeType;
@@ -521,10 +518,6 @@ Object doPtrArrayMultiCtx(@SuppressWarnings("unused") PSequence object,
521518
@Shared("callUnaryNode") @Cached PCallCapiFunction callUnaryNode) {
522519
return callUnaryNode.call(FUN_GET_PTR_ARRAY_TYPE_ID, 0);
523520
}
524-
525-
protected Assumption singleContextAssumption() {
526-
return PythonLanguage.get(this).singleContextAssumption;
527-
}
528521
}
529522

530523
protected static boolean hasByteArrayContent(Object object) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ public final Assumption ensureHandleValidAssumption() {
120120
return handleValidAssumption;
121121
}
122122

123-
protected static Assumption singleContextAssumption() {
124-
return PythonLanguage.get(null).singleContextAssumption;
123+
protected static boolean isSingleContext() {
124+
CompilerAsserts.neverPartOfCompilation();
125+
return PythonLanguage.get(null).isSingleContext();
125126
}
126127

127128
@ExportMessage(name = "getDelegate")
128129
protected static class GetDelegate {
129-
@Specialization(guards = {"cachedWrapper == wrapper", "delegate != null"}, assumptions = "singleContextAssumption()")
130+
@Specialization(guards = {"isSingleContext()", "cachedWrapper == wrapper", "delegate != null"})
130131
protected static Object getCachedDel(@SuppressWarnings("unused") PythonNativeWrapper wrapper,
131132
@SuppressWarnings("unused") @Cached(value = "wrapper", weak = true) PythonNativeWrapper cachedWrapper,
132133
@Cached(value = "wrapper.getDelegateSlowPath()", weak = true) Object delegate) {
@@ -154,7 +155,7 @@ protected void setDelegate(Object delegate) {
154155

155156
@ExportMessage(name = "getNativePointer")
156157
protected static class GetNativePointer {
157-
@Specialization(guards = {"cachedWrapper == wrapper", "nativePointer != null"}, assumptions = {"singleContextAssumption()", "cachedAssumption"})
158+
@Specialization(guards = {"isSingleContext()", "cachedWrapper == wrapper", "nativePointer != null"}, assumptions = {"cachedAssumption"})
158159
protected static Object getCachedPtr(@SuppressWarnings("unused") PythonNativeWrapper wrapper,
159160
@SuppressWarnings("unused") @Cached(value = "wrapper", weak = true) PythonNativeWrapper cachedWrapper,
160161
@SuppressWarnings("unused") @Cached("wrapper.getHandleValidAssumption()") Assumption cachedAssumption,
@@ -183,7 +184,7 @@ public void setNativePointer(Object nativePointer) {
183184

184185
@ExportMessage(name = "isNative")
185186
protected static class IsNative {
186-
@Specialization(guards = {"cachedWrapper == wrapper", "nativePointer != null"}, assumptions = {"singleContextAssumption()", "cachedAssumption"})
187+
@Specialization(guards = {"isSingleContext()", "cachedWrapper == wrapper", "nativePointer != null"}, assumptions = {"cachedAssumption"})
187188
protected static boolean isCachedNative(@SuppressWarnings("unused") PythonNativeWrapper wrapper,
188189
@SuppressWarnings("unused") @Cached(value = "wrapper", weak = true) PythonNativeWrapper cachedWrapper,
189190
@SuppressWarnings("unused") @Cached("wrapper.getHandleValidAssumption()") Assumption cachedAssumption,

0 commit comments

Comments
 (0)