Skip to content

Commit 6e2055d

Browse files
committed
Fix: implement missing cases in the generic specialization.
1 parent b2b8ca7 commit 6e2055d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public abstract static class GetGlobalsNode extends PythonBuiltinNode {
7070

7171
@Specialization
7272
Object get(VirtualFrame curFrame, PFrame self) {
73-
if (self.hasFrame()) {
73+
if (self.isAssociated()) {
7474
PythonObject globals = self.getGlobals();
7575
if (globals instanceof PythonModule) {
7676
if (getDictNode == null) {
@@ -152,7 +152,7 @@ Object getUpdating(VirtualFrame frame, PFrame self,
152152
@Cached ReadLocalsNode readLocals,
153153
@Cached("createBinaryProfile()") ConditionProfile profile,
154154
@Cached MaterializeFrameNode materializeNode) {
155-
assert self.hasFrame() : "It's impossible to call f_locals on a frame without that frame having escaped";
155+
assert self.isAssociated() : "It's impossible to call f_locals on a frame without that frame having escaped";
156156
// Special case because this builtin can be called without going through an invoke node:
157157
// we need to sync the values of the frame if and only if 'self' represents the current
158158
// frame. If 'self' represents another frame on the stack, the values are already

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ public boolean isIncomplete() {
267267
}
268268

269269
/**
270-
* When this is true, the frame has escaped
270+
* {@code true} if this {@code PFrame} is associated with a {@code Frame}, i.e., it has a frame
271+
* info. On the other hand, {@code false} means that this {@code PFrame} has been created
272+
* artificially which is most commonly done to carry custom locals.
271273
**/
272-
public boolean hasFrame() {
274+
public boolean isAssociated() {
273275
return virtualFrameInfo != null;
274276
}
275277

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static PFrame freshPFrameInClassBody(VirtualFrame frame, Node location, boolean
145145
*
146146
* @see PFrame#isIncomplete
147147
**/
148-
@Specialization(guards = {"getPFrame(frameToMaterialize) != null", "!getPFrame(frameToMaterialize).hasFrame()"})
148+
@Specialization(guards = {"getPFrame(frameToMaterialize) != null", "!getPFrame(frameToMaterialize).isAssociated()"})
149149
static PFrame incompleteFrame(VirtualFrame frame, Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
150150
@Shared("factory") @Cached("createFactory()") PythonObjectFactory factory,
151151
@Shared("syncValuesNode") @Cached("createSyncNode()") SyncFrameValuesNode syncValuesNode) {
@@ -154,7 +154,7 @@ static PFrame incompleteFrame(VirtualFrame frame, Node location, boolean markAsE
154154
return doEscapeFrame(frame, frameToMaterialize, escapedFrame, markAsEscaped, forceSync && !inModuleRoot(location), syncValuesNode);
155155
}
156156

157-
@Specialization(guards = {"getPFrame(frameToMaterialize) != null", "getPFrame(frameToMaterialize).hasFrame()"}, replaces = "freshPFrame")
157+
@Specialization(guards = {"getPFrame(frameToMaterialize) != null", "getPFrame(frameToMaterialize).isAssociated()"}, replaces = "freshPFrame")
158158
static PFrame alreadyEscapedFrame(VirtualFrame frame, Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
159159
@Shared("syncValuesNode") @Cached("createSyncNode()") SyncFrameValuesNode syncValuesNode,
160160
@Cached("createBinaryProfile()") ConditionProfile syncProfile) {
@@ -170,16 +170,23 @@ static PFrame alreadyEscapedFrame(VirtualFrame frame, Node location, boolean mar
170170
return pyFrame;
171171
}
172172

173-
@Specialization(replaces = {"freshPFrame", "alreadyEscapedFrame"})
174-
static PFrame notInClassBody(VirtualFrame frame, Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
173+
@Specialization(replaces = {"freshPFrame", "alreadyEscapedFrame", "incompleteFrame"})
174+
static PFrame generic(VirtualFrame frame, Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize,
175175
@Shared("factory") @Cached("createFactory()") PythonObjectFactory factory,
176176
@Shared("syncValuesNode") @Cached("createSyncNode()") SyncFrameValuesNode syncValuesNode,
177177
@Cached("createBinaryProfile()") ConditionProfile syncProfile) {
178-
if (getPFrame(frameToMaterialize) != null) {
179-
return alreadyEscapedFrame(frame, location, markAsEscaped, forceSync, frameToMaterialize, syncValuesNode, syncProfile);
178+
PFrame pyFrame = getPFrame(frameToMaterialize);
179+
if (pyFrame != null) {
180+
if (pyFrame.isAssociated()) {
181+
return alreadyEscapedFrame(frame, location, markAsEscaped, forceSync, frameToMaterialize, syncValuesNode, syncProfile);
182+
} else {
183+
return incompleteFrame(frame, location, markAsEscaped, forceSync, frameToMaterialize, factory, syncValuesNode);
184+
}
180185
} else {
181186
if (inClassBody(frameToMaterialize)) {
182187
return freshPFrameInClassBody(frame, location, markAsEscaped, forceSync, frameToMaterialize, factory, syncValuesNode);
188+
} else if (isGeneratorFrame(frameToMaterialize)) {
189+
return freshPFrameForGenerator(location, markAsEscaped, forceSync, frameToMaterialize, factory);
183190
} else {
184191
return freshPFrame(frame, location, markAsEscaped, forceSync, frameToMaterialize, factory, syncValuesNode);
185192
}

0 commit comments

Comments
 (0)