|
52 | 52 | import com.oracle.truffle.api.dsl.Specialization;
|
53 | 53 | import com.oracle.truffle.api.frame.VirtualFrame;
|
54 | 54 | import com.oracle.truffle.api.object.DynamicObject;
|
| 55 | +import com.oracle.truffle.api.profiles.ConditionProfile; |
55 | 56 | import com.oracle.truffle.api.profiles.ValueProfile;
|
56 | 57 |
|
57 | 58 | @NodeChildren({@NodeChild(value = "object", type = PNode.class), @NodeChild(value = "key", type = PNode.class), @NodeChild(value = "rhs", type = PNode.class)})
|
@@ -93,16 +94,21 @@ public PNode getPrimaryNode() {
|
93 | 94 | protected Object doClass(PythonClass cls, Object key, Object value,
|
94 | 95 | @Cached("createIdentityProfile()") ValueProfile setattributeProfile,
|
95 | 96 | @Cached("create(__SETATTR__)") LookupAttributeInMRONode setattributeLookup,
|
96 |
| - @Cached("create()") CallTernaryMethodNode callSetattr) { |
97 |
| - Object descr = setattributeProfile.profile(setattributeLookup.execute(cls)); |
98 |
| - PythonClass[] mro = cls.getMethodResolutionOrder(); |
99 |
| - for (int i = 0; i < mro.length; i++) { |
100 |
| - PythonClass kls = mro[i]; |
101 |
| - DynamicObject storage = kls.getStorage(); |
102 |
| - if (storage.containsKey(key)) { |
103 |
| - storage.getShape().getProperty(key).getLocation().getFinalAssumption().invalidate(); |
| 97 | + @Cached("create()") CallTernaryMethodNode callSetattr, |
| 98 | + @Cached("createBinaryProfile()") ConditionProfile isAddingAttributeProfile) { |
| 99 | + // add new attribute case: invalidate the final assumption for the classes in the MRO chain |
| 100 | + // this is needed to de-specialize LookupAttributeInMRONode.lookupConstantMROCached |
| 101 | + if (isAddingAttributeProfile.profile(cls.getStorage().containsKey(key))) { |
| 102 | + PythonClass[] mro = cls.getMethodResolutionOrder(); |
| 103 | + for (int i = 0; i < mro.length; i++) { |
| 104 | + PythonClass kls = mro[i]; |
| 105 | + DynamicObject storage = kls.getStorage(); |
| 106 | + if (storage.containsKey(key)) { |
| 107 | + storage.getShape().getProperty(key).getLocation().getFinalAssumption().invalidate(); |
| 108 | + } |
104 | 109 | }
|
105 | 110 | }
|
| 111 | + Object descr = setattributeProfile.profile(setattributeLookup.execute(cls)); |
106 | 112 | return callSetattr.execute(descr, cls, key, value);
|
107 | 113 | }
|
108 | 114 |
|
|
0 commit comments