260
260
import com .oracle .truffle .api .source .SourceSection ;
261
261
import com .oracle .truffle .api .strings .TruffleString ;
262
262
import com .oracle .truffle .api .strings .TruffleStringBuilder ;
263
+ import com .oracle .truffle .api .strings .TruffleStringBuilderUTF32 ;
263
264
264
265
@ GenerateBytecode (//
265
266
languageClass = PythonLanguage .class , //
@@ -1651,30 +1652,13 @@ public static Object doGeneric(Object start, Object end, Object step,
1651
1652
public static final class MakeKeywords {
1652
1653
@ Specialization
1653
1654
public static PKeyword [] perform (@ Variadic Object [] values , TruffleString [] keys ) {
1654
- if (keys .length <= EXPLODE_LOOP_THRESHOLD ) {
1655
- return doExploded (keys , values );
1656
- } else {
1657
- return doRegular (keys , values );
1658
- }
1659
- }
1660
-
1661
- @ ExplodeLoop
1662
- private static PKeyword [] doExploded (TruffleString [] keys , Object [] values ) {
1663
1655
CompilerAsserts .partialEvaluationConstant (keys .length );
1664
1656
PKeyword [] result = new PKeyword [keys .length ];
1665
1657
for (int i = 0 ; i < keys .length ; i ++) {
1666
1658
result [i ] = new PKeyword (keys [i ], values [i ]);
1667
1659
}
1668
1660
return result ;
1669
1661
}
1670
-
1671
- private static PKeyword [] doRegular (TruffleString [] keys , Object [] values ) {
1672
- PKeyword [] result = new PKeyword [keys .length ];
1673
- for (int i = 0 ; i < keys .length ; i ++) {
1674
- result [i ] = new PKeyword (keys [i ], values [i ]);
1675
- }
1676
- return result ;
1677
- }
1678
1662
}
1679
1663
1680
1664
@ Operation
@@ -1758,7 +1742,6 @@ public static void doIt(VirtualFrame frame, Object value, Object primary, Object
1758
1742
@ ImportStatic ({PGuards .class })
1759
1743
public static final class UnpackToLocals {
1760
1744
@ Specialization (guards = "isBuiltinSequence(sequence)" )
1761
- @ ExplodeLoop
1762
1745
public static void doUnpackSequence (VirtualFrame localFrame , LocalRangeAccessor results , PSequence sequence ,
1763
1746
@ Bind Node inliningTarget ,
1764
1747
@ Bind BytecodeNode bytecode ,
@@ -1767,25 +1750,28 @@ public static void doUnpackSequence(VirtualFrame localFrame, LocalRangeAccessor
1767
1750
@ Shared @ Cached PRaiseNode raiseNode ) {
1768
1751
SequenceStorage storage = getSequenceStorageNode .execute (inliningTarget , sequence );
1769
1752
int len = storage .length ();
1770
-
1771
1753
int count = results .getLength ();
1772
1754
CompilerAsserts .partialEvaluationConstant (count );
1773
1755
1774
- if (len == count ) {
1775
- for (int i = 0 ; i < count ; i ++) {
1776
- results .setObject (bytecode , localFrame , i , getItemNode .execute (inliningTarget , storage , i ));
1777
- }
1756
+ if (len != count ) {
1757
+ raiseError (inliningTarget , raiseNode , len , count );
1758
+ }
1759
+
1760
+ for (int i = 0 ; i < count ; i ++) {
1761
+ results .setObject (bytecode , localFrame , i , getItemNode .execute (inliningTarget , storage , i ));
1762
+ }
1763
+ }
1764
+
1765
+ @ InliningCutoff
1766
+ private static void raiseError (Node inliningTarget , PRaiseNode raiseNode , int len , int count ) {
1767
+ if (len < count ) {
1768
+ throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .NOT_ENOUGH_VALUES_TO_UNPACK , count , len );
1778
1769
} else {
1779
- if (len < count ) {
1780
- throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .NOT_ENOUGH_VALUES_TO_UNPACK , count , len );
1781
- } else {
1782
- throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .TOO_MANY_VALUES_TO_UNPACK , count );
1783
- }
1770
+ throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .TOO_MANY_VALUES_TO_UNPACK , count );
1784
1771
}
1785
1772
}
1786
1773
1787
1774
@ Specialization
1788
- @ ExplodeLoop
1789
1775
@ InliningCutoff
1790
1776
public static void doUnpackIterable (VirtualFrame virtualFrame , LocalRangeAccessor results , Object collection ,
1791
1777
@ Bind Node inliningTarget ,
@@ -1904,7 +1890,6 @@ public static void doUnpackIterable(VirtualFrame frame,
1904
1890
}
1905
1891
}
1906
1892
1907
- @ ExplodeLoop
1908
1893
private static void copyToLocalsFromIterator (VirtualFrame frame , Node inliningTarget , Object iterator , int length , LocalRangeAccessor results ,
1909
1894
BytecodeNode bytecode , int requiredLength ,
1910
1895
PyIterNextNode getNextNode , PRaiseNode raiseNode ) {
@@ -1919,7 +1904,6 @@ private static void copyToLocalsFromIterator(VirtualFrame frame, Node inliningTa
1919
1904
}
1920
1905
}
1921
1906
1922
- @ ExplodeLoop
1923
1907
private static void copyToLocalsFromSequence (SequenceStorage storage , int runOffset , int offset , int length , LocalRangeAccessor run ,
1924
1908
VirtualFrame localFrame , Node inliningTarget , BytecodeNode bytecode , SequenceStorageNodes .GetItemScalarNode getItemNode ) {
1925
1909
CompilerAsserts .partialEvaluationConstant (length );
@@ -2423,7 +2407,6 @@ public static PCell[] doLoadClosure(VirtualFrame frame) {
2423
2407
@ ConstantOperand (type = LocalRangeAccessor .class )
2424
2408
public static final class StoreRange {
2425
2409
@ Specialization
2426
- @ ExplodeLoop
2427
2410
public static void perform (VirtualFrame frame , LocalRangeAccessor locals , Object [] values ,
2428
2411
@ Bind BytecodeNode bytecode ) {
2429
2412
CompilerAsserts .partialEvaluationConstant (locals .getLength ());
@@ -2550,33 +2533,34 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame, Object collec
2550
2533
@ ImportStatic ({PGuards .class })
2551
2534
public static final class UnpackSequence {
2552
2535
@ Specialization (guards = "isBuiltinSequence(sequence)" )
2553
- @ ExplodeLoop
2554
- public static Object [] doUnpackSequence (VirtualFrame localFrame ,
2555
- int count ,
2556
- PSequence sequence ,
2536
+ public static Object [] doUnpackSequence (VirtualFrame localFrame , int count , PSequence sequence ,
2557
2537
@ Bind Node inliningTarget ,
2558
2538
@ Cached SequenceNodes .GetSequenceStorageNode getSequenceStorageNode ,
2559
2539
@ Cached SequenceStorageNodes .GetItemScalarNode getItemNode ,
2560
- @ Shared @ Cached PRaiseNode raiseNode ) {
2540
+ @ Exclusive @ Cached PRaiseNode raiseNode ) {
2541
+ CompilerAsserts .partialEvaluationConstant (count );
2561
2542
SequenceStorage storage = getSequenceStorageNode .execute (inliningTarget , sequence );
2562
2543
int len = storage .length ();
2563
- if (len == count ) {
2564
- Object [] result = new Object [len ];
2565
- for (int i = 0 ; i < count ; i ++) {
2566
- result [i ] = getItemNode .execute (inliningTarget , storage , i );
2567
- }
2568
- return result ;
2544
+ if (len != count ) {
2545
+ throw raiseError (inliningTarget , raiseNode , len , count );
2546
+ }
2547
+ Object [] result = new Object [len ];
2548
+ for (int i = 0 ; i < count ; i ++) {
2549
+ result [i ] = getItemNode .execute (inliningTarget , storage , i );
2550
+ }
2551
+ return result ;
2552
+ }
2553
+
2554
+ @ InliningCutoff
2555
+ private static PException raiseError (Node inliningTarget , PRaiseNode raiseNode , int len , int count ) {
2556
+ if (len < count ) {
2557
+ throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .NOT_ENOUGH_VALUES_TO_UNPACK , count , len );
2569
2558
} else {
2570
- if (len < count ) {
2571
- throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .NOT_ENOUGH_VALUES_TO_UNPACK , count , len );
2572
- } else {
2573
- throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .TOO_MANY_VALUES_TO_UNPACK , count );
2574
- }
2559
+ throw raiseNode .raise (inliningTarget , ValueError , ErrorMessages .TOO_MANY_VALUES_TO_UNPACK , count );
2575
2560
}
2576
2561
}
2577
2562
2578
2563
@ Specialization
2579
- @ ExplodeLoop
2580
2564
@ InliningCutoff
2581
2565
public static Object [] doUnpackIterable (VirtualFrame virtualFrame ,
2582
2566
int count ,
@@ -2585,7 +2569,8 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame,
2585
2569
@ Cached PyObjectGetIter getIter ,
2586
2570
@ Cached PyIterNextNode getNextNode ,
2587
2571
@ Cached IsBuiltinObjectProfile notIterableProfile ,
2588
- @ Shared @ Cached PRaiseNode raiseNode ) {
2572
+ @ Exclusive @ Cached PRaiseNode raiseNode ) {
2573
+ CompilerAsserts .partialEvaluationConstant (count );
2589
2574
Object iterator ;
2590
2575
try {
2591
2576
iterator = getIter .execute (virtualFrame , inliningTarget , collection );
@@ -2683,7 +2668,6 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame,
2683
2668
return result ;
2684
2669
}
2685
2670
2686
- @ ExplodeLoop
2687
2671
private static void copyItemsToArray (VirtualFrame frame , Node inliningTarget , Object iterator , Object [] destination , int destinationOffset , int length , int totalLength ,
2688
2672
PyIterNextNode getNextNode , PRaiseNode raiseNode ) {
2689
2673
CompilerAsserts .partialEvaluationConstant (destinationOffset );
@@ -2699,7 +2683,6 @@ private static void copyItemsToArray(VirtualFrame frame, Node inliningTarget, Ob
2699
2683
}
2700
2684
}
2701
2685
2702
- @ ExplodeLoop
2703
2686
private static void copyItemsToArray (Node inliningTarget , SequenceStorage source , int sourceOffset , Object [] destination , int destinationOffset , int length ,
2704
2687
SequenceStorageNodes .GetItemScalarNode getItemNode ) {
2705
2688
CompilerAsserts .partialEvaluationConstant (sourceOffset );
@@ -2950,27 +2933,12 @@ public static Object perform(
2950
2933
@ Variadic Object [] strings ,
2951
2934
@ Cached TruffleStringBuilder .AppendStringNode appendNode ,
2952
2935
@ Cached TruffleStringBuilder .ToStringNode toString ) {
2953
- TruffleStringBuilder tsb = TruffleStringBuilder .create (PythonUtils .TS_ENCODING );
2954
- if (length <= EXPLODE_LOOP_THRESHOLD ) {
2955
- doExploded (strings , length , appendNode , tsb );
2956
- } else {
2957
- doRegular (strings , length , appendNode , tsb );
2958
- }
2959
- return toString .execute (tsb );
2960
- }
2961
-
2962
- @ ExplodeLoop
2963
- private static void doExploded (Object [] strings , int length , TruffleStringBuilder .AppendStringNode appendNode , TruffleStringBuilder tsb ) {
2936
+ var tsb = TruffleStringBuilderUTF32 .create (PythonUtils .TS_ENCODING );
2964
2937
CompilerAsserts .partialEvaluationConstant (length );
2965
2938
for (int i = 0 ; i < length ; i ++) {
2966
2939
appendNode .execute (tsb , (TruffleString ) strings [i ]);
2967
2940
}
2968
- }
2969
-
2970
- private static void doRegular (Object [] strings , int length , TruffleStringBuilder .AppendStringNode appendNode , TruffleStringBuilder tsb ) {
2971
- for (int i = 0 ; i < length ; i ++) {
2972
- appendNode .execute (tsb , (TruffleString ) strings [i ]);
2973
- }
2941
+ return toString .execute (tsb );
2974
2942
}
2975
2943
}
2976
2944
0 commit comments