Skip to content

Commit 246bc43

Browse files
committed
[GR-23216] Make test_dictviews pass.
PullRequest: graalpython/999
2 parents a70eec5 + 5532abc commit 246bc43

File tree

8 files changed

+91
-17
lines changed

8 files changed

+91
-17
lines changed

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

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,98 @@ def test_set_or_union():
6464
s2 = {4, 5, 6}
6565
s3 = {1, 2, 4}
6666
s4 = {1, 2, 3}
67-
67+
68+
sstr1 = {'a', 'b', 'c'}
69+
sstr2 = {'d', 'e', 'f'}
70+
sstr3 = {'a', 'b', 'd'}
71+
sstr4 = {'a', 'b', 'c'}
72+
6873
or_result = s1 | s2
6974
union_result = s1.union(s2)
7075
assert or_result == {1, 2, 3, 4, 5, 6}
7176
assert union_result == {1, 2, 3, 4, 5, 6}
77+
78+
or_result = s2 | s1
79+
union_result = s2.union(s1)
80+
assert or_result == {1, 2, 3, 4, 5, 6}
81+
assert union_result == {1, 2, 3, 4, 5, 6}
7282

83+
or_result = sstr1 | sstr2
84+
union_result = sstr1.union(sstr2)
85+
assert or_result == {'a', 'b', 'c', 'd', 'e', 'f'}
86+
assert union_result == {'a', 'b', 'c', 'd', 'e', 'f'}
87+
88+
or_result = s1 | sstr2
89+
union_result = s1.union(sstr2)
90+
assert or_result == {1, 2, 3, 'd', 'e', 'f'}
91+
assert union_result == {1, 2, 3, 'd', 'e', 'f'}
92+
93+
or_result = sstr1 | s1
94+
union_result = sstr1.union(s1)
95+
assert or_result == {1, 2, 3, 'a', 'b', 'c'}
96+
assert union_result == {1, 2, 3, 'a', 'b', 'c'}
97+
7398
or_result = s1 | s3
7499
union_result = s1.union(s3)
75100
assert or_result == {1, 2, 3, 4}
76101
assert union_result == {1, 2, 3, 4}
77-
102+
103+
or_result = s3 | s1
104+
union_result = s3.union(s1)
105+
assert or_result == {1, 2, 3, 4}
106+
assert union_result == {1, 2, 3, 4}
107+
108+
or_result = sstr1 | sstr3
109+
union_result = sstr1.union(sstr3)
110+
assert or_result == {'a', 'b', 'c', 'd'}
111+
assert union_result == {'a', 'b', 'c', 'd'}
112+
113+
or_result = sstr3 | sstr1
114+
union_result = sstr3.union(sstr1)
115+
assert or_result == {'a', 'b', 'c', 'd'}
116+
assert union_result == {'a', 'b', 'c', 'd'}
117+
118+
or_result = s1 | sstr3
119+
union_result = s1.union(sstr3)
120+
assert or_result == {1, 2, 3, 'a', 'b', 'd'}
121+
assert union_result == {1, 2, 3, 'a', 'b', 'd'}
122+
123+
or_result = sstr1 | s3
124+
union_result = sstr1.union(s3)
125+
assert or_result == {1, 2, 4, 'a', 'b', 'c'}
126+
assert union_result == {1, 2, 4, 'a', 'b', 'c'}
127+
78128
or_result = s1 | s4
79129
union_result = s1.union(s4)
80130
assert or_result == {1, 2, 3}
81131
assert union_result == {1, 2, 3}
132+
133+
or_result = s4 | s1
134+
union_result = s4.union(s1)
135+
assert or_result == {1, 2, 3}
136+
assert union_result == {1, 2, 3}
137+
138+
or_result = sstr1 | sstr4
139+
union_result = sstr1.union(sstr4)
140+
assert or_result == {'a','b','c'}
141+
assert union_result == {'a','b','c'}
142+
143+
or_result = sstr4 | sstr1
144+
union_result = sstr4.union(sstr1)
145+
assert or_result == {'a','b','c'}
146+
assert union_result == {'a','b','c'}
82147

83148
assert frozenset((1,2)) | {1:2}.items() == {1, 2, (1, 2)}
84149
assert frozenset((1,2)) | {1:2}.keys() == {1, 2}
150+
151+
assert frozenset(('a','b')) | {1:2}.keys() == {'a', 'b', 1}
152+
assert frozenset(('a','b')) | {1:2, 3:4}.keys() == {'a', 'b', 1, 3}
153+
assert frozenset((1,2)) | {'a':2, 'b':4}.keys() == {'a', 'b', 1, 2}
154+
155+
assert {1,2} | {3:4, 5:6}.keys() == {1, 2, 3, 5}
156+
assert {3:4, 5:6}.keys() | {1,2} == {1, 2, 3, 5}
157+
assert {1,2} | {'a':1, 'b':2}.keys() == {1, 2, 'a', 'b'}
158+
assert {'a','b'} | {1:'c', 2:'d'}.keys() == {1, 2, 'a', 'b'}
85159

86160
def test_set_and():
87161
assert frozenset((1,2)) & {1:2}.items() == set()

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ private PSet readSet(int depth, HashingStorageLibrary lib) {
683683
Object key = readObject(depth + 1, lib);
684684
// note: we may pass a 'null' frame here because global state is ensured to be
685685
// transfered
686-
lib.setItem(newStorage, key, PNone.NO_VALUE);
686+
newStorage = lib.setItem(newStorage, key, PNone.NO_VALUE);
687687
}
688688

689689
return factory().createSet(newStorage);
@@ -699,7 +699,7 @@ private PFrozenSet readFrozenSet(int depth, HashingStorageLibrary lib) {
699699
Object key = readObject(depth + 1, lib);
700700
// note: we may pass a 'null' frame here because global state is ensured to be
701701
// transfered
702-
lib.setItem(newStorage, key, PNone.NO_VALUE);
702+
newStorage = lib.setItem(newStorage, key, PNone.NO_VALUE);
703703
}
704704

705705
return factory().createFrozenSet(newStorage);
@@ -785,7 +785,7 @@ private CreateCodeNode ensureCreateCodeNode() {
785785
@Specialization
786786
Object readObject(VirtualFrame frame, byte[] dataBytes, @SuppressWarnings("unused") int version,
787787
@CachedContext(PythonLanguage.class) PythonContext context,
788-
@CachedLibrary(limit = "1") HashingStorageLibrary lib) {
788+
@CachedLibrary(limit = "3") HashingStorageLibrary lib) {
789789
reset();
790790
this.data = dataBytes;
791791
Object state = IndirectCallContext.enter(frame, context, this);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EconomicMapStorage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ static HashingStorage toSameType(EconomicMapStorage self, EconomicMapStorage oth
326326
}
327327

328328
@TruffleBoundary
329-
@Specialization(limit = "2")
329+
@Specialization
330330
static HashingStorage generic(EconomicMapStorage self, HashingStorage other,
331-
@CachedLibrary("other") HashingStorageLibrary lib) {
331+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
332332
HashingStorage result = other;
333333
MapCursor<DictKey, Object> cursor = self.map.getEntries();
334334
while (cursor.advance()) {
335-
result = lib.setItem(other, cursor.getKey().value, cursor.getValue());
335+
result = lib.setItem(result, cursor.getKey().value, cursor.getValue());
336336
}
337337
return result;
338338
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/KeywordsStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static class AddAllToOther {
238238
@ExplodeLoop
239239
static HashingStorage cached(KeywordsStorage self, HashingStorage other,
240240
@Exclusive @Cached("self.length()") int cachedLen,
241-
@CachedLibrary(limit = "1") HashingStorageLibrary lib) {
241+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
242242
HashingStorage result = other;
243243
for (int i = 0; i < cachedLen; i++) {
244244
PKeyword entry = self.keywords[i];

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/LocalsStorage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected static FrameSlot[] getSlots(FrameDescriptor desc) {
235235
@Specialization(guards = {"desc == self.frame.getFrameDescriptor()"}, limit = "1", assumptions = "desc.getVersion()")
236236
@ExplodeLoop
237237
static HashingStorage cached(LocalsStorage self, HashingStorage other,
238-
@CachedLibrary("other") HashingStorageLibrary lib,
238+
@CachedLibrary(limit = "2") HashingStorageLibrary lib,
239239
@Exclusive @SuppressWarnings("unused") @Cached("self.frame.getFrameDescriptor()") FrameDescriptor desc,
240240
@Exclusive @Cached(value = "getSlots(desc)", dimensions = 1) FrameSlot[] slots) {
241241
HashingStorage result = other;
@@ -249,9 +249,9 @@ static HashingStorage cached(LocalsStorage self, HashingStorage other,
249249
return result;
250250
}
251251

252-
@Specialization(replaces = "cached", limit = "1")
252+
@Specialization(replaces = "cached")
253253
static HashingStorage generic(LocalsStorage self, HashingStorage other,
254-
@CachedLibrary("other") HashingStorageLibrary lib) {
254+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
255255
bailout();
256256
HashingStorage result = other;
257257
FrameSlot[] slots = getSlots(self.frame.getFrameDescriptor());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ PNotImplemented doGeneric(Object self, Object other) {
150150
}
151151
}
152152

153-
protected static HashingStorage getStringAsHashingStorage(VirtualFrame frame, String str, HashingStorageLibrary lib, ConditionProfile hasFrame) {
153+
private static HashingStorage getStringAsHashingStorage(VirtualFrame frame, String str, HashingStorageLibrary lib, ConditionProfile hasFrame) {
154154
HashingStorage storage = EconomicMapStorage.create(PString.length(str));
155155
for (int i = 0; i < PString.length(str); i++) {
156156
String key = PString.valueOf(PString.charAt(str, i));
@@ -444,13 +444,13 @@ HashingStorage doHashingCollection(@SuppressWarnings("unused") VirtualFrame fram
444444
return lib.union(selfStorage, other.getDictStorage());
445445
}
446446

447-
@Specialization(limit = "1")
447+
@Specialization
448448
HashingStorage doIterable(VirtualFrame frame, HashingStorage dictStorage, Object iterable,
449449
@Cached("create()") GetIteratorNode getIteratorNode,
450450
@Cached("create()") GetNextNode next,
451451
@Cached("create()") IsBuiltinClassProfile errorProfile,
452452
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
453-
@CachedLibrary("dictStorage") HashingStorageLibrary lib) {
453+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
454454
HashingStorage curStorage = dictStorage;
455455
Object iterator = getIteratorNode.executeWith(frame, iterable);
456456
while (true) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public abstract static class MakeTransNode extends PythonTernaryBuiltinNode {
730730
PDict doString(@SuppressWarnings("unused") VirtualFrame frame, Object from, Object to, @SuppressWarnings("unused") Object z,
731731
@Cached CastToJavaStringCheckedNode castFromNode,
732732
@Cached CastToJavaStringCheckedNode castToNode,
733-
@CachedLibrary(limit = "1") HashingStorageLibrary lib) {
733+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
734734

735735
String toStr = castToNode.cast(to, "argument 2 must be str, not %p", to);
736736
String fromStr = castFromNode.cast(from, "first maketrans argument must be a string if there is a second argument");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/DictConcatNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected DictConcatNode(ExpressionNode... mappablesNodes) {
6666
@Specialization
6767
public Object concat(VirtualFrame frame,
6868
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
69-
@CachedLibrary(limit = "1") HashingStorageLibrary firstlib,
69+
@CachedLibrary(limit = "2") HashingStorageLibrary firstlib,
7070
@CachedLibrary(limit = "1") HashingStorageLibrary otherlib) {
7171
PDict first = null;
7272
PDict other;

0 commit comments

Comments
 (0)