@@ -232,28 +232,44 @@ public PNone initNoArgs(Object self, Object[] arguments, PKeyword[] keywords) {
232
232
@ SuppressWarnings ("unused" )
233
233
public PNone init (Object self , Object [] arguments , PKeyword [] keywords ,
234
234
@ CachedLibrary ("self" ) PythonObjectLibrary lib ,
235
+ @ Cached ConditionProfile overridesNew ,
236
+ @ Cached ConditionProfile overridesInit ,
235
237
@ Cached ("create(__INIT__)" ) LookupAttributeInMRONode lookupInit ,
236
- @ Cached ("createIdentityProfile()" ) ValueProfile profileInit ,
238
+ @ Cached ("createLookupProfile()" ) ValueProfile profileInit ,
239
+ @ Cached ("createIdentityProfile()" ) ValueProfile profileInitFactory ,
237
240
@ Cached ("create(__NEW__)" ) LookupAttributeInMRONode lookupNew ,
238
- @ Cached ("createIdentityProfile()" ) ValueProfile profileNew ) {
241
+ @ Cached ("createLookupProfile()" ) ValueProfile profileNew ,
242
+ @ Cached ("createIdentityProfile()" ) ValueProfile profileNewFactory ) {
239
243
if (arguments .length != 0 || keywords .length != 0 ) {
240
244
Object type = lib .getLazyPythonClass (self );
241
- if (overridesBuiltinMethod (type , profileInit , lookupInit , ObjectBuiltinsFactory .InitNodeFactory .class )) {
245
+ if (overridesNew . profile ( overridesBuiltinMethod (type , profileInit , lookupInit , profileInitFactory , ObjectBuiltinsFactory .InitNodeFactory .class ) )) {
242
246
throw raise (TypeError , ErrorMessages .INIT_TAKES_ONE_ARG_OBJECT );
243
247
}
244
248
245
- if (!overridesBuiltinMethod (type , profileInit , lookupNew , BuiltinConstructorsFactory .ObjectNodeFactory .class )) {
249
+ if (overridesInit . profile ( !overridesBuiltinMethod (type , profileInit , lookupNew , profileNewFactory , BuiltinConstructorsFactory .ObjectNodeFactory .class ) )) {
246
250
throw raise (TypeError , ErrorMessages .INIT_TAKES_ONE_ARG , type );
247
251
}
248
252
}
249
253
return PNone .NONE ;
250
254
}
251
255
256
+ protected static ValueProfile createLookupProfile () {
257
+ if (PythonLanguage .getCurrent ().singleContextAssumption .isValid ()) {
258
+ return ValueProfile .createIdentityProfile ();
259
+ } else {
260
+ return ValueProfile .createClassProfile ();
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Simple utility method to check if a method was overridden. The {@code profile} parameter
266
+ * must {@emph not} be an identity profile when AST sharing is enabled.
267
+ */
252
268
public static <T extends NodeFactory <? extends PythonBuiltinBaseNode >> boolean overridesBuiltinMethod (Object type , ValueProfile profile , LookupAttributeInMRONode lookup ,
253
- Class <T > builtinNodeFactoryClass ) {
269
+ ValueProfile factoryProfile , Class <T > builtinNodeFactoryClass ) {
254
270
Object method = profile .profile (lookup .execute (type ));
255
271
if (method instanceof PBuiltinFunction ) {
256
- NodeFactory <? extends PythonBuiltinBaseNode > factory = (( PBuiltinFunction ) method ).getBuiltinNodeFactory ();
272
+ NodeFactory <? extends PythonBuiltinBaseNode > factory = factoryProfile . profile ((( PBuiltinFunction ) method ).getBuiltinNodeFactory () );
257
273
return !builtinNodeFactoryClass .isInstance (factory );
258
274
}
259
275
return true ;
0 commit comments