Skip to content

Commit a1012ee

Browse files
committed
make set modifiable
1 parent 366fc8a commit a1012ee

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public abstract class PBaseSet extends PHashingCollection {
3535

36-
protected final HashingStorage set;
36+
private HashingStorage set;
3737

3838
public PBaseSet(Object clazz, DynamicObject storage) {
3939
super(clazz, storage);
@@ -58,4 +58,9 @@ public int size() {
5858
public HashingStorage getDictStorage() {
5959
return set;
6060
}
61+
62+
@Override
63+
public void setDictStorage(HashingStorage storage) {
64+
set = storage;
65+
}
6166
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package com.oracle.graal.python.builtins.objects.set;
2727

2828
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
29-
import com.oracle.truffle.api.CompilerDirectives;
3029
import com.oracle.truffle.api.object.DynamicObject;
3130

3231
public final class PSet extends PBaseSet {
@@ -38,13 +37,4 @@ public PSet(Object clazz, DynamicObject storage) {
3837
public PSet(Object clazz, DynamicObject storage, HashingStorage store) {
3938
super(clazz, storage, store);
4039
}
41-
42-
@Override
43-
public void setDictStorage(HashingStorage newStorage) {
44-
// ignore if storage stays unchanged
45-
if (newStorage != getDictStorage()) {
46-
CompilerDirectives.transferToInterpreterAndInvalidate();
47-
throw new RuntimeException("set has fixed storage");
48-
}
49-
}
5040
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import com.oracle.graal.python.builtins.PythonBuiltins;
3939
import com.oracle.graal.python.builtins.objects.PNone;
4040
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
41+
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes.GetDictStorageNode;
42+
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes.SetDictStorageNode;
4143
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
4244
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
4345
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -74,9 +76,13 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7476
@GenerateNodeFactory
7577
public abstract static class ClearNode extends PythonUnaryBuiltinNode {
7678

77-
@Specialization
78-
public Object clear(PSet self, @CachedLibrary(limit = "1") HashingStorageLibrary lib) {
79-
lib.clear(self.getDictStorage());
79+
@Specialization(limit = "1")
80+
public Object clear(PSet self,
81+
@Cached GetDictStorageNode getStorage,
82+
@Cached SetDictStorageNode setStorage,
83+
@CachedLibrary("getStorage.execute(self)") HashingStorageLibrary lib) {
84+
HashingStorage newStorage = lib.clear(getStorage.execute(self));
85+
setStorage.execute(self, newStorage);
8086
return PNone.NONE;
8187
}
8288
}

0 commit comments

Comments
 (0)