Skip to content

Commit 3f4d72a

Browse files
committed
Move 'attributeInMroFinal' assumptions to 'MroSequenceStorage'.
1 parent 355b41f commit 3f4d72a

File tree

9 files changed

+415
-364
lines changed

9 files changed

+415
-364
lines changed

graalpython/com.oracle.graal.python.cext/src/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ int PyType_Ready(PyTypeObject* cls) {
383383
}
384384

385385
/* initialize mro */
386-
cls->tp_mro = UPCALL_CEXT_O(_jls_PyTruffle_Compute_Mro, cls);
386+
cls->tp_mro = UPCALL_CEXT_O(_jls_PyTruffle_Compute_Mro, cls, polyglot_from_string(cls->tp_name, SRC_CS));
387387

388388
/* Inherit special flags from dominant base */
389389
if (cls->tp_base != NULL)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@
118118
import com.oracle.graal.python.builtins.objects.str.PString;
119119
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
120120
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
121-
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
122121
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
123-
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
122+
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
124123
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
125124
import com.oracle.graal.python.builtins.objects.type.PythonClass;
125+
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
126126
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
127127
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
128128
import com.oracle.graal.python.nodes.PGuards;
@@ -2312,14 +2312,15 @@ int add(Object self, @SuppressWarnings("unused") Object o) {
23122312

23132313
}
23142314

2315-
@Builtin(name = "PyTruffle_Compute_Mro", fixedNumOfPositionalArgs = 1)
2315+
@Builtin(name = "PyTruffle_Compute_Mro", fixedNumOfPositionalArgs = 2)
23162316
@GenerateNodeFactory
2317-
public abstract static class PyTruffle_Compute_Mro extends PythonUnaryBuiltinNode {
2317+
@TypeSystemReference(PythonArithmeticTypes.class)
2318+
public abstract static class PyTruffle_Compute_Mro extends PythonBinaryBuiltinNode {
23182319

23192320
@Specialization
2320-
Object doIt(PythonNativeObject self) {
2321+
Object doIt(PythonNativeObject self, String className) {
23212322
PythonAbstractClass[] doSlowPath = TypeNodes.ComputeMroNode.doSlowPath(PythonNativeClass.cast(self));
2322-
return factory().createTuple(new MroSequenceStorage(doSlowPath));
2323+
return factory().createTuple(new MroSequenceStorage(className, doSlowPath));
23232324
}
23242325
}
23252326
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import java.util.ArrayList;
4444

45+
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
4546
import com.oracle.truffle.api.Assumption;
4647
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4748
import com.oracle.truffle.api.object.DynamicObject;
@@ -143,7 +144,7 @@ public DynamicObject getStore() {
143144
return store;
144145
}
145146

146-
public static class FastDictStorage extends DynamicObjectStorage {
147+
public static final class FastDictStorage extends DynamicObjectStorage {
147148
public FastDictStorage() {
148149
}
149150

@@ -159,7 +160,7 @@ public HashingStorage copy(Equivalence eq) {
159160
}
160161
}
161162

162-
public static class PythonObjectDictStorage extends DynamicObjectStorage {
163+
public static final class PythonObjectDictStorage extends DynamicObjectStorage {
163164
private final Assumption dictUnsetOrSameAsStorage;
164165

165166
public PythonObjectDictStorage(DynamicObject store) {
@@ -179,11 +180,40 @@ public Assumption getDictUnsetOrSameAsStorage() {
179180
@TruffleBoundary
180181
public HashingStorage copy(Equivalence eq) {
181182
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()));
183213
}
184214
}
185215

186-
public static class PythonObjectHybridDictStorage extends DynamicObjectStorage {
216+
public static final class PythonObjectHybridDictStorage extends DynamicObjectStorage {
187217
private final EconomicMapStorage nonAttributesStorage;
188218

189219
public PythonObjectHybridDictStorage(PythonObjectDictStorage storage) {

0 commit comments

Comments
 (0)