@@ -2042,27 +2042,28 @@ long doGeneric(Object n) {
20422042
20432043 @ Builtin (name = "PyType_IsSubtype" , fixedNumOfPositionalArgs = 2 )
20442044 @ GenerateNodeFactory
2045- abstract static class PyType_IsSubtype extends PythonBinaryBuiltinNode {
2046- private static long calls = 0 ;
2045+ abstract static class PyType_IsSubtype extends PythonBuiltinNode {
20472046
20482047 @ Child private IsSubtypeNode isSubtypeNode = IsSubtypeNode .create ();
2048+ @ Child private CExtNodes .AsPythonObjectNode asPythonObjectNode = CExtNodes .AsPythonObjectNode .create ();
20492049
2050- @ Specialization
2051- int doI (PythonClass a , PythonClass b ) {
2052- calls ++;
2053- if (calls % 1000 == 0 ) {
2054- print (calls );
2055- }
2056- if (isSubtypeNode .execute (a , b )) {
2057- return 1 ;
2058- }
2059- return 0 ;
2050+ @ Specialization (guards = {"a == cachedA" , "b == cachedB" })
2051+ int doCached (@ SuppressWarnings ("unused" ) PythonNativeWrapper a , @ SuppressWarnings ("unused" ) PythonNativeWrapper b ,
2052+ @ Cached ("a" ) @ SuppressWarnings ("unused" ) PythonNativeWrapper cachedA ,
2053+ @ Cached ("b" ) @ SuppressWarnings ("unused" ) PythonNativeWrapper cachedB ,
2054+ @ Cached ("isNativeSubtype(a, b)" ) int result ) {
2055+ return result ;
20602056 }
20612057
2062- @ TruffleBoundary
2063- private static void print (long calls2 ) {
2064- System .out .println ("######### CALLS: " + calls2 );
2065- System .out .flush ();
2058+ @ Specialization (replaces = "doCached" )
2059+ int doGeneric (PythonNativeWrapper a , PythonNativeWrapper b ) {
2060+ return isNativeSubtype (a , b );
2061+ }
2062+
2063+ protected int isNativeSubtype (PythonNativeWrapper a , PythonNativeWrapper b ) {
2064+ assert a instanceof PythonClassNativeWrapper || a instanceof PythonClassInitNativeWrapper ;
2065+ assert b instanceof PythonClassNativeWrapper || b instanceof PythonClassInitNativeWrapper ;
2066+ return isSubtypeNode .execute (asPythonObjectNode .execute (a ), asPythonObjectNode .execute (b )) ? 1 : 0 ;
20662067 }
20672068 }
20682069
0 commit comments