48
48
import com .oracle .graal .python .builtins .objects .PNone ;
49
49
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
50
50
import com .oracle .graal .python .builtins .objects .common .EconomicMapStorage ;
51
- import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
52
51
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
53
52
import com .oracle .graal .python .builtins .objects .common .HashingStorage .Equivalence ;
54
53
import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
72
71
import com .oracle .graal .python .runtime .PythonContext ;
73
72
import com .oracle .graal .python .runtime .exception .PException ;
74
73
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
75
- import com .oracle .graal .python .runtime .sequence .PSequence ;
76
74
import com .oracle .truffle .api .CompilerDirectives ;
77
75
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
78
76
import com .oracle .truffle .api .dsl .Cached ;
@@ -140,29 +138,6 @@ PNotImplemented doGeneric(Object self, Object other) {
140
138
}
141
139
}
142
140
143
- @ Builtin (name = __LE__ , minNumOfPositionalArgs = 2 )
144
- @ GenerateNodeFactory
145
- abstract static class LeNode extends PythonBinaryBuiltinNode {
146
- @ Child private HashingStorageNodes .ContainsKeyNode containsKeyNode = HashingStorageNodes .ContainsKeyNode .create ();
147
-
148
- @ Specialization
149
- Object run (VirtualFrame frame , PBaseSet self , PBaseSet other ,
150
- @ Cached HashingCollectionNodes .LenNode selfLen ,
151
- @ Cached HashingCollectionNodes .LenNode otherLen ) {
152
- if (selfLen .execute (self ) > otherLen .execute (other )) {
153
- return false ;
154
- }
155
-
156
- for (Object value : self .values ()) {
157
- if (!containsKeyNode .execute (frame , other .getDictStorage (), value )) {
158
- return false ;
159
- }
160
- }
161
-
162
- return true ;
163
- }
164
- }
165
-
166
141
@ Builtin (name = __AND__ , minNumOfPositionalArgs = 2 )
167
142
@ GenerateNodeFactory
168
143
abstract static class AndNode extends PythonBinaryBuiltinNode {
@@ -467,14 +442,14 @@ public static BinaryUnionNode create() {
467
442
abstract static class IsSubsetNode extends PythonBinaryBuiltinNode {
468
443
@ Specialization
469
444
boolean isSubSet (VirtualFrame frame , PBaseSet self , PBaseSet other ,
470
- @ Cached ( "create()" ) HashingStorageNodes .KeysIsSubsetNode isSubsetNode ) {
445
+ @ Cached HashingStorageNodes .KeysIsSubsetNode isSubsetNode ) {
471
446
return isSubsetNode .execute (frame , self .getDictStorage (), other .getDictStorage ());
472
447
}
473
448
474
- @ Specialization
475
- boolean isSubSet (VirtualFrame frame , PBaseSet self , String other ,
476
- @ Cached ( "create()" ) SetNodes .ConstructSetNode constructSetNode ,
477
- @ Cached ( "create()" ) HashingStorageNodes .KeysIsSubsetNode isSubsetNode ) {
449
+ @ Specialization ( replaces = "isSubSet" )
450
+ boolean isSubSetGeneric (VirtualFrame frame , PBaseSet self , Object other ,
451
+ @ Cached SetNodes .ConstructSetNode constructSetNode ,
452
+ @ Cached HashingStorageNodes .KeysIsSubsetNode isSubsetNode ) {
478
453
PSet otherSet = constructSetNode .executeWith (frame , other );
479
454
return isSubsetNode .execute (frame , self .getDictStorage (), otherSet .getDictStorage ());
480
455
}
@@ -485,52 +460,49 @@ boolean isSubSet(VirtualFrame frame, PBaseSet self, String other,
485
460
abstract static class IsSupersetNode extends PythonBinaryBuiltinNode {
486
461
@ Specialization
487
462
boolean isSuperSet (VirtualFrame frame , PBaseSet self , PBaseSet other ,
488
- @ Cached ( "create()" ) HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
463
+ @ Cached HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
489
464
return isSupersetNode .execute (frame , self .getDictStorage (), other .getDictStorage ());
490
465
}
491
466
492
- @ Specialization
493
- boolean isSuperSetPSequence (VirtualFrame frame , PBaseSet self , PSequence other ,
494
- @ Cached ( "create()" ) SetNodes .ConstructSetNode constructSetNode ,
495
- @ Cached ( "create()" ) HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
467
+ @ Specialization ( replaces = "isSuperSet" )
468
+ boolean isSuperSetGeneric (VirtualFrame frame , PBaseSet self , Object other ,
469
+ @ Cached SetNodes .ConstructSetNode constructSetNode ,
470
+ @ Cached HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
496
471
PSet otherSet = constructSetNode .executeWith (frame , other );
497
472
return isSupersetNode .execute (frame , self .getDictStorage (), otherSet .getDictStorage ());
498
473
}
499
474
500
- @ Specialization
501
- boolean isSuperSetString (VirtualFrame frame , PBaseSet self , String other ,
502
- @ Cached ("create()" ) SetNodes .ConstructSetNode constructSetNode ,
503
- @ Cached ("create()" ) HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
504
- PSet otherSet = constructSetNode .executeWith (frame , other );
505
- return isSupersetNode .execute (frame , self .getDictStorage (), otherSet .getDictStorage ());
506
- }
507
475
}
508
476
509
477
@ Builtin (name = __LE__ , minNumOfPositionalArgs = 2 )
510
478
@ GenerateNodeFactory
511
- abstract static class LessEqualNode extends IsSubsetNode {
479
+ abstract static class LessEqualNode extends PythonBinaryBuiltinNode {
512
480
@ Specialization
513
- Object isLessEqual (VirtualFrame frame , PBaseSet self , Object other ,
514
- @ Cached ("create(__GE__)" ) LookupAndCallBinaryNode lookupAndCallBinaryNode ) {
515
- Object result = lookupAndCallBinaryNode .executeObject (frame , other , self );
516
- if (result != PNone .NO_VALUE ) {
517
- return result ;
518
- }
519
- throw raise (PythonErrorType .TypeError , "unorderable types: %p <= %p" , self , other );
481
+ boolean doLE (VirtualFrame frame , PBaseSet self , PBaseSet other ,
482
+ @ Cached HashingStorageNodes .KeysIsSubsetNode isSubsetNode ) {
483
+ return isSubsetNode .execute (frame , self .getDictStorage (), other .getDictStorage ());
484
+ }
485
+
486
+ @ Fallback
487
+ @ SuppressWarnings ("unused" )
488
+ PNotImplemented doNotImplemented (Object self , Object other ) {
489
+ return PNotImplemented .NOT_IMPLEMENTED ;
520
490
}
521
491
}
522
492
523
493
@ Builtin (name = __GE__ , minNumOfPositionalArgs = 2 )
524
494
@ GenerateNodeFactory
525
- abstract static class GreaterEqualNode extends IsSupersetNode {
495
+ abstract static class GreaterEqualNode extends PythonBinaryBuiltinNode {
526
496
@ Specialization
527
- Object isGreaterEqual (VirtualFrame frame , PBaseSet self , Object other ,
528
- @ Cached ("create(__LE__)" ) LookupAndCallBinaryNode lookupAndCallBinaryNode ) {
529
- Object result = lookupAndCallBinaryNode .executeObject (frame , other , self );
530
- if (result != PNone .NO_VALUE ) {
531
- return result ;
532
- }
533
- throw raise (PythonErrorType .TypeError , "unorderable types: %p >= %p" , self , other );
497
+ boolean doGE (VirtualFrame frame , PBaseSet self , PBaseSet other ,
498
+ @ Cached HashingStorageNodes .KeysIsSupersetNode isSupersetNode ) {
499
+ return isSupersetNode .execute (frame , self .getDictStorage (), other .getDictStorage ());
500
+ }
501
+
502
+ @ Fallback
503
+ @ SuppressWarnings ("unused" )
504
+ PNotImplemented doNotImplemented (Object self , Object other ) {
505
+ return PNotImplemented .NOT_IMPLEMENTED ;
534
506
}
535
507
}
536
508
0 commit comments