50
50
import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
51
51
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
52
52
import com .oracle .graal .python .nodes .object .GetClassNode ;
53
+ import com .oracle .graal .python .runtime .PythonOptions ;
53
54
import com .oracle .graal .python .util .Supplier ;
54
55
import com .oracle .truffle .api .CompilerDirectives ;
55
56
import com .oracle .truffle .api .dsl .Cached ;
73
74
// Although it would produce correct results, the special handling of long to double comparison
74
75
// is slower than converting int->double, which is always correct.
75
76
@ ReportPolymorphism
77
+ @ ImportStatic (PythonOptions .class )
76
78
public abstract class LookupAndCallBinaryNode extends Node {
77
79
78
80
public abstract static class NotImplementedHandler extends PNodeWithContext {
@@ -283,51 +285,51 @@ boolean callBoolean(VirtualFrame frame, long left, long right,
283
285
// int, double
284
286
285
287
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
286
- boolean callBoolean (VirtualFrame frame , int left , double right ,
288
+ static boolean callBoolean (VirtualFrame frame , int left , double right ,
287
289
@ Cached ("getBuiltin(right)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
288
290
return function .executeBool (frame , left , right );
289
291
}
290
292
291
293
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
292
- boolean callBoolean (VirtualFrame frame , double left , int right ,
294
+ static boolean callBoolean (VirtualFrame frame , double left , int right ,
293
295
@ Cached ("getBuiltin(left)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
294
296
return function .executeBool (frame , left , right );
295
297
}
296
298
297
299
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
298
- double callDouble (VirtualFrame frame , int left , double right ,
300
+ static double callDouble (VirtualFrame frame , int left , double right ,
299
301
@ Cached ("getBuiltin(right)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
300
302
return function .executeDouble (frame , left , right );
301
303
}
302
304
303
305
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
304
- double callDouble (VirtualFrame frame , double left , int right ,
306
+ static double callDouble (VirtualFrame frame , double left , int right ,
305
307
@ Cached ("getBuiltin(left)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
306
308
return function .executeDouble (frame , left , right );
307
309
}
308
310
309
311
// long, double
310
312
311
313
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
312
- boolean callBoolean (VirtualFrame frame , long left , double right ,
314
+ static boolean callBoolean (VirtualFrame frame , long left , double right ,
313
315
@ Cached ("getBuiltin(right)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
314
316
return function .executeBool (frame , left , right );
315
317
}
316
318
317
319
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
318
- boolean callBoolean (VirtualFrame frame , double left , long right ,
320
+ static boolean callBoolean (VirtualFrame frame , double left , long right ,
319
321
@ Cached ("getBuiltin(left)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
320
322
return function .executeBool (frame , left , right );
321
323
}
322
324
323
325
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
324
- double callDouble (VirtualFrame frame , long left , double right ,
326
+ static double callDouble (VirtualFrame frame , long left , double right ,
325
327
@ Cached ("getBuiltin(right)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
326
328
return function .executeDouble (frame , left , right );
327
329
}
328
330
329
331
@ Specialization (guards = "function != null" , rewriteOn = UnexpectedResultException .class )
330
- double callDouble (VirtualFrame frame , double left , long right ,
332
+ static double callDouble (VirtualFrame frame , double left , long right ,
331
333
@ Cached ("getBuiltin(left)" ) PythonBinaryBuiltinNode function ) throws UnexpectedResultException {
332
334
return function .executeDouble (frame , left , right );
333
335
}
@@ -356,7 +358,7 @@ boolean callBoolean(VirtualFrame frame, double left, double right,
356
358
357
359
// Object, Object
358
360
359
- @ Specialization (guards = {"!isReversible()" }, limit = "2 " )
361
+ @ Specialization (guards = {"!isReversible()" }, limit = "5 " )
360
362
Object callObject (VirtualFrame frame , Object left , Object right ,
361
363
@ CachedLibrary ("left" ) PythonObjectLibrary libLeft ,
362
364
@ Cached ("create(name, ignoreDescriptorException)" ) LookupSpecialMethodNode getattr ) {
@@ -373,8 +375,15 @@ Object callObject(VirtualFrame frame, Object left, Object right,
373
375
return ensureDispatch ().executeObject (frame , leftCallable , leftValue , right );
374
376
}
375
377
376
- @ Specialization (guards = {"isReversible()" }, limit = "4" )
377
- Object callObject (VirtualFrame frame , Object left , Object right ,
378
+ @ Specialization (guards = {"!isReversible()" }, replaces = "callObject" )
379
+ Object callObjectUncached (VirtualFrame frame , Object left , Object right ,
380
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary libLeft ,
381
+ @ Cached ("create(name, ignoreDescriptorException)" ) LookupSpecialMethodNode getattr ) {
382
+ return callObject (frame , left , right , libLeft , getattr );
383
+ }
384
+
385
+ @ Specialization (guards = {"isReversible()" }, limit = "5" )
386
+ Object callObjectR (VirtualFrame frame , Object left , Object right ,
378
387
@ Cached ("create(name, ignoreDescriptorException)" ) LookupSpecialMethodNode getattr ,
379
388
@ Cached ("create(rname, ignoreDescriptorException)" ) LookupSpecialMethodNode getattrR ,
380
389
@ CachedLibrary ("left" ) PythonObjectLibrary libLeft ,
@@ -424,6 +433,18 @@ Object callObject(VirtualFrame frame, Object left, Object right,
424
433
return result ;
425
434
}
426
435
436
+ @ Specialization (guards = {"isReversible()" }, replaces = "callObjectR" )
437
+ Object callObjectRUncached (VirtualFrame frame , Object left , Object right ,
438
+ @ Cached ("create(name, ignoreDescriptorException)" ) LookupSpecialMethodNode getattr ,
439
+ @ Cached ("create(rname, ignoreDescriptorException)" ) LookupSpecialMethodNode getattrR ,
440
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary libLeft ,
441
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary libRight ,
442
+ @ Cached ("create()" ) TypeNodes .IsSameTypeNode isSameTypeNode ,
443
+ @ Cached ("create()" ) IsSubtypeNode isSubtype ,
444
+ @ Cached ("createBinaryProfile()" ) ConditionProfile notImplementedBranch ) {
445
+ return callObjectR (frame , left , right , getattr , getattrR , libLeft , libRight , isSameTypeNode , isSubtype , notImplementedBranch );
446
+ }
447
+
427
448
private Object runErrorHandler (Object left , Object right ) {
428
449
if (handler == null ) {
429
450
CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments