Skip to content

Commit 02c4dfa

Browse files
committed
Push SequenceStorage.copy down
1 parent d378bb3 commit 02c4dfa

File tree

5 files changed

+17
-53
lines changed

5 files changed

+17
-53
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,9 +2871,18 @@ public abstract static class CopyNode extends Node {
28712871

28722872
public abstract SequenceStorage execute(Node node, SequenceStorage s);
28732873

2874-
@Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = {"s.getClass() == cachedClass", "!isNativeStorage(s)"})
2875-
static SequenceStorage doSpecial(SequenceStorage s,
2876-
@Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
2874+
public static SequenceStorage executeUncached(SequenceStorage s) {
2875+
return SequenceStorageNodesFactory.CopyNodeGen.getUncached().execute(null, s);
2876+
}
2877+
2878+
@Specialization
2879+
static SequenceStorage doEmpty(EmptySequenceStorage s) {
2880+
return s;
2881+
}
2882+
2883+
@Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = "s.getClass() == cachedClass")
2884+
static SequenceStorage doSpecial(BasicSequenceStorage s,
2885+
@Cached("s.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
28772886
return CompilerDirectives.castExact(CompilerDirectives.castExact(s, cachedClass).copy(), cachedClass);
28782887
}
28792888

@@ -2896,16 +2905,6 @@ static SequenceStorage doNativeObjects(NativeObjectSequenceStorage s,
28962905
}
28972906
return new ObjectSequenceStorage(objects);
28982907
}
2899-
2900-
@Specialization(guards = "!isNativeStorage(s)", replaces = "doSpecial")
2901-
@TruffleBoundary
2902-
static SequenceStorage doGeneric(SequenceStorage s) {
2903-
return s.copy();
2904-
}
2905-
2906-
protected static boolean isNativeStorage(SequenceStorage storage) {
2907-
return storage instanceof NativeSequenceStorage;
2908-
}
29092908
}
29102909

29112910
@GenerateUncached
@@ -3893,12 +3892,11 @@ public SequenceStorage execute(VirtualFrame frame, Object iterator, int len) {
38933892

38943893
@TruffleBoundary
38953894
private static SequenceStorage executeImpl(Object iterator, int len) {
3896-
if (iterator instanceof PBuiltinIterator) {
3897-
PBuiltinIterator pbi = (PBuiltinIterator) iterator;
3895+
if (iterator instanceof PBuiltinIterator pbi) {
38983896
if (GetPythonObjectClassNode.executeUncached(pbi) == PythonBuiltinClassType.PIterator && pbi.index == 0 && !pbi.isExhausted()) {
38993897
SequenceStorage s = GetInternalIteratorSequenceStorage.executeUncached(pbi);
39003898
if (s != null) {
3901-
return s.copy();
3899+
return SequenceStorageNodes.CopyNode.executeUncached(s);
39023900
}
39033901
}
39043902
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/BasicSequenceStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public abstract class BasicSequenceStorage extends SequenceStorage {
3838

3939
public abstract void reverse();
4040

41+
public abstract SequenceStorage copy();
42+
4143
public abstract Object getCopyOfInternalArrayObject();
4244

4345
public abstract void setInternalArrayObject(Object arrayObject);
@@ -63,7 +65,6 @@ private static int capacityFor(int length) throws ArithmeticException {
6365
* Ensure that the current capacity is big enough. If not, we increase capacity to the next
6466
* designated size (not necessarily the requested one).
6567
*/
66-
@Override
6768
public final void ensureCapacity(int newCapacity) throws ArithmeticException {
6869
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.UNLIKELY_PROBABILITY, newCapacity > capacity)) {
6970
increaseCapacityExactWithCopy(capacityFor(newCapacity));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/EmptySequenceStorage.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525
*/
2626
package com.oracle.graal.python.runtime.sequence.storage;
2727

28-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
29-
3028
import java.nio.ByteOrder;
3129

3230
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
33-
import com.oracle.graal.python.nodes.ErrorMessages;
34-
import com.oracle.graal.python.nodes.PRaiseNode;
3531
import com.oracle.graal.python.util.PythonUtils;
3632
import com.oracle.truffle.api.CompilerAsserts;
37-
import com.oracle.truffle.api.CompilerDirectives;
3833
import com.oracle.truffle.api.library.ExportLibrary;
3934
import com.oracle.truffle.api.library.ExportMessage;
4035

@@ -77,11 +72,6 @@ public Object getIndicativeValue() {
7772
return null;
7873
}
7974

80-
@Override
81-
public SequenceStorage copy() {
82-
return this;
83-
}
84-
8575
@Override
8676
public Object[] getInternalArray() {
8777
return PythonUtils.EMPTY_OBJECT_ARRAY;
@@ -103,11 +93,6 @@ public boolean equals(SequenceStorage other) {
10393
return other == EmptySequenceStorage.INSTANCE;
10494
}
10595

106-
@Override
107-
public void ensureCapacity(int newCapacity) {
108-
109-
}
110-
11196
@Override
11297
public Object getInternalArrayObject() {
11398
return null;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeStorageReference;
4848
import com.oracle.graal.python.util.PythonUtils;
4949
import com.oracle.truffle.api.CompilerDirectives;
50-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5150
import com.oracle.truffle.api.TruffleLogger;
5251

5352
public abstract class NativeSequenceStorage extends SequenceStorage {
@@ -62,15 +61,10 @@ public abstract class NativeSequenceStorage extends SequenceStorage {
6261
super(length, capacity);
6362
this.ptr = ptr;
6463
if (LOGGER.isLoggable(Level.FINE)) {
65-
LOGGER.fine(PythonUtils.formatJString("new %s", toJString()));
64+
LOGGER.fine(PythonUtils.formatJString("new %s", this));
6665
}
6766
}
6867

69-
@TruffleBoundary
70-
private String toJString() {
71-
return toString();
72-
}
73-
7468
public final Object getPtr() {
7569
return ptr;
7670
}
@@ -103,16 +97,6 @@ public final void setNewLength(int length) {
10397
}
10498
}
10599

106-
@Override
107-
public final void ensureCapacity(int newCapacity) {
108-
throw CompilerDirectives.shouldNotReachHere();
109-
}
110-
111-
@Override
112-
public final SequenceStorage copy() {
113-
throw CompilerDirectives.shouldNotReachHere();
114-
}
115-
116100
@Override
117101
public final Object[] getInternalArray() {
118102
throw CompilerDirectives.shouldNotReachHere();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/SequenceStorage.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public final int getCapacity() {
7777
return capacity;
7878
}
7979

80-
public abstract SequenceStorage copy();
81-
8280
/**
8381
* Get internal array object without copying. Note: The length must be taken from the sequence
8482
* storage object.
@@ -98,6 +96,4 @@ public final int getCapacity() {
9896
public abstract SequenceStorage generalizeFor(Object value, SequenceStorage other);
9997

10098
public abstract Object getIndicativeValue();
101-
102-
public abstract void ensureCapacity(int newCapacity);
10399
}

0 commit comments

Comments
 (0)