260260import com .oracle .truffle .api .source .SourceSection ;
261261import com .oracle .truffle .api .strings .TruffleString ;
262262import com .oracle .truffle .api .strings .TruffleStringBuilder ;
263+ import com .oracle .truffle .api .strings .TruffleStringBuilderUTF32 ;
263264
264265@ GenerateBytecode (//
265266 languageClass = PythonLanguage .class , //
@@ -1651,30 +1652,13 @@ public static Object doGeneric(Object start, Object end, Object step,
16511652 public static final class MakeKeywords {
16521653 @ Specialization
16531654 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 ) {
16631655 CompilerAsserts .partialEvaluationConstant (keys .length );
16641656 PKeyword [] result = new PKeyword [keys .length ];
16651657 for (int i = 0 ; i < keys .length ; i ++) {
16661658 result [i ] = new PKeyword (keys [i ], values [i ]);
16671659 }
16681660 return result ;
16691661 }
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- }
16781662 }
16791663
16801664 @ Operation
@@ -1758,7 +1742,6 @@ public static void doIt(VirtualFrame frame, Object value, Object primary, Object
17581742 @ ImportStatic ({PGuards .class })
17591743 public static final class UnpackToLocals {
17601744 @ Specialization (guards = "isBuiltinSequence(sequence)" )
1761- @ ExplodeLoop
17621745 public static void doUnpackSequence (VirtualFrame localFrame , LocalRangeAccessor results , PSequence sequence ,
17631746 @ Bind Node inliningTarget ,
17641747 @ Bind BytecodeNode bytecode ,
@@ -1767,25 +1750,28 @@ public static void doUnpackSequence(VirtualFrame localFrame, LocalRangeAccessor
17671750 @ Shared @ Cached PRaiseNode raiseNode ) {
17681751 SequenceStorage storage = getSequenceStorageNode .execute (inliningTarget , sequence );
17691752 int len = storage .length ();
1770-
17711753 int count = results .getLength ();
17721754 CompilerAsserts .partialEvaluationConstant (count );
17731755
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 );
17781769 } 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 );
17841771 }
17851772 }
17861773
17871774 @ Specialization
1788- @ ExplodeLoop
17891775 @ InliningCutoff
17901776 public static void doUnpackIterable (VirtualFrame virtualFrame , LocalRangeAccessor results , Object collection ,
17911777 @ Bind Node inliningTarget ,
@@ -1904,7 +1890,6 @@ public static void doUnpackIterable(VirtualFrame frame,
19041890 }
19051891 }
19061892
1907- @ ExplodeLoop
19081893 private static void copyToLocalsFromIterator (VirtualFrame frame , Node inliningTarget , Object iterator , int length , LocalRangeAccessor results ,
19091894 BytecodeNode bytecode , int requiredLength ,
19101895 PyIterNextNode getNextNode , PRaiseNode raiseNode ) {
@@ -1919,7 +1904,6 @@ private static void copyToLocalsFromIterator(VirtualFrame frame, Node inliningTa
19191904 }
19201905 }
19211906
1922- @ ExplodeLoop
19231907 private static void copyToLocalsFromSequence (SequenceStorage storage , int runOffset , int offset , int length , LocalRangeAccessor run ,
19241908 VirtualFrame localFrame , Node inliningTarget , BytecodeNode bytecode , SequenceStorageNodes .GetItemScalarNode getItemNode ) {
19251909 CompilerAsserts .partialEvaluationConstant (length );
@@ -2423,7 +2407,6 @@ public static PCell[] doLoadClosure(VirtualFrame frame) {
24232407 @ ConstantOperand (type = LocalRangeAccessor .class )
24242408 public static final class StoreRange {
24252409 @ Specialization
2426- @ ExplodeLoop
24272410 public static void perform (VirtualFrame frame , LocalRangeAccessor locals , Object [] values ,
24282411 @ Bind BytecodeNode bytecode ) {
24292412 CompilerAsserts .partialEvaluationConstant (locals .getLength ());
@@ -2550,33 +2533,34 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame, Object collec
25502533 @ ImportStatic ({PGuards .class })
25512534 public static final class UnpackSequence {
25522535 @ 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 ,
25572537 @ Bind Node inliningTarget ,
25582538 @ Cached SequenceNodes .GetSequenceStorageNode getSequenceStorageNode ,
25592539 @ Cached SequenceStorageNodes .GetItemScalarNode getItemNode ,
2560- @ Shared @ Cached PRaiseNode raiseNode ) {
2540+ @ Exclusive @ Cached PRaiseNode raiseNode ) {
2541+ CompilerAsserts .partialEvaluationConstant (count );
25612542 SequenceStorage storage = getSequenceStorageNode .execute (inliningTarget , sequence );
25622543 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 );
25692558 } 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 );
25752560 }
25762561 }
25772562
25782563 @ Specialization
2579- @ ExplodeLoop
25802564 @ InliningCutoff
25812565 public static Object [] doUnpackIterable (VirtualFrame virtualFrame ,
25822566 int count ,
@@ -2585,7 +2569,8 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame,
25852569 @ Cached PyObjectGetIter getIter ,
25862570 @ Cached PyIterNextNode getNextNode ,
25872571 @ Cached IsBuiltinObjectProfile notIterableProfile ,
2588- @ Shared @ Cached PRaiseNode raiseNode ) {
2572+ @ Exclusive @ Cached PRaiseNode raiseNode ) {
2573+ CompilerAsserts .partialEvaluationConstant (count );
25892574 Object iterator ;
25902575 try {
25912576 iterator = getIter .execute (virtualFrame , inliningTarget , collection );
@@ -2683,7 +2668,6 @@ public static Object[] doUnpackIterable(VirtualFrame virtualFrame,
26832668 return result ;
26842669 }
26852670
2686- @ ExplodeLoop
26872671 private static void copyItemsToArray (VirtualFrame frame , Node inliningTarget , Object iterator , Object [] destination , int destinationOffset , int length , int totalLength ,
26882672 PyIterNextNode getNextNode , PRaiseNode raiseNode ) {
26892673 CompilerAsserts .partialEvaluationConstant (destinationOffset );
@@ -2699,7 +2683,6 @@ private static void copyItemsToArray(VirtualFrame frame, Node inliningTarget, Ob
26992683 }
27002684 }
27012685
2702- @ ExplodeLoop
27032686 private static void copyItemsToArray (Node inliningTarget , SequenceStorage source , int sourceOffset , Object [] destination , int destinationOffset , int length ,
27042687 SequenceStorageNodes .GetItemScalarNode getItemNode ) {
27052688 CompilerAsserts .partialEvaluationConstant (sourceOffset );
@@ -2950,27 +2933,12 @@ public static Object perform(
29502933 @ Variadic Object [] strings ,
29512934 @ Cached TruffleStringBuilder .AppendStringNode appendNode ,
29522935 @ 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 );
29642937 CompilerAsserts .partialEvaluationConstant (length );
29652938 for (int i = 0 ; i < length ; i ++) {
29662939 appendNode .execute (tsb , (TruffleString ) strings [i ]);
29672940 }
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 );
29742942 }
29752943 }
29762944
0 commit comments