@@ -1094,8 +1094,6 @@ public BytecodeDSLCompilerResult visit(ExprTy.ListComp node) {
10941094 return buildComprehensionCodeUnit (node , node .generators , "<listcomp>" ,
10951095 (statementCompiler ) -> {
10961096 statementCompiler .b .beginMakeList ();
1097- // TODO: GR-64741 (do not collect to array manually)
1098- statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
10991097 statementCompiler .b .endMakeList ();
11001098 },
11011099 (statementCompiler , collection ) -> {
@@ -1127,7 +1125,6 @@ public BytecodeDSLCompilerResult visit(ExprTy.SetComp node) {
11271125 return buildComprehensionCodeUnit (node , node .generators , "<setcomp>" ,
11281126 (statementCompiler ) -> {
11291127 statementCompiler .b .beginMakeSet ();
1130- statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
11311128 statementCompiler .b .endMakeSet ();
11321129 },
11331130 (statementCompiler , collection ) -> {
@@ -1788,7 +1785,9 @@ private void emitCall(ExprTy func, ExprTy[] args, KeywordTy[] keywords) {
17881785 b .emitLoadLocal (function );
17891786 b .endBlock ();
17901787
1788+ b .beginCollectToObjectArray ();
17911789 emitUnstar (() -> b .emitLoadLocal (receiver ), args );
1790+ b .endCollectToObjectArray ();
17921791 emitKeywords (keywords , function );
17931792 } else {
17941793 assert len (keywords ) == 0 ;
@@ -1809,7 +1808,9 @@ private void emitCall(ExprTy func, ExprTy[] args, KeywordTy[] keywords) {
18091808 b .emitLoadLocal (function );
18101809 b .endBlock ();
18111810
1811+ b .beginCollectToObjectArray ();
18121812 emitUnstar (args );
1813+ b .endCollectToObjectArray ();
18131814 emitKeywords (keywords , function );
18141815 } else {
18151816 assert len (keywords ) == 0 ;
@@ -2011,12 +2012,9 @@ private void createConstant(ConstantValue value) {
20112012 break ;
20122013 case TUPLE :
20132014 b .beginMakeTuple ();
2014- // TODO: GR-64741 (do not collect to array manually)
2015- b .beginCollectToObjectArray ();
20162015 for (ConstantValue cv : value .getTupleElements ()) {
20172016 createConstant (cv );
20182017 }
2019- b .endCollectToObjectArray ();
20202018 b .endMakeTuple ();
20212019 break ;
20222020 case FROZENSET :
@@ -2309,97 +2307,69 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
23092307 private void emitUnstar (Runnable initialElementsProducer , ExprTy [] args , Runnable finalElementsProducer ) {
23102308 boolean noExtraElements = initialElementsProducer == null && finalElementsProducer == null ;
23112309 if (noExtraElements && len (args ) == 0 ) {
2312- b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
2310+ /**
2311+ * We don't need to emit anything for an empty array.
2312+ */
23132313 } else if (noExtraElements && len (args ) == 1 && args [0 ] instanceof ExprTy .Starred ) {
23142314 // Optimization for single starred argument: we can just upack it. For generic
23152315 // algorithm see the next branch
2316- b .beginUnpackStarred ();
2316+ b .beginUnpackStarredVariadic ();
23172317 ((ExprTy .Starred ) args [0 ]).value .accept (this );
2318- b .endUnpackStarred ();
2318+ b .endUnpackStarredVariadic ();
23192319 } else if (anyIsStarred (args )) {
23202320 /**
2321- * We emit one or more arrays and concatenate them using Unstar. Each array
2322- * corresponds to a contiguous sequence of arguments or the result of unpacking a
2323- * single starred argument.
2321+ * We emit one or more arrays. These are not concatenated directly, but rather
2322+ * expect that the caller is receiving them into @Variadic annotated argument, as that handles
2323+ * the concatenation. Each array corresponds to a contiguous sequence of arguments or the result
2324+ * of unpacking a single starred argument.
23242325 *
23252326 * For example, for the argument list a, b, *c, d, e, *f, g we would emit:
23262327 *
23272328 * @formatter:off
2328- * Unstar(
2329- * CollectToObjectArray(a, b) ,
2330- * UnpackStarred (c),
2331- * CollectToObjectArray(d, e) ,
2332- * UnpackStarred(f) ,
2333- * CollectToObjectArray(g)
2334- * )
2329+ * a,
2330+ * b ,
2331+ * UnpackStarredVariadic (c),
2332+ * d ,
2333+ * e ,
2334+ * UnpackStarredVariadic(f),
2335+ * g
23352336 * @formatter:on
2337+ *
2338+ * CollectObjectToArray is no longer necessary, as the UnpackStarredVariadic return @Variadic.
23362339 */
2337- b .beginUnstar ();
2338- boolean inVariadic = false ;
2339- int numOperands = 0 ;
2340-
23412340 if (initialElementsProducer != null ) {
2342- b .beginCollectToObjectArray ();
23432341 initialElementsProducer .run ();
2344- inVariadic = true ;
23452342 }
23462343
23472344 for (int i = 0 ; i < args .length ; i ++) {
23482345 if (args [i ] instanceof ExprTy .Starred ) {
2349- if (inVariadic ) {
2350- b .endCollectToObjectArray ();
2351- inVariadic = false ;
2352- numOperands ++;
2353- }
2354-
2355- b .beginUnpackStarred ();
2346+ b .beginUnpackStarredVariadic ();
23562347 ((ExprTy .Starred ) args [i ]).value .accept (this );
2357- b .endUnpackStarred ();
2358- numOperands ++;
2348+ b .endUnpackStarredVariadic ();
23592349 } else {
2360- if (!inVariadic ) {
2361- b .beginCollectToObjectArray ();
2362- inVariadic = true ;
2363- }
2364-
23652350 args [i ].accept (this );
23662351 }
23672352 }
23682353
23692354 if (finalElementsProducer != null ) {
2370- if (!inVariadic ) {
2371- b .beginCollectToObjectArray ();
2372- inVariadic = true ;
2373- }
23742355 finalElementsProducer .run ();
23752356 }
2376-
2377- if (inVariadic ) {
2378- b .endCollectToObjectArray ();
2379- numOperands ++;
2380- }
2381-
2382- b .endUnstar (numOperands );
23832357 } else {
2384- b .beginCollectToObjectArray ();
23852358 if (initialElementsProducer != null ) {
23862359 initialElementsProducer .run ();
23872360 }
23882361 visitSequence (args );
23892362 if (finalElementsProducer != null ) {
23902363 finalElementsProducer .run ();
23912364 }
2392- b .endCollectToObjectArray ();
23932365 }
23942366 }
23952367
23962368 @ Override
23972369 public Void visit (ExprTy .Set node ) {
23982370 boolean newStatement = beginSourceSection (node , b );
23992371 b .beginMakeSet ();
2400- if (len (node .elements ) == 0 ) {
2401- b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
2402- } else {
2372+ if (len (node .elements ) != 0 ) {
24032373 emitUnstar (node .elements );
24042374 }
24052375 b .endMakeSet ();
@@ -2814,12 +2784,9 @@ public void visitTypeParams(TypeParamTy[] typeParams) {
28142784 } else {
28152785 b .beginMakeTuple ();
28162786 }
2817- // TODO: GR-64741 (do not collect to array manually)
2818- b .beginCollectToObjectArray ();
28192787 for (TypeParamTy typeParam : typeParams ) {
28202788 typeParam .accept (this );
28212789 }
2822- b .endCollectToObjectArray ();
28232790 if (useList ) {
28242791 b .endMakeList ();
28252792 } else {
@@ -3348,10 +3315,12 @@ private void emitBuildClass(BytecodeDSLCodeUnit body, ClassDef node) {
33483315 }
33493316
33503317 // positional args
3318+ b .beginCollectToObjectArray ();
33513319 emitUnstar (() -> {
33523320 emitMakeFunction (body , node , node .name , null , null );
33533321 emitPythonConstant (toTruffleStringUncached (node .name ), b );
33543322 }, node .bases , finalElements );
3323+ b .endCollectToObjectArray ();
33553324
33563325 // keyword args
33573326 validateKeywords (node .keywords );
0 commit comments