228228import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
229229import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
230230import com .oracle .truffle .api .HostCompilerDirectives .InliningCutoff ;
231+ import com .oracle .truffle .api .Truffle ;
231232import com .oracle .truffle .api .bytecode .BytecodeConfig ;
232233import com .oracle .truffle .api .bytecode .BytecodeLocation ;
233234import com .oracle .truffle .api .bytecode .BytecodeNode ;
262263import com .oracle .truffle .api .frame .VirtualFrame ;
263264import com .oracle .truffle .api .library .CachedLibrary ;
264265import com .oracle .truffle .api .nodes .EncapsulatingNodeReference ;
266+ import com .oracle .truffle .api .nodes .ExplodeLoop ;
265267import com .oracle .truffle .api .nodes .Node ;
266268import com .oracle .truffle .api .nodes .UnexpectedResultException ;
267269import com .oracle .truffle .api .object .DynamicObjectLibrary ;
@@ -345,6 +347,7 @@ public abstract class PBytecodeDSLRootNode extends PRootNode implements Bytecode
345347 @ CompilationFinal protected transient int selfIndex ;
346348 @ CompilationFinal protected transient int classcellIndex ;
347349 @ CompilationFinal public int yieldFromGeneratorIndex = -1 ;
350+ @ CompilationFinal (dimensions = 1 ) protected transient Assumption [] cellEffectivelyFinalAssumptions ;
348351
349352 private transient boolean pythonInternal ;
350353 @ CompilationFinal private transient boolean internal ;
@@ -370,6 +373,12 @@ public void setMetadata(BytecodeDSLCodeUnit co, ParserCallbacksImpl parserErrorC
370373 this .selfIndex = co .selfIndex ;
371374 this .internal = getSource ().isInternal ();
372375 this .parserErrorCallback = parserErrorCallback ;
376+ if (co .cellvars .length > 0 ) {
377+ this .cellEffectivelyFinalAssumptions = new Assumption [co .cellvars .length ];
378+ for (int i = 0 ; i < co .cellvars .length ; i ++) {
379+ cellEffectivelyFinalAssumptions [i ] = Truffle .getRuntime ().createAssumption ("cell is effectively final" );
380+ }
381+ }
373382 }
374383
375384 @ Override
@@ -1043,24 +1052,34 @@ public static boolean hasLocals(VirtualFrame frame) {
10431052 }
10441053
10451054 @ Operation
1055+ @ ConstantOperand (type = LocalRangeAccessor .class )
1056+ public static final class CopyArguments {
1057+ @ Specialization
1058+ @ ExplodeLoop
1059+ public static void perform (VirtualFrame frame , LocalRangeAccessor locals ,
1060+ @ Bind BytecodeNode bytecodeNode ) {
1061+ for (int i = 0 ; i < locals .getLength (); i ++) {
1062+ locals .setObject (bytecodeNode , frame , i , PArguments .getArgument (frame , i ));
1063+ }
1064+ }
1065+ }
1066+
1067+ @ Operation
1068+ @ ConstantOperand (type = int .class )
10461069 public static final class LoadVariableArguments {
10471070 @ Specialization
1048- public static Object perform (VirtualFrame frame ,
1071+ public static Object perform (VirtualFrame frame , int index ,
10491072 @ Bind PBytecodeDSLRootNode rootNode ) {
1050- int index = rootNode .co .getRegularArgCount ();
10511073 return PFactory .createTuple (rootNode .getLanguage (), (Object []) PArguments .getArgument (frame , index ));
10521074 }
10531075 }
10541076
10551077 @ Operation
1078+ @ ConstantOperand (type = int .class )
10561079 public static final class LoadKeywordArguments {
10571080 @ Specialization
1058- public static Object perform (VirtualFrame frame ,
1081+ public static Object perform (VirtualFrame frame , int index ,
10591082 @ Bind PBytecodeDSLRootNode rootNode ) {
1060- int index = rootNode .co .getRegularArgCount ();
1061- if (rootNode .co .takesVarArgs ()) {
1062- index ++;
1063- }
10641083 return PFactory .createDict (rootNode .getLanguage (), (PKeyword []) PArguments .getArgument (frame , index ));
10651084 }
10661085 }
@@ -2454,12 +2473,16 @@ public static void doStoreCell(PCell cell, Object value) {
24542473 }
24552474
24562475 @ Operation
2457- public static final class CreateCell {
2476+ @ ConstantOperand (type = LocalRangeAccessor .class )
2477+ public static final class CreateCells {
24582478 @ Specialization
2459- public static PCell doCreateCell (Object value ) {
2460- PCell cell = new PCell (Assumption .create ());
2461- cell .setRef (value );
2462- return cell ;
2479+ @ ExplodeLoop
2480+ public static void doCreateCells (VirtualFrame frame , LocalRangeAccessor locals ,
2481+ @ Bind PBytecodeDSLRootNode rootNode ) {
2482+ for (int i = 0 ; i < locals .getLength (); i ++) {
2483+ PCell cell = new PCell (rootNode .cellEffectivelyFinalAssumptions [i ]);
2484+ locals .setObject (rootNode .getBytecodeNode (), frame , i , cell );
2485+ }
24632486 }
24642487 }
24652488
@@ -2486,24 +2509,16 @@ public static void doClearLocal(VirtualFrame frame, LocalAccessor localAccessor,
24862509 }
24872510 }
24882511
2489- @ Operation
2490- public static final class LoadClosure {
2491- @ Specialization
2492- public static PCell [] doLoadClosure (VirtualFrame frame ) {
2493- return PArguments .getFunctionObject (frame .getArguments ()).getClosure ();
2494- }
2495- }
2496-
24972512 @ Operation
24982513 @ ConstantOperand (type = LocalRangeAccessor .class )
2499- public static final class StoreRange {
2514+ public static final class InitFreeVars {
25002515 @ Specialization
2501- public static void perform (VirtualFrame frame , LocalRangeAccessor locals , Object [] values ,
2516+ @ ExplodeLoop
2517+ public static void doLoadClosure (VirtualFrame frame , LocalRangeAccessor locals ,
25022518 @ Bind BytecodeNode bytecode ) {
2503- CompilerAsserts .partialEvaluationConstant (locals .getLength ());
2504- assert values .length == locals .getLength ();
2519+ PCell [] closure = PArguments .getFunctionObject (frame .getArguments ()).getClosure ();
25052520 for (int i = 0 ; i < locals .getLength (); i ++) {
2506- locals .setObject (bytecode , frame , i , values [i ]);
2521+ locals .setObject (bytecode , frame , i , closure [i ]);
25072522 }
25082523 }
25092524 }
0 commit comments