|
28 | 28 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.KeyError;
|
29 | 29 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.NameError;
|
30 | 30 |
|
31 |
| -import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
32 | 31 | import com.oracle.graal.python.builtins.objects.PNone;
|
33 | 32 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
|
34 | 33 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
35 | 34 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
36 |
| -import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy; |
37 | 35 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
38 |
| -import com.oracle.graal.python.nodes.SpecialMethodNames; |
39 | 36 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
|
40 |
| -import com.oracle.graal.python.nodes.expression.BinaryComparisonNode; |
41 | 37 | import com.oracle.graal.python.nodes.expression.ExpressionNode;
|
42 | 38 | import com.oracle.graal.python.nodes.statement.StatementNode;
|
43 | 39 | import com.oracle.graal.python.nodes.subscript.GetItemNode;
|
|
49 | 45 | import com.oracle.truffle.api.dsl.Specialization;
|
50 | 46 | import com.oracle.truffle.api.frame.VirtualFrame;
|
51 | 47 | import com.oracle.truffle.api.nodes.NodeInfo;
|
52 |
| -import com.oracle.truffle.api.profiles.BranchProfile; |
53 | 48 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
54 | 49 |
|
55 | 50 | @NodeInfo(shortName = "read_global")
|
@@ -82,60 +77,33 @@ protected Object readGlobal(VirtualFrame frame) {
|
82 | 77 | return returnGlobalOrBuiltin(result);
|
83 | 78 | }
|
84 | 79 |
|
85 |
| - protected BinaryComparisonNode createContainsNode() { |
86 |
| - return BinaryComparisonNode.create(SpecialMethodNames.__CONTAINS__, null, "in"); |
87 |
| - } |
88 |
| - |
89 |
| - @Specialization(guards = "isInDict(frame)", rewriteOn = PException.class) |
| 80 | + @Specialization(guards = "isInBuiltinDict(frame)") |
90 | 81 | protected Object readGlobalDict(VirtualFrame frame,
|
91 |
| - @Cached("create()") BranchProfile isDict, |
92 |
| - @Cached("create()") BranchProfile isMappingproxy) { |
| 82 | + @Cached("create()") HashingStorageNodes.GetItemNode getItemNode) { |
93 | 83 | PythonObject globals = PArguments.getGlobals(frame);
|
94 |
| - if (globals instanceof PMappingproxy && globals.getPythonClass() == lookupClass(PythonBuiltinClassType.PMappingproxy)) { |
95 |
| - isMappingproxy.enter(); |
96 |
| - Object result = getGetItemNode().execute(((PMappingproxy) globals).getDictStorage(), attributeId); |
97 |
| - return returnGlobalOrBuiltin(result == null ? PNone.NO_VALUE : result); |
98 |
| - } else if (globals instanceof PDict && globals.getPythonClass() == lookupClass(PythonBuiltinClassType.PDict)) { |
99 |
| - isDict.enter(); |
100 |
| - Object result = getGetItemNode().execute(((PDict) globals).getDictStorage(), attributeId); |
101 |
| - return returnGlobalOrBuiltin(result == null ? PNone.NO_VALUE : result); |
102 |
| - } else { |
103 |
| - return returnGlobalOrBuiltin(getReadFromDict().execute(globals, attributeId)); |
104 |
| - } |
| 84 | + Object result = getItemNode.execute(((PDict) globals).getDictStorage(), attributeId); |
| 85 | + return returnGlobalOrBuiltin(result == null ? PNone.NO_VALUE : result); |
105 | 86 | }
|
106 | 87 |
|
107 |
| - private GetItemNode getReadFromDict() { |
108 |
| - if (readFromDictNode == null) { |
109 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
110 |
| - readFromDictNode = insert(GetItemNode.create()); |
111 |
| - } |
112 |
| - return readFromDictNode; |
113 |
| - } |
114 |
| - |
115 |
| - private HashingStorageNodes.GetItemNode getGetItemNode() { |
116 |
| - if (getHashingItemNode == null) { |
117 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
118 |
| - getHashingItemNode = insert(HashingStorageNodes.GetItemNode.create()); |
119 |
| - } |
120 |
| - return getHashingItemNode; |
| 88 | + @Specialization(guards = "isInDict(frame)", rewriteOn = PException.class) |
| 89 | + protected Object readGlobalDict(VirtualFrame frame, |
| 90 | + @Cached("create()") GetItemNode getItemNode) { |
| 91 | + return returnGlobalOrBuiltin(getItemNode.execute(PArguments.getGlobals(frame), attributeId)); |
121 | 92 | }
|
122 | 93 |
|
123 | 94 | @Specialization(guards = "isInDict(frame)")
|
124 | 95 | protected Object readGlobalDictWithException(VirtualFrame frame,
|
| 96 | + @Cached("create()") GetItemNode getItemNode, |
125 | 97 | @Cached("createBinaryProfile()") ConditionProfile errorProfile) {
|
126 | 98 | try {
|
127 |
| - Object result = getReadFromDict().execute(PArguments.getGlobals(frame), attributeId); |
| 99 | + Object result = getItemNode.execute(PArguments.getGlobals(frame), attributeId); |
128 | 100 | return returnGlobalOrBuiltin(result);
|
129 | 101 | } catch (PException e) {
|
130 | 102 | e.expect(KeyError, getCore(), errorProfile);
|
131 | 103 | return returnGlobalOrBuiltin(PNone.NO_VALUE);
|
132 | 104 | }
|
133 | 105 | }
|
134 | 106 |
|
135 |
| - public Object readGlobal(Object globals) { |
136 |
| - return returnGlobalOrBuiltin(globals); |
137 |
| - } |
138 |
| - |
139 | 107 | private Object returnGlobalOrBuiltin(Object result) {
|
140 | 108 | if (isGlobalProfile.profile(result != PNone.NO_VALUE)) {
|
141 | 109 | return result;
|
|
0 commit comments