|
310 | 310 | import com.oracle.truffle.api.nodes.Node; |
311 | 311 | import com.oracle.truffle.api.nodes.RootNode; |
312 | 312 | import com.oracle.truffle.api.object.DynamicObject; |
313 | | -import com.oracle.truffle.api.object.Property; |
314 | 313 | import com.oracle.truffle.api.object.PropertyGetter; |
315 | 314 | import com.oracle.truffle.api.object.Shape; |
316 | 315 | import com.oracle.truffle.api.profiles.InlinedBranchProfile; |
@@ -1933,19 +1932,8 @@ public static Object doIt(VirtualFrame frame, |
1933 | 1932 |
|
1934 | 1933 | @Operation(storeBytecodeIndex = true) |
1935 | 1934 | @ConstantOperand(type = TruffleString.class) |
1936 | | - @ImportStatic({PGuards.class, TpSlots.class}) |
| 1935 | + @ImportStatic({PGuards.class, TpSlots.class, PythonUtils.class}) |
1937 | 1936 | public static final class GetAttribute { |
1938 | | - static PropertyGetter getPropertyGetterWithFinalAssumption(Shape shape, Object key) { |
1939 | | - PropertyGetter getter = shape.makePropertyGetter(key); |
1940 | | - if (getter != null) { |
1941 | | - Property property = shape.getProperty(key); |
1942 | | - if (property != null) { |
1943 | | - property.getLocation().getFinalAssumption(); |
1944 | | - } |
1945 | | - } |
1946 | | - return getter; |
1947 | | - } |
1948 | | - |
1949 | 1937 | // Builtin module object fast-path: we know there aren't any descriptors for other than |
1950 | 1938 | // dunder (__xxx__) names |
1951 | 1939 | public static Object loadModuleValue(PythonModule object, Shape cachedShape, PropertyGetter cachedPropertyGetter) { |
@@ -2018,7 +2006,7 @@ static Object doType(VirtualFrame frame, TruffleString key, PythonManagedClass r |
2018 | 2006 | return value; |
2019 | 2007 | } |
2020 | 2008 |
|
2021 | | - // Object instance field fast-path: for cases where there is no descriptor and it's just |
| 2009 | + // Object instance field fast-path: for cases where there is no descriptor, and it's just |
2022 | 2010 | // simple DOM property read |
2023 | 2011 | public static Object loadInstanceValue(Node inliningTarget, PythonObject object, LookupAttributeInMRONode getDesc, Shape cachedShape, PropertyGetter cachedPropertyGetter, |
2024 | 2012 | InlineWeakValueProfile slotsValueProfile) { |
@@ -2086,13 +2074,46 @@ public static Object doItUncached(VirtualFrame frame, TruffleString key, Object |
2086 | 2074 | @Operation(storeBytecodeIndex = true) |
2087 | 2075 | @ConstantOperand(type = TruffleString.class) |
2088 | 2076 | public static final class SetAttribute { |
2089 | | - @Specialization |
| 2077 | + public static boolean canStoreInstanceValue(Node inliningTarget, PythonObject object, Shape cachedShape, LookupAttributeInMRONode getDesc, |
| 2078 | + GetObjectSlotsNode getDescSlotsNode, InlineWeakValueProfile slotsValueProfile) { |
| 2079 | + TpSlots slots; |
| 2080 | + Object type = cachedShape.getDynamicType(); |
| 2081 | + if (type instanceof PythonBuiltinClassType pbct) { |
| 2082 | + slots = pbct.getSlots(); |
| 2083 | + } else if (type instanceof PythonManagedClass klass) { |
| 2084 | + slots = slotsValueProfile.execute(inliningTarget, klass.getTpSlots()); |
| 2085 | + } else { |
| 2086 | + return false; |
| 2087 | + } |
| 2088 | + if (slots.tp_setattro() == ObjectBuiltins.SLOTS.tp_setattro()) { |
| 2089 | + Object descr = getDesc.execute(type); |
| 2090 | + if (descr == PNone.NO_VALUE || getDescSlotsNode.execute(inliningTarget, descr).tp_descr_set() == null) { |
| 2091 | + assert object.checkDictFlags(); |
| 2092 | + return (cachedShape.getFlags() & (PythonObject.HAS_MATERIALIZED_DICT | PythonObject.HAS_SLOTS_BUT_NO_DICT_FLAG)) == 0; |
| 2093 | + } |
| 2094 | + } |
| 2095 | + return false; |
| 2096 | + } |
| 2097 | + |
| 2098 | + @ForceQuickening |
| 2099 | + @Specialization(guards = {"cachedShape.check(receiver)", "canStoreInstanceValue(inliningTarget, receiver, cachedShape, getDesc, getDescSlotsNode, slotsValueProfile)"}, limit = "3") |
| 2100 | + static void doInstanceValue(TruffleString key, Object value, PythonObject receiver, |
| 2101 | + @Bind Node inliningTarget, |
| 2102 | + @Cached("receiver.getShape()") Shape cachedShape, |
| 2103 | + @Cached("create(key)") LookupAttributeInMRONode getDesc, |
| 2104 | + @Cached GetObjectSlotsNode getDescSlotsNode, |
| 2105 | + @Cached InlineWeakValueProfile slotsValueProfile, |
| 2106 | + @Cached DynamicObject.PutNode putNode) { |
| 2107 | + putNode.execute(receiver, key, value); |
| 2108 | + } |
| 2109 | + |
| 2110 | + @Specialization(replaces = "doInstanceValue") |
2090 | 2111 | public static void doIt(VirtualFrame frame, |
2091 | 2112 | TruffleString key, |
2092 | 2113 | Object value, |
2093 | 2114 | Object object, |
2094 | 2115 | @Bind Node inliningTarget, |
2095 | | - @Cached PyObjectSetAttr setAttrNode) { |
| 2116 | + @Exclusive @Cached PyObjectSetAttr setAttrNode) { |
2096 | 2117 | setAttrNode.execute(frame, inliningTarget, object, key, value); |
2097 | 2118 | } |
2098 | 2119 | } |
|
0 commit comments