55
55
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
56
56
import com .oracle .graal .python .builtins .PythonBuiltins ;
57
57
import com .oracle .graal .python .builtins .objects .PNone ;
58
+ import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
58
59
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
59
60
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
60
61
import com .oracle .graal .python .builtins .objects .common .SequenceNodes ;
66
67
import com .oracle .graal .python .builtins .objects .tuple .TupleBuiltins ;
67
68
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
68
69
import com .oracle .graal .python .lib .PyCallableCheckNode ;
70
+ import com .oracle .graal .python .lib .PyDictCheckExactNode ;
69
71
import com .oracle .graal .python .lib .PyObjectReprAsJavaStringNode ;
70
72
import com .oracle .graal .python .lib .PyObjectStrAsJavaStringNode ;
73
+ import com .oracle .graal .python .lib .PyTupleCheckExactNode ;
71
74
import com .oracle .graal .python .nodes .ErrorMessages ;
72
75
import com .oracle .graal .python .nodes .PGuards ;
73
76
import com .oracle .graal .python .nodes .argument .keywords .ExpandKeywordStarargsNode ;
77
+ import com .oracle .graal .python .nodes .builtins .TupleNodes ;
74
78
import com .oracle .graal .python .nodes .call .special .CallVarargsMethodNode ;
75
79
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
76
80
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
77
81
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
78
82
import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
83
+ import com .oracle .graal .python .nodes .object .DeleteDictNode ;
79
84
import com .oracle .graal .python .nodes .object .GetClassNode ;
80
85
import com .oracle .graal .python .nodes .object .GetDictIfExistsNode ;
81
86
import com .oracle .graal .python .nodes .object .GetOrCreateDictNode ;
@@ -190,15 +195,21 @@ Object reduce(PPartial self,
190
195
@ Builtin (name = __SETSTATE__ , minNumOfPositionalArgs = 2 )
191
196
@ GenerateNodeFactory
192
197
public abstract static class PartialSetStateNode extends PythonBinaryBuiltinNode {
198
+
193
199
@ Specialization
194
200
public Object setState (VirtualFrame frame , PPartial self , PTuple state ,
195
201
@ Cached SetDictNode setDictNode ,
202
+ @ Cached DeleteDictNode deleteDictNode ,
196
203
@ Cached SequenceNodes .GetSequenceStorageNode storageNode ,
197
204
@ Cached SequenceStorageNodes .GetInternalObjectArrayNode arrayNode ,
198
205
@ Cached PyCallableCheckNode callableCheckNode ,
206
+ @ Cached PyTupleCheckExactNode tupleCheckExactNode ,
207
+ @ Cached PyDictCheckExactNode dictCheckExactNode ,
199
208
@ Cached TupleBuiltins .GetItemNode getItemNode ,
209
+ @ Cached TupleNodes .ConstructTupleNode constructTupleNode ,
200
210
@ Cached SequenceStorageNodes .LenNode lenNode ,
201
- @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
211
+ @ Cached HashingCollectionNodes .GetHashingStorageNode getHashingStorageNode ,
212
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
202
213
if (lenNode .execute (state .getSequenceStorage ()) != 4 ) {
203
214
throw raise (PythonBuiltinClassType .TypeError , INVALID_PARTIAL_STATE );
204
215
}
@@ -216,13 +227,27 @@ public Object setState(VirtualFrame frame, PPartial self, PTuple state,
216
227
217
228
self .setFn (function );
218
229
219
- assert fnArgs instanceof PTuple ;
220
- self .setArgs ((PTuple ) fnArgs , storageNode , arrayNode );
230
+ final PTuple fnArgsTuple ;
231
+ if (!tupleCheckExactNode .execute (fnArgs )) {
232
+ fnArgsTuple = constructTupleNode .execute (frame , fnArgs );
233
+ } else {
234
+ fnArgsTuple = (PTuple ) fnArgs ;
235
+ }
236
+ self .setArgs (fnArgsTuple , storageNode , arrayNode );
221
237
222
- assert fnKwargs instanceof PDict ;
223
- self .setKwCopy ((PDict ) fnKwargs , factory (), lib );
238
+ final PDict fnKwargsDict ;
239
+ if (fnKwargs == PNone .NONE ) {
240
+ fnKwargsDict = factory ().createDict ();
241
+ } else if (!dictCheckExactNode .execute (fnKwargs )) {
242
+ fnKwargsDict = factory ().createDict (lib .copy (getHashingStorageNode .execute (frame , fnKwargs )));
243
+ } else {
244
+ fnKwargsDict = (PDict ) fnKwargs ;
245
+ }
246
+ self .setKw (fnKwargsDict );
224
247
225
- if (dict != PNone .NONE ) {
248
+ if (dict == PNone .NONE ) {
249
+ deleteDictNode .execute (self );
250
+ } else {
226
251
assert dict instanceof PDict ;
227
252
setDictNode .execute (self , (PDict ) dict );
228
253
}
@@ -240,7 +265,7 @@ public Object fallback(Object self, Object state) {
240
265
@ Builtin (name = __CALL__ , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true )
241
266
@ GenerateNodeFactory
242
267
protected abstract static class PartialCallNode extends PythonVarargsBuiltinNode {
243
- private int indexOf (PKeyword [] keywords , PKeyword kw ) {
268
+ private static int indexOf (PKeyword [] keywords , PKeyword kw ) {
244
269
for (int i = 0 ; i < keywords .length ; i ++) {
245
270
if (keywords [i ].getName ().equals (kw .getName ())) {
246
271
return i ;
@@ -257,17 +282,17 @@ protected boolean withKeywords(PKeyword[] keywords) {
257
282
Object callWoDict (VirtualFrame frame , PPartial self , Object [] args , PKeyword [] keywords ,
258
283
@ Cached ConditionProfile hasArgsProfile ,
259
284
@ Cached CallVarargsMethodNode callNode ,
260
- @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
285
+ @ SuppressWarnings ( "unused" ) @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
261
286
Object [] callArgs = getNewPartialArgs (self , args , hasArgsProfile );
262
287
return callNode .execute (frame , self .getFn (), callArgs , keywords );
263
288
}
264
289
265
290
@ Specialization (guards = {"self.hasKw(lib)" , "!withKeywords(keywords)" })
266
- Object callWDictWoKw (VirtualFrame frame , PPartial self , Object [] args , PKeyword [] keywords ,
291
+ Object callWDictWoKw (VirtualFrame frame , PPartial self , Object [] args , @ SuppressWarnings ( "unused" ) PKeyword [] keywords ,
267
292
@ Cached ExpandKeywordStarargsNode starargsNode ,
268
293
@ Cached ConditionProfile hasArgsProfile ,
269
294
@ Cached CallVarargsMethodNode callNode ,
270
- @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
295
+ @ SuppressWarnings ( "unused" ) @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
271
296
Object [] callArgs = getNewPartialArgs (self , args , hasArgsProfile );
272
297
return callNode .execute (frame , self .getFn (), callArgs , starargsNode .execute (self .getKw ()));
273
298
}
@@ -277,7 +302,7 @@ Object callWDictWKw(VirtualFrame frame, PPartial self, Object[] args, PKeyword[]
277
302
@ Cached ExpandKeywordStarargsNode starargsNode ,
278
303
@ Cached ConditionProfile hasArgsProfile ,
279
304
@ Cached CallVarargsMethodNode callNode ,
280
- @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
305
+ @ SuppressWarnings ( "unused" ) @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ) {
281
306
Object [] callArgs = getNewPartialArgs (self , args , hasArgsProfile );
282
307
283
308
final PKeyword [] pKeywords = starargsNode .execute (self .getKw ());
0 commit comments