51
51
import com .oracle .graal .python .builtins .objects .dict .PDict ;
52
52
import com .oracle .graal .python .builtins .objects .type .MroShape ;
53
53
import com .oracle .graal .python .builtins .objects .type .MroShape .MroShapeLookupResult ;
54
+ import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
54
55
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
55
56
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
56
57
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroStorageNode ;
70
71
import com .oracle .truffle .api .dsl .ImportStatic ;
71
72
import com .oracle .truffle .api .dsl .ReportPolymorphism .Megamorphic ;
72
73
import com .oracle .truffle .api .dsl .Specialization ;
74
+ import com .oracle .truffle .api .library .CachedLibrary ;
73
75
import com .oracle .truffle .api .nodes .ExplodeLoop ;
76
+ import com .oracle .truffle .api .object .DynamicObjectLibrary ;
74
77
75
78
@ ImportStatic (PythonOptions .class )
76
79
public abstract class LookupAttributeInMRONode extends LookupInMROBaseNode {
@@ -99,7 +102,7 @@ protected Object lookupInBuiltinType(PythonBuiltinClassType klass, Object key,
99
102
protected static Object lookupGeneric (Object klass , Object key ,
100
103
@ Cached GetMroStorageNode getMroNode ,
101
104
@ Cached (value = "createForceType()" , uncached = "getUncachedForceType()" ) ReadAttributeFromObjectNode readAttrNode ) {
102
- return lookup (klass , key , getMroNode , readAttrNode , false );
105
+ return lookup (klass , key , getMroNode , readAttrNode , false , DynamicObjectLibrary . getUncached () );
103
106
}
104
107
105
108
public static LookupAttributeInMRONode .Dynamic create () {
@@ -111,14 +114,14 @@ public static LookupAttributeInMRONode.Dynamic getUncached() {
111
114
}
112
115
}
113
116
114
- private final boolean skipPythonClasses ;
117
+ private final boolean skipNonStaticBases ;
115
118
protected final String key ;
116
119
@ Child private TypeNodes .IsSameTypeNode isSameTypeNode = IsSameTypeNodeGen .create ();
117
120
@ Child private GetMroStorageNode getMroNode ;
118
121
119
- public LookupAttributeInMRONode (String key , boolean skipPythonClasses ) {
122
+ public LookupAttributeInMRONode (String key , boolean skipNonStaticBases ) {
120
123
this .key = key ;
121
- this .skipPythonClasses = skipPythonClasses ;
124
+ this .skipNonStaticBases = skipNonStaticBases ;
122
125
}
123
126
124
127
public static LookupAttributeInMRONode create (String key ) {
@@ -215,7 +218,11 @@ static final class AttributeAssumptionPair {
215
218
}
216
219
}
217
220
218
- protected AttributeAssumptionPair findAttrAndAssumptionInMRO (Object klass ) {
221
+ private static boolean skipNonStaticBase (Object clsObj , boolean skipNonStaticBases , DynamicObjectLibrary dylib ) {
222
+ return skipNonStaticBases && clsObj instanceof PythonClass && !((PythonClass ) clsObj ).isStaticBase (dylib );
223
+ }
224
+
225
+ protected AttributeAssumptionPair findAttrAndAssumptionInMRO (Object klass , DynamicObjectLibrary dylib ) {
219
226
CompilerAsserts .neverPartOfCompilation ();
220
227
// - avoid cases when attributes are stored in a dict containing elements
221
228
// with a potential MRO sideeffect on access.
@@ -236,12 +243,12 @@ protected AttributeAssumptionPair findAttrAndAssumptionInMRO(Object klass) {
236
243
MroSequenceStorage mro = getMro (klass );
237
244
Assumption attrAssumption = mro .createAttributeInMROFinalAssumption (key );
238
245
for (int i = 0 ; i < mro .length (); i ++) {
239
- Object clsObj = mro .getItemNormalized (i );
246
+ PythonAbstractClass clsObj = mro .getItemNormalized (i );
240
247
if (i > 0 ) {
241
248
assert clsObj != klass : "MRO chain is incorrect: '" + klass + "' was found at position " + i ;
242
249
getMro (clsObj ).addAttributeInMROFinalAssumption (key , attrAssumption );
243
250
}
244
- if (skipPythonClasses && clsObj instanceof PythonClass ) {
251
+ if (skipNonStaticBase ( clsObj , skipNonStaticBases , dylib ) ) {
245
252
continue ;
246
253
}
247
254
Object value = ReadAttributeFromObjectNode .getUncachedForceType ().execute (clsObj , key );
@@ -257,7 +264,8 @@ protected AttributeAssumptionPair findAttrAndAssumptionInMRO(Object klass) {
257
264
assumptions = "cachedAttrInMROInfo.assumption" )
258
265
protected static Object lookupConstantMROCached (@ SuppressWarnings ("unused" ) Object klass ,
259
266
@ Cached ("klass" ) @ SuppressWarnings ("unused" ) Object cachedKlass ,
260
- @ Cached ("findAttrAndAssumptionInMRO(cachedKlass)" ) AttributeAssumptionPair cachedAttrInMROInfo ) {
267
+ @ CachedLibrary (limit = "1" ) DynamicObjectLibrary dylib ,
268
+ @ Cached ("findAttrAndAssumptionInMRO(cachedKlass, dylib)" ) AttributeAssumptionPair cachedAttrInMROInfo ) {
261
269
return cachedAttrInMROInfo .value ;
262
270
}
263
271
@@ -295,10 +303,11 @@ protected Object lookupConstantMRO(@SuppressWarnings("unused") Object klass,
295
303
@ Cached ("getMro(cachedKlass)" ) MroSequenceStorage mro ,
296
304
@ Cached ("mro.getLookupStableAssumption()" ) @ SuppressWarnings ("unused" ) Assumption lookupStable ,
297
305
@ Cached ("mro.length()" ) int mroLength ,
306
+ @ CachedLibrary (limit = "1" ) DynamicObjectLibrary dylib ,
298
307
@ Cached ("create(mroLength)" ) ReadAttributeFromObjectNode [] readAttrNodes ) {
299
308
for (int i = 0 ; i < mroLength ; i ++) {
300
309
Object kls = mro .getItemNormalized (i );
301
- if (skipPythonClasses && kls instanceof PythonClass ) {
310
+ if (skipNonStaticBase ( kls , skipNonStaticBases , dylib ) ) {
302
311
continue ;
303
312
}
304
313
Object value = readAttrNodes [i ].execute (kls , key );
@@ -317,10 +326,11 @@ protected Object lookupCachedLen(@SuppressWarnings("unused") Object klass,
317
326
@ Bind ("getMro(klass)" ) MroSequenceStorage mro ,
318
327
@ Bind ("mro.length()" ) @ SuppressWarnings ("unused" ) int mroLength ,
319
328
@ Cached ("mro.length()" ) int cachedMroLength ,
329
+ @ CachedLibrary (limit = "1" ) DynamicObjectLibrary dylib ,
320
330
@ Cached ("create(cachedMroLength)" ) ReadAttributeFromObjectNode [] readAttrNodes ) {
321
331
for (int i = 0 ; i < cachedMroLength ; i ++) {
322
332
Object kls = mro .getItemNormalized (i );
323
- if (skipPythonClasses && kls instanceof PythonClass ) {
333
+ if (skipNonStaticBase ( kls , skipNonStaticBases , dylib ) ) {
324
334
continue ;
325
335
}
326
336
Object value = readAttrNodes [i ].execute (kls , key );
@@ -334,8 +344,9 @@ protected Object lookupCachedLen(@SuppressWarnings("unused") Object klass,
334
344
@ Specialization (replaces = {"lookupConstantMROCached" , "lookupConstantMRO" , "lookupCachedLen" })
335
345
@ Megamorphic
336
346
protected Object lookupGeneric (Object klass ,
347
+ @ CachedLibrary (limit = "1" ) DynamicObjectLibrary dylib ,
337
348
@ Cached ("createForceType()" ) ReadAttributeFromObjectNode readAttrNode ) {
338
- return lookup (klass , key , ensureGetMroNode (), readAttrNode , skipPythonClasses );
349
+ return lookup (klass , key , ensureGetMroNode (), readAttrNode , skipNonStaticBases , dylib );
339
350
}
340
351
341
352
protected GetMroStorageNode ensureGetMroNode () {
@@ -352,14 +363,14 @@ protected MroSequenceStorage getMro(Object clazz) {
352
363
353
364
@ TruffleBoundary
354
365
public static Object lookupSlowPath (Object klass , Object key ) {
355
- return lookup (klass , key , GetMroStorageNode .getUncached (), ReadAttributeFromObjectNode .getUncachedForceType (), false );
366
+ return lookup (klass , key , GetMroStorageNode .getUncached (), ReadAttributeFromObjectNode .getUncachedForceType (), false , DynamicObjectLibrary . getUncached () );
356
367
}
357
368
358
- public static Object lookup (Object klass , Object key , GetMroStorageNode getMroNode , ReadAttributeFromObjectNode readAttrNode , boolean skipPythonClasses ) {
369
+ public static Object lookup (Object klass , Object key , GetMroStorageNode getMroNode , ReadAttributeFromObjectNode readAttrNode , boolean skipNonStaticBases , DynamicObjectLibrary dylib ) {
359
370
MroSequenceStorage mro = getMroNode .execute (klass );
360
371
for (int i = 0 ; i < mro .length (); i ++) {
361
372
Object kls = mro .getItemNormalized (i );
362
- if (skipPythonClasses && kls instanceof PythonClass ) {
373
+ if (skipNonStaticBase ( kls , skipNonStaticBases , dylib ) ) {
363
374
continue ;
364
375
}
365
376
Object value = readAttrNode .execute (kls , key );
0 commit comments