42
42
43
43
import java .util .ArrayList ;
44
44
45
+ import com .oracle .graal .python .runtime .sequence .storage .MroSequenceStorage ;
45
46
import com .oracle .truffle .api .Assumption ;
46
47
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
47
48
import com .oracle .truffle .api .object .DynamicObject ;
@@ -143,7 +144,7 @@ public DynamicObject getStore() {
143
144
return store ;
144
145
}
145
146
146
- public static class FastDictStorage extends DynamicObjectStorage {
147
+ public static final class FastDictStorage extends DynamicObjectStorage {
147
148
public FastDictStorage () {
148
149
}
149
150
@@ -159,7 +160,7 @@ public HashingStorage copy(Equivalence eq) {
159
160
}
160
161
}
161
162
162
- public static class PythonObjectDictStorage extends DynamicObjectStorage {
163
+ public static final class PythonObjectDictStorage extends DynamicObjectStorage {
163
164
private final Assumption dictUnsetOrSameAsStorage ;
164
165
165
166
public PythonObjectDictStorage (DynamicObject store ) {
@@ -179,11 +180,40 @@ public Assumption getDictUnsetOrSameAsStorage() {
179
180
@ TruffleBoundary
180
181
public HashingStorage copy (Equivalence eq ) {
181
182
assert eq == HashingStorage .DEFAULT_EQIVALENCE ;
182
- return new PythonObjectDictStorage (getStore ().copy (getStore ().getShape ()));
183
+ return new FastDictStorage (getStore ().copy (getStore ().getShape ()));
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Special storage that is used in the type dict (i.e. {@code tp_dict}) of native types. Writing
189
+ * to this storage will cause the appropriate <it>attribute final</it> assumptions to be
190
+ * invalidated. Therefore, this storage links to the {@link MroSequenceStorage} of the type.
191
+ */
192
+ public static final class PythonNativeObjectDictStorage extends DynamicObjectStorage {
193
+ private final MroSequenceStorage mro ;
194
+
195
+ public PythonNativeObjectDictStorage (DynamicObject store , MroSequenceStorage mro ) {
196
+ super (store );
197
+ this .mro = mro ;
198
+ }
199
+
200
+ public MroSequenceStorage getMro () {
201
+ return mro ;
202
+ }
203
+
204
+ public void invalidateAttributeInMROFinalAssumptions (String name ) {
205
+ mro .invalidateAttributeInMROFinalAssumptions (name );
206
+ }
207
+
208
+ @ Override
209
+ @ TruffleBoundary
210
+ public HashingStorage copy (Equivalence eq ) {
211
+ assert eq == HashingStorage .DEFAULT_EQIVALENCE ;
212
+ return new FastDictStorage (getStore ().copy (getStore ().getShape ()));
183
213
}
184
214
}
185
215
186
- public static class PythonObjectHybridDictStorage extends DynamicObjectStorage {
216
+ public static final class PythonObjectHybridDictStorage extends DynamicObjectStorage {
187
217
private final EconomicMapStorage nonAttributesStorage ;
188
218
189
219
public PythonObjectHybridDictStorage (PythonObjectDictStorage storage ) {
0 commit comments