Skip to content

Commit c6b6b87

Browse files
committed
[GR-23251] Get test_pkg to pass.
PullRequest: graalpython/1158
2 parents d6a19b5 + 1f2dccb commit c6b6b87

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_1
2+
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_2
23
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_3
34
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_4
5+
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_5
6+
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_6
7+
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_7
48
*graalpython.lib-python.3.test.test_pkg.TestPkg.test_8

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,8 @@ static ConditionProfile[] getFlag() {
115115
static ConditionProfile[] getFlagUncached() {
116116
return DISABLED;
117117
}
118+
119+
public static GetCurrentFrameRef create() {
120+
return GetCurrentFrameRefNodeGen.create();
121+
}
118122
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
4444
import com.oracle.graal.python.builtins.objects.frame.PFrame;
4545
import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference;
4646
import com.oracle.graal.python.builtins.objects.function.PArguments;
47+
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4748
import com.oracle.graal.python.nodes.function.ClassBodyRootNode;
4849
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
4950
import com.oracle.truffle.api.dsl.Cached;
@@ -52,6 +53,7 @@
5253
import com.oracle.truffle.api.frame.Frame;
5354
import com.oracle.truffle.api.frame.VirtualFrame;
5455
import com.oracle.truffle.api.nodes.Node;
56+
import com.oracle.truffle.api.profiles.ConditionProfile;
5557

5658
/**
5759
* Read the locals from the passed frame, updating them from the frame if that is needed. This does
@@ -97,4 +99,26 @@ Object frameToUpdate(PFrame frame,
9799
@Shared("factory") @Cached PythonObjectFactory factory) {
98100
return frame.getLocals(factory);
99101
}
102+
103+
public static ReadLocalsNode create() {
104+
return ReadLocalsNodeGen.create();
105+
}
106+
107+
/**
108+
* Fast access to custom locals if a custom dict was provided by the caller and the python frame
109+
* does not escape.
110+
*
111+
* @param frame the current frame
112+
* @param havePyFrame profile if we do have a python frame (PFrame)
113+
* @param haveCustomLocals profile if the python frame has a custom set locals dict
114+
* @return the custom locals (if found) or the globals
115+
*/
116+
public static PythonObject fastGetCustomLocalsOrGlobals(VirtualFrame frame, ConditionProfile havePyFrame, ConditionProfile haveCustomLocals) {
117+
PFrame pyFrame = PArguments.getCurrentFrameInfo(frame).getPyFrame();
118+
if (havePyFrame.profile(pyFrame != null) && haveCustomLocals.profile(pyFrame.getLocals(null) != null)) {
119+
return (PythonObject) pyFrame.getLocals(null);
120+
}
121+
// return the globals
122+
return PArguments.getGlobals(frame);
123+
}
100124
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package com.oracle.graal.python.nodes.statement;
2727

28+
import static com.oracle.graal.python.nodes.frame.ReadLocalsNode.fastGetCustomLocalsOrGlobals;
29+
2830
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
2931
import com.oracle.graal.python.builtins.objects.dict.PDict;
3032
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -57,6 +59,8 @@
5759

5860
public class ImportStarNode extends AbstractImportNode {
5961
private final ConditionProfile javaImport = ConditionProfile.createBinaryProfile();
62+
private final ConditionProfile havePyFrame = ConditionProfile.createBinaryProfile();
63+
private final ConditionProfile haveCustomLocals = ConditionProfile.createBinaryProfile();
6064

6165
@Child private SetItemNode dictWriteNode;
6266
@Child private SetAttributeNode.Dynamic setAttributeNode;
@@ -105,7 +109,7 @@ public ImportStarNode(String moduleName, int level) {
105109
@Override
106110
public void executeVoid(VirtualFrame frame) {
107111
Object importedModule = importModule(frame, moduleName, PArguments.getGlobals(frame), new String[]{"*"}, level);
108-
PythonObject globals = PArguments.getGlobals(frame);
112+
PythonObject locals = fastGetCustomLocalsOrGlobals(frame, havePyFrame, haveCustomLocals);
109113

110114
if (javaImport.profile(emulateJython() && getContext().getEnv().isHostObject(importedModule))) {
111115
try {
@@ -116,7 +120,7 @@ public void executeVoid(VirtualFrame frame) {
116120
// interop protocol guarantees these are Strings
117121
String attrName = (String) interopLib.readArrayElement(hostAttrs, i);
118122
Object attr = interopLib.readMember(importedModule, attrName);
119-
writeAttribute(frame, globals, attrName, attr);
123+
writeAttribute(frame, locals, attrName, attr);
120124
}
121125
} catch (UnknownIdentifierException | UnsupportedMessageException | InvalidArrayIndexException e) {
122126
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -137,7 +141,7 @@ public void executeVoid(VirtualFrame frame) {
137141
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, attrNameObj);
138142
}
139143
Object attr = readAttribute(frame, importedModule, attrName);
140-
writeAttribute(frame, globals, attrName, attr);
144+
writeAttribute(frame, locals, attrName, attr);
141145
}
142146
} catch (PException e) {
143147
e.expectAttributeError(ensureIsAttributeErrorProfile());
@@ -148,7 +152,7 @@ public void executeVoid(VirtualFrame frame) {
148152
// 'ceval.c: import_all_from')
149153
if (!name.startsWith("__")) {
150154
Object attr = readAttribute(frame, importedModule, name);
151-
writeAttribute(frame, globals, name, attr);
155+
writeAttribute(frame, locals, name, attr);
152156
}
153157
}
154158
}

mx.graalpython/suite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@
4444
},
4545
{
4646
"name": "tools",
47-
"version": "d6816740ee697b99c43e8d7112cd368a9557a965",
47+
"version": "65dac0b492ab4f3a327e07cfc8b54558685b5b1c",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
],
5252
},
5353
{
5454
"name": "sulong",
55-
"version": "d6816740ee697b99c43e8d7112cd368a9557a965",
55+
"version": "65dac0b492ab4f3a327e07cfc8b54558685b5b1c",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},
5959
]
6060
},
6161
{
6262
"name": "regex",
63-
"version": "d6816740ee697b99c43e8d7112cd368a9557a965",
63+
"version": "65dac0b492ab4f3a327e07cfc8b54558685b5b1c",
6464
"subdir": True,
6565
"urls": [
6666
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)