218
218
import com .oracle .graal .python .nodes .expression .BinaryArithmetic ;
219
219
import com .oracle .graal .python .nodes .expression .BinaryComparisonNode ;
220
220
import com .oracle .graal .python .nodes .expression .BinaryOpNode ;
221
- import com .oracle .graal .python .nodes .expression .CoerceToBooleanNode ;
222
221
import com .oracle .graal .python .nodes .expression .TernaryArithmetic ;
223
222
import com .oracle .graal .python .nodes .frame .GetFrameLocalsNode ;
224
223
import com .oracle .graal .python .nodes .frame .ReadCallerFrameNode ;
@@ -334,9 +333,8 @@ public abstract static class AbsNode extends PythonUnaryBuiltinNode {
334
333
335
334
@ Specialization
336
335
static Object absObject (VirtualFrame frame , Object object ,
337
- @ Bind ("this" ) Node inliningTarget ,
338
336
@ Cached PyNumberAbsoluteNode absoluteNode ) {
339
- return absoluteNode .execute (frame , inliningTarget , object );
337
+ return absoluteNode .executeCached (frame , object );
340
338
}
341
339
}
342
340
@@ -403,11 +401,11 @@ static boolean doGenericSequence(VirtualFrame frame, Node inliningTarget, Sequen
403
401
404
402
for (int i = 0 ; loopConditionProfile .profile (inliningTarget , i < seqLength ); i ++) {
405
403
if (nodeType == AnyOrAllNodeType .ALL &&
406
- earlyExitProfile .profile (inliningTarget , !isTrueNode .execute (frame , inliningTarget , getItem .execute (inliningTarget , sequenceStorage , i )))) {
404
+ earlyExitProfile .profile (inliningTarget , !isTrueNode .execute (frame , getItem .execute (inliningTarget , sequenceStorage , i )))) {
407
405
LoopNode .reportLoopCount (inliningTarget , i );
408
406
return false ;
409
407
} else if (nodeType == AnyOrAllNodeType .ANY &&
410
- earlyExitProfile .profile (inliningTarget , isTrueNode .execute (frame , inliningTarget , getItem .execute (inliningTarget , sequenceStorage , i )))) {
408
+ earlyExitProfile .profile (inliningTarget , isTrueNode .execute (frame , getItem .execute (inliningTarget , sequenceStorage , i )))) {
411
409
LoopNode .reportLoopCount (inliningTarget , i );
412
410
return true ;
413
411
}
@@ -436,10 +434,10 @@ protected boolean doHashStorage(VirtualFrame frame, HashingStorage hashingStorag
436
434
while (loopConditionProfile .profile (inliningTarget , getIterNext .execute (inliningTarget , hashingStorage , it ))) {
437
435
Object key = getIterKey .execute (inliningTarget , hashingStorage , it );
438
436
if (nodeType == AnyOrAllNodeType .ALL ) {
439
- if (!isTrueNode .execute (frame , inliningTarget , key )) {
437
+ if (!isTrueNode .execute (frame , key )) {
440
438
return false ;
441
439
}
442
- } else if (nodeType == AnyOrAllNodeType .ANY && isTrueNode .execute (frame , inliningTarget , key )) {
440
+ } else if (nodeType == AnyOrAllNodeType .ANY && isTrueNode .execute (frame , key )) {
443
441
return true ;
444
442
}
445
443
}
@@ -485,7 +483,7 @@ static boolean doObject(VirtualFrame frame, Object object,
485
483
try {
486
484
Object next = nextNode .execute (frame , iterator );
487
485
nbrIter ++;
488
- if (!isTrueNode .execute (frame , inliningTarget , next )) {
486
+ if (!isTrueNode .execute (frame , next )) {
489
487
return false ;
490
488
}
491
489
} catch (PException e ) {
@@ -538,7 +536,7 @@ static boolean doObject(VirtualFrame frame, Object object,
538
536
try {
539
537
Object next = nextNode .execute (frame , iterator );
540
538
nbrIter ++;
541
- if (isTrueNode .execute (frame , inliningTarget , next )) {
539
+ if (isTrueNode .execute (frame , next )) {
542
540
return true ;
543
541
}
544
542
} catch (PException e ) {
@@ -1458,35 +1456,35 @@ public IsInstanceNode createRecursive(byte newDepth) {
1458
1456
return BuiltinFunctionsFactory .IsInstanceNodeFactory .create (newDepth );
1459
1457
}
1460
1458
1461
- private static TriState isInstanceCheckInternal (VirtualFrame frame , Node inliningTarget , Object instance , Object cls , LookupAndCallBinaryNode instanceCheckNode ,
1462
- CoerceToBooleanNode castToBooleanNode ) {
1459
+ private static TriState isInstanceCheckInternal (VirtualFrame frame , Object instance , Object cls , LookupAndCallBinaryNode instanceCheckNode ,
1460
+ PyObjectIsTrueNode castToBooleanNode ) {
1463
1461
Object instanceCheckResult = instanceCheckNode .executeObject (frame , cls , instance );
1464
1462
if (instanceCheckResult == NOT_IMPLEMENTED ) {
1465
1463
return TriState .UNDEFINED ;
1466
1464
}
1467
- return TriState .valueOf (castToBooleanNode .executeBoolean (frame , inliningTarget , instanceCheckResult ));
1465
+ return TriState .valueOf (castToBooleanNode .execute (frame , instanceCheckResult ));
1468
1466
}
1469
1467
1470
1468
@ Specialization (guards = "isPythonClass(cls)" )
1471
1469
static boolean isInstance (VirtualFrame frame , Object instance , Object cls ,
1472
1470
@ Bind ("this" ) Node inliningTarget ,
1473
1471
@ Shared ("instanceCheck" ) @ Cached ("create(InstanceCheck)" ) LookupAndCallBinaryNode instanceCheckNode ,
1474
- @ Exclusive @ Cached CoerceToBooleanNode . YesNode castToBooleanNode ,
1472
+ @ Exclusive @ Cached PyObjectIsTrueNode castToBooleanNode ,
1475
1473
@ Cached GetClassNode getClassNode ,
1476
1474
@ Cached IsSameTypeNode isSameTypeNode ,
1477
1475
@ Cached IsSubtypeNode isSubtypeNode ) {
1478
1476
Object instanceClass = getClassNode .execute (inliningTarget , instance );
1479
1477
return isSameTypeNode .execute (inliningTarget , instanceClass , cls ) || isSubtypeNode .execute (frame , instanceClass , cls )//
1480
- || isInstanceCheckInternal (frame , inliningTarget , instance , cls , instanceCheckNode , castToBooleanNode ) == TriState .TRUE ;
1478
+ || isInstanceCheckInternal (frame , instance , cls , instanceCheckNode , castToBooleanNode ) == TriState .TRUE ;
1481
1479
}
1482
1480
1483
1481
@ Specialization (guards = {"!isPTuple(cls)" , "!isPythonClass(cls)" })
1484
1482
static boolean isInstance (VirtualFrame frame , Object instance , Object cls ,
1485
1483
@ Bind ("this" ) Node inliningTarget ,
1486
1484
@ Shared ("instanceCheck" ) @ Cached ("create(InstanceCheck)" ) LookupAndCallBinaryNode instanceCheckNode ,
1487
- @ Exclusive @ Cached CoerceToBooleanNode . YesNode castToBooleanNode ,
1485
+ @ Exclusive @ Cached PyObjectIsTrueNode castToBooleanNode ,
1488
1486
@ Cached TypeBuiltins .InstanceCheckNode typeInstanceCheckNode ) {
1489
- TriState check = isInstanceCheckInternal (frame , inliningTarget , instance , cls , instanceCheckNode , castToBooleanNode );
1487
+ TriState check = isInstanceCheckInternal (frame , instance , cls , instanceCheckNode , castToBooleanNode );
1490
1488
if (check == TriState .UNDEFINED ) {
1491
1489
return typeInstanceCheckNode .executeWith (frame , cls , instance );
1492
1490
}
@@ -1515,13 +1513,12 @@ public IsSubClassNode createRecursive(byte newDepth) {
1515
1513
1516
1514
@ Specialization (guards = "!isPTuple(cls)" )
1517
1515
static boolean isSubclass (VirtualFrame frame , Object derived , Object cls ,
1518
- @ Bind ("this" ) Node inliningTarget ,
1519
1516
@ Cached ("create(Subclasscheck)" ) LookupAndCallBinaryNode subclassCheckNode ,
1520
- @ Cached CoerceToBooleanNode . YesNode castToBooleanNode ,
1517
+ @ Cached PyObjectIsTrueNode castToBooleanNode ,
1521
1518
@ Cached IsSubtypeNode isSubtypeNode ) {
1522
1519
Object instanceCheckResult = subclassCheckNode .executeObject (frame , cls , derived );
1523
1520
if (instanceCheckResult != NOT_IMPLEMENTED ) {
1524
- return castToBooleanNode .executeBoolean (frame , inliningTarget , instanceCheckResult );
1521
+ return castToBooleanNode .execute (frame , instanceCheckResult );
1525
1522
}
1526
1523
return isSubtypeNode .execute (frame , derived , cls );
1527
1524
}
@@ -1583,7 +1580,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
1583
1580
BinaryComparisonNode compare ,
1584
1581
@ Exclusive @ Cached PyObjectGetIter getIter ,
1585
1582
@ Cached (inline = false ) GetNextNode nextNode ,
1586
- @ Exclusive @ Cached CoerceToBooleanNode . YesNode castToBooleanNode ,
1583
+ @ Exclusive @ Cached PyObjectIsTrueNode castToBooleanNode ,
1587
1584
@ Exclusive @ Cached CallNode .Lazy keyCall ,
1588
1585
@ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
1589
1586
@ Exclusive @ Cached InlinedConditionProfile keywordArgIsNone ,
@@ -1624,10 +1621,10 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
1624
1621
isTrue = compare .executeBool (frame , nextKey , currentKey );
1625
1622
} catch (UnexpectedResultException e ) {
1626
1623
seenNonBoolean .enter (inliningTarget );
1627
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , e .getResult ());
1624
+ isTrue = castToBooleanNode .execute (frame , e .getResult ());
1628
1625
}
1629
1626
} else {
1630
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , compare .executeObject (frame , nextKey , currentKey ));
1627
+ isTrue = castToBooleanNode .execute (frame , compare .executeObject (frame , nextKey , currentKey ));
1631
1628
}
1632
1629
if (isTrue ) {
1633
1630
currentKey = nextKey ;
@@ -1644,7 +1641,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
1644
1641
@ Specialization (guards = {"args.length != 0" })
1645
1642
static Object minmaxBinaryWithKey (VirtualFrame frame , Node inliningTarget , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal , String name , BinaryComparisonNode compare ,
1646
1643
@ Exclusive @ Cached CallNode .Lazy keyCall ,
1647
- @ Exclusive @ Cached CoerceToBooleanNode . YesNode castToBooleanNode ,
1644
+ @ Exclusive @ Cached PyObjectIsTrueNode castToBooleanNode ,
1648
1645
@ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
1649
1646
@ Exclusive @ Cached InlinedConditionProfile keywordArgIsNone ,
1650
1647
@ Exclusive @ Cached InlinedConditionProfile moreThanTwo ,
@@ -1668,10 +1665,10 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
1668
1665
isTrue = compare .executeBool (frame , nextKey , currentKey );
1669
1666
} catch (UnexpectedResultException e ) {
1670
1667
seenNonBoolean .enter (inliningTarget );
1671
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , e .getResult ());
1668
+ isTrue = castToBooleanNode .execute (frame , e .getResult ());
1672
1669
}
1673
1670
} else {
1674
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , compare .executeObject (frame , nextKey , currentKey ));
1671
+ isTrue = castToBooleanNode .execute (frame , compare .executeObject (frame , nextKey , currentKey ));
1675
1672
}
1676
1673
if (isTrue ) {
1677
1674
currentKey = nextKey ;
@@ -1688,10 +1685,10 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
1688
1685
isTrue = compare .executeBool (frame , nextKey , currentKey );
1689
1686
} catch (UnexpectedResultException e ) {
1690
1687
seenNonBoolean .enter (inliningTarget );
1691
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , e .getResult ());
1688
+ isTrue = castToBooleanNode .execute (frame , e .getResult ());
1692
1689
}
1693
1690
} else {
1694
- isTrue = castToBooleanNode .executeBoolean (frame , inliningTarget , compare .executeObject (frame , nextKey , currentKey ));
1691
+ isTrue = castToBooleanNode .execute (frame , compare .executeObject (frame , nextKey , currentKey ));
1695
1692
}
1696
1693
if (isTrue ) {
1697
1694
currentKey = nextKey ;
@@ -1882,7 +1879,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1882
1879
@ Bind ("this" ) Node inliningTarget ,
1883
1880
@ Cached CastToTruffleStringNode castSep ,
1884
1881
@ Cached CastToTruffleStringNode castEnd ,
1885
- @ Cached CoerceToBooleanNode . YesNode castFlush ,
1882
+ @ Cached PyObjectIsTrueNode castFlush ,
1886
1883
@ Exclusive @ Cached PyObjectGetAttr getWriteMethod ,
1887
1884
@ Exclusive @ Cached CallNode callWrite ,
1888
1885
@ Exclusive @ Cached PyObjectCallMethodObjArgs callFlush ,
@@ -1916,7 +1913,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1916
1913
if (flushIn instanceof PNone ) {
1917
1914
flush = false ;
1918
1915
} else {
1919
- flush = castFlush .executeBoolean (frame , inliningTarget , flushIn );
1916
+ flush = castFlush .execute (frame , flushIn );
1920
1917
}
1921
1918
return printAllGiven (frame , values , sep , end , file , flush , inliningTarget , getWriteMethod , callWrite , callFlush , strNode );
1922
1919
}
@@ -2152,21 +2149,18 @@ public abstract static class SumFunctionNode extends PythonBuiltinNode {
2152
2149
2153
2150
@ Child private LookupAndCallUnaryNode next = LookupAndCallUnaryNode .create (SpecialMethodSlot .Next );
2154
2151
2155
- @ Specialization (guards = "isNoValue(start)" , rewriteOn = UnexpectedResultException .class )
2156
- int sumIntNone (VirtualFrame frame , Object arg1 , @ SuppressWarnings ("unused" ) PNone start ,
2157
- @ Bind ("this" ) Node inliningTarget ,
2158
- @ Shared @ Cached PyNumberAddNode addNode ,
2159
- @ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2160
- @ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) throws UnexpectedResultException {
2161
- return sumIntInternal (frame , inliningTarget , arg1 , 0 , addNode , getIter , errorProfile );
2152
+ public static boolean isIntOrNone (Object o ) {
2153
+ return o instanceof Integer || PGuards .isNoValue (o );
2162
2154
}
2163
2155
2164
- @ Specialization (rewriteOn = UnexpectedResultException .class )
2165
- int sumIntInt (VirtualFrame frame , Object arg1 , int start ,
2156
+ @ Specialization (guards = "isIntOrNone(startIn)" , rewriteOn = UnexpectedResultException .class )
2157
+ int sumInt (VirtualFrame frame , Object arg1 , Object startIn ,
2166
2158
@ Bind ("this" ) Node inliningTarget ,
2159
+ @ Shared @ Cached InlinedConditionProfile hasStart ,
2167
2160
@ Shared @ Cached PyNumberAddNode addNode ,
2168
2161
@ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2169
2162
@ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) throws UnexpectedResultException {
2163
+ int start = hasStart .profile (inliningTarget , startIn instanceof Integer ) ? (Integer ) startIn : 0 ;
2170
2164
return sumIntInternal (frame , inliningTarget , arg1 , start , addNode , getIter , errorProfile );
2171
2165
}
2172
2166
@@ -2229,7 +2223,7 @@ private double sumDoubleInternal(VirtualFrame frame, Node inliningTarget, Object
2229
2223
}
2230
2224
}
2231
2225
2232
- @ Specialization (replaces = {"sumIntNone" , "sumIntInt " , "sumDoubleDouble" })
2226
+ @ Specialization (replaces = {"sumInt " , "sumDoubleDouble" })
2233
2227
Object sum (VirtualFrame frame , Object arg1 , Object start ,
2234
2228
@ Bind ("this" ) Node inliningTarget ,
2235
2229
@ Shared @ Cached PyNumberAddNode addNode ,
0 commit comments