Skip to content

Commit 86f849c

Browse files
committed
Fix missing storage generalization in PList.writeArrayElement
1 parent 0d462a8 commit 86f849c

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.GetItemSliceNodeGen;
6868
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.InsertItemNodeGen;
6969
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ListGeneralizationNodeGen;
70+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.MemMoveNodeGen;
7071
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.NoGeneralizationCustomMessageNodeGen;
7172
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.NoGeneralizationNodeGen;
7273
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.RepeatNodeGen;
7374
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.SetItemDynamicNodeGen;
7475
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.SetItemNodeGen;
75-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
7676
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.StorageToNativeNodeGen;
77-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.MemMoveNodeGen;
77+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
7878
import com.oracle.graal.python.builtins.objects.ints.PInt;
7979
import com.oracle.graal.python.builtins.objects.iterator.IteratorBuiltins.NextHelperNode;
8080
import com.oracle.graal.python.builtins.objects.iterator.IteratorNodes.BuiltinIteratorLengthHint;
@@ -1076,6 +1076,34 @@ protected static void doNative(NativeSequenceStorage storage, int idx, Object va
10761076
}
10771077
}
10781078

1079+
@GenerateUncached
1080+
@GenerateInline
1081+
@GenerateCached(false)
1082+
public abstract static class SetItemScalarGeneralizingNode extends Node {
1083+
public abstract SequenceStorage execute(Node inliningTarget, SequenceStorage storage, int idx, Object value, GenNodeSupplier genNodeSupplier);
1084+
1085+
@Specialization
1086+
static SequenceStorage set(Node inliningTarget, SequenceStorage storage, int idx, Object value, GenNodeSupplier genNodeSupplier,
1087+
@Cached InlinedBranchProfile generalizeProfile,
1088+
@Cached SetItemScalarNode setItemScalarNode,
1089+
@Cached DoGeneralizationNode doGeneralizationNode) {
1090+
try {
1091+
setItemScalarNode.execute(inliningTarget, storage, idx, value);
1092+
return storage;
1093+
} catch (SequenceStoreException e) {
1094+
generalizeProfile.enter(inliningTarget);
1095+
SequenceStorage generalized = doGeneralizationNode.execute(inliningTarget, genNodeSupplier, storage, e.getIndicationValue());
1096+
try {
1097+
setItemScalarNode.execute(inliningTarget, generalized, idx, value);
1098+
} catch (SequenceStoreException e1) {
1099+
CompilerDirectives.transferToInterpreterAndInvalidate();
1100+
throw new IllegalStateException();
1101+
}
1102+
return generalized;
1103+
}
1104+
}
1105+
}
1106+
10791107
@GenerateUncached
10801108
@GenerateInline
10811109
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/PList.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.truffle.api.library.ExportMessage;
5151
import com.oracle.truffle.api.nodes.Node;
5252
import com.oracle.truffle.api.object.Shape;
53+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5354
import com.oracle.truffle.api.source.SourceSection;
5455

5556
@SuppressWarnings("truffle-abstract-export")
@@ -115,7 +116,7 @@ public boolean hasSourceLocation() {
115116

116117
@ExportMessage
117118
public boolean isArrayElementModifiable(long index,
118-
@Cached.Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
119+
@Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
119120
@Exclusive @Cached GilNode gil) {
120121
boolean mustRelease = gil.acquire();
121122
try {
@@ -145,7 +146,7 @@ public boolean isArrayElementInsertable(long index,
145146

146147
@ExportMessage
147148
public boolean isArrayElementRemovable(long index,
148-
@Cached.Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
149+
@Exclusive @Cached IndexNodes.NormalizeIndexCustomMessageNode normalize,
149150
@Exclusive @Cached GilNode gil) {
150151
boolean mustRelease = gil.acquire();
151152
try {
@@ -165,17 +166,24 @@ public boolean isArrayElementRemovable(long index,
165166
public void writeArrayElement(long index, Object value,
166167
@Bind("$node") Node inliningTarget,
167168
@Cached PForeignToPTypeNode convert,
168-
@Cached.Exclusive @Cached SequenceStorageNodes.SetItemScalarNode setItem,
169+
@Exclusive @Cached SequenceStorageNodes.SetItemScalarGeneralizingNode setItem,
169170
@Cached SequenceStorageNodes.AppendNode appendNode,
171+
@Cached InlinedBranchProfile generalizedProfile,
170172
@Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
171173
boolean mustRelease = gil.acquire();
172174
try {
173175
final int len = store.length();
176+
value = convert.executeConvert(value);
174177
try {
178+
SequenceStorage newStorage;
175179
if (index == len) {
176-
appendNode.execute(inliningTarget, store, convert.executeConvert(value), SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
180+
newStorage = appendNode.execute(inliningTarget, store, value, SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
177181
} else {
178-
setItem.execute(inliningTarget, store, PInt.intValueExact(index), convert.executeConvert(value));
182+
newStorage = setItem.execute(inliningTarget, store, PInt.intValueExact(index), value, SequenceStorageNodes.ListGeneralizationNode.SUPPLIER);
183+
}
184+
if (newStorage != store) {
185+
generalizedProfile.enter(inliningTarget);
186+
store = newStorage;
179187
}
180188
} catch (OverflowException e) {
181189
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)