Skip to content

Commit bcd7d27

Browse files
committed
Fix ordering issue between libraries, @Bind and guards in GetRegisteredClassNode
1 parent 177e611 commit bcd7d27

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetRegisteredClassNode.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,27 @@ static Object noRegisteredClass(Object foreignObject,
9292
return getForeignObjectClassNode.execute(foreignObject);
9393
}
9494

95-
// Always return ForeignObject for meta objects (classes), because custom behavior should only
96-
// be added to instances.
95+
// Always delegate to GetForeignObjectClassNode for meta objects (classes), because custom
96+
// behavior should only be added to instances.
9797
@Specialization(guards = "objectLibrary.isMetaObject(foreignObject) || !objectLibrary.hasMetaObject(foreignObject)")
9898
static Object getClassLookup(Object foreignObject,
99-
@SuppressWarnings("unused") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") @Exclusive InteropLibrary objectLibrary,
99+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") @Exclusive InteropLibrary objectLibrary,
100100
@Shared @Cached GetForeignObjectClassNode getForeignObjectClassNode) {
101101
return getForeignObjectClassNode.execute(foreignObject);
102102
}
103103

104+
// Note: libraries except objectLibrary must not use @CachedLibrary("receiver") style as that
105+
// would cause getMetaObject() to get called before the hasMetaObject guard, which can then
106+
// cause a UnsupportedMessageException
104107
@Specialization(guards = {"isSingleContext()",
105108
"!objectLibrary.isMetaObject(foreignObject)",
106109
"objectLibrary.hasMetaObject(foreignObject)",
107-
"metaObjectLibrary.isIdentical(metaObject, cachedMetaObject, cachedMetaObjectLibrary)"}, limit = "getCallSiteInlineCacheMaxDepth()", assumptions = "getContext().interopTypeRegistryCacheValidAssumption.getAssumption()")
108-
static Object getCachedClassLookup(@SuppressWarnings("unused") Object foreignObject,
109-
@SuppressWarnings("unused") @CachedLibrary("foreignObject") InteropLibrary objectLibrary,
110-
@SuppressWarnings("unused") @Bind("getMetaObject(objectLibrary, foreignObject)") Object metaObject,
111-
@SuppressWarnings("unused") @CachedLibrary("metaObject") InteropLibrary metaObjectLibrary,
112-
@SuppressWarnings("unused") @Cached("metaObject") Object cachedMetaObject,
113-
@SuppressWarnings("unused") @CachedLibrary("cachedMetaObject") InteropLibrary cachedMetaObjectLibrary,
110+
"metaObjectLibrary.isIdentical(metaObject, cachedMetaObject, metaObjectLibrary)"}, limit = "getCallSiteInlineCacheMaxDepth()", assumptions = "getContext().interopTypeRegistryCacheValidAssumption.getAssumption()")
111+
static Object getCachedClassLookup(Object foreignObject,
112+
@CachedLibrary("foreignObject") InteropLibrary objectLibrary,
113+
@Bind("getMetaObject(objectLibrary, foreignObject)") Object metaObject,
114+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") @Exclusive InteropLibrary metaObjectLibrary,
115+
@Cached("metaObject") Object cachedMetaObject,
114116
@Cached(value = "lookupUncached($node, foreignObject, cachedMetaObject)") Object pythonClass) {
115117
return pythonClass;
116118
}

0 commit comments

Comments
 (0)