42
42
43
43
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
44
44
import com .oracle .graal .python .builtins .objects .PNone ;
45
+ import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
45
46
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .GetTypeMemberNode ;
46
47
import com .oracle .graal .python .builtins .objects .cext .capi .NativeMember ;
47
- import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
48
48
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
49
49
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
50
50
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
72
72
import com .oracle .truffle .api .dsl .ImportStatic ;
73
73
import com .oracle .truffle .api .dsl .Specialization ;
74
74
import com .oracle .truffle .api .library .CachedLibrary ;
75
+ import com .oracle .truffle .api .object .DynamicObjectLibrary ;
75
76
import com .oracle .truffle .api .profiles .BranchProfile ;
76
77
import com .oracle .truffle .api .profiles .ConditionProfile ;
77
78
@@ -92,11 +93,14 @@ public static WriteAttributeToObjectNode getUncached() {
92
93
return WriteAttributeToObjectNotTypeUncachedNodeGen .getUncached ();
93
94
}
94
95
95
- protected static boolean isAttrWritable (IsBuiltinClassProfile exactBuiltinInstanceProfile , PythonObject self , Object key ) {
96
+ protected static boolean isAttrWritable (DynamicObjectLibrary dyLib , IsBuiltinClassProfile exactBuiltinInstanceProfile , PythonObject self , Object key ) {
96
97
if (isHiddenKey (key ) || self instanceof PythonManagedClass || self instanceof PFunction || self instanceof PDecoratedMethod || self instanceof PythonModule ||
97
98
self instanceof PBaseException ) {
98
99
return true ;
99
100
}
101
+ if ((dyLib .getShapeFlags (self ) & PythonObject .HAS_SLOTS_BUT_NO_DICT_FLAG ) != 0 ) {
102
+ return false ;
103
+ }
100
104
return !exactBuiltinInstanceProfile .profileIsAnyBuiltinObject (self );
101
105
}
102
106
@@ -108,13 +112,14 @@ private static void handlePythonClass(ConditionProfile isClassProfile, PythonObj
108
112
109
113
// write to the DynamicObject
110
114
@ Specialization (guards = {
111
- "isAttrWritable(exactBuiltinInstanceProfile, object, key)" ,
115
+ "isAttrWritable(dyLib, exactBuiltinInstanceProfile, object, key)" ,
112
116
"isHiddenKey(key) || !lib.hasDict(object)"
113
117
}, limit = "1" )
114
118
protected boolean writeToDynamicStorage (PythonObject object , Object key , Object value ,
115
119
@ CachedLibrary ("object" ) @ SuppressWarnings ("unused" ) PythonObjectLibrary lib ,
116
120
@ Cached ("create()" ) WriteAttributeToDynamicObjectNode writeAttributeToDynamicObjectNode ,
117
121
@ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile isClassProfile ,
122
+ @ CachedLibrary ("object" ) @ SuppressWarnings ("unused" ) DynamicObjectLibrary dyLib ,
118
123
@ Exclusive @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile exactBuiltinInstanceProfile ) {
119
124
handlePythonClass (isClassProfile , object , key );
120
125
return writeAttributeToDynamicObjectNode .execute (object .getStorage (), key , value );
@@ -151,18 +156,19 @@ private static boolean writeNativeGeneric(PythonAbstractNativeObject object, Obj
151
156
}
152
157
}
153
158
154
- @ Specialization (guards = "isErrorCase(exactBuiltinInstanceProfile, lib, object, key)" )
159
+ @ Specialization (guards = "isErrorCase(dyLib, exactBuiltinInstanceProfile, lib, object, key)" )
155
160
protected static boolean doError (Object object , Object key , @ SuppressWarnings ("unused" ) Object value ,
156
161
@ CachedLibrary (limit = "1" ) @ SuppressWarnings ("unused" ) PythonObjectLibrary lib ,
162
+ @ CachedLibrary (limit = "1" ) @ SuppressWarnings ("unused" ) DynamicObjectLibrary dyLib ,
157
163
@ Exclusive @ Cached @ SuppressWarnings ("unused" ) IsBuiltinClassProfile exactBuiltinInstanceProfile ,
158
164
@ Exclusive @ Cached PRaiseNode raiseNode ) {
159
165
throw raiseNode .raise (PythonBuiltinClassType .AttributeError , ErrorMessages .OBJ_P_HAS_NO_ATTR_S , object , key );
160
166
}
161
167
162
- protected static boolean isErrorCase (IsBuiltinClassProfile exactBuiltinInstanceProfile , PythonObjectLibrary lib , Object object , Object key ) {
168
+ protected static boolean isErrorCase (DynamicObjectLibrary dyLib , IsBuiltinClassProfile exactBuiltinInstanceProfile , PythonObjectLibrary lib , Object object , Object key ) {
163
169
if (object instanceof PythonObject ) {
164
170
PythonObject self = (PythonObject ) object ;
165
- if (isAttrWritable (exactBuiltinInstanceProfile , self , key ) && (isHiddenKey (key ) || !lib .hasDict (self ))) {
171
+ if (isAttrWritable (dyLib , exactBuiltinInstanceProfile , self , key ) && (isHiddenKey (key ) || !lib .hasDict (self ))) {
166
172
return false ;
167
173
}
168
174
if (!isHiddenKey (key ) && lib .hasDict (self )) {
0 commit comments