Skip to content

Commit c0ac08f

Browse files
committed
Push setNewLength method down
1 parent ba5fcf0 commit c0ac08f

File tree

13 files changed

+37
-62
lines changed

13 files changed

+37
-62
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,13 +2229,13 @@ ObjectSequenceStorage doObjectSingleElement(ObjectSequenceStorage s, int times,
22292229
@Specialization(limit = "MAX_ARRAY_STORAGES", guards = {"times > 0", "!isNative(s)", "s.getClass() == cachedClass"})
22302230
SequenceStorage doManaged(BasicSequenceStorage s, int times,
22312231
@Shared @Cached PRaiseNode raiseNode,
2232-
@Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
2232+
@Cached("s.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
22332233
try {
2234-
SequenceStorage profiled = cachedClass.cast(s);
2234+
BasicSequenceStorage profiled = cachedClass.cast(s);
22352235
Object arr1 = profiled.getInternalArrayObject();
22362236
int len = profiled.length();
22372237
int newLength = PythonUtils.multiplyExact(len, times);
2238-
SequenceStorage repeated = profiled.createEmpty(newLength);
2238+
BasicSequenceStorage repeated = profiled.createEmpty(newLength);
22392239
Object destArr = repeated.getInternalArrayObject();
22402240
repeat(destArr, arr1, len, times);
22412241
repeated.setNewLength(newLength);
@@ -2259,7 +2259,7 @@ SequenceStorage doGeneric(SequenceStorage s, int times,
22592259
try {
22602260
int len = s.length();
22612261
int newLen = PythonUtils.multiplyExact(len, times);
2262-
SequenceStorage repeated = createEmptyNode.execute(inliningTarget, s, newLen, -1);
2262+
BasicSequenceStorage repeated = createEmptyNode.execute(inliningTarget, s, newLen, -1);
22632263

22642264
for (int i = 0; i < len; i++) {
22652265
setItemNode.execute(inliningTarget, repeated, i, getItemNode.execute(inliningTarget, s, i));
@@ -2498,7 +2498,7 @@ static ObjectSequenceStorage doObject(@SuppressWarnings("unused") ObjectSequence
24982498
}
24992499

25002500
@Specialization
2501-
static SequenceStorage doEmptyStorage(Node inliningTarget, @SuppressWarnings("unused") EmptySequenceStorage s, SequenceStorage other,
2501+
static SequenceStorage doEmptyStorage(Node inliningTarget, @SuppressWarnings("unused") EmptySequenceStorage s, BasicSequenceStorage other,
25022502
@Exclusive @Cached InlinedExactClassProfile otherProfile) {
25032503
return otherProfile.profile(inliningTarget, other).createEmpty(DEFAULT_CAPACITY);
25042504
}
@@ -2702,10 +2702,10 @@ public static AppendNode getUncached() {
27022702
@GenerateCached(false)
27032703
public abstract static class CreateEmptyNode extends SequenceStorageBaseNode {
27042704

2705-
public abstract SequenceStorage execute(Node inliningTarget, SequenceStorage s, int cap, int len);
2705+
public abstract BasicSequenceStorage execute(Node inliningTarget, SequenceStorage s, int cap, int len);
27062706

27072707
@Specialization
2708-
static SequenceStorage doIt(Node inliningTarget, SequenceStorage s, int cap, int len,
2708+
static BasicSequenceStorage doIt(Node inliningTarget, SequenceStorage s, int cap, int len,
27092709
@Cached GetElementType getElementType,
27102710
@Cached CreateEmptyForTypeNode createEmptyForTypeNode) {
27112711
BasicSequenceStorage ss = createEmptyForTypeNode.execute(inliningTarget, getElementType.execute(inliningTarget, s), cap);
@@ -2937,14 +2937,8 @@ public abstract static class SetLenNode extends Node {
29372937

29382938
public abstract void execute(Node inliningTarget, SequenceStorage s, int len);
29392939

2940-
@Specialization(limit = "MAX_SEQUENCE_STORAGES", guards = "s.getClass() == cachedClass")
2941-
static void doSpecial(BasicSequenceStorage s, int len,
2942-
@Cached("s.getClass()") Class<? extends SequenceStorage> cachedClass) {
2943-
cachedClass.cast(s).setNewLength(len);
2944-
}
2945-
2946-
@Specialization(replaces = "doSpecial")
2947-
static void doGeneric(BasicSequenceStorage s, int len) {
2940+
@Specialization
2941+
static void doBasic(BasicSequenceStorage s, int len) {
29482942
s.setNewLength(len);
29492943
}
29502944

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ public abstract class ErrorMessages {
443443
public static final TruffleString LIBRARY_VERSION_MISMATCH = tsLiteral("library version mismatch");
444444
public static final TruffleString LIST_ASSIGMENT_INDEX_OUT_OF_RANGE = tsLiteral("list assignment index out of range");
445445
public static final TruffleString LIST_INDEX_OUT_OF_RANGE = tsLiteral("list index out of range");
446-
public static final TruffleString LIST_LENGTH_OUT_OF_RANGE = tsLiteral("list length out of range");
447446
public static final TruffleString LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT = tsLiteral("local variable '%s' referenced before assignment");
448447
public static final TruffleString UNBOUNDFREEVAR = tsLiteral("cannot access free variable '%s' where it is not associated with a value in enclosing scope");
449448
public static final TruffleString LOCALS_MUST_BE_MAPPING = tsLiteral("%s() locals must be a mapping or None, not %p");

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -33,6 +33,16 @@ public abstract class BasicSequenceStorage extends SequenceStorage {
3333

3434
public abstract void setInternalArrayObject(Object arrayObject);
3535

36+
public final void setNewLength(int length) {
37+
this.length = length;
38+
}
39+
40+
protected final void incLength() {
41+
this.length++;
42+
}
43+
44+
public abstract BasicSequenceStorage createEmpty(int newCapacity);
45+
3646
/**
3747
* The capacity we should allocate for a given length.
3848
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -71,7 +71,7 @@ public SequenceStorage copy() {
7171
}
7272

7373
@Override
74-
public SequenceStorage createEmpty(int newLength) {
74+
public BasicSequenceStorage createEmpty(int newLength) {
7575
return new BoolSequenceStorage(newLength);
7676
}
7777

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -79,7 +79,7 @@ public SequenceStorage copy() {
7979
}
8080

8181
@Override
82-
public SequenceStorage createEmpty(int newCapacity) {
82+
public BasicSequenceStorage createEmpty(int newCapacity) {
8383
return new ByteSequenceStorage(newCapacity);
8484
}
8585

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -73,7 +73,7 @@ public SequenceStorage copy() {
7373
}
7474

7575
@Override
76-
public SequenceStorage createEmpty(int newCapacity) {
76+
public BasicSequenceStorage createEmpty(int newCapacity) {
7777
return new DoubleSequenceStorage(newCapacity);
7878
}
7979

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -27,6 +27,8 @@
2727

2828
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
2929

30+
import java.nio.ByteOrder;
31+
3032
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
3133
import com.oracle.graal.python.nodes.ErrorMessages;
3234
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -35,8 +37,6 @@
3537
import com.oracle.truffle.api.library.ExportLibrary;
3638
import com.oracle.truffle.api.library.ExportMessage;
3739

38-
import java.nio.ByteOrder;
39-
4040
@ExportLibrary(PythonBufferAccessLibrary.class)
4141
public final class EmptySequenceStorage extends SequenceStorage {
4242

@@ -76,24 +76,11 @@ public Object getIndicativeValue() {
7676
return null;
7777
}
7878

79-
@Override
80-
public void setNewLength(int length) {
81-
if (length != 0) {
82-
CompilerDirectives.transferToInterpreter();
83-
throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.LIST_LENGTH_OUT_OF_RANGE);
84-
}
85-
}
86-
8779
@Override
8880
public SequenceStorage copy() {
8981
return this;
9082
}
9183

92-
@Override
93-
public SequenceStorage createEmpty(int newCapacity) {
94-
return this;
95-
}
96-
9784
@Override
9885
public Object[] getInternalArray() {
9986
return PythonUtils.EMPTY_OBJECT_ARRAY;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -73,7 +73,7 @@ public SequenceStorage copy() {
7373
}
7474

7575
@Override
76-
public SequenceStorage createEmpty(int newCapacity) {
76+
public BasicSequenceStorage createEmpty(int newCapacity) {
7777
return new IntSequenceStorage(newCapacity);
7878
}
7979

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -75,7 +75,7 @@ public SequenceStorage copy() {
7575
}
7676

7777
@Override
78-
public SequenceStorage createEmpty(int newCapacity) {
78+
public BasicSequenceStorage createEmpty(int newCapacity) {
7979
return new LongSequenceStorage(newCapacity);
8080
}
8181

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public SequenceStorage copy() {
153153
}
154154

155155
@Override
156-
public SequenceStorage createEmpty(int newCapacity) {
156+
public BasicSequenceStorage createEmpty(int newCapacity) {
157157
return new MroSequenceStorage(getClassName(), newCapacity);
158158
}
159159

0 commit comments

Comments
 (0)