Skip to content

Commit 94bad7e

Browse files
author
Franziska Geiger
committed
[GR-17350] Add new specialization to isSuperSet node
PullRequest: graalpython/596
2 parents 06c2eb0 + 204e40c commit 94bad7e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_set.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ def test_sub_and_super():
187187
assert not set('cbs').issuperset('a')
188188

189189

190+
def test_superset_list():
191+
set = {1, 2, 3, 4}
192+
list = [1, 2, 3, 4]
193+
visited= False
194+
if set.issuperset(list):
195+
visited = True
196+
assert visited
197+
198+
190199
def test_intersection():
191200
word = 'simsalabim'
192201
otherword = 'madagascar'

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.oracle.graal.python.runtime.PythonContext;
7373
import com.oracle.graal.python.runtime.exception.PException;
7474
import com.oracle.graal.python.runtime.exception.PythonErrorType;
75+
import com.oracle.graal.python.runtime.sequence.PSequence;
7576
import com.oracle.truffle.api.CompilerDirectives;
7677
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7778
import com.oracle.truffle.api.dsl.Cached;
@@ -489,7 +490,15 @@ boolean isSuperSet(VirtualFrame frame, PBaseSet self, PBaseSet other,
489490
}
490491

491492
@Specialization
492-
boolean isSuperSet(VirtualFrame frame, PBaseSet self, String other,
493+
boolean isSuperSetPSequence(VirtualFrame frame, PBaseSet self, PSequence other,
494+
@Cached("create()") SetNodes.ConstructSetNode constructSetNode,
495+
@Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) {
496+
PSet otherSet = constructSetNode.executeWith(frame, other);
497+
return isSupersetNode.execute(frame, self.getDictStorage(), otherSet.getDictStorage());
498+
}
499+
500+
@Specialization
501+
boolean isSuperSetString(VirtualFrame frame, PBaseSet self, String other,
493502
@Cached("create()") SetNodes.ConstructSetNode constructSetNode,
494503
@Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) {
495504
PSet otherSet = constructSetNode.executeWith(frame, other);

0 commit comments

Comments
 (0)