Skip to content

Commit 2c19c19

Browse files
committed
ImportStarNode: do not force frame materialization, probe for custom locals or else use the globals
1 parent 33176dc commit 2c19c19

File tree

1 file changed

+10
-23
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement

1 file changed

+10
-23
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/ImportStarNode.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import com.oracle.graal.python.nodes.attributes.GetAttributeNode;
4040
import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetAnyAttributeNode;
4141
import com.oracle.graal.python.nodes.attributes.SetAttributeNode;
42-
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
43-
import com.oracle.graal.python.nodes.frame.ReadLocalsNode;
4442
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
4543
import com.oracle.graal.python.nodes.subscript.GetItemNode;
4644
import com.oracle.graal.python.nodes.subscript.SetItemNode;
@@ -60,6 +58,7 @@
6058

6159
public class ImportStarNode extends AbstractImportNode {
6260
private final ConditionProfile javaImport = ConditionProfile.createBinaryProfile();
61+
private final ConditionProfile haveCustomLocals = ConditionProfile.createBinaryProfile();
6362

6463
@Child private SetItemNode dictWriteNode;
6564
@Child private SetAttributeNode.Dynamic setAttributeNode;
@@ -68,8 +67,6 @@ public class ImportStarNode extends AbstractImportNode {
6867
@Child private CastToJavaStringNode castToStringNode;
6968
@Child private GetAnyAttributeNode readNode;
7069
@Child private PRaiseNode raiseNode;
71-
@Child private MaterializeFrameNode getPFrameNode;
72-
@Child private ReadLocalsNode getLocalsNode;
7370

7471
@Child private IsBuiltinClassProfile isAttributeErrorProfile;
7572

@@ -109,9 +106,15 @@ public ImportStarNode(String moduleName, int level) {
109106

110107
@Override
111108
public void executeVoid(VirtualFrame frame) {
112-
Object importedModule = importModule(frame, moduleName, PArguments.getGlobals(frame), new String[]{"*"}, level);
113-
PFrame pFrame = ensureGetPFrameNode().execute(frame, this, true, true);
114-
PythonObject locals = (PythonObject) ensureGetLocalsNode().execute(frame, pFrame);
109+
PythonObject globals = PArguments.getGlobals(frame);
110+
Object importedModule = importModule(frame, moduleName, globals, new String[]{"*"}, level);
111+
PythonObject locals = globals;
112+
113+
Object customLocals = PArguments.getCustomLocals(frame);
114+
if (haveCustomLocals.profile(customLocals != null)) {
115+
assert customLocals instanceof PFrame.Reference;
116+
locals = (PythonObject) ((PFrame.Reference) customLocals).getPyFrame().getLocals(factory());
117+
}
115118

116119
if (javaImport.profile(emulateJython() && getContext().getEnv().isHostObject(importedModule))) {
117120
try {
@@ -185,22 +188,6 @@ private CastToJavaStringNode ensureCastToStringNode() {
185188
return castToStringNode;
186189
}
187190

188-
private MaterializeFrameNode ensureGetPFrameNode() {
189-
if (getPFrameNode == null) {
190-
CompilerDirectives.transferToInterpreterAndInvalidate();
191-
getPFrameNode = insert(MaterializeFrameNode.create());
192-
}
193-
return getPFrameNode;
194-
}
195-
196-
private ReadLocalsNode ensureGetLocalsNode() {
197-
if (getLocalsNode == null) {
198-
CompilerDirectives.transferToInterpreterAndInvalidate();
199-
getLocalsNode = insert(ReadLocalsNode.create());
200-
}
201-
return getLocalsNode;
202-
}
203-
204191
private IsBuiltinClassProfile ensureIsAttributeErrorProfile() {
205192
if (isAttributeErrorProfile == null) {
206193
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)