101
101
import com .oracle .graal .python .nodes .BuiltinNames ;
102
102
import com .oracle .graal .python .nodes .ErrorMessages ;
103
103
import com .oracle .graal .python .nodes .PGuards ;
104
+ import com .oracle .graal .python .nodes .PNodeWithContext ;
104
105
import com .oracle .graal .python .nodes .PNodeWithRaise ;
105
106
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
106
107
import com .oracle .graal .python .nodes .argument .positional .PositionalArgumentsNode ;
113
114
import com .oracle .graal .python .nodes .call .special .CallTernaryMethodNode ;
114
115
import com .oracle .graal .python .nodes .call .special .CallVarargsMethodNode ;
115
116
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
116
- import com .oracle .graal .python .nodes .call .special .LookupAndCallTernaryNode ;
117
117
import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodNode ;
118
118
import com .oracle .graal .python .nodes .classes .AbstractObjectGetBasesNode ;
119
119
import com .oracle .graal .python .nodes .classes .AbstractObjectIsSubclassNode ;
@@ -363,11 +363,42 @@ Object selfSeparate(VirtualFrame frame, Object self, Object[] arguments, PKeywor
363
363
}
364
364
}
365
365
366
+ @ ReportPolymorphism
367
+ protected abstract static class BindNew extends PNodeWithContext {
368
+ public abstract Object execute (VirtualFrame frame , Object descriptor , Object type );
369
+
370
+ @ Specialization
371
+ static Object doBuiltin (PBuiltinFunction descriptor , @ SuppressWarnings ("unused" ) Object type ) {
372
+ return descriptor ;
373
+ }
374
+
375
+ @ Specialization
376
+ static Object doFunction (PFunction descriptor , @ SuppressWarnings ("unused" ) Object type ) {
377
+ return descriptor ;
378
+ }
379
+
380
+ @ Fallback
381
+ static Object doBind (VirtualFrame frame , Object descriptor , Object type ,
382
+ @ Cached GetClassNode getClassNode ,
383
+ @ Cached (parameters = "Get" ) LookupCallableSlotInMRONode lookupGet ,
384
+ @ Cached CallTernaryMethodNode callGet ) {
385
+ Object getMethod = lookupGet .execute (getClassNode .execute (descriptor ));
386
+ if (getMethod != PNone .NO_VALUE ) {
387
+ return callGet .execute (frame , getMethod , descriptor , PNone .NONE , type );
388
+ }
389
+ return descriptor ;
390
+ }
391
+
392
+ public static BindNew create () {
393
+ return TypeBuiltinsFactory .BindNewNodeGen .create ();
394
+ }
395
+ }
396
+
366
397
@ ReportPolymorphism
367
398
protected abstract static class CallNodeHelper extends PNodeWithRaise {
368
399
@ Child private CallVarargsMethodNode dispatchNew = CallVarargsMethodNode .create ();
369
- @ Child private LookupAndCallTernaryNode callNewGet = LookupAndCallTernaryNode .create (__GET__ );
370
400
@ Child private LookupAttributeInMRONode lookupNew = LookupAttributeInMRONode .create (__NEW__ );
401
+ @ Child private BindNew bindNew = BindNew .create ();
371
402
@ Child private CallVarargsMethodNode dispatchInit ;
372
403
@ Child private LookupSpecialMethodNode lookupInit ;
373
404
@ Child private IsSubtypeNode isSubTypeNode ;
@@ -378,8 +409,6 @@ protected abstract static class CallNodeHelper extends PNodeWithRaise {
378
409
@ CompilationFinal private ConditionProfile hasInit = ConditionProfile .createBinaryProfile ();
379
410
@ CompilationFinal private ConditionProfile gotInitResult = ConditionProfile .createBinaryProfile ();
380
411
381
- @ CompilationFinal private boolean newWasDescriptor = false ;
382
-
383
412
abstract Object execute (VirtualFrame frame , Object self , Object [] args , PKeyword [] keywords , boolean doCreateArgs );
384
413
385
414
@ Specialization (limit = "getCallSiteInlineCacheMaxDepth()" , guards = {"self == cachedSelf" }, assumptions = "singleContextAssumption()" )
@@ -450,17 +479,7 @@ private Object op(VirtualFrame frame, Object self, Object[] arguments, PKeyword[
450
479
if (hasNew .profile (newMethod != PNone .NO_VALUE )) {
451
480
CompilerAsserts .partialEvaluationConstant (doCreateArgs );
452
481
Object [] newArgs = doCreateArgs ? PositionalArgumentsNode .prependArgument (self , arguments ) : arguments ;
453
- Object newInstance ;
454
- if (!newWasDescriptor && (newMethod instanceof PFunction || newMethod instanceof PBuiltinFunction )) {
455
- newInstance = dispatchNew .execute (frame , newMethod , newArgs , keywords );
456
- } else {
457
- if (!newWasDescriptor ) {
458
- CompilerDirectives .transferToInterpreterAndInvalidate ();
459
- reportPolymorphicSpecialize ();
460
- newWasDescriptor = true ;
461
- }
462
- newInstance = dispatchNew .execute (frame , callNewGet .execute (frame , newMethod , PNone .NONE , self ), newArgs , keywords );
463
- }
482
+ Object newInstance = dispatchNew .execute (frame , bindNew .execute (frame , newMethod , self ), newArgs , keywords );
464
483
465
484
// see typeobject.c#type_call()
466
485
// Ugly exception: when the call was type(something),
0 commit comments