Skip to content

Commit 95f5007

Browse files
committed
fix import node
1 parent cae90ef commit 95f5007

File tree

1 file changed

+19
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
2929
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
30+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
3031
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ImportError;
3132

3233
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -40,6 +41,7 @@
4041
import com.oracle.graal.python.nodes.subscript.GetItemNode;
4142
import com.oracle.graal.python.runtime.exception.PException;
4243
import com.oracle.truffle.api.CompilerDirectives;
44+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
4345
import com.oracle.truffle.api.frame.VirtualFrame;
4446
import com.oracle.truffle.api.nodes.ExplodeLoop;
4547

@@ -51,9 +53,11 @@ public class ImportFromNode extends AbstractImportNode {
5153
@Child private GetAttributeNode getName;
5254
@Child private GetItemNode getItem;
5355
@Child private ReadAttributeFromObjectNode readModules;
54-
@Child private LookupAndCallBinaryNode readNode = LookupAndCallBinaryNode.create(__GETATTRIBUTE__);
56+
@Child private LookupAndCallBinaryNode getAttributeNode = LookupAndCallBinaryNode.create(__GETATTRIBUTE__);
57+
@Child private LookupAndCallBinaryNode getAttrNode = LookupAndCallBinaryNode.create(__GETATTR__);
5558
@Child private PRaiseNode raiseNode;
56-
private final IsBuiltinClassProfile attrErrorProfile = IsBuiltinClassProfile.create();
59+
@CompilationFinal private final IsBuiltinClassProfile getAttributeErrorProfile = IsBuiltinClassProfile.create();
60+
@CompilationFinal private final IsBuiltinClassProfile getAttrErrorProfile = IsBuiltinClassProfile.create();
5761

5862
public static ImportFromNode create(String importee, String[] fromlist, WriteNode[] readNodes, int level) {
5963
return new ImportFromNode(importee, fromlist, readNodes, level);
@@ -70,6 +74,15 @@ protected ImportFromNode(String importee, String[] fromlist, WriteNode[] readNod
7074
this.level = level;
7175
}
7276

77+
private Object readAttributeFromModule(VirtualFrame frame, Object module, String attr) {
78+
try {
79+
return getAttributeNode.executeObject(frame, module, attr);
80+
} catch (PException pe) {
81+
pe.expectAttributeError(getAttributeErrorProfile);
82+
return getAttrNode.executeObject(frame, module, attr);
83+
}
84+
}
85+
7386
@Override
7487
@ExplodeLoop
7588
public void executeVoid(VirtualFrame frame) {
@@ -79,9 +92,9 @@ public void executeVoid(VirtualFrame frame) {
7992
String attr = fromlist[i];
8093
WriteNode writeNode = aslist[i];
8194
try {
82-
writeNode.doWrite(frame, readNode.executeObject(frame, importedModule, attr));
83-
} catch (PException e) {
84-
e.expectAttributeError(attrErrorProfile);
95+
writeNode.doWrite(frame, readAttributeFromModule(frame, importedModule, attr));
96+
} catch (PException pe) {
97+
pe.expectAttributeError(getAttrErrorProfile);
8598
if (getName == null) {
8699
CompilerDirectives.transferToInterpreterAndInvalidate();
87100
getName = insert(GetAttributeNode.create(__NAME__, null));
@@ -94,7 +107,7 @@ public void executeVoid(VirtualFrame frame) {
94107
} else if (pkgname_o instanceof String) {
95108
pkgname = (String) pkgname_o;
96109
} else {
97-
throw e;
110+
throw pe;
98111
}
99112
String fullname = pkgname + "." + attr;
100113
if (getItem == null) {

0 commit comments

Comments
 (0)