50
50
import com .oracle .graal .python .builtins .objects .cext .structs .CFields ;
51
51
import com .oracle .graal .python .builtins .objects .cext .structs .CStructAccess ;
52
52
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
53
+ import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
53
54
import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes .HashingStorageSetItem ;
54
55
import com .oracle .graal .python .builtins .objects .dict .PDict ;
55
56
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
@@ -188,7 +189,7 @@ private static boolean writeToDynamicStorageManagedClass(PythonManagedClass klas
188
189
}
189
190
190
191
// write to the dict: the basic specialization for non-classes
191
- @ Specialization (guards = {"dict != null" , "!isManagedClass(object)" })
192
+ @ Specialization (guards = {"dict != null" , "!isManagedClass(object)" , "!isNoValue(value)" })
192
193
static boolean writeToDictNoType (@ SuppressWarnings ("unused" ) PythonObject object , TruffleString key , Object value ,
193
194
@ Bind ("this" ) Node inliningTarget ,
194
195
@ SuppressWarnings ("unused" ) @ Shared ("getDict" ) @ Cached GetDictIfExistsNode getDict ,
@@ -199,7 +200,7 @@ static boolean writeToDictNoType(@SuppressWarnings("unused") PythonObject object
199
200
}
200
201
201
202
// write to the dict & PythonManagedClass -> requires calling onAttributeUpdate
202
- @ Specialization (guards = {"dict != null" })
203
+ @ Specialization (guards = {"dict != null" , "!isNoValue(value)" })
203
204
boolean writeToDictBuiltinType (PythonBuiltinClass klass , TruffleString key , Object value ,
204
205
@ Bind ("this" ) Node inliningTarget ,
205
206
@ SuppressWarnings ("unused" ) @ Shared ("getDict" ) @ Cached GetDictIfExistsNode getDict ,
@@ -216,7 +217,7 @@ boolean writeToDictBuiltinType(PythonBuiltinClass klass, TruffleString key, Obje
216
217
}
217
218
}
218
219
219
- @ Specialization (guards = {"dict != null" })
220
+ @ Specialization (guards = {"dict != null" , "!isNoValue(value)" })
220
221
static boolean writeToDictClass (PythonClass klass , TruffleString key , Object value ,
221
222
@ Bind ("this" ) Node inliningTarget ,
222
223
@ SuppressWarnings ("unused" ) @ Shared ("getDict" ) @ Cached GetDictIfExistsNode getDict ,
@@ -229,6 +230,36 @@ static boolean writeToDictClass(PythonClass klass, TruffleString key, Object val
229
230
return writeToDictManagedClass (klass , dict , key , value , inliningTarget , callAttrUpdate , updateStorage , setHashingStorageItem , codePointLengthNode , codePointAtIndexNode );
230
231
}
231
232
233
+ @ Specialization (guards = {"dict != null" , "isNoValue(value)" , "!isPythonBuiltinClass(obj)" })
234
+ static boolean deleteFromPythonObject (PythonObject obj , TruffleString key , Object value ,
235
+ @ Bind ("this" ) Node inliningTarget ,
236
+ @ SuppressWarnings ("unused" ) @ Shared ("getDict" ) @ Cached GetDictIfExistsNode getDict ,
237
+ @ Bind ("getDict.execute(obj)" ) PDict dict ,
238
+ @ Shared ("callAttrUpdate" ) @ Cached InlinedBranchProfile callAttrUpdate ,
239
+ @ Cached HashingStorageNodes .HashingStorageDelItem hashingStorageDelItem ,
240
+ @ Shared ("cpLen" ) @ Cached TruffleString .CodePointLengthNode codePointLengthNode ,
241
+ @ Shared ("cpAtIndex" ) @ Cached TruffleString .CodePointAtIndexNode codePointAtIndexNode ) {
242
+ try {
243
+ HashingStorage dictStorage = dict .getDictStorage ();
244
+ return hashingStorageDelItem .execute (inliningTarget , dictStorage , key , dict );
245
+ } finally {
246
+ if (obj instanceof PythonManagedClass klass ) {
247
+ if (!klass .canSkipOnAttributeUpdate (key , value , codePointLengthNode , codePointAtIndexNode )) {
248
+ callAttrUpdate .enter (inliningTarget );
249
+ klass .onAttributeUpdate (key , value );
250
+ }
251
+ }
252
+ }
253
+ }
254
+
255
+ @ Specialization (guards = {"dict != null" , "isNoValue(value)" })
256
+ static boolean deleteFromPythonBuiltinClass (PythonBuiltinClass klass , TruffleString key , Object value ,
257
+ @ Bind ("this" ) Node inliningTarget ,
258
+ @ SuppressWarnings ("unused" ) @ Shared ("getDict" ) @ Cached GetDictIfExistsNode getDict ,
259
+ @ Bind ("getDict.execute(klass)" ) PDict dict ) {
260
+ throw PRaiseNode .raiseStatic (inliningTarget , TypeError , ErrorMessages .CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N , key , klass );
261
+ }
262
+
232
263
private static boolean writeToDictManagedClass (PythonManagedClass klass , PDict dict , TruffleString key , Object value , Node inliningTarget ,
233
264
InlinedBranchProfile callAttrUpdate , InlinedBranchProfile updateStorage , HashingStorageSetItem setHashingStorageItem , TruffleString .CodePointLengthNode codePointLengthNode ,
234
265
TruffleString .CodePointAtIndexNode codePointAtIndexNode ) {
0 commit comments