61
61
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
62
62
import com .oracle .graal .python .nodes .object .GetClassNode ;
63
63
import com .oracle .graal .python .runtime .PythonOptions ;
64
+ import com .oracle .graal .python .runtime .exception .PException ;
64
65
import com .oracle .graal .python .util .Supplier ;
65
66
import com .oracle .truffle .api .CompilerDirectives ;
66
67
import com .oracle .truffle .api .dsl .Cached ;
@@ -174,7 +175,7 @@ public static LookupAndCallBinaryNode create(String name, String rname, Supplier
174
175
}
175
176
176
177
protected Object getMethod (Object receiver , String methodName ) {
177
- return LookupSpecialMethodNode .Dynamic .getUncached ().execute (null , GetClassNode .getUncached ().execute (receiver ), methodName , receiver , ignoreDescriptorException );
178
+ return LookupSpecialMethodNode .Dynamic .getUncached ().execute (null , GetClassNode .getUncached ().execute (receiver ), methodName , receiver );
178
179
}
179
180
180
181
protected boolean isReversible () {
@@ -217,7 +218,17 @@ private CallBinaryMethodNode ensureReverseDispatch() {
217
218
218
219
private UnexpectedResultException handleLeftURE (VirtualFrame frame , Object left , Object right , UnexpectedResultException e ) throws UnexpectedResultException {
219
220
if (isReversible () && e .getResult () == PNotImplemented .NOT_IMPLEMENTED ) {
220
- throw new UnexpectedResultException (ensureReverseDispatch ().executeObject (frame , getMethod (right , rname ), right , left ));
221
+ Object method ;
222
+ try {
223
+ method = getMethod (right , rname );
224
+ } catch (PException e1 ) {
225
+ if (ignoreDescriptorException ) {
226
+ throw e ;
227
+ } else {
228
+ throw e1 ;
229
+ }
230
+ }
231
+ throw new UnexpectedResultException (ensureReverseDispatch ().executeObject (frame , method , right , left ));
221
232
} else {
222
233
throw e ;
223
234
}
@@ -392,21 +403,30 @@ Object callObjectGeneric(VirtualFrame frame, Object left, Object right,
392
403
@ SuppressWarnings ("unused" ) @ Cached ("left.getClass()" ) Class <?> cachedLeftClass ,
393
404
@ SuppressWarnings ("unused" ) @ Cached ("right.getClass()" ) Class <?> cachedRightClass ,
394
405
@ Cached GetClassNode getClassNode ,
395
- @ Cached ("create(name, ignoreDescriptorException )" ) LookupSpecialMethodSlotNode getattr ) {
406
+ @ Cached ("create(name)" ) LookupSpecialMethodSlotNode getattr ) {
396
407
return doCallObject (frame , left , right , getClassNode , getattr );
397
408
}
398
409
399
410
@ Specialization (guards = "!isReversible()" , replaces = "callObjectGeneric" )
400
411
@ Megamorphic
401
412
Object callObjectMegamorphic (VirtualFrame frame , Object left , Object right ,
402
413
@ Cached GetClassNode getClassNode ,
403
- @ Cached ("create(name, ignoreDescriptorException )" ) LookupSpecialMethodSlotNode getattr ) {
414
+ @ Cached ("create(name)" ) LookupSpecialMethodSlotNode getattr ) {
404
415
return doCallObject (frame , left , right , getClassNode , getattr );
405
416
}
406
417
407
418
private Object doCallObject (VirtualFrame frame , Object left , Object right , GetClassNode getClassNode , LookupSpecialMethodSlotNode getattr ) {
408
419
Object leftClass = getClassNode .execute (left );
409
- Object leftCallable = getattr .execute (frame , leftClass , left );
420
+ Object leftCallable ;
421
+ try {
422
+ leftCallable = getattr .execute (frame , leftClass , left );
423
+ } catch (PException e ) {
424
+ if (ignoreDescriptorException ) {
425
+ leftCallable = PNone .NO_VALUE ;
426
+ } else {
427
+ throw e ;
428
+ }
429
+ }
410
430
if (leftCallable == PNone .NO_VALUE ) {
411
431
if (handlerFactory != null ) {
412
432
return runErrorHandler (frame , left , right );
@@ -421,8 +441,8 @@ private Object doCallObject(VirtualFrame frame, Object left, Object right, GetCl
421
441
Object callObjectGenericR (VirtualFrame frame , Object left , Object right ,
422
442
@ SuppressWarnings ("unused" ) @ Cached ("left.getClass()" ) Class <?> cachedLeftClass ,
423
443
@ SuppressWarnings ("unused" ) @ Cached ("right.getClass()" ) Class <?> cachedRightClass ,
424
- @ Cached ("create(name, ignoreDescriptorException )" ) LookupSpecialMethodNode getattr ,
425
- @ Cached ("create(rname, ignoreDescriptorException )" ) LookupSpecialMethodNode getattrR ,
444
+ @ Cached ("create(name)" ) LookupSpecialMethodNode getattr ,
445
+ @ Cached ("create(rname)" ) LookupSpecialMethodNode getattrR ,
426
446
@ Cached GetClassNode getLeftClassNode ,
427
447
@ Cached GetClassNode getRightClassNode ,
428
448
@ Cached TypeNodes .IsSameTypeNode isSameTypeNode ,
@@ -441,8 +461,8 @@ Object callObjectGenericR(VirtualFrame frame, Object left, Object right,
441
461
@ Specialization (guards = "isReversible()" , replaces = "callObjectGenericR" )
442
462
@ Megamorphic
443
463
Object callObjectRMegamorphic (VirtualFrame frame , Object left , Object right ,
444
- @ Cached ("create(name, ignoreDescriptorException )" ) LookupSpecialMethodNode getattr ,
445
- @ Cached ("create(rname, ignoreDescriptorException )" ) LookupSpecialMethodNode getattrR ,
464
+ @ Cached ("create(name)" ) LookupSpecialMethodNode getattr ,
465
+ @ Cached ("create(rname)" ) LookupSpecialMethodNode getattrR ,
446
466
@ Cached GetClassNode getLeftClassNode ,
447
467
@ Cached GetClassNode getRightClassNode ,
448
468
@ Cached TypeNodes .IsSameTypeNode isSameTypeNode ,
@@ -474,9 +494,27 @@ private Object doCallObjectR(VirtualFrame frame, Object left, Object right, Look
474
494
475
495
Object result = PNotImplemented .NOT_IMPLEMENTED ;
476
496
Object leftClass = getLeftClassNode .execute (left );
477
- Object leftCallable = getattr .execute (frame , leftClass , left );
497
+ Object leftCallable ;
498
+ try {
499
+ leftCallable = getattr .execute (frame , leftClass , left );
500
+ } catch (PException e ) {
501
+ if (ignoreDescriptorException ) {
502
+ leftCallable = PNone .NO_VALUE ;
503
+ } else {
504
+ throw e ;
505
+ }
506
+ }
478
507
Object rightClass = getRightClassNode .execute (right );
479
- Object rightCallable = getattrR .execute (frame , rightClass , right );
508
+ Object rightCallable ;
509
+ try {
510
+ rightCallable = getattrR .execute (frame , rightClass , right );
511
+ } catch (PException e ) {
512
+ if (ignoreDescriptorException ) {
513
+ rightCallable = PNone .NO_VALUE ;
514
+ } else {
515
+ throw e ;
516
+ }
517
+ }
480
518
481
519
if (!alwaysCheckReverse && leftCallable == rightCallable ) {
482
520
rightCallable = PNone .NO_VALUE ;
0 commit comments