Skip to content

Commit f06e982

Browse files
committed
[GR-33173] Migrate to new context reference API - removing PythonLanguage.getCurrent()
1 parent c191a11 commit f06e982

38 files changed

+108
-98
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/ConversionNodeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class ConversionNodeTests {
6666
@Rule public ExpectedException expectedException = ExpectedException.none();
6767

6868
protected static Object call(Object arg, ArgumentCastNodeWithRaise castNode) {
69-
PythonLanguage language = PythonLanguage.getCurrent();
69+
PythonLanguage language = PythonLanguage.get(castNode);
7070
final PythonContext pythonContext = PythonLanguage.getContext();
7171

7272
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(new PRootNode(language) {

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public void doInsert(Node child) {
6464
public void loopWithOnlyStop() throws UnexpectedResultException {
6565
PythonTests.enterContext();
6666
try {
67-
PRange range = PythonObjectFactory.getUncached().createIntRange(10);
67+
PythonObjectFactory factory = PythonObjectFactory.getUncached();
68+
PRange range = factory.createIntRange(10);
6869
int index = 0;
69-
TestRoot testRoot = new TestRoot(PythonLanguage.getCurrent());
70+
TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
7071
Object iter = PythonObjectLibrary.getUncached().getIterator(range);
7172
GetNextNode next = GetNextNode.create();
7273
testRoot.doInsert(next);
@@ -91,9 +92,10 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
9192
public void loopWithStep() throws UnexpectedResultException {
9293
PythonTests.enterContext();
9394
try {
95+
PythonObjectFactory factory = PythonObjectFactory.getUncached();
9496
PRange range = PythonObjectFactory.getUncached().createIntRange(0, 10, 2, 5);
9597
int index = 0;
96-
TestRoot testRoot = new TestRoot(PythonLanguage.getCurrent());
98+
TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
9799
Object iter = PythonObjectLibrary.getUncached().getIterator(range);
98100
GetNextNode next = GetNextNode.create();
99101
testRoot.doInsert(next);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,6 @@ public String getHome() {
608608
return getLanguageHome();
609609
}
610610

611-
public static PythonLanguage getCurrent() {
612-
return PythonLanguage.get(null);
613-
}
614-
615611
public static PythonContext getContext() {
616612
return PythonContext.get(null);
617613
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ private PCode readCode() {
954954
ByteBuffer.wrap(codeString).putLong(codeLen, PythonLanguage.getContext().getDeserializationId(fileName));
955955
int firstLineNo = readInt();
956956
byte[] lnoTab = readBytes();
957-
return CreateCodeNode.createCode(PythonLanguage.getCurrent(), PythonLanguage.getContext(), flags, codeString, fileName, firstLineNo, lnoTab);
957+
return CreateCodeNode.createCode(PythonLanguage.getContext(), flags, codeString, fileName, firstLineNo, lnoTab);
958958
}
959959

960960
@SuppressWarnings("unused")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
8585
@TruffleBoundary
8686
protected PTuple call(PJSONScanner self, String string, int idx) {
8787
if (tupleInstanceShape == null) {
88-
tupleInstanceShape = PythonLanguage.getCurrent().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PTuple);
88+
tupleInstanceShape = PythonLanguage.get(null).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PTuple);
8989
}
9090
if (listInstanceShape == null) {
91-
listInstanceShape = PythonLanguage.getCurrent().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PList);
91+
listInstanceShape = PythonLanguage.get(null).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PList);
9292
}
9393
if (dictInstanceShape == null) {
94-
dictInstanceShape = PythonLanguage.getCurrent().getBuiltinTypeInstanceShape(PythonBuiltinClassType.PDict);
94+
dictInstanceShape = PythonLanguage.get(null).getBuiltinTypeInstanceShape(PythonBuiltinClassType.PDict);
9595
}
9696
IntRef nextIdx = new IntRef();
9797
Object result = scanOnceUnicode(self, string, idx, nextIdx);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ public abstract class PythonAbstractObject extends DynamicObject implements Truf
175175
private DynamicObjectNativeWrapper nativeWrapper;
176176

177177
public static final Assumption singleContextAssumption() {
178-
return PythonLanguage.getCurrent().singleContextAssumption;
178+
return PythonLanguage.get(null).singleContextAssumption;
179+
}
180+
181+
public static final Assumption singleContextAssumption(Node node) {
182+
return PythonLanguage.get(node).singleContextAssumption;
179183
}
180184

181185
protected static final Shape ABSTRACT_SHAPE = Shape.newBuilder().build();
@@ -1816,8 +1820,8 @@ public TriState isIdenticalOrUndefined(Object otherInterop,
18161820
*/
18171821
@ExportMessage
18181822
public static class GetIteratorWithState {
1819-
public static ValueProfile createIterMethodProfile() {
1820-
if (singleContextAssumption().isValid()) {
1823+
public static ValueProfile createIterMethodProfile(Node node) {
1824+
if (singleContextAssumption(node).isValid()) {
18211825
return ValueProfile.createIdentityProfile();
18221826
} else {
18231827
return ValueProfile.createClassProfile();
@@ -1826,9 +1830,9 @@ public static ValueProfile createIterMethodProfile() {
18261830

18271831
@Specialization
18281832
public static Object getIteratorWithState(PythonAbstractObject self, ThreadState state,
1829-
@Cached("createIterMethodProfile()") ValueProfile iterMethodProfile,
18301833
@CachedLibrary("self") PythonObjectLibrary plib,
18311834
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
1835+
@Cached("createIterMethodProfile(plib)") ValueProfile iterMethodProfile,
18321836
@Cached IteratorNodes.IsIteratorObjectNode isIteratorObjectNode,
18331837
@Cached PythonObjectFactory factory,
18341838
@Shared("raise") @Cached PRaiseNode raise) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static Object asPointer(Object ptr, InteropLibrary lib) {
282282
private RootCallTarget getReferenceCleanerCallTarget() {
283283
if (referenceCleanerCallTarget == null) {
284284
CompilerDirectives.transferToInterpreterAndInvalidate();
285-
referenceCleanerCallTarget = PythonLanguage.getCurrent().createCachedCallTarget(l -> new CApiReferenceCleanerRootNode(l), CApiReferenceCleanerRootNode.class);
285+
referenceCleanerCallTarget = PythonLanguage.get(null).createCachedCallTarget(l -> new CApiReferenceCleanerRootNode(l), CApiReferenceCleanerRootNode.class);
286286
}
287287
return referenceCleanerCallTarget;
288288
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,8 +3154,8 @@ static boolean isSame(InteropLibrary lib, Object left, Object right) {
31543154
return lib.isIdentical(left, right, lib);
31553155
}
31563156

3157-
static Assumption singleContextAssumption() {
3158-
return PythonLanguage.getCurrent().singleContextAssumption;
3157+
Assumption singleContextAssumption() {
3158+
return PythonLanguage.get(this).singleContextAssumption;
31593159
}
31603160

31613161
static Assumption getHandleValidAssumption(PythonNativeWrapper nativeWrapper) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected static PythonContext getContext(Node node) {
129129

130130
@Specialization(guards = {"!isResolved(pointerObject)", "ref != null", "isSame(interoplibrary, pointerObject, ref)"}, //
131131
rewriteOn = {CannotCastException.class, InvalidCacheEntry.class}, //
132-
assumptions = "singleContextAssumption()", //
132+
assumptions = "singleContextAssumption(interoplibrary)", //
133133
limit = "1")
134134
static PythonAbstractNativeObject doCachedPointer(@SuppressWarnings("unused") Object pointerObject, @SuppressWarnings("unused") Object refCnt, boolean steal,
135135
@Shared("stealProfile") @Cached ConditionProfile stealProfile,
@@ -235,8 +235,8 @@ static boolean isResolved(Object object) {
235235
return CApiGuards.isNativeWrapper(object) || object instanceof String;
236236
}
237237

238-
static Assumption singleContextAssumption() {
239-
return PythonLanguage.getCurrent().singleContextAssumption;
238+
static Assumption singleContextAssumption(Node node) {
239+
return PythonLanguage.get(node).singleContextAssumption;
240240
}
241241

242242
static boolean isNoRefCnt(Object refCnt) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.truffle.api.library.CachedLibrary;
6363
import com.oracle.truffle.api.library.ExportLibrary;
6464
import com.oracle.truffle.api.library.ExportMessage;
65+
import com.oracle.truffle.api.nodes.Node;
6566
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
6667

6768
/**
@@ -255,9 +256,10 @@ static Object callGetUInt32ArrayTypeIDUncached(@SuppressWarnings("unused") PyLon
255256
return PCallCapiFunction.getUncached().call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
256257
}
257258

258-
@Specialization(assumptions = "singleContextAssumption()")
259+
@Specialization(assumptions = "singleContextAssumption(lib)")
259260
static Object doByteArray(@SuppressWarnings("unused") PyLongDigitsWrapper object,
260-
@Exclusive @Cached("callGetUInt32ArrayTypeIDUncached(object)") Object nativeType) {
261+
@Exclusive @Cached("callGetUInt32ArrayTypeIDUncached(object)") Object nativeType,
262+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") InteropLibrary lib) {
261263
return nativeType;
262264
}
263265

@@ -267,8 +269,8 @@ static Object doByteArrayMultiCtx(@SuppressWarnings("unused") PyLongDigitsWrappe
267269
return callGetTypeIDNode.call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
268270
}
269271

270-
protected static Assumption singleContextAssumption() {
271-
return PythonLanguage.getCurrent().singleContextAssumption;
272+
protected static Assumption singleContextAssumption(Node node) {
273+
return PythonLanguage.get(node).singleContextAssumption;
272274
}
273275
}
274276
}

0 commit comments

Comments
 (0)