Skip to content

Commit 25ecc66

Browse files
committed
Add IntNativeStorage strategy
1 parent b817122 commit 25ecc66

17 files changed

+764
-12
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from tests.util import storage_to_arrow
2+
3+
def test_access():
4+
a = [1, 2, 3]
5+
storage_to_arrow(a)
6+
7+
assert a[0] == 1
8+
assert a[1] == 2
9+
assert a[2] == 3
10+
11+
def test_modify():
12+
a = [1, 2, 3]
13+
storage_to_arrow(a)
14+
a[0] = 11
15+
16+
assert a[0] == 11
17+
18+
19+
def test_add():
20+
a = [1, 2, 3]
21+
storage_to_arrow(a)
22+
a.append(4)
23+
24+
assert a[0] == 1
25+
assert a[1] == 2
26+
assert a[2] == 3
27+
assert a[3] == 4
28+
29+
def test_remove():
30+
a = [1, 2, 3]
31+
storage_to_arrow(a)
32+
a.remove(2)
33+
34+
assert a[0] == 1
35+
assert a[1] == 3
36+
37+
assert a.pop(0) == 1
38+
39+
assert len(a) == 1
40+
assert a[0] == 3
41+
42+
43+
def test_slice():
44+
a = [1, 2, 3, 4]
45+
storage_to_arrow(a)
46+
b = a[1:3]
47+
48+
assert len(b) == 2
49+
assert b[0] == 2
50+
assert b[1] == 3
51+
52+
53+
def test_reverse():
54+
a = [1, 2, 3]
55+
storage_to_arrow(a)
56+
b = a.reverse()
57+
58+
assert b is None
59+
assert a[0] == 3
60+
assert a[1] == 2
61+
assert a[2] == 1
62+
63+
64+

graalpython/com.oracle.graal.python.test/src/tests/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ def storage_to_native(s):
4444
if sys.implementation.name == 'graalpy':
4545
assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins"
4646
__graalpython__.storage_to_native(s)
47+
48+
49+
def storage_to_arrow(s):
50+
if sys.implementation.name == 'graalpy':
51+
assert hasattr(__graalpython__, 'storage_to_arrow')
52+
__graalpython__.storage_to_arrow(s)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
import java.util.List;
7979
import java.util.logging.Level;
8080

81+
import com.oracle.graal.python.runtime.sequence.storage.native2.ArrowSequenceStorage;
82+
import com.oracle.graal.python.runtime.sequence.storage.native2.ToArrowStorageNode;
8183
import org.graalvm.home.Version;
8284
import org.graalvm.nativeimage.ImageInfo;
8385

@@ -163,6 +165,7 @@
163165
import com.oracle.truffle.api.TruffleLogger;
164166
import com.oracle.truffle.api.dsl.Bind;
165167
import com.oracle.truffle.api.dsl.Cached;
168+
import com.oracle.truffle.api.dsl.Cached.Shared;
166169
import com.oracle.truffle.api.dsl.Fallback;
167170
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
168171
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -845,6 +848,29 @@ Object toNative(PSequence sequence) {
845848
}
846849
}
847850

851+
@Builtin(name = "storage_to_arrow", minNumOfPositionalArgs = 1)
852+
@GenerateNodeFactory
853+
abstract static class StorageToArrow extends PythonUnaryBuiltinNode {
854+
855+
@Specialization
856+
static Object doArray(PArray array,
857+
@Shared @Cached ToArrowStorageNode toArrowStorageNode,
858+
@Bind("this") Node inliningTarget) {
859+
ArrowSequenceStorage newStorage = toArrowStorageNode.execute(inliningTarget, array.getSequenceStorage());
860+
array.setSequenceStorage(newStorage);
861+
return array;
862+
}
863+
864+
@Specialization
865+
Object doSequence(PSequence sequence,
866+
@Shared @Cached ToArrowStorageNode toArrowStorageNode,
867+
@Bind("this") Node inliningTarget) {
868+
ArrowSequenceStorage newStorage = toArrowStorageNode.execute(inliningTarget, sequence.getSequenceStorage());
869+
sequence.setSequenceStorage(newStorage);
870+
return sequence;
871+
}
872+
}
873+
848874
@Builtin(name = J_EXTEND, minNumOfPositionalArgs = 1, doc = "Extends Java class and return HostAdapterCLass")
849875
@GenerateNodeFactory
850876
public abstract static class JavaExtendNode extends PythonUnaryBuiltinNode {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ abstract static class PrefixSuffixBaseNode extends PythonQuaternaryClinicBuiltin
446446
// common and specialized cases --------------------
447447

448448
@Specialization
449+
@SuppressWarnings("truffle-static-method")
449450
boolean doIt(VirtualFrame frame, Object self, Object substrs, int start, int end,
450451
@Bind("this") Node inliningTarget,
451452
@Cached GetBytesStorage getBytesStorage,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PySequenceArrayWrapper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
5555
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
5656
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
57+
import com.oracle.graal.python.runtime.sequence.storage.native2.ArrowSequenceStorage;
5758
import com.oracle.graal.python.util.PythonUtils;
5859
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5960
import com.oracle.truffle.api.TruffleLogger;
@@ -83,7 +84,9 @@ public static NativeSequenceStorage executeUncached(SequenceStorage object, bool
8384
return ToNativeStorageNodeGen.getUncached().execute(null, object, isBytesLike);
8485
}
8586

87+
// TODO Ivo REMOVE warning
8688
@Specialization(guards = "!isMroSequenceStorage(s)")
89+
@SuppressWarnings("truffle-sharing")
8790
static NativeSequenceStorage doManaged(Node inliningTarget, ArrayBasedSequenceStorage s, boolean isBytesLike,
8891
@Exclusive @Cached SequenceStorageNodes.StorageToNativeNode storageToNativeNode,
8992
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getInternalArrayNode) {
@@ -97,6 +100,16 @@ static NativeSequenceStorage doManaged(Node inliningTarget, ArrayBasedSequenceSt
97100
return storageToNativeNode.execute(inliningTarget, array, s.length());
98101
}
99102

103+
// TODO Ivo TEMPORAL
104+
@Specialization
105+
@SuppressWarnings("truffle-sharing")
106+
static NativeSequenceStorage doArrow(Node inliningTarget, ArrowSequenceStorage s, boolean isBytesLike,
107+
@Exclusive @Cached SequenceStorageNodes.StorageToNativeNode storageToNativeNode,
108+
@Cached SequenceStorageNodes.GetInternalObjectArrayNode getInternalArrayNode) {
109+
Object array = getInternalArrayNode.execute(inliningTarget, s);
110+
return storageToNativeNode.execute(inliningTarget, array, s.length());
111+
}
112+
100113
/*
101114
* This specialization uses a TruffleBoundary because we assume that there is a fixed number
102115
* of types (and therefore MroSequenceStorages). If types are created on a fast path, this

0 commit comments

Comments
 (0)