67
67
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
68
68
import com .oracle .graal .python .builtins .objects .dict .PDictView .PDictItemsView ;
69
69
import com .oracle .graal .python .builtins .objects .dict .PDictView .PDictKeysView ;
70
- import com .oracle .graal .python .builtins .objects .list .PList ;
71
70
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
72
71
import com .oracle .graal .python .builtins .objects .set .PBaseSet ;
73
72
import com .oracle .graal .python .builtins .objects .set .PSet ;
74
73
import com .oracle .graal .python .builtins .objects .set .SetNodes ;
75
74
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
75
+ import com .oracle .graal .python .nodes .ErrorMessages ;
76
76
import com .oracle .graal .python .nodes .PNodeWithContext ;
77
77
import com .oracle .graal .python .nodes .SpecialMethodNames ;
78
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .ISDISJOINT ;
78
79
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
79
80
import com .oracle .graal .python .nodes .control .GetIteratorExpressionNode .GetIteratorNode ;
80
81
import com .oracle .graal .python .nodes .control .GetNextNode ;
@@ -166,6 +167,13 @@ boolean contains(VirtualFrame frame, PDictItemsView self, PTuple key,
166
167
return false ;
167
168
}
168
169
}
170
+
171
+ @ SuppressWarnings ("unused" )
172
+ @ Fallback
173
+ boolean contains (Object self , Object key ) {
174
+ return false ;
175
+ }
176
+
169
177
}
170
178
171
179
/**
@@ -326,6 +334,18 @@ PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysVie
326
334
return factory ().createSet (storage );
327
335
}
328
336
337
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
338
+ PBaseSet doKeysView (VirtualFrame frame , PDictKeysView self , Object other ,
339
+ @ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
340
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
341
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
342
+ @ CachedLibrary ("self.getWrappedDict().getDictStorage()" ) HashingStorageLibrary lib ) {
343
+ HashingStorage left = self .getWrappedDict ().getDictStorage ();
344
+ HashingStorage right = constructSetNode .executeWith (frame , other ).getDictStorage ();
345
+ HashingStorage storage = lib .diffWithFrame (left , right , hasFrame , frame );
346
+ return factory ().createSet (storage );
347
+ }
348
+
329
349
@ Specialization
330
350
PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PBaseSet other ,
331
351
@ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
@@ -337,7 +357,7 @@ PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PBaseSet other,
337
357
}
338
358
339
359
@ Specialization
340
- PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PDictItemsView other ,
360
+ PBaseSet doNotIterable (VirtualFrame frame , PDictItemsView self , PDictItemsView other ,
341
361
@ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
342
362
@ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
343
363
@ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ) {
@@ -347,16 +367,24 @@ PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PDictItemsView oth
347
367
return factory ().createSet (storage );
348
368
}
349
369
350
- @ Specialization
351
- PBaseSet doItemsView (VirtualFrame frame , PDictKeysView self , PList other ,
370
+ @ Specialization ( guards = "libOther.isIterable(other)" , limit = "1" )
371
+ PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , Object other ,
352
372
@ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
353
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
354
- @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ) {
355
- PSet selfSet = constructSetNode .executeWith (frame , self );
356
- PSet otherSet = constructSetNode .executeWith (frame , other );
357
- HashingStorage storage = lib .diffWithFrame (selfSet .getDictStorage (), otherSet .getDictStorage (), hasFrame , frame );
373
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
374
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
375
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
376
+ HashingStorage left = constructSetNode .executeWith (frame , self ).getDictStorage ();
377
+ HashingStorage right = constructSetNode .executeWith (frame , other ).getDictStorage ();
378
+ HashingStorage storage = lib .diffWithFrame (left , right , hasFrame , frame );
358
379
return factory ().createSet (storage );
359
380
}
381
+
382
+ @ SuppressWarnings ("unused" )
383
+ @ Specialization (guards = {"!isDictKeysView(other)" , "!isDictItemsView(other)" , "!lib.isIterable(other)" }, limit = "1" )
384
+ PBaseSet doNotIterable (VirtualFrame frame , PDictView self , Object other ,
385
+ @ CachedLibrary ("other" ) PythonObjectLibrary lib ) {
386
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , other );
387
+ }
360
388
}
361
389
362
390
@ Builtin (name = __AND__ , minNumOfPositionalArgs = 2 )
@@ -383,6 +411,18 @@ PBaseSet doKeysView(VirtualFrame frame, PDictKeysView self, PDictKeysView other,
383
411
return factory ().createSet (intersectedStorage );
384
412
}
385
413
414
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
415
+ PBaseSet doKeysView (VirtualFrame frame , PDictKeysView self , Object other ,
416
+ @ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
417
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
418
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
419
+ @ CachedLibrary ("self.getWrappedDict().getDictStorage()" ) HashingStorageLibrary lib ) {
420
+ HashingStorage left = self .getWrappedDict ().getDictStorage ();
421
+ HashingStorage right = constructSetNode .executeWith (frame , other ).getDictStorage ();
422
+ HashingStorage intersectedStorage = lib .intersectWithFrame (left , right , hasFrame , frame );
423
+ return factory ().createSet (intersectedStorage );
424
+ }
425
+
386
426
@ Specialization
387
427
PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PBaseSet other ,
388
428
@ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
@@ -407,6 +447,26 @@ PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PDictItemsView oth
407
447
HashingStorage intersectedStorage = lib .intersectWithFrame (left , right , hasFrame , frame );
408
448
return factory ().createSet (intersectedStorage );
409
449
}
450
+
451
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
452
+ PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , Object other ,
453
+ @ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
454
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
455
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
456
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
457
+ HashingStorage left = constructSetNode .executeWith (frame , self ).getDictStorage ();
458
+ HashingStorage right = constructSetNode .executeWith (frame , other ).getDictStorage ();
459
+ HashingStorage intersectedStorage = lib .intersectWithFrame (left , right , hasFrame , frame );
460
+ return factory ().createSet (intersectedStorage );
461
+ }
462
+
463
+ @ SuppressWarnings ("unused" )
464
+ @ Specialization (guards = {"!isDictKeysView(other)" , "!isDictItemsView(other)" ,
465
+ "!lib.isIterable(other)" }, limit = "1" )
466
+ PBaseSet doNotIterable (VirtualFrame frame , PDictView self , Object other ,
467
+ @ CachedLibrary ("other" ) PythonObjectLibrary lib ) {
468
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , other );
469
+ }
410
470
}
411
471
412
472
@ Builtin (name = __OR__ , minNumOfPositionalArgs = 2 )
@@ -429,6 +489,14 @@ PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysVie
429
489
return factory ().createSet (union (lib , self .getWrappedDict ().getDictStorage (), other .getWrappedDict ().getDictStorage ()));
430
490
}
431
491
492
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
493
+ PBaseSet doKeysView (@ SuppressWarnings ("unused" ) VirtualFrame frame , PDictKeysView self , Object other ,
494
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
495
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
496
+ @ CachedLibrary ("self.getWrappedDict().getDictStorage()" ) HashingStorageLibrary lib ) {
497
+ return factory ().createSet (union (lib , self .getWrappedDict ().getDictStorage (), constructSetNode .executeWith (frame , other ).getDictStorage ()));
498
+ }
499
+
432
500
@ Specialization
433
501
PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PBaseSet other ,
434
502
@ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
@@ -445,6 +513,20 @@ PBaseSet doItemsView(VirtualFrame frame, PDictItemsView self, PDictItemsView oth
445
513
PSet otherSet = constructSetNode .executeWith (frame , other );
446
514
return factory ().createSet (union (lib , selfSet .getDictStorage (), otherSet .getDictStorage ()));
447
515
}
516
+
517
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
518
+ PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , Object other ,
519
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
520
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
521
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
522
+ return factory ().createSet (union (lib , constructSetNode .executeWith (frame , self ).getDictStorage (), constructSetNode .executeWith (frame , other ).getDictStorage ()));
523
+ }
524
+
525
+ @ Specialization (guards = {"!isDictKeysView(other)" , "!isDictItemsView(other)" , "!lib.isIterable(other)" }, limit = "1" )
526
+ PBaseSet doNotIterable (@ SuppressWarnings ("unused" ) VirtualFrame frame , @ SuppressWarnings ("unused" ) PDictView self , Object other ,
527
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary lib ) {
528
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , other );
529
+ }
448
530
}
449
531
450
532
@ Builtin (name = __XOR__ , minNumOfPositionalArgs = 2 )
@@ -467,22 +549,44 @@ PBaseSet doKeysView(@SuppressWarnings("unused") VirtualFrame frame, PDictKeysVie
467
549
return factory ().createSet (xor (lib , self .getWrappedDict ().getDictStorage (), other .getWrappedDict ().getDictStorage ()));
468
550
}
469
551
552
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
553
+ PBaseSet doKeysView (@ SuppressWarnings ("unused" ) VirtualFrame frame , PDictKeysView self , Object other ,
554
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
555
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
556
+ @ CachedLibrary ("self.getWrappedDict().getDictStorage()" ) HashingStorageLibrary lib ) {
557
+ return factory ().createSet (xor (lib , self .getWrappedDict ().getDictStorage (), constructSetNode .executeWith (frame , other ).getDictStorage ()));
558
+ }
559
+
470
560
@ Specialization
471
- PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PBaseSet other ,
561
+ PBaseSet doItemsView (@ SuppressWarnings ( "unused" ) VirtualFrame frame , PDictItemsView self , PBaseSet other ,
472
562
@ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
473
563
@ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ) {
474
564
PSet selfSet = constructSetNode .executeWith (frame , self );
475
565
return factory ().createSet (xor (lib , selfSet .getDictStorage (), other .getDictStorage ()));
476
566
}
477
567
478
568
@ Specialization
479
- PBaseSet doItemsView (VirtualFrame frame , PDictItemsView self , PDictItemsView other ,
569
+ PBaseSet doItemsView (@ SuppressWarnings ( "unused" ) VirtualFrame frame , PDictItemsView self , PDictItemsView other ,
480
570
@ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
481
571
@ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ) {
482
572
PSet selfSet = constructSetNode .executeWith (frame , self );
483
573
PSet otherSet = constructSetNode .executeWith (frame , other );
484
574
return factory ().createSet (xor (lib , selfSet .getDictStorage (), otherSet .getDictStorage ()));
485
575
}
576
+
577
+ @ Specialization (guards = "libOther.isIterable(other)" , limit = "1" )
578
+ PBaseSet doItemsView (@ SuppressWarnings ("unused" ) VirtualFrame frame , PDictItemsView self , Object other ,
579
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary libOther ,
580
+ @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
581
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) {
582
+ return factory ().createSet (xor (lib , constructSetNode .executeWith (frame , self ).getDictStorage (), constructSetNode .executeWith (frame , other ).getDictStorage ()));
583
+ }
584
+
585
+ @ Specialization (guards = {"!isDictKeysView(other)" , "!isDictItemsView(other)" , "!lib.isIterable(other)" }, limit = "1" )
586
+ PBaseSet doNotIterable (@ SuppressWarnings ("unused" ) VirtualFrame frame , @ SuppressWarnings ("unused" ) PDictView self , Object other ,
587
+ @ SuppressWarnings ("unused" ) @ CachedLibrary ("other" ) PythonObjectLibrary lib ) {
588
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .OBJ_NOT_ITERABLE , other );
589
+ }
486
590
}
487
591
488
592
@ Builtin (name = __LE__ , minNumOfPositionalArgs = 2 )
0 commit comments