Skip to content

Commit d033d9b

Browse files
committed
refactor: remove generilize form ArrayBasedSequenceStorage
1 parent e1314a5 commit d033d9b

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@ static Object[] doBool(BoolSequenceStorage storage) {
32233223

32243224
@Specialization
32253225
static Object[] doMro(MroSequenceStorage storage) {
3226-
return storage.getCopyOfInternalArray();
3226+
throw CompilerDirectives.shouldNotReachHere();
32273227
}
32283228

32293229
@Specialization
@@ -3611,7 +3611,12 @@ static Object[] doObjectSequenceStorage(ObjectSequenceStorage s) {
36113611
return s.getInternalArray();
36123612
}
36133613

3614-
@Specialization(guards = "!isObjectStorage(s)")
3614+
@Specialization
3615+
static Object[] doMroSequenceStorage(MroSequenceStorage s) {
3616+
return s.getInternalArray();
3617+
}
3618+
3619+
@Specialization(guards = "!isObjectStorage(s) || isMroStorage(s)")
36153620
static Object[] doArrayBasedSequenceStorage(Node inliningTarget, ArrayBasedSequenceStorage s,
36163621
@Cached CopyInternalArrayNode copy) {
36173622
Object[] internalArray = copy.execute(inliningTarget, s);
@@ -3647,6 +3652,10 @@ private static Object[] materializeGeneric(Node inliningTarget, SequenceStorage
36473652
protected static boolean isObjectStorage(ArrayBasedSequenceStorage storage) {
36483653
return storage instanceof ObjectSequenceStorage;
36493654
}
3655+
3656+
protected static boolean isMroStorage(ArrayBasedSequenceStorage storage) {
3657+
return storage instanceof MroSequenceStorage;
3658+
}
36503659
}
36513660

36523661
@GenerateUncached
@@ -3682,9 +3691,8 @@ static boolean isObjectSequenceStorage(SequenceStorage s) {
36823691

36833692
}
36843693

3685-
@GenerateCached
36863694
@GenerateUncached
3687-
@GenerateInline(inlineByDefault = true)
3695+
@GenerateInline
36883696
public abstract static class InsertItemArrayBasedStorageNode extends Node {
36893697

36903698
public static SequenceStorage executeUncached(ArrayBasedSequenceStorage storage, int index, Object value) {
@@ -3693,10 +3701,6 @@ public static SequenceStorage executeUncached(ArrayBasedSequenceStorage storage,
36933701

36943702
protected abstract SequenceStorage execute(Node inliningTarget, ArrayBasedSequenceStorage storage, int index, Object value);
36953703

3696-
public final SequenceStorage executeCached(ArrayBasedSequenceStorage storage, int index, Object value) {
3697-
return execute(this, storage, index, value);
3698-
}
3699-
37003704
@Specialization
37013705
static SequenceStorage doIntStorage(IntSequenceStorage storage, int idx, int value) {
37023706
storage.insertIntItem(idx, value);
@@ -3757,10 +3761,12 @@ static SequenceStorage doMroStorage(MroSequenceStorage storage, int idx, Object
37573761
}
37583762

37593763
@Fallback
3760-
static SequenceStorage doGeneralization(ArrayBasedSequenceStorage storage, int idx, Object value,
3761-
@Cached(inline = false) InsertItemArrayBasedStorageNode recursiveNode) {
3762-
ObjectSequenceStorage newStorage = storage.generalize();
3763-
return recursiveNode.executeCached(newStorage, idx, value);
3764+
static SequenceStorage doGeneralization(Node inliningTarget, ArrayBasedSequenceStorage storage, int idx, Object value,
3765+
@Cached GetInternalObjectArrayNode getInternalObjectArrayNode) {
3766+
Object[] values = getInternalObjectArrayNode.execute(inliningTarget, storage);
3767+
ObjectSequenceStorage newStorage = new ObjectSequenceStorage(values);
3768+
newStorage.insertItem(idx, value);
3769+
return newStorage;
37643770
}
37653771
}
37663772

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,4 @@ public abstract class ArrayBasedSequenceStorage extends BasicSequenceStorage {
5151
public abstract void setInternalArrayObject(Object arrayObject);
5252

5353
public abstract ArrayBasedSequenceStorage createEmpty(int newCapacity);
54-
55-
public ObjectSequenceStorage generalize() {
56-
return new ObjectSequenceStorage(getInternalArray());
57-
}
58-
5954
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ public abstract class BasicSequenceStorage extends SequenceStorage {
3333

3434
public abstract void setItemNormalized(int idx, Object value) throws SequenceStoreException;
3535

36-
/**
37-
* Get internal array object without copying. Note: The length must be taken from the sequence
38-
* storage object.
39-
*/
4036
public final void setNewLength(int length) {
4137
this.length = length;
4238
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ private static boolean invalidateAttributesInMROFinalAssumptions(List<Assumption
243243
return true;
244244
}
245245

246-
public Object[] getCopyOfInternalArray() {
247-
return getInternalArray();
248-
}
249-
250246
public boolean hasAttributeInMROFinalAssumptions() {
251247
return hasAttributesInMROFinalAssumptions;
252248
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public void ensureCapacity(int newCapacity) throws ArithmeticException {
118118
}
119119
}
120120

121-
@Override
122-
public ObjectSequenceStorage generalize() {
123-
throw CompilerDirectives.shouldNotReachHere();
124-
}
125-
126121
@Override
127122
public Object getIndicativeValue() {
128123
return null;

0 commit comments

Comments
 (0)