Skip to content

Commit 442fc43

Browse files
committed
[GR-53462] EnsureCapacityNode is now void
PullRequest: graalpython/3286
2 parents f131a6f + 9d20325 commit 442fc43

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.oracle.graal.python.nodes.PRaiseNode;
4949
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
5050
import com.oracle.graal.python.runtime.sequence.storage.NativeByteSequenceStorage;
51-
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
5251
import com.oracle.graal.python.util.OverflowException;
5352
import com.oracle.graal.python.util.PythonUtils;
5453
import com.oracle.truffle.api.CompilerDirectives;
@@ -59,7 +58,6 @@
5958
import com.oracle.truffle.api.dsl.Specialization;
6059
import com.oracle.truffle.api.frame.VirtualFrame;
6160
import com.oracle.truffle.api.nodes.Node;
62-
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
6361

6462
public abstract class ArrayNodes {
6563
@GenerateInline
@@ -108,15 +106,10 @@ public abstract static class EnsureCapacityNode extends Node {
108106

109107
@Specialization
110108
static void ensure(Node inliningTarget, PArray array, int newCapacity,
111-
@Cached SequenceStorageNodes.EnsureCapacityNode ensureCapacityNode,
112-
@Cached InlinedBranchProfile updateProfile) {
109+
@Cached SequenceStorageNodes.EnsureCapacityNode ensureCapacityNode) {
113110
try {
114111
int internalCapacity = PythonUtils.multiplyExact(newCapacity, array.getItemSize());
115-
SequenceStorage newStorage = ensureCapacityNode.execute(inliningTarget, array.getSequenceStorage(), internalCapacity);
116-
if (array.getSequenceStorage() != newStorage) {
117-
updateProfile.enter(inliningTarget);
118-
array.setSequenceStorage(newStorage);
119-
}
112+
ensureCapacityNode.execute(inliningTarget, array.getSequenceStorage(), internalCapacity);
120113
} catch (OverflowException e) {
121114
CompilerDirectives.transferToInterpreterAndInvalidate();
122115
PRaiseNode.raiseUncached(inliningTarget, PythonBuiltinClassType.MemoryError);

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,18 +2074,17 @@ SequenceStorage doWithStorage(SequenceStorage left, PSequence seq, int len,
20742074
} else {
20752075
lenResult = lengthResult(lenLeft, right.length());
20762076
}
2077-
SequenceStorage dest = null;
20782077
while (true) {
20792078
// unbounded loop should not be a problem for PE because generalizeStore() in the
20802079
// catch block immediately de-opts in the first iteration, i.e. if the storages are
20812080
// compatible and SequenceStoreException does not happen, then this compiles as if
20822081
// the while loop was not here at all
20832082
try {
20842083
// EnsureCapacityNode handles the overflow and raises an error
2085-
dest = ensureCapacityNode.execute(inliningTarget, left, lenResult);
2086-
return concatStoragesNode.execute(dest, left, right);
2084+
ensureCapacityNode.execute(inliningTarget, left, lenResult);
2085+
return concatStoragesNode.execute(left, left, right);
20872086
} catch (SequenceStoreException e) {
2088-
left = generalizeStore(dest, e.getIndicationValue());
2087+
left = generalizeStore(left, e.getIndicationValue());
20892088
}
20902089
}
20912090
}
@@ -2777,40 +2776,39 @@ static ObjectSequenceStorage doObject(@SuppressWarnings("unused") StorageType ty
27772776
@GenerateCached(false)
27782777
public abstract static class EnsureCapacityNode extends SequenceStorageBaseNode {
27792778

2780-
public abstract SequenceStorage execute(Node inliningTarget, SequenceStorage s, int cap);
2779+
public abstract void execute(Node inliningTarget, SequenceStorage s, int cap);
27812780

27822781
@Specialization
2783-
static EmptySequenceStorage doEmpty(EmptySequenceStorage s, @SuppressWarnings("unused") int cap) {
2784-
return s;
2782+
static void doEmpty(EmptySequenceStorage s, @SuppressWarnings("unused") int cap) {
2783+
// do nothing
27852784
}
27862785

27872786
@Specialization(limit = "MAX_BASIC_STORAGES", guards = "s.getClass() == cachedClass")
2788-
static BasicSequenceStorage doManaged(Node inliningTarget, BasicSequenceStorage s, int cap,
2787+
static void doManaged(Node inliningTarget, BasicSequenceStorage s, int cap,
27892788
@Cached PRaiseNode.Lazy raiseNode,
27902789
@Cached("s.getClass()") Class<? extends BasicSequenceStorage> cachedClass) {
27912790
try {
27922791
BasicSequenceStorage profiled = cachedClass.cast(s);
27932792
profiled.ensureCapacity(cap);
2794-
return profiled;
27952793
} catch (OutOfMemoryError | ArithmeticException e) {
27962794
throw raiseNode.get(inliningTarget).raise(MemoryError);
27972795
}
27982796
}
27992797

28002798
@Specialization
28012799
@InliningCutoff
2802-
static NativeSequenceStorage doNative(NativeSequenceStorage s, int cap,
2800+
static void doNative(NativeSequenceStorage s, int cap,
28032801
@Cached(inline = false) EnsureCapacityNativeNode helper) {
2804-
return helper.execute(s, cap);
2802+
helper.execute(s, cap);
28052803
}
28062804

28072805
@GenerateInline(false)
28082806
@GenerateUncached
28092807
abstract static class EnsureCapacityNativeNode extends Node {
2810-
abstract NativeSequenceStorage execute(NativeSequenceStorage s, int cap);
2808+
abstract void execute(NativeSequenceStorage s, int cap);
28112809

28122810
@Specialization
2813-
static NativeByteSequenceStorage doNativeByte(NativeByteSequenceStorage s, int cap,
2811+
static void doNativeByte(NativeByteSequenceStorage s, int cap,
28142812
@Bind("this") Node inliningTarget,
28152813
@Shared @CachedLibrary(limit = "2") InteropLibrary lib,
28162814
@Shared @Cached CStructAccess.AllocateNode alloc,
@@ -2834,11 +2832,10 @@ static NativeByteSequenceStorage doNativeByte(NativeByteSequenceStorage s, int c
28342832
s.setPtr(newMem);
28352833
s.setCapacity(newCapacity);
28362834
}
2837-
return s;
28382835
}
28392836

28402837
@Specialization
2841-
static NativeObjectSequenceStorage doNativeObject(NativeObjectSequenceStorage s, int cap,
2838+
static void doNativeObject(NativeObjectSequenceStorage s, int cap,
28422839
@Bind("this") Node inliningTarget,
28432840
@Shared @CachedLibrary(limit = "2") InteropLibrary lib,
28442841
@Shared @Cached CStructAccess.AllocateNode alloc,
@@ -2863,7 +2860,6 @@ static NativeObjectSequenceStorage doNativeObject(NativeObjectSequenceStorage s,
28632860
s.setPtr(newMem);
28642861
s.setCapacity(newCapacity);
28652862
}
2866-
return s;
28672863
}
28682864

28692865
private static int computeNewCapacity(int cap) {

0 commit comments

Comments
 (0)