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