Skip to content

Commit 7ff5327

Browse files
committed
Replace PFrame.arguments with PFrame.globals
1 parent 296b0d2 commit 7ff5327

File tree

5 files changed

+15
-50
lines changed

5 files changed

+15
-50
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4545
import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeRootNode;
4646
import com.oracle.graal.python.builtins.objects.code.PCode;
47-
import com.oracle.graal.python.builtins.objects.frame.FrameBuiltins.GetLocalsNode;
4847
import com.oracle.graal.python.builtins.objects.function.PArguments;
4948
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
5049
import com.oracle.graal.python.builtins.objects.object.PythonObject;
@@ -68,12 +67,15 @@
6867
public final class PFrame extends PythonBuiltinObject {
6968
private static final int UNINITIALIZED_LINE = -2;
7069

71-
private Object[] arguments;
7270
private MaterializedFrame locals;
73-
// Whether the frame has dict locals passed from the caller (happens in eval/exec and class
74-
// bodies)
71+
/**
72+
* Whether the frame has dict locals passed from the caller (happens in eval/exec and class
73+
* bodies). Then locals is null and localsDict contains the dict locals. Otherwise both locals
74+
* and localsDict might contain a copy of the frame locals.
75+
*/
7576
private final boolean hasCustomLocals;
7677
private Object localsDict;
78+
private PythonObject globals;
7779
private final Reference virtualFrameInfo;
7880
/**
7981
* For the manual bytecode interpreter the location can be the {@link PBytecodeRootNode} itself,
@@ -211,15 +213,12 @@ public PFrame(PythonLanguage lang, Reference virtualFrameInfo, Node location, bo
211213
public PFrame(PythonLanguage lang, @SuppressWarnings("unused") Object threadState, PCode code, PythonObject globals, Object localsDict) {
212214
super(PythonBuiltinClassType.PFrame, PythonBuiltinClassType.PFrame.getInstanceShape(lang));
213215
// TODO: frames: extract the information from the threadState object
214-
Object[] frameArgs = PArguments.create();
215-
PArguments.setGlobals(frameArgs, globals);
216-
PArguments.setSpecialArgument(frameArgs, localsDict);
216+
this.globals = globals;
217217
this.location = GetCodeRootNode.executeUncached(code);
218218
Reference curFrameInfo = new Reference(location != null ? location.getRootNode() : null, null);
219219
this.virtualFrameInfo = curFrameInfo;
220220
curFrameInfo.setPyFrame(this);
221221
this.line = this.location == null ? code.getFirstLineNo() : UNINITIALIZED_LINE;
222-
this.arguments = frameArgs;
223222
this.hasCustomLocals = true;
224223
this.localsDict = localsDict;
225224
// This is a synthetic frame, there will be no sync, mark everything as current
@@ -342,16 +341,10 @@ public int getLine() {
342341
}
343342

344343
/**
345-
* Prefer to use the
346-
* {@link com.oracle.graal.python.builtins.objects.frame.FrameBuiltins.GetGlobalsNode}.<br/>
347-
* <br/>
348-
*
349-
* Returns a dictionary with the locals, possibly creating it from the frame. Note that the
350-
* dictionary may have been modified and should then be updated with the current frame locals.
351-
* To that end, use the {@link GetLocalsNode} instead of calling this method directly.
344+
* Get the frame globals. Might be a dictionary or a PythonModule.
352345
*/
353346
public PythonObject getGlobals() {
354-
return PArguments.getGlobals(arguments);
347+
return globals;
355348
}
356349

357350
public RootCallTarget getTarget() {
@@ -365,12 +358,8 @@ public RootCallTarget getTarget() {
365358
return callTarget;
366359
}
367360

368-
public Object[] getArguments() {
369-
return arguments;
370-
}
371-
372-
public void setArguments(Object[] arguments2) {
373-
this.arguments = arguments2;
361+
public void setGlobals(PythonObject globals) {
362+
this.globals = globals;
374363
}
375364

376365
public void setLocation(Node location) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,4 @@ public static Object getArgument(Object[] arguments, int index) {
208208
public static Object getArgument(Frame frame, int index) {
209209
return getArgument(frame.getArguments(), index);
210210
}
211-
212-
/**
213-
* Synchronizes the arguments array of a Truffle frame with a {@link PFrame}. Copies only those
214-
* arguments that are necessary to be synchronized between the two.
215-
*/
216-
public static void synchronizeArgs(Frame frameToMaterialize, PFrame escapedFrame) {
217-
Object[] arguments = frameToMaterialize.getArguments();
218-
Object[] copiedArgs = new Object[arguments.length];
219-
220-
// copy only some carefully picked internal arguments
221-
setSpecialArgument(copiedArgs, getSpecialArgument(arguments));
222-
setGlobals(copiedArgs, getGlobals(arguments));
223-
setFunctionObject(copiedArgs, getFunctionObject(arguments));
224-
225-
escapedFrame.setArguments(copiedArgs);
226-
}
227211
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static Object executeUncached(RootCallTarget callTarget, Object[] argumen
153153
}
154154

155155
@Specialization
156-
static Object doDirect(VirtualFrame frame, Node inliningTarget, RootCallTarget callTarget, Object[] arguments,
156+
static Object doIndirect(VirtualFrame frame, Node inliningTarget, RootCallTarget callTarget, Object[] arguments,
157157
@Cached InlinedConditionProfile profileIsNullFrame,
158158
@Cached ExecutionContext.CallContext callContext,
159159
@Cached IndirectCallNode callNode) {
@@ -167,7 +167,7 @@ static Object doDirect(VirtualFrame frame, Node inliningTarget, RootCallTarget c
167167
IndirectCalleeContext.exit(threadState, state);
168168
}
169169
} else {
170-
callContext.prepareIndirectCall(frame, arguments, callTarget);
170+
callContext.prepareCall(frame, arguments, callTarget);
171171
return callNode.call(callTarget, arguments);
172172
}
173173
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static PFrame alreadyEscapedFrame(@SuppressWarnings("unused") Node location, boo
205205
public static PFrame materializeGeneratorFrame(Node location, MaterializedFrame generatorFrame, PFrame.Reference frameRef) {
206206
PFrame escapedFrame = PFactory.createPFrame(PythonLanguage.get(location), frameRef, location, false);
207207
escapedFrame.setLocals(generatorFrame);
208-
PArguments.synchronizeArgs(generatorFrame, escapedFrame);
208+
escapedFrame.setGlobals(PArguments.getGlobals(generatorFrame));
209209
return escapedFrame;
210210
}
211211

@@ -241,7 +241,7 @@ private static PFrame doEscapeFrame(Frame frameToMaterialize, PFrame escapedFram
241241
topFrameRef.setPyFrame(escapedFrame);
242242

243243
// on a freshly created PFrame, we do always sync the arguments
244-
PArguments.synchronizeArgs(frameToMaterialize, escapedFrame);
244+
escapedFrame.setGlobals(PArguments.getGlobals(frameToMaterialize));
245245
escapedFrame.setLastCallerFlags(getCallerFlags(forceSync));
246246
if (forceSync) {
247247
syncValuesNode.execute(escapedFrame, frameToMaterialize, location);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,6 @@ public abstract class ExecutionContext {
164164
@GenerateUncached
165165
public abstract static class CallContext extends Node {
166166

167-
/**
168-
* Prepare an indirect call from a Python frame to a Python function.
169-
*/
170-
public void prepareIndirectCall(VirtualFrame frame, Object[] callArguments, RootCallTarget callTarget) {
171-
PRootNode rootNode = (PRootNode) callTarget.getRootNode();
172-
executePrepareCall(frame, callArguments, rootNode.getCallerFlags());
173-
}
174-
175167
/**
176168
* Prepare a call from a Python frame to a Python function.
177169
*/

0 commit comments

Comments
 (0)