@@ -158,15 +158,27 @@ protected static LazyPythonClass getIt(@SuppressWarnings("unused") PythonNativeV
158
158
159
159
// if object is constant here, storage will also be constant, so the shape
160
160
// lookup is the only thing we need.
161
- @ Specialization (guards = "object.getStorage().getShape() == cachedShape" , assumptions = {"singleContextAssumption" }, limit = "1 " )
162
- protected static LazyPythonClass getPythonClassCached (@ SuppressWarnings ("unused" ) PythonObject object ,
161
+ @ Specialization (guards = "object.getStorage().getShape() == cachedShape" , assumptions = {"singleContextAssumption" }, limit = "4 " )
162
+ protected static LazyPythonClass getPythonClassCachedSingle (@ SuppressWarnings ("unused" ) PythonObject object ,
163
163
@ SuppressWarnings ("unused" ) @ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
164
164
@ SuppressWarnings ("unused" ) @ Cached ("singleContextAssumption()" ) Assumption singleContextAssumption ,
165
165
@ Cached ("object.getLazyPythonClass()" ) LazyPythonClass klass ) {
166
166
return klass ;
167
167
}
168
168
169
- @ Specialization (replaces = "getPythonClassCached" )
169
+ protected static boolean isBuiltinType (Shape shape ) {
170
+ return PythonObject .getLazyPythonClass (shape .getObjectType ()) instanceof PythonBuiltinClassType ;
171
+ }
172
+
173
+ // we can at least cache builtin types in the multi-context case
174
+ @ Specialization (guards = {"object.getStorage().getShape() == cachedShape" , "isBuiltinType(cachedShape)" }, limit = "4" )
175
+ protected static LazyPythonClass getPythonClassCached (@ SuppressWarnings ("unused" ) PythonObject object ,
176
+ @ SuppressWarnings ("unused" ) @ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
177
+ @ Cached ("object.getLazyPythonClass()" ) LazyPythonClass klass ) {
178
+ return klass ;
179
+ }
180
+
181
+ @ Specialization (replaces = {"getPythonClassCached" , "getPythonClassCachedSingle" })
170
182
protected static LazyPythonClass getPythonClassGeneric (PythonObject object ) {
171
183
return object .getLazyPythonClass ();
172
184
}
0 commit comments