154
154
import com .oracle .graal .python .builtins .objects .range .PBigRange ;
155
155
import com .oracle .graal .python .builtins .objects .range .PIntRange ;
156
156
import com .oracle .graal .python .builtins .objects .range .RangeNodes ;
157
+ import com .oracle .graal .python .builtins .objects .range .RangeNodes .LenOfIntRangeNodeExact ;
157
158
import com .oracle .graal .python .builtins .objects .set .PFrozenSet ;
158
159
import com .oracle .graal .python .builtins .objects .set .PSet ;
159
160
import com .oracle .graal .python .builtins .objects .str .PString ;
212
213
import com .oracle .graal .python .runtime .sequence .storage .ObjectSequenceStorage ;
213
214
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
214
215
import com .oracle .graal .python .util .PythonUtils ;
216
+ import com .oracle .graal .python .util .OverflowException ;
215
217
import com .oracle .truffle .api .Assumption ;
216
218
import com .oracle .truffle .api .CompilerAsserts ;
217
219
import com .oracle .truffle .api .CompilerDirectives ;
@@ -700,7 +702,7 @@ public PythonObject reversed(@SuppressWarnings("unused") Object cls, PIntRange r
700
702
int lstart = range .getIntStart ();
701
703
int lstop = range .getIntStop ();
702
704
int lstep = range .getIntStep ();
703
- int ulen = lenOfRangeNode .len (lstart , lstop , lstep );
705
+ int ulen = lenOfRangeNode .executeInt (lstart , lstop , lstep );
704
706
int new_stop = lstart - lstep ;
705
707
int new_start = new_stop + ulen * lstep ;
706
708
@@ -714,7 +716,7 @@ public PythonObject reversed(@SuppressWarnings("unused") Object cls, PBigRange r
714
716
BigInteger lstart = range .getBigIntegerStart ();
715
717
BigInteger lstop = range .getBigIntegerStop ();
716
718
BigInteger lstep = range .getBigIntegerStep ();
717
- BigInteger ulen = ( BigInteger ) lenOfRangeNode .execute (lstart , lstop , lstep );
719
+ BigInteger ulen = lenOfRangeNode .execute (lstart , lstop , lstep );
718
720
719
721
BigInteger new_stop = lstart .subtract (lstep );
720
722
BigInteger new_start = new_stop .add (ulen .multiply (lstep ));
@@ -1648,9 +1650,9 @@ public abstract static class RangeNode extends PythonQuaternaryBuiltinNode {
1648
1650
Object doIntStop (Object cls , int stop , @ SuppressWarnings ("unused" ) PNone start , @ SuppressWarnings ("unused" ) PNone step ,
1649
1651
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1650
1652
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1651
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1653
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNodeExact ,
1652
1654
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ) {
1653
- return doInt (cls , 0 , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode );
1655
+ return doInt (cls , 0 , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode );
1654
1656
}
1655
1657
1656
1658
@ Specialization (guards = "isStop(start, stop, step)" )
@@ -1664,21 +1666,21 @@ Object doPintStop(Object cls, PInt stop, @SuppressWarnings("unused") PNone start
1664
1666
Object doGenericStop (Object cls , Object stop , @ SuppressWarnings ("unused" ) PNone start , @ SuppressWarnings ("unused" ) PNone step ,
1665
1667
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1666
1668
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1667
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1669
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNodeExact ,
1668
1670
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ,
1669
1671
@ Shared ("polGeneric" ) @ CachedLibrary (limit = "3" ) PythonObjectLibrary pol ,
1670
1672
@ Shared ("libGeneric" ) @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
1671
- return doGeneric (cls , 0 , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode , pol , lib );
1673
+ return doGeneric (cls , 0 , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode , pol , lib );
1672
1674
}
1673
1675
1674
1676
// start stop
1675
1677
@ Specialization (guards = "isStartStop(start, stop, step)" )
1676
1678
Object doIntStartStop (Object cls , int start , int stop , @ SuppressWarnings ("unused" ) PNone step ,
1677
1679
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1678
1680
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1679
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1681
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNodeExact ,
1680
1682
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ) {
1681
- return doInt (cls , start , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode );
1683
+ return doInt (cls , start , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode );
1682
1684
}
1683
1685
1684
1686
@ Specialization (guards = "isStartStop(start, stop, step)" )
@@ -1692,27 +1694,27 @@ Object doPintStartStop(Object cls, PInt start, PInt stop, @SuppressWarnings("unu
1692
1694
Object doGenericStartStop (Object cls , Object start , Object stop , @ SuppressWarnings ("unused" ) PNone step ,
1693
1695
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1694
1696
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1695
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1697
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNodeExact ,
1696
1698
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ,
1697
1699
@ Shared ("polGeneric" ) @ CachedLibrary (limit = "3" ) PythonObjectLibrary pol ,
1698
1700
@ Shared ("libGeneric" ) @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
1699
- return doGeneric (cls , start , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode , pol , lib );
1701
+ return doGeneric (cls , start , stop , 1 , stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode , pol , lib );
1700
1702
}
1701
1703
1702
1704
// start stop step
1703
1705
@ Specialization
1704
1706
Object doInt (@ SuppressWarnings ("unused" ) Object cls , int start , int stop , int step ,
1705
1707
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1706
1708
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1707
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1709
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNode ,
1708
1710
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ) {
1709
1711
if (stepZeroProfile .profile (step == 0 )) {
1710
1712
throw raise (ValueError , ARG_MUST_NOT_BE_ZERO , "range()" , 3 );
1711
1713
}
1712
1714
try {
1713
- int len = lenOfRangeNode .len (start , stop , step );
1715
+ int len = lenOfRangeNode .executeInt (start , stop , step );
1714
1716
return factory ().createIntRange (start , stop , step , len );
1715
- } catch (ArithmeticException e ) {
1717
+ } catch (OverflowException e ) {
1716
1718
exceptionProfile .enter ();
1717
1719
return createBigRangeNode .execute (start , stop , step , factory ());
1718
1720
}
@@ -1725,20 +1727,20 @@ Object doPint(@SuppressWarnings("unused") Object cls, PInt start, PInt stop, PIn
1725
1727
if (stepZeroProfile .profile (step .isZero ())) {
1726
1728
throw raise (ValueError , ARG_MUST_NOT_BE_ZERO , "range()" , 3 );
1727
1729
}
1728
- BigInteger len = ( BigInteger ) lenOfRangeNode .execute (start , stop , step );
1730
+ BigInteger len = lenOfRangeNode .execute (start . getValue () , stop . getValue () , step . getValue () );
1729
1731
return factory ().createBigRange (start , stop , step , factory ().createInt (len ));
1730
1732
}
1731
1733
1732
1734
@ Specialization (guards = "isStartStopStep(start, stop, step)" )
1733
1735
Object doGeneric (@ SuppressWarnings ("unused" ) Object cls , Object start , Object stop , Object step ,
1734
1736
@ Shared ("stepZeroProfile" ) @ Cached ConditionProfile stepZeroProfile ,
1735
1737
@ Shared ("exceptionProfile" ) @ Cached BranchProfile exceptionProfile ,
1736
- @ Shared ("lenOfRangeNode " ) @ Cached RangeNodes . LenOfRangeNode lenOfRangeNode ,
1738
+ @ Shared ("lenOfRangeNodeExact " ) @ Cached LenOfIntRangeNodeExact lenOfRangeNodeExact ,
1737
1739
@ Shared ("createBigRangeNode" ) @ Cached RangeNodes .CreateBigRangeNode createBigRangeNode ,
1738
1740
@ Shared ("polGeneric" ) @ CachedLibrary (limit = "3" ) PythonObjectLibrary pol ,
1739
1741
@ Shared ("libGeneric" ) @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
1740
1742
if (canBeInt (start , stop , step , lib )) {
1741
- return doInt (cls , pol .asSize (start ), pol .asSize (stop ), pol .asSize (step ), stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode );
1743
+ return doInt (cls , pol .asSize (start ), pol .asSize (stop ), pol .asSize (step ), stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode );
1742
1744
} else if (canBePint (start , stop , step , pol )) {
1743
1745
return createBigRangeNode .execute (start , stop , step , factory ());
1744
1746
} else {
@@ -1747,7 +1749,7 @@ Object doGeneric(@SuppressWarnings("unused") Object cls, Object start, Object st
1747
1749
Object lstep = pol .asIndex (step );
1748
1750
1749
1751
if (canBeInt (start , stop , step , lib )) {
1750
- return doInt (cls , pol .asSize (start ), pol .asSize (stop ), pol .asSize (step ), stepZeroProfile , exceptionProfile , lenOfRangeNode , createBigRangeNode );
1752
+ return doInt (cls , pol .asSize (start ), pol .asSize (stop ), pol .asSize (step ), stepZeroProfile , exceptionProfile , lenOfRangeNodeExact , createBigRangeNode );
1751
1753
} else {
1752
1754
return createBigRangeNode .execute (lstart , lstop , lstep , factory ());
1753
1755
}
0 commit comments