Skip to content

Commit 8fad812

Browse files
committed
Remove obsolete method 'PSequence.getSlice'.
1 parent ad0e446 commit 8fad812

File tree

11 files changed

+23
-194
lines changed

11 files changed

+23
-194
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,4 @@ public void setSequenceStorage(SequenceStorage store) {
7979
public int len() {
8080
return store.length();
8181
}
82-
83-
@Override
84-
protected Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
85-
throw new UnsupportedOperationException();
86-
}
87-
8882
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public void setItemNormalized(int index, Object value) {
7777
}
7878
}
7979

80-
@Override
81-
public Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
82-
return factory.createByteArray(this.getPythonClass(), store.getSliceInBound(start, stop, step, length));
83-
}
84-
8580
@Override
8681
public void setSlice(int start, int stop, int step, PSequence value) {
8782
final int normalizedStart = SequenceUtil.normalizeSliceStart(start, step, store.length());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ public Object getItemNormalized(int index) {
7575
return store.getItemNormalized(index);
7676
}
7777

78-
@Override
79-
public Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
80-
CompilerDirectives.transferToInterpreter();
81-
throw new UnsupportedOperationException();
82-
}
83-
8478
@Override
8579
public int index(Object value) {
8680
int index = store.index(value);

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

Lines changed: 11 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ abstract static class GetItemSliceNode extends PBaseNode {
377377

378378
public abstract SequenceStorage execute(SequenceStorage s, int start, int stop, int step, int length);
379379

380+
@Specialization
381+
@SuppressWarnings("unused")
382+
protected EmptySequenceStorage doEmpty(EmptySequenceStorage storage, int start, int stop, int step, int length) {
383+
return EmptySequenceStorage.INSTANCE;
384+
}
385+
380386
@Specialization(limit = "5", guards = {"storage.getClass() == cachedClass"})
381387
protected SequenceStorage doManagedStorage(BasicSequenceStorage storage, int start, int stop, int step, int length,
382388
@Cached("storage.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
@@ -487,7 +493,7 @@ protected void doScalarPInt(SequenceStorage storage, PInt idx, Object value) {
487493
@Specialization
488494
protected void doSlice(SequenceStorage storage, PSlice slice, PSequence value) {
489495
SliceInfo info = slice.computeActualIndices(storage.length());
490-
getSetItemSliceNode().execute(storage, info.start, info.stop, info.step, info.length);
496+
getSetItemSliceNode().execute(storage, info, value);
491497
}
492498

493499
private SetItemScalarNode getSetItemScalarNode() {
@@ -612,78 +618,11 @@ public abstract static class SetItemSliceNode extends PBaseNode {
612618
@Child private Node readNode;
613619
@Child private Node executeNode;
614620

615-
public abstract Object execute(SequenceStorage s, int start, int stop, int step, int length);
616-
617-
@Specialization(limit = "5", guards = {"storage.getClass() == cachedClass"})
618-
protected SequenceStorage doManagedStorage(BasicSequenceStorage storage, int start, int stop, int step, int length,
619-
@Cached("storage.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
620-
return cachedClass.cast(storage).getSliceInBound(start, stop, step, length);
621-
}
622-
623-
@Specialization(guards = "storage.getElementType() == BYTE")
624-
protected NativeSequenceStorage doNativeByte(NativeSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length,
625-
@Cached("create()") StorageToNativeNode storageToNativeNode) {
626-
byte[] newArray = new byte[length];
627-
for (int i = start, j = 0; j < length; i += step, j++) {
628-
newArray[j] = (byte) readNativeElement((TruffleObject) storage.getPtr(), i);
629-
}
630-
return storageToNativeNode.execute(newArray);
631-
}
632-
633-
@Specialization(guards = "storage.getElementType() == INT")
634-
protected NativeSequenceStorage doNativeInt(NativeSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length,
635-
@Cached("create()") StorageToNativeNode storageToNativeNode) {
636-
int[] newArray = new int[length];
637-
for (int i = start, j = 0; j < length; i += step, j++) {
638-
newArray[j] = (int) readNativeElement((TruffleObject) storage.getPtr(), i);
639-
}
640-
return storageToNativeNode.execute(newArray);
641-
}
621+
public abstract Object execute(SequenceStorage s, SliceInfo info, Object iterable);
642622

643-
@Specialization(guards = "storage.getElementType() == LONG")
644-
protected NativeSequenceStorage doNativeLong(NativeSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length,
645-
@Cached("create()") StorageToNativeNode storageToNativeNode) {
646-
long[] newArray = new long[length];
647-
for (int i = start, j = 0; j < length; i += step, j++) {
648-
newArray[j] = (long) readNativeElement((TruffleObject) storage.getPtr(), i);
649-
}
650-
return storageToNativeNode.execute(newArray);
651-
}
652-
653-
@Specialization(guards = "storage.getElementType() == DOUBLE")
654-
protected NativeSequenceStorage doNativeDouble(NativeSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length,
655-
@Cached("create()") StorageToNativeNode storageToNativeNode) {
656-
double[] newArray = new double[length];
657-
for (int i = start, j = 0; j < length; i += step, j++) {
658-
newArray[j] = (double) readNativeElement((TruffleObject) storage.getPtr(), i);
659-
}
660-
return storageToNativeNode.execute(newArray);
661-
}
662-
663-
@Specialization(guards = "storage.getElementType() == OBJECT")
664-
protected NativeSequenceStorage doNativeObject(NativeSequenceStorage storage, int start, @SuppressWarnings("unused") int stop, int step, int length,
665-
@Cached("create()") StorageToNativeNode storageToNativeNode) {
666-
Object[] newArray = new Object[length];
667-
for (int i = start, j = 0; j < length; i += step, j++) {
668-
newArray[j] = readNativeElement((TruffleObject) storage.getPtr(), i);
669-
}
670-
return storageToNativeNode.execute(newArray);
671-
}
672-
673-
private Object readNativeElement(TruffleObject ptr, int idx) {
674-
try {
675-
return ForeignAccess.sendRead(getReadNode(), ptr, idx);
676-
} catch (InteropException e) {
677-
throw e.raise();
678-
}
679-
}
680-
681-
private Node getReadNode() {
682-
if (readNode == null) {
683-
CompilerDirectives.transferToInterpreterAndInvalidate();
684-
readNode = insert(Message.READ.createNode());
685-
}
686-
return readNode;
623+
@Specialization
624+
Object doGeneric(@SuppressWarnings("unused") SequenceStorage s, @SuppressWarnings("unused") SliceInfo info, @SuppressWarnings("unused") Object iterable) {
625+
throw new UnsupportedOperationException();
687626
}
688627

689628
public static SetItemSliceNode create() {

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

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -268,84 +268,20 @@ protected Object doGeneric(Object self, Object objectIdx) {
268268
@GenerateNodeFactory
269269
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
270270

271-
@Child private NormalizeIndexNode normalize = NormalizeIndexNode.forList();
272-
273-
@Specialization(guards = "isIntStorage(primary)")
274-
protected int doPListInt(PList primary, long idx) {
275-
IntSequenceStorage storage = (IntSequenceStorage) primary.getSequenceStorage();
276-
return storage.getIntItemNormalized(normalize.execute(idx, storage.length()));
277-
}
278-
279-
@Specialization(guards = "isLongStorage(primary)")
280-
protected long doPListLong(PList primary, long idx) {
281-
LongSequenceStorage storage = (LongSequenceStorage) primary.getSequenceStorage();
282-
return storage.getLongItemNormalized(normalize.execute(idx, storage.length()));
283-
}
284-
285-
@Specialization(guards = "isDoubleStorage(primary)")
286-
protected double doPListDouble(PList primary, long idx) {
287-
DoubleSequenceStorage storage = (DoubleSequenceStorage) primary.getSequenceStorage();
288-
return storage.getDoubleItemNormalized(normalize.execute(idx, storage.length()));
289-
}
290-
291-
@Specialization(guards = "isObjectStorage(primary)")
292-
protected Object doPListObject(PList primary, long idx) {
293-
ObjectSequenceStorage storage = (ObjectSequenceStorage) primary.getSequenceStorage();
294-
return storage.getItemNormalized(normalize.execute(idx, storage.length()));
295-
}
296-
297-
@Specialization
298-
protected Object doPList(PList list, long idx) {
299-
SequenceStorage storage = list.getSequenceStorage();
300-
return storage.getItemNormalized(normalize.execute(idx, storage.length()));
301-
}
302-
303-
@Specialization(guards = "isIntStorage(primary)")
304-
protected int doPListInt(PList primary, PInt idx) {
305-
IntSequenceStorage storage = (IntSequenceStorage) primary.getSequenceStorage();
306-
return storage.getIntItemNormalized(normalize.execute(idx, storage.length()));
307-
}
308-
309-
@Specialization(guards = "isLongStorage(primary)")
310-
protected long doPListLong(PList primary, PInt idx) {
311-
LongSequenceStorage storage = (LongSequenceStorage) primary.getSequenceStorage();
312-
return storage.getLongItemNormalized(normalize.execute(idx, storage.length()));
313-
}
314-
315-
@Specialization(guards = "isDoubleStorage(primary)")
316-
protected double doPListDouble(PList primary, PInt idx) {
317-
DoubleSequenceStorage storage = (DoubleSequenceStorage) primary.getSequenceStorage();
318-
return storage.getDoubleItemNormalized(normalize.execute(idx, storage.length()));
319-
}
320-
321-
@Specialization(guards = "isObjectStorage(primary)")
322-
protected Object doPListObject(PList primary, PInt idx) {
323-
ObjectSequenceStorage storage = (ObjectSequenceStorage) primary.getSequenceStorage();
324-
return storage.getItemNormalized(normalize.execute(idx, storage.length()));
325-
}
326-
327271
@Specialization
328-
protected Object doPList(PList list, PInt idx) {
329-
SequenceStorage storage = list.getSequenceStorage();
330-
return storage.getItemNormalized(normalize.execute(idx, storage.length()));
272+
protected Object doScalar(PList self, Object key,
273+
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
274+
return getItemNode.execute(self.getSequenceStorage(), key);
331275
}
332276

333-
@Specialization
334-
protected Object doPListSlice(PList self, PSlice slice) {
335-
return self.getSlice(factory(), slice);
277+
protected static SequenceStorageNodes.GetItemNode createGetItemNode() {
278+
return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forList(), (s, f) -> f.createList(s));
336279
}
337280

338281
protected static GetItemNode create() {
339282
return ListBuiltinsFactory.GetItemNodeFactory.create();
340283
}
341284

342-
@Specialization
343-
protected Object doObjectIndex(PList self, Object objectIdx,
344-
@Cached("create()") IndexNode getIndexNode,
345-
@Cached("create()") GetItemNode getRecursiveNode) {
346-
return getRecursiveNode.execute(self, getIndexNode.execute(objectIdx));
347-
}
348-
349285
@SuppressWarnings("unused")
350286
@Fallback
351287
protected Object doGeneric(Object self, Object objectIdx) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ public final void setSequenceStorage(SequenceStorage newStorage) {
5555
this.store = newStorage;
5656
}
5757

58-
@Override
59-
public final Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
60-
return factory.createList(getPythonClass(), store.getSliceInBound(start, stop, step, length));
61-
}
62-
6358
@Override
6459
public final void setSlice(PSlice slice, PSequence value) {
6560
// Should not be used. Replaces with ListNodes.SetSliceNode.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/PRange.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,6 @@ public Object getItemNormalized(int index) {
111111
return index * step + start;
112112
}
113113

114-
@Override
115-
public Object getSlice(PythonObjectFactory factory, int sliceStart, int sliceStop, int sliceStep, int slicelength) {
116-
// Parameters 'sliceStart', 'sliceStop', ... are again a range but of indices.
117-
int newStep = step * sliceStep;
118-
int newStart = sliceStart == SequenceUtil.MISSING_INDEX ? start : start + sliceStart * step;
119-
int newStop = sliceStop == SequenceUtil.MISSING_INDEX ? stop : Math.min(stop, newStart + slicelength * newStep);
120-
return factory.createRange(newStart, newStop, newStep);
121-
}
122-
123114
@Override
124115
public int len() {
125116
return length;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
import com.oracle.graal.python.builtins.objects.ints.PInt;
4343
import com.oracle.graal.python.builtins.objects.iterator.PIntegerIterator;
4444
import com.oracle.graal.python.builtins.objects.slice.PSlice;
45+
import com.oracle.graal.python.builtins.objects.slice.PSlice.SliceInfo;
4546
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4647
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
4748
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
4849
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
4950
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
51+
import com.oracle.graal.python.runtime.sequence.SequenceUtil;
5052
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5153
import com.oracle.truffle.api.dsl.Fallback;
5254
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -195,7 +197,11 @@ Object doPRange(PRange primary, long idx) {
195197

196198
@Specialization
197199
Object doPRange(PRange range, PSlice slice) {
198-
return range.getSlice(factory(), slice);
200+
SliceInfo info = slice.computeActualIndices(range.len());
201+
int newStep = range.getStep() * info.step;
202+
int newStart = info.start == SequenceUtil.MISSING_INDEX ? range.getStart() : range.getStart() + info.start * range.getStep();
203+
int newStop = info.stop == SequenceUtil.MISSING_INDEX ? range.getStop() : Math.min(range.getStop(), newStart + info.length * newStep);
204+
return factory().createRange(newStart, newStop, newStep);
199205
}
200206

201207
@Fallback

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public int len() {
5252
return value.length();
5353
}
5454

55-
@Override
56-
public Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
57-
throw new UnsupportedOperationException();
58-
}
59-
6055
@Override
6156
public String toString() {
6257
return value.toString();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/PTuple.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public Object getItemNormalized(int index) {
7373
return store.getItemNormalized(index);
7474
}
7575

76-
@Override
77-
public Object getSlice(PythonObjectFactory factory, int start, int stop, int step, int length) {
78-
return factory.createTuple(store.getSliceInBound(start, stop, step, length));
79-
}
80-
8176
@Override
8277
public String toString() {
8378
CompilerAsserts.neverPartOfCompilation();

0 commit comments

Comments
 (0)