Skip to content

Commit abc5cd1

Browse files
committed
[GR-27847] Avoid using DynamicObjectLibrary for checking shape flags
PullRequest: graalpython/1443
2 parents 4a9c2f2 + 4ffea5d commit abc5cd1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import com.oracle.truffle.api.dsl.ImportStatic;
7373
import com.oracle.truffle.api.dsl.Specialization;
7474
import com.oracle.truffle.api.library.CachedLibrary;
75-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
7675
import com.oracle.truffle.api.profiles.BranchProfile;
7776
import com.oracle.truffle.api.profiles.ConditionProfile;
7877

@@ -93,12 +92,12 @@ public static WriteAttributeToObjectNode getUncached() {
9392
return WriteAttributeToObjectNotTypeUncachedNodeGen.getUncached();
9493
}
9594

96-
protected static boolean isAttrWritable(DynamicObjectLibrary dyLib, IsBuiltinClassProfile exactBuiltinInstanceProfile, PythonObject self, Object key) {
95+
protected static boolean isAttrWritable(IsBuiltinClassProfile exactBuiltinInstanceProfile, PythonObject self, Object key) {
9796
if (isHiddenKey(key) || self instanceof PythonManagedClass || self instanceof PFunction || self instanceof PDecoratedMethod || self instanceof PythonModule ||
9897
self instanceof PBaseException) {
9998
return true;
10099
}
101-
if ((dyLib.getShapeFlags(self) & PythonObject.HAS_SLOTS_BUT_NO_DICT_FLAG) != 0) {
100+
if ((self.getShape().getFlags() & PythonObject.HAS_SLOTS_BUT_NO_DICT_FLAG) != 0) {
102101
return false;
103102
}
104103
return !exactBuiltinInstanceProfile.profileIsAnyBuiltinObject(self);
@@ -112,14 +111,13 @@ private static void handlePythonClass(ConditionProfile isClassProfile, PythonObj
112111

113112
// write to the DynamicObject
114113
@Specialization(guards = {
115-
"isAttrWritable(dyLib, exactBuiltinInstanceProfile, object, key)",
114+
"isAttrWritable(exactBuiltinInstanceProfile, object, key)",
116115
"isHiddenKey(key) || !lib.hasDict(object)"
117116
}, limit = "1")
118117
protected boolean writeToDynamicStorage(PythonObject object, Object key, Object value,
119118
@CachedLibrary("object") @SuppressWarnings("unused") PythonObjectLibrary lib,
120119
@Cached("create()") WriteAttributeToDynamicObjectNode writeAttributeToDynamicObjectNode,
121120
@Exclusive @Cached("createBinaryProfile()") ConditionProfile isClassProfile,
122-
@CachedLibrary("object") @SuppressWarnings("unused") DynamicObjectLibrary dyLib,
123121
@Exclusive @Cached @SuppressWarnings("unused") IsBuiltinClassProfile exactBuiltinInstanceProfile) {
124122
handlePythonClass(isClassProfile, object, key);
125123
return writeAttributeToDynamicObjectNode.execute(object.getStorage(), key, value);
@@ -156,19 +154,18 @@ private static boolean writeNativeGeneric(PythonAbstractNativeObject object, Obj
156154
}
157155
}
158156

159-
@Specialization(guards = "isErrorCase(dyLib, exactBuiltinInstanceProfile, lib, object, key)")
157+
@Specialization(guards = "isErrorCase(exactBuiltinInstanceProfile, lib, object, key)")
160158
protected static boolean doError(Object object, Object key, @SuppressWarnings("unused") Object value,
161159
@CachedLibrary(limit = "1") @SuppressWarnings("unused") PythonObjectLibrary lib,
162-
@CachedLibrary(limit = "1") @SuppressWarnings("unused") DynamicObjectLibrary dyLib,
163160
@Exclusive @Cached @SuppressWarnings("unused") IsBuiltinClassProfile exactBuiltinInstanceProfile,
164161
@Exclusive @Cached PRaiseNode raiseNode) {
165162
throw raiseNode.raise(PythonBuiltinClassType.AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, object, key);
166163
}
167164

168-
protected static boolean isErrorCase(DynamicObjectLibrary dyLib, IsBuiltinClassProfile exactBuiltinInstanceProfile, PythonObjectLibrary lib, Object object, Object key) {
165+
protected static boolean isErrorCase(IsBuiltinClassProfile exactBuiltinInstanceProfile, PythonObjectLibrary lib, Object object, Object key) {
169166
if (object instanceof PythonObject) {
170167
PythonObject self = (PythonObject) object;
171-
if (isAttrWritable(dyLib, exactBuiltinInstanceProfile, self, key) && (isHiddenKey(key) || !lib.hasDict(self))) {
168+
if (isAttrWritable(exactBuiltinInstanceProfile, self, key) && (isHiddenKey(key) || !lib.hasDict(self))) {
172169
return false;
173170
}
174171
if (!isHiddenKey(key) && lib.hasDict(self)) {

0 commit comments

Comments
 (0)