Skip to content

Commit 5532abc

Browse files
committed
fixed HashingStorageLibrary usage:
- using a receiver bound HashingStorageLibrary when setting items might cause 'Invalid library usage' assertion error - limit should be > 1 - setitem might create a new storage, so when setting more items, the result from the previous setitem call should be used
1 parent 3ffb1c5 commit 5532abc

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

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)