43
43
import static com .oracle .graal .python .nodes .truffle .TruffleStringMigrationPythonTypes .assertNoJavaString ;
44
44
45
45
import java .util .ArrayList ;
46
+ import java .util .Arrays ;
46
47
import java .util .List ;
47
48
48
49
import org .graalvm .polyglot .io .ByteSequence ;
@@ -101,8 +102,8 @@ public Assumption needNotPassExceptionAssumption() {
101
102
public PCode execute (VirtualFrame frame , int argcount ,
102
103
int posonlyargcount , int kwonlyargcount ,
103
104
int nlocals , int stacksize , int flags ,
104
- byte [] codedata , Object [] constants , Object [] names ,
105
- Object [] varnames , Object [] freevars , Object [] cellvars ,
105
+ byte [] codedata , Object [] constants , TruffleString [] names ,
106
+ TruffleString [] varnames , TruffleString [] freevars , TruffleString [] cellvars ,
106
107
TruffleString filename , TruffleString name , int firstlineno ,
107
108
byte [] lnotab ) {
108
109
@@ -122,8 +123,8 @@ public PCode execute(VirtualFrame frame, int argcount,
122
123
private static PCode createCode (PythonLanguage language , PythonContext context , @ SuppressWarnings ("unused" ) int argcount ,
123
124
@ SuppressWarnings ("unused" ) int posonlyargcount , @ SuppressWarnings ("unused" ) int kwonlyargcount ,
124
125
int nlocals , int stacksize , int flags ,
125
- byte [] codedata , Object [] constants , Object [] names ,
126
- Object [] varnames , Object [] freevars , Object [] cellvars ,
126
+ byte [] codedata , Object [] constants , TruffleString [] names ,
127
+ TruffleString [] varnames , TruffleString [] freevars , TruffleString [] cellvars ,
127
128
TruffleString filename , TruffleString name , int firstlineno ,
128
129
byte [] lnotab ) {
129
130
@@ -132,7 +133,7 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
132
133
ct = language .createCachedCallTarget (l -> new BadOPCodeNode (l , name ), BadOPCodeNode .class , filename , name );
133
134
} else {
134
135
if (context .getOption (PythonOptions .EnableBytecodeInterpreter )) {
135
- ct = create ().deserializeForBytecodeInterpreter (language , codedata );
136
+ ct = create ().deserializeForBytecodeInterpreter (language , codedata , cellvars , freevars );
136
137
} else {
137
138
RootNode rootNode = context .getSerializer ().deserialize (context , codedata , toStringArray (cellvars ), toStringArray (freevars ));
138
139
ct = PythonUtils .getOrCreateCallTarget (rootNode );
@@ -146,8 +147,17 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
146
147
firstlineno , lnotab );
147
148
}
148
149
149
- private RootCallTarget deserializeForBytecodeInterpreter (PythonLanguage language , byte [] data ) {
150
+ private RootCallTarget deserializeForBytecodeInterpreter (PythonLanguage language , byte [] data , TruffleString [] cellvars , TruffleString [] freevars ) {
150
151
CodeUnit code = MarshalModuleBuiltins .deserializeCodeUnit (data );
152
+ if (cellvars != null && !Arrays .equals (code .cellvars , cellvars ) || freevars != null && !Arrays .equals (code .freevars , freevars )) {
153
+ code = new CodeUnit (code .name , code .qualname , code .argCount , code .kwOnlyArgCount , code .positionalOnlyArgCount , code .stacksize , code .code ,
154
+ code .srcOffsetTable , code .flags , code .names , code .varnames ,
155
+ cellvars != null ? cellvars : code .cellvars , freevars != null ? freevars : code .freevars ,
156
+ code .cell2arg , code .constants , code .primitiveConstants , code .exceptionHandlerRanges , code .conditionProfileCount ,
157
+ code .startOffset , code .startLine ,
158
+ code .outputCanQuicken , code .variableShouldUnbox ,
159
+ code .generalizeInputsMap , code .generalizeVarsMap );
160
+ }
151
161
RootNode rootNode = new PBytecodeRootNode (language , code , null , null );
152
162
if (code .isGeneratorOrCoroutine ()) {
153
163
rootNode = new PBytecodeGeneratorFunctionRootNode (language , rootNode .getFrameDescriptor (), (PBytecodeRootNode ) rootNode , code .name );
0 commit comments