Skip to content

Commit 2cf5ffe

Browse files
committed
Change back to clear() being implemented for all array stores.
1 parent 5d38f2d commit 2cf5ffe

File tree

9 files changed

+32
-90
lines changed

9 files changed

+32
-90
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,7 @@ protected Object compactObjects(RubyArray array,
571571
profileAndReportLoopCount(loopProfile, n);
572572
}
573573

574-
if (stores.isMutable(oldStore)) {
575-
stores.clear(oldStore, m, size - m);
576-
}
574+
stores.clear(oldStore, m, size - m);
577575

578576
array.store = newStore;
579577
array.size = m;
@@ -735,7 +733,7 @@ private Object delete(RubyArray array, Object value, Object maybeBlock,
735733
}
736734

737735
if (i != n) {
738-
if (sameStores && !oldStores.isPrimitive(oldStore)) {
736+
if (sameStores) {
739737
oldStores.clear(oldStore, i, size - i);
740738
}
741739
array.store = newStore;
@@ -772,7 +770,7 @@ protected ToIntNode coerceOtherToInt(RubyBaseNodeWithExecute index) {
772770
}
773771

774772
@Specialization(
775-
guards = { "stores.isMutable(store)", "!stores.isPrimitive(store)" },
773+
guards = "stores.isMutable(store)",
776774
limit = "storageStrategyLimit()")
777775
protected Object deleteAt(RubyArray array, int index,
778776
@Bind("array.store") Object store,
@@ -798,31 +796,6 @@ protected Object deleteAt(RubyArray array, int index,
798796
}
799797
}
800798

801-
@Specialization(
802-
guards = { "stores.isMutable(store)", "stores.isPrimitive(store)" },
803-
limit = "storageStrategyLimit()")
804-
protected Object deleteAtPrimitive(RubyArray array, int index,
805-
@Bind("array.store") Object store,
806-
@CachedLibrary("store") ArrayStoreLibrary stores,
807-
@Cached ConditionProfile negativeIndexProfile,
808-
@Cached ConditionProfile notInBoundsProfile) {
809-
final int size = array.size;
810-
int i = index;
811-
if (negativeIndexProfile.profile(index < 0)) {
812-
i += size;
813-
}
814-
815-
if (notInBoundsProfile.profile(i < 0 || i >= size)) {
816-
return nil;
817-
} else {
818-
final Object value = stores.read(store, i);
819-
stores.copyContents(store, i + 1, store, i, size - i - 1);
820-
array.store = store;
821-
array.size = size - 1;
822-
return value;
823-
}
824-
}
825-
826799
@Specialization(
827800
guards = "!stores.isMutable(store)",
828801
limit = "storageStrategyLimit()")
@@ -1754,9 +1727,7 @@ protected RubyArray popNotEmptyUnsharedStorage(RubyArray array, int n,
17541727
stores.copyContents(store, size - numPop, popped, 0, numPop);
17551728

17561729
// Remove the end from the original array.
1757-
if (!stores.isPrimitive(store)) {
1758-
stores.clear(store, size - numPop, numPop);
1759-
}
1730+
stores.clear(store, size - numPop, numPop);
17601731
setSize(array, size - numPop);
17611732

17621733
return createArray(popped, numPop);
@@ -1927,9 +1898,7 @@ private Object rejectInPlaceInternal(RubyArray array, RubyProc block, ArrayStore
19271898
profileAndReportLoopCount(loop2Profile, size - n);
19281899

19291900
// Null out the elements behind the size
1930-
if (!stores.isPrimitive(store)) {
1931-
stores.clear(store, i, n - i);
1932-
}
1901+
stores.clear(store, i, n - i);
19331902
setSize(array, i);
19341903
}
19351904

@@ -2162,10 +2131,8 @@ protected Object shiftEmpty(RubyArray array, NotProvided n) {
21622131
return nil;
21632132
}
21642133

2165-
@Specialization(
2166-
guards = { "!isEmptyArray(array)", "mutableNonPrimitive(stores,store)" },
2167-
limit = "storageStrategyLimit()")
2168-
protected Object shiftAndClear(RubyArray array, NotProvided n,
2134+
@Specialization(guards = "!isEmptyArray(array)", limit = "storageStrategyLimit()")
2135+
protected Object shiftOther(RubyArray array, NotProvided n,
21692136
@Bind("array.store") Object store,
21702137
@CachedLibrary("store") ArrayStoreLibrary stores) {
21712138
final int size = array.size;
@@ -2176,19 +2143,6 @@ protected Object shiftAndClear(RubyArray array, NotProvided n,
21762143
return value;
21772144
}
21782145

2179-
@Specialization(
2180-
guards = { "!isEmptyArray(array)", "!mutableNonPrimitive(stores,store)" },
2181-
limit = "storageStrategyLimit()")
2182-
protected Object shiftDontClear(RubyArray array, NotProvided n,
2183-
@Bind("array.store") Object store,
2184-
@CachedLibrary("store") ArrayStoreLibrary stores) {
2185-
final int size = array.size;
2186-
final Object value = stores.read(store, 0);
2187-
array.store = stores.extractRange(store, 1, size);
2188-
setSize(array, size - 1);
2189-
return value;
2190-
}
2191-
21922146
// n given, shift the first n elements and return them as an Array
21932147

21942148
@Specialization(guards = "n < 0")
@@ -2226,10 +2180,6 @@ protected Object shiftNToInt(RubyArray array, Object n,
22262180
@Cached ToIntNode toIntNode) {
22272181
return executeShift(array, toIntNode.execute(n));
22282182
}
2229-
2230-
protected boolean mutableNonPrimitive(ArrayStoreLibrary stores, Object store) {
2231-
return !stores.isPrimitive(store) && stores.isMutable(store);
2232-
}
22332183
}
22342184

22352185
@CoreMethod(names = { "size", "length" })

src/main/java/org/truffleruby/core/array/ArrayPopOneNode.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ protected Object popOneEmpty(RubyArray array) {
3333

3434
// Pop from a non-empty array
3535

36-
@Specialization(
37-
guards = { "!isEmptyArray(array)", "mutableNonPrimitive(stores, store)" },
38-
limit = "storageStrategyLimit()")
39-
protected Object popOneAndClear(RubyArray array,
36+
@Specialization(guards = "!isEmptyArray(array)", limit = "storageStrategyLimit()")
37+
protected Object popOne(RubyArray array,
4038
@Bind("array.store") Object store,
4139
@CachedLibrary("store") ArrayStoreLibrary stores) {
4240
final int size = array.size;
@@ -46,20 +44,4 @@ protected Object popOneAndClear(RubyArray array,
4644
return value;
4745
}
4846

49-
@Specialization(
50-
guards = { "!isEmptyArray(array)", "!mutableNonPrimitive(stores, store)" },
51-
limit = "storageStrategyLimit()")
52-
protected Object popOneDontClear(RubyArray array,
53-
@Bind("array.store") Object store,
54-
@CachedLibrary("store") ArrayStoreLibrary stores) {
55-
final int size = array.size;
56-
final Object value = stores.read(store, size - 1);
57-
setSize(array, size - 1);
58-
return value;
59-
}
60-
61-
protected boolean mutableNonPrimitive(ArrayStoreLibrary stores, Object store) {
62-
return !stores.isPrimitive(store) && stores.isMutable(store);
63-
}
64-
6547
}

src/main/java/org/truffleruby/core/array/ArrayTruncateNode.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static ArrayTruncateNode create() {
3030
public abstract void execute(RubyArray array, int size);
3131

3232
@Specialization(
33-
guards = { "array.size > size", "stores.isMutable(store)", "!stores.isPrimitive(store)" },
33+
guards = { "array.size > size", "stores.isMutable(store)" },
3434
limit = "storageStrategyLimit()")
3535
protected void truncate(RubyArray array, int size,
3636
@Bind("array.store") Object store,
@@ -41,15 +41,6 @@ protected void truncate(RubyArray array, int size,
4141
stores.clear(store, size, oldSize - size);
4242
}
4343

44-
@Specialization(
45-
guards = { "array.size > size", "stores.isMutable(store)", "stores.isPrimitive(store)" },
46-
limit = "storageStrategyLimit()")
47-
protected void truncatePrimitive(RubyArray array, int size,
48-
@Bind("array.store") Object store,
49-
@CachedLibrary("store") ArrayStoreLibrary stores) {
50-
array.size = size;
51-
}
52-
5344
@Specialization(
5445
guards = { "array.size > size", "!stores.isMutable(store)" },
5546
limit = "storageStrategyLimit()")

src/main/java/org/truffleruby/core/array/library/ArrayStoreLibrary.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ public Object extractRange(Object store, int start, int end) {
153153
/** If the array is mutable, clears the part of the array starting at {@code start} and extending for {@code length}
154154
* elements, so that that range does not retain references to objects/memory/resources. This can be understood as
155155
* "nulling out" that part of the array, and will do nothing for primitive arrays. */
156-
public void clear(Object store, int start, int length) {
157-
throw new UnsupportedOperationException("clear operation not supported");
158-
}
156+
public abstract void clear(Object store, int start, int length);
157+
159158

160159
/** Fill the part of the array starting at {@code start} and extending for {@code length} elements using
161160
* {@code value}, which must be accepted by the store. */

src/main/java/org/truffleruby/core/array/library/DelegatedArrayStorage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ protected void copyContents(int srcStart, Object destStore, int destStart, int l
145145
}
146146
}
147147

148+
@ExportMessage
149+
protected void clear(int start, int length) {
150+
}
151+
148152
@ExportMessage
149153
protected Object toJavaArrayCopy(int length,
150154
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {

src/main/java/org/truffleruby/core/array/library/DoubleArrayStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ protected static boolean isDoubleStore(Object store) {
171171
}
172172
}
173173

174+
@ExportMessage
175+
protected static void clear(double[] store, int start, int length) {
176+
}
177+
174178
@ExportMessage
175179
protected static void fill(double[] store, int start, int length, Object value) {
176180
Arrays.fill(store, start, start + length, (double) value);

src/main/java/org/truffleruby/core/array/library/IntegerArrayStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ protected static boolean isIntStore(Object store) {
170170
}
171171
}
172172

173+
@ExportMessage
174+
protected static void clear(int[] store, int start, int length) {
175+
}
176+
173177
@ExportMessage
174178
protected static void fill(int[] store, int start, int length, Object value) {
175179
Arrays.fill(store, start, start + length, (int) value);

src/main/java/org/truffleruby/core/array/library/LongArrayStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ protected static boolean isLongStore(Object store) {
183183
}
184184
}
185185

186+
@ExportMessage
187+
protected static void clear(long[] store, int start, int length) {
188+
}
189+
186190
@ExportMessage
187191
static class Fill {
188192
@Specialization

src/main/java/org/truffleruby/core/array/library/ZeroLengthArrayStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ protected void copyContents(int srcStart, Object destStore, int destStart, int l
108108
assert length == 0;
109109
}
110110

111+
@ExportMessage
112+
protected void clear(int start, int length) {
113+
}
114+
111115
@ExportMessage
112116
protected Object[] toJavaArrayCopy(int length) {
113117
assert length == 0;

0 commit comments

Comments
 (0)