27
27
28
28
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__NAME__ ;
29
29
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETATTRIBUTE__ ;
30
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETATTR__ ;
30
31
import static com .oracle .graal .python .runtime .exception .PythonErrorType .ImportError ;
31
32
32
33
import com .oracle .graal .python .builtins .objects .function .PArguments ;
40
41
import com .oracle .graal .python .nodes .subscript .GetItemNode ;
41
42
import com .oracle .graal .python .runtime .exception .PException ;
42
43
import com .oracle .truffle .api .CompilerDirectives ;
44
+ import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
43
45
import com .oracle .truffle .api .frame .VirtualFrame ;
44
46
import com .oracle .truffle .api .nodes .ExplodeLoop ;
45
47
@@ -51,9 +53,11 @@ public class ImportFromNode extends AbstractImportNode {
51
53
@ Child private GetAttributeNode getName ;
52
54
@ Child private GetItemNode getItem ;
53
55
@ 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__ );
55
58
@ 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 ();
57
61
58
62
public static ImportFromNode create (String importee , String [] fromlist , WriteNode [] readNodes , int level ) {
59
63
return new ImportFromNode (importee , fromlist , readNodes , level );
@@ -70,6 +74,15 @@ protected ImportFromNode(String importee, String[] fromlist, WriteNode[] readNod
70
74
this .level = level ;
71
75
}
72
76
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
+
73
86
@ Override
74
87
@ ExplodeLoop
75
88
public void executeVoid (VirtualFrame frame ) {
@@ -79,9 +92,9 @@ public void executeVoid(VirtualFrame frame) {
79
92
String attr = fromlist [i ];
80
93
WriteNode writeNode = aslist [i ];
81
94
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 );
85
98
if (getName == null ) {
86
99
CompilerDirectives .transferToInterpreterAndInvalidate ();
87
100
getName = insert (GetAttributeNode .create (__NAME__ , null ));
@@ -94,7 +107,7 @@ public void executeVoid(VirtualFrame frame) {
94
107
} else if (pkgname_o instanceof String ) {
95
108
pkgname = (String ) pkgname_o ;
96
109
} else {
97
- throw e ;
110
+ throw pe ;
98
111
}
99
112
String fullname = pkgname + "." + attr ;
100
113
if (getItem == null ) {
0 commit comments