41
41
package com .oracle .graal .python .nodes .attributes ;
42
42
43
43
import com .oracle .graal .python .builtins .objects .PNone ;
44
+ import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
45
+ import com .oracle .graal .python .builtins .objects .common .PHashingCollection ;
44
46
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
45
47
import com .oracle .graal .python .builtins .objects .str .PString ;
48
+ import com .oracle .graal .python .nodes .PGuards ;
46
49
import com .oracle .graal .python .nodes .PNodeWithContext ;
47
50
import com .oracle .graal .python .nodes .interop .PForeignToPTypeNode ;
48
- import com .oracle .graal .python .nodes .PGuards ;
49
51
import com .oracle .graal .python .runtime .PythonOptions ;
50
52
import com .oracle .truffle .api .Assumption ;
51
53
import com .oracle .truffle .api .CompilerDirectives ;
@@ -102,6 +104,7 @@ protected Object attrKey(Object key) {
102
104
@ Specialization (limit = "1" , //
103
105
guards = {
104
106
"object == cachedObject" ,
107
+ "cachedDict == null" ,
105
108
"checkShape(object, cachedObject, cachedShape)" ,
106
109
"key == cachedKey" ,
107
110
"!isNull(loc)" ,
@@ -116,6 +119,7 @@ protected Object readDirectFinal(PythonObject object, Object key,
116
119
@ Cached ("key" ) Object cachedKey ,
117
120
@ Cached ("attrKey(key)" ) Object attrKey ,
118
121
@ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
122
+ @ Cached ("object.getDict()" ) PHashingCollection cachedDict ,
119
123
@ Cached ("cachedShape.getValidAssumption()" ) Assumption layoutAssumption ,
120
124
@ Cached ("getLocationOrNull(cachedShape.getProperty(attrKey))" ) Location loc ,
121
125
@ Cached ("loc.getFinalAssumption()" ) Assumption finalAssumption ,
@@ -133,6 +137,7 @@ private static boolean assertFinal(PythonObject object, Object key, Object cache
133
137
@ Specialization (limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)" , //
134
138
guards = {
135
139
"object.getStorage().getShape() == cachedShape" ,
140
+ "cachedDict == null" ,
136
141
"key == cachedKey" ,
137
142
"isNull(loc) || !loc.isAssumedFinal()" ,
138
143
}, //
@@ -141,6 +146,7 @@ protected Object readDirect(PythonObject object, Object key,
141
146
@ Cached ("key" ) Object cachedKey ,
142
147
@ Cached ("attrKey(cachedKey)" ) Object attrKey ,
143
148
@ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
149
+ @ Cached ("object.getDict()" ) PHashingCollection cachedDict ,
144
150
@ Cached ("cachedShape.getValidAssumption()" ) Assumption layoutAssumption ,
145
151
@ Cached ("getLocationOrNull(cachedShape.getProperty(attrKey))" ) Location loc ) {
146
152
if (loc == null ) {
@@ -153,18 +159,20 @@ protected Object readDirect(PythonObject object, Object key,
153
159
@ SuppressWarnings ("unused" )
154
160
@ Specialization (guards = {
155
161
"object.getStorage().getShape() == cachedShape" ,
162
+ "cachedDict == null" ,
156
163
"!layoutAssumption.isValid()"
157
164
})
158
165
protected Object updateShapeAndRead (PythonObject object , Object key ,
159
166
@ Cached ("object.getStorage().getShape()" ) Shape cachedShape ,
167
+ @ Cached ("object.getDict()" ) PHashingCollection cachedDict ,
160
168
@ Cached ("cachedShape.getValidAssumption()" ) Assumption layoutAssumption ,
161
169
@ Cached ("create()" ) ReadAttributeFromObjectNode nextNode ) {
162
170
CompilerDirectives .transferToInterpreter ();
163
171
object .getStorage ().updateShape ();
164
172
return nextNode .execute (object , key );
165
173
}
166
174
167
- @ Specialization (replaces = "readDirect" )
175
+ @ Specialization (guards = "object.getDict() == null" , replaces = "readDirect" )
168
176
protected Object readIndirect (PythonObject object , Object key ) {
169
177
Object value = object .getStorage ().get (attrKey (key ));
170
178
if (value == null ) {
@@ -174,6 +182,17 @@ protected Object readIndirect(PythonObject object, Object key) {
174
182
}
175
183
}
176
184
185
+ @ Specialization (guards = "object.getDict() != null" )
186
+ protected Object readFromDict (PythonObject object , Object key ,
187
+ @ Cached ("create()" ) HashingStorageNodes .GetItemNode getItemNode ) {
188
+ Object value = getItemNode .execute (object .getDict ().getDictStorage (), key );
189
+ if (value == null ) {
190
+ return PNone .NO_VALUE ;
191
+ } else {
192
+ return value ;
193
+ }
194
+ }
195
+
177
196
@ Specialization (guards = "isForeignObject(object)" )
178
197
protected Object readForeign (TruffleObject object , Object key ,
179
198
@ Cached ("create()" ) PForeignToPTypeNode fromForeign ,
0 commit comments