@@ -1094,8 +1094,6 @@ public BytecodeDSLCompilerResult visit(ExprTy.ListComp node) {
1094
1094
return buildComprehensionCodeUnit (node , node .generators , "<listcomp>" ,
1095
1095
(statementCompiler ) -> {
1096
1096
statementCompiler .b .beginMakeList ();
1097
- // TODO: GR-64741 (do not collect to array manually)
1098
- statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
1099
1097
statementCompiler .b .endMakeList ();
1100
1098
},
1101
1099
(statementCompiler , collection ) -> {
@@ -1127,7 +1125,6 @@ public BytecodeDSLCompilerResult visit(ExprTy.SetComp node) {
1127
1125
return buildComprehensionCodeUnit (node , node .generators , "<setcomp>" ,
1128
1126
(statementCompiler ) -> {
1129
1127
statementCompiler .b .beginMakeSet ();
1130
- statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
1131
1128
statementCompiler .b .endMakeSet ();
1132
1129
},
1133
1130
(statementCompiler , collection ) -> {
@@ -1788,7 +1785,9 @@ private void emitCall(ExprTy func, ExprTy[] args, KeywordTy[] keywords) {
1788
1785
b .emitLoadLocal (function );
1789
1786
b .endBlock ();
1790
1787
1788
+ b .beginCollectToObjectArray ();
1791
1789
emitUnstar (() -> b .emitLoadLocal (receiver ), args );
1790
+ b .endCollectToObjectArray ();
1792
1791
emitKeywords (keywords , function );
1793
1792
} else {
1794
1793
assert len (keywords ) == 0 ;
@@ -1809,7 +1808,9 @@ private void emitCall(ExprTy func, ExprTy[] args, KeywordTy[] keywords) {
1809
1808
b .emitLoadLocal (function );
1810
1809
b .endBlock ();
1811
1810
1811
+ b .beginCollectToObjectArray ();
1812
1812
emitUnstar (args );
1813
+ b .endCollectToObjectArray ();
1813
1814
emitKeywords (keywords , function );
1814
1815
} else {
1815
1816
assert len (keywords ) == 0 ;
@@ -2011,12 +2012,9 @@ private void createConstant(ConstantValue value) {
2011
2012
break ;
2012
2013
case TUPLE :
2013
2014
b .beginMakeTuple ();
2014
- // TODO: GR-64741 (do not collect to array manually)
2015
- b .beginCollectToObjectArray ();
2016
2015
for (ConstantValue cv : value .getTupleElements ()) {
2017
2016
createConstant (cv );
2018
2017
}
2019
- b .endCollectToObjectArray ();
2020
2018
b .endMakeTuple ();
2021
2019
break ;
2022
2020
case FROZENSET :
@@ -2309,97 +2307,69 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
2309
2307
private void emitUnstar (Runnable initialElementsProducer , ExprTy [] args , Runnable finalElementsProducer ) {
2310
2308
boolean noExtraElements = initialElementsProducer == null && finalElementsProducer == null ;
2311
2309
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
+ */
2313
2313
} else if (noExtraElements && len (args ) == 1 && args [0 ] instanceof ExprTy .Starred ) {
2314
2314
// Optimization for single starred argument: we can just upack it. For generic
2315
2315
// algorithm see the next branch
2316
- b .beginUnpackStarred ();
2316
+ b .beginUnpackStarredVariadic ();
2317
2317
((ExprTy .Starred ) args [0 ]).value .accept (this );
2318
- b .endUnpackStarred ();
2318
+ b .endUnpackStarredVariadic ();
2319
2319
} else if (anyIsStarred (args )) {
2320
2320
/**
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.
2324
2325
*
2325
2326
* For example, for the argument list a, b, *c, d, e, *f, g we would emit:
2326
2327
*
2327
2328
* @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
2335
2336
* @formatter:on
2337
+ *
2338
+ * CollectObjectToArray is no longer necessary, as the UnpackStarredVariadic return @Variadic.
2336
2339
*/
2337
- b .beginUnstar ();
2338
- boolean inVariadic = false ;
2339
- int numOperands = 0 ;
2340
-
2341
2340
if (initialElementsProducer != null ) {
2342
- b .beginCollectToObjectArray ();
2343
2341
initialElementsProducer .run ();
2344
- inVariadic = true ;
2345
2342
}
2346
2343
2347
2344
for (int i = 0 ; i < args .length ; i ++) {
2348
2345
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 ();
2356
2347
((ExprTy .Starred ) args [i ]).value .accept (this );
2357
- b .endUnpackStarred ();
2358
- numOperands ++;
2348
+ b .endUnpackStarredVariadic ();
2359
2349
} else {
2360
- if (!inVariadic ) {
2361
- b .beginCollectToObjectArray ();
2362
- inVariadic = true ;
2363
- }
2364
-
2365
2350
args [i ].accept (this );
2366
2351
}
2367
2352
}
2368
2353
2369
2354
if (finalElementsProducer != null ) {
2370
- if (!inVariadic ) {
2371
- b .beginCollectToObjectArray ();
2372
- inVariadic = true ;
2373
- }
2374
2355
finalElementsProducer .run ();
2375
2356
}
2376
-
2377
- if (inVariadic ) {
2378
- b .endCollectToObjectArray ();
2379
- numOperands ++;
2380
- }
2381
-
2382
- b .endUnstar (numOperands );
2383
2357
} else {
2384
- b .beginCollectToObjectArray ();
2385
2358
if (initialElementsProducer != null ) {
2386
2359
initialElementsProducer .run ();
2387
2360
}
2388
2361
visitSequence (args );
2389
2362
if (finalElementsProducer != null ) {
2390
2363
finalElementsProducer .run ();
2391
2364
}
2392
- b .endCollectToObjectArray ();
2393
2365
}
2394
2366
}
2395
2367
2396
2368
@ Override
2397
2369
public Void visit (ExprTy .Set node ) {
2398
2370
boolean newStatement = beginSourceSection (node , b );
2399
2371
b .beginMakeSet ();
2400
- if (len (node .elements ) == 0 ) {
2401
- b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
2402
- } else {
2372
+ if (len (node .elements ) != 0 ) {
2403
2373
emitUnstar (node .elements );
2404
2374
}
2405
2375
b .endMakeSet ();
@@ -2814,12 +2784,9 @@ public void visitTypeParams(TypeParamTy[] typeParams) {
2814
2784
} else {
2815
2785
b .beginMakeTuple ();
2816
2786
}
2817
- // TODO: GR-64741 (do not collect to array manually)
2818
- b .beginCollectToObjectArray ();
2819
2787
for (TypeParamTy typeParam : typeParams ) {
2820
2788
typeParam .accept (this );
2821
2789
}
2822
- b .endCollectToObjectArray ();
2823
2790
if (useList ) {
2824
2791
b .endMakeList ();
2825
2792
} else {
@@ -3348,10 +3315,12 @@ private void emitBuildClass(BytecodeDSLCodeUnit body, ClassDef node) {
3348
3315
}
3349
3316
3350
3317
// positional args
3318
+ b .beginCollectToObjectArray ();
3351
3319
emitUnstar (() -> {
3352
3320
emitMakeFunction (body , node , node .name , null , null );
3353
3321
emitPythonConstant (toTruffleStringUncached (node .name ), b );
3354
3322
}, node .bases , finalElements );
3323
+ b .endCollectToObjectArray ();
3355
3324
3356
3325
// keyword args
3357
3326
validateKeywords (node .keywords );
0 commit comments