Skip to content

Commit 09ef110

Browse files
committed
implement isIdentical in PythonAbstractNativeObject
1 parent 93f50a7 commit 09ef110

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import com.oracle.truffle.api.object.Shape;
9292
import com.oracle.truffle.api.profiles.ConditionProfile;
9393
import com.oracle.truffle.api.profiles.ValueProfile;
94+
import com.oracle.truffle.api.utilities.TriState;
9495
import com.oracle.truffle.llvm.spi.ReferenceLibrary;
9596

9697
@ExportLibrary(PythonObjectLibrary.class)
@@ -228,9 +229,8 @@ public static Assumption getSingleContextAssumption() {
228229
return PythonLanguage.getCurrent().singleContextAssumption;
229230
}
230231

231-
@Specialization(guards = "object == cachedObject.get()", limit = "1", assumptions = "singleContextAssumption")
232+
@Specialization(guards = "object == cachedObject.get()", limit = "1", assumptions = "getSingleContextAssumption()")
232233
static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
233-
@Shared("assumption") @Cached(value = "getSingleContextAssumption()") Assumption singleContextAssumption,
234234
@Exclusive @Cached("weak(object)") WeakReference<PythonAbstractNativeObject> cachedObject,
235235
@Exclusive @Cached("getNativeClassUncached(object)") Object cachedClass) {
236236
// TODO: (tfel) is this really something we can do? It's so rare for this class to
@@ -240,12 +240,11 @@ static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
240240
return cachedClass;
241241
}
242242

243-
@Specialization(guards = "isSame(referenceLibrary, cachedObject, object)", limit = "1", assumptions = "singleContextAssumption")
243+
@Specialization(guards = "isSame(lib, cachedObject, object)", assumptions = "getSingleContextAssumption()")
244244
static Object getNativeClassCached(PythonAbstractNativeObject object,
245-
@Shared("assumption") @Cached(value = "getSingleContextAssumption()") Assumption singleContextAssumption,
246245
@Exclusive @Cached("weak(object)") WeakReference<PythonAbstractNativeObject> cachedObject,
247246
@Exclusive @Cached("getNativeClassUncached(object)") Object cachedClass,
248-
@CachedLibrary("object.object") @SuppressWarnings("unused") ReferenceLibrary referenceLibrary) {
247+
@CachedLibrary(limit = "3") @SuppressWarnings("unused") InteropLibrary lib) {
249248
// TODO same as for 'getNativeClassCachedIdentity'
250249
return cachedClass;
251250
}
@@ -274,10 +273,10 @@ static WeakReference<PythonAbstractNativeObject> weak(PythonAbstractNativeObject
274273
return new WeakReference<>(object);
275274
}
276275

277-
static boolean isSame(ReferenceLibrary referenceLibrary, WeakReference<PythonAbstractNativeObject> cachedObjectRef, PythonAbstractNativeObject object) {
276+
static boolean isSame(InteropLibrary lib, WeakReference<PythonAbstractNativeObject> cachedObjectRef, PythonAbstractNativeObject object) {
278277
PythonAbstractNativeObject cachedObject = cachedObjectRef.get();
279278
if (cachedObject != null) {
280-
return referenceLibrary.isSame(cachedObject.object, object.object);
279+
return lib.isIdentical(cachedObject.object, object.object, lib);
281280
}
282281
return false;
283282
}
@@ -288,6 +287,23 @@ public static Object getNativeClassUncached(PythonAbstractNativeObject object) {
288287
}
289288
}
290289

290+
@ExportMessage
291+
int identityHashCode(@CachedLibrary("this.object") InteropLibrary lib) throws UnsupportedMessageException {
292+
return lib.identityHashCode(object);
293+
}
294+
295+
@ExportMessage
296+
boolean isIdentical(Object other, InteropLibrary otherInterop,
297+
@CachedLibrary("this.object") InteropLibrary lib) {
298+
return lib.isIdentical(object, other, otherInterop);
299+
}
300+
301+
@ExportMessage
302+
TriState isIdenticalOrUndefined(Object other,
303+
@CachedLibrary(limit = "3") InteropLibrary lib) {
304+
return TriState.valueOf(lib.isIdentical(object, other, lib));
305+
}
306+
291307
@ExportMessage
292308
static class IsSame {
293309

0 commit comments

Comments
 (0)