Skip to content

Commit 50c28ac

Browse files
committed
[GR-20016] RRawVector - R vectors should use "storage strategy" pattern.
PullRequest: fastr/2412
2 parents 9816408 + 18c09d7 commit 50c28ac

File tree

42 files changed

+133
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+133
-186
lines changed

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,6 @@
4242
import com.oracle.truffle.r.runtime.data.RDataFactory;
4343
import com.oracle.truffle.r.runtime.data.RNull;
4444
import com.oracle.truffle.r.runtime.data.RRawVector;
45-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
4645
import com.oracle.truffle.r.runtime.data.nodes.VectorReuse;
4746
import com.oracle.truffle.r.runtime.interop.ConvertForeignObjectNode;
4847

@@ -57,38 +56,38 @@ public abstract class AsRaw extends RBuiltinNode.Arg1 {
5756
}
5857

5958
@Specialization
60-
protected RAbstractRawVector asRaw(@SuppressWarnings("unused") RNull n) {
59+
protected RRawVector asRaw(@SuppressWarnings("unused") RNull n) {
6160
return RDataFactory.createEmptyRawVector();
6261
}
6362

6463
@Specialization(guards = "reuseTemporaryNode.supports(v)", limit = "getVectorAccessCacheSize()")
65-
protected RAbstractRawVector asRawVec(RAbstractRawVector v,
64+
protected RRawVector asRawVec(RRawVector v,
6665
@Cached("createTemporary(v)") VectorReuse reuseTemporaryNode,
6766
@Cached("createBinaryProfile()") ConditionProfile noAttributes) {
6867
if (noAttributes.profile(v.getAttributes() == null)) {
6968
return v;
7069
} else {
71-
RRawVector res = (RRawVector) reuseTemporaryNode.getMaterializedResult(v);
70+
RRawVector res = reuseTemporaryNode.getMaterializedResult(v);
7271
res.resetAllAttributes(true);
7372
return res;
7473
}
7574
}
7675

7776
@Specialization(replaces = "asRawVec")
78-
protected RAbstractRawVector asRawVecGeneric(RAbstractRawVector v,
77+
protected RRawVector asRawVecGeneric(RRawVector v,
7978
@Cached("createTemporaryGeneric()") VectorReuse reuseTemporaryNode,
8079
@Cached("createBinaryProfile()") ConditionProfile noAttributes) {
8180
return asRawVec(v, reuseTemporaryNode, noAttributes);
8281
}
8382

8483
@Specialization(guards = "isForeignObject(obj)")
85-
protected RAbstractRawVector asRawForeign(VirtualFrame frame, TruffleObject obj,
84+
protected RRawVector asRawForeign(VirtualFrame frame, TruffleObject obj,
8685
@Cached("create()") ConvertForeignObjectNode convertForeign,
8786
@Cached("createNonPreserving()") CastRawNode castRaw,
8887
@Cached("create()") AsRaw asRaw) {
8988
Object o = convertForeign.convert(obj, true, false, true);
9089
if (!RRuntime.isForeignObject(o)) {
91-
return (RAbstractRawVector) asRaw.execute(frame, castRaw.executeRaw(o));
90+
return (RRawVector) asRaw.execute(frame, castRaw.executeRaw(o));
9291
}
9392
throw error(RError.Message.CANNOT_COERCE, "polyglot.value", "raw");
9493
}

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@
112112
import com.oracle.truffle.r.runtime.data.RLogicalVector;
113113
import com.oracle.truffle.r.runtime.data.RMissing;
114114
import com.oracle.truffle.r.runtime.data.RNull;
115-
import com.oracle.truffle.r.runtime.data.RRawVector;
116115
import com.oracle.truffle.r.runtime.data.RStringVector;
117116
import com.oracle.truffle.r.runtime.data.RTypes;
118117
import com.oracle.truffle.r.runtime.data.model.RAbstractAtomicVector;
119118
import com.oracle.truffle.r.runtime.data.RIntVector;
120-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
119+
import com.oracle.truffle.r.runtime.data.RRawVector;
121120
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
122121
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
123122
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
@@ -885,7 +884,7 @@ public abstract static class ReadBin extends RBuiltinNode.Arg6 {
885884
@SuppressWarnings("unused")
886885
@Specialization
887886
@TruffleBoundary
888-
protected Object readBin(RAbstractRawVector vec, String what, int n, int sizeInput, boolean signed, boolean swap) {
887+
protected Object readBin(RRawVector vec, String what, int n, int sizeInput, boolean signed, boolean swap) {
889888
Object result;
890889
switch (what) {
891890
case "character":
@@ -1060,10 +1059,10 @@ private static RStringVector readString(RConnection con, int n) throws IOExcepti
10601059
return RDataFactory.createStringVector(stringData, RDataFactory.COMPLETE_VECTOR);
10611060
}
10621061

1063-
private static RStringVector readString(RAbstractRawVector vec, int n) {
1062+
private static RStringVector readString(RRawVector vec, int n) {
10641063
String[] stringData = new String[n];
10651064
byte[] chars;
1066-
chars = ((RRawVector) vec).getReadonlyData();
1065+
chars = vec.getReadonlyData();
10671066
stringData[0] = new String(chars, 0, vec.getLength());
10681067
for (int i = 1; i < stringData.length; i++) {
10691068
stringData[i] = "";
@@ -1072,11 +1071,11 @@ private static RStringVector readString(RAbstractRawVector vec, int n) {
10721071
return RDataFactory.createStringVector(stringData, RDataFactory.COMPLETE_VECTOR);
10731072
}
10741073

1075-
private static RAbstractRawVector readRaw(RAbstractRawVector vec, int n) {
1074+
private static RRawVector readRaw(RRawVector vec, int n) {
10761075
byte[] b;
10771076
int length = Math.min(vec.getLength(), n);
10781077
b = new byte[length];
1079-
System.arraycopy(((RRawVector) vec).getReadonlyData(), 0, b, 0, length);
1078+
System.arraycopy(vec.getReadonlyData(), 0, b, 0, length);
10801079
return RDataFactory.createRawVector(b);
10811080
}
10821081

@@ -1088,7 +1087,7 @@ private static RRawVector readRaw(RConnection con, int n) throws IOException {
10881087
}
10891088

10901089
/*
1091-
* private static RRawVector readRaw(RAbstractRawVector raw, int n) { ByteBuffer buffer =
1090+
* private static RRawVector readRaw(RRawVector raw, int n) { ByteBuffer buffer =
10921091
* ByteBuffer.allocate(n); int bytesRead = con.readBin(buffer); if (bytesRead == 0) { return
10931092
* RDataFactory.createEmptyRawVector(); } buffer.flip(); byte[] data = new byte[bytesRead];
10941093
* buffer.get(data); return RDataFactory.createRawVector(data); }
@@ -1235,7 +1234,7 @@ protected Object writeBin(RAbstractVector object, int con, int size, boolean swa
12351234
}
12361235

12371236
@Specialization
1238-
protected RRawVector writeBin(RAbstractVector object, @SuppressWarnings("unused") RAbstractRawVector con, int size, boolean swap, boolean useBytes,
1237+
protected RRawVector writeBin(RAbstractVector object, @SuppressWarnings("unused") RRawVector con, int size, boolean swap, boolean useBytes,
12391238
@Cached("create()") WriteDataNode writeData) {
12401239
ByteBuffer buffer = writeData.execute(object, size, swap, useBytes);
12411240
buffer.flip();

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IntToBits.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@
3131
import com.oracle.truffle.r.runtime.data.RDataFactory;
3232
import com.oracle.truffle.r.runtime.data.RNull;
3333
import com.oracle.truffle.r.runtime.data.RIntVector;
34-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
34+
import com.oracle.truffle.r.runtime.data.RRawVector;
3535

3636
@RBuiltin(name = "intToBits", kind = INTERNAL, parameterNames = {"x"}, behavior = PURE)
3737
public abstract class IntToBits extends RBuiltinNode.Arg1 {
@@ -42,12 +42,12 @@ public abstract class IntToBits extends RBuiltinNode.Arg1 {
4242
}
4343

4444
@Specialization
45-
protected RAbstractRawVector intToBits(@SuppressWarnings("unused") RNull x) {
45+
protected RRawVector intToBits(@SuppressWarnings("unused") RNull x) {
4646
return RDataFactory.createEmptyRawVector();
4747
}
4848

4949
@Specialization
50-
protected RAbstractRawVector intToBits(RIntVector x) {
50+
protected RRawVector intToBits(RIntVector x) {
5151
byte[] result = new byte[32 * x.getLength()];
5252
int pos = 0;
5353
for (int j = 0; j < x.getLength(); j++) {

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsFiniteFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector;
5050
import com.oracle.truffle.r.runtime.data.RIntVector;
5151
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
52-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
52+
import com.oracle.truffle.r.runtime.data.RRawVector;
5353
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
5454
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
5555

@@ -81,7 +81,7 @@ public RLogicalVector doString(RAbstractStringVector x) {
8181
}
8282

8383
@Specialization
84-
public RLogicalVector doRaw(RAbstractRawVector x) {
84+
public RLogicalVector doRaw(RRawVector x) {
8585
return doFunConstant(x, RRuntime.LOGICAL_FALSE);
8686
}
8787

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsTypeFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
import com.oracle.truffle.r.runtime.data.RIntVector;
6666
import com.oracle.truffle.r.runtime.data.model.RAbstractListBaseVector;
6767
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
68-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
68+
import com.oracle.truffle.r.runtime.data.RRawVector;
6969
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
7070
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
7171

@@ -549,7 +549,7 @@ public abstract static class IsRaw extends RBuiltinNode.Arg1 {
549549
}
550550

551551
@Specialization
552-
protected byte isType(@SuppressWarnings("unused") RAbstractRawVector value) {
552+
protected byte isType(@SuppressWarnings("unused") RRawVector value) {
553553
return RRuntime.LOGICAL_TRUE;
554554
}
555555

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsUnsorted.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import com.oracle.truffle.r.runtime.data.RDoubleVector;
4040
import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector;
4141
import com.oracle.truffle.r.runtime.data.RIntVector;
42-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
42+
import com.oracle.truffle.r.runtime.data.RRawVector;
4343
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
4444
import com.oracle.truffle.r.runtime.ops.BinaryCompare;
4545

@@ -120,7 +120,7 @@ protected CmpNode createCmpNode() {
120120
}
121121

122122
@Specialization
123-
protected byte isUnsorted(RAbstractRawVector x, boolean strictly) {
123+
protected byte isUnsorted(RRawVector x, boolean strictly) {
124124
byte last = x.getRawDataAt(0);
125125
for (int k = 1; k < x.getLength(); k++) {
126126
byte current = x.getRawDataAt(k);

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PackBits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
4040
import com.oracle.truffle.r.runtime.data.RDataFactory;
4141
import com.oracle.truffle.r.runtime.data.RIntVector;
4242
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
43-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
43+
import com.oracle.truffle.r.runtime.data.RRawVector;
4444
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
4545

4646
@RBuiltin(name = "packBits", kind = INTERNAL, parameterNames = {"x", "type"}, behavior = PURE)
@@ -143,7 +143,7 @@ protected RAbstractVector packBits(RAbstractLogicalVector x, String type) {
143143

144144
@Specialization
145145
@TruffleBoundary
146-
protected RAbstractVector packBits(RAbstractRawVector x, String type) {
146+
protected RAbstractVector packBits(RRawVector x, String type) {
147147
checkLength(x.getLength(), type);
148148

149149
BitSet bitSet = new BitSet();

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RawFunctions.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
4141
import com.oracle.truffle.r.runtime.data.RDataFactory;
4242
import com.oracle.truffle.r.runtime.data.RRawVector;
43-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
4443
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
4544
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
4645
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess.RandomIterator;
@@ -83,7 +82,7 @@ public abstract static class RawToChar extends RBuiltinNode.Arg2 {
8382

8483
static {
8584
Casts casts = new Casts(RawToChar.class);
86-
casts.arg("x").boxPrimitive().mustBe(instanceOf(RAbstractRawVector.class), RError.Message.ARGUMENT_MUST_BE_RAW_VECTOR, "x");
85+
casts.arg("x").boxPrimitive().mustBe(instanceOf(RRawVector.class), RError.Message.ARGUMENT_MUST_BE_RAW_VECTOR, "x");
8786
casts.arg("multiple").defaultError(RError.Message.INVALID_LOGICAL).asLogicalVector().findFirst().mustNotBeNA().map(toBoolean());
8887
}
8988

@@ -98,7 +97,7 @@ private static String createString(byte value) {
9897
}
9998

10099
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
101-
protected Object rawToChar(RAbstractRawVector x, boolean multiple,
100+
protected Object rawToChar(RRawVector x, boolean multiple,
102101
@Cached("x.access()") VectorAccess xAccess) {
103102
try (SequentialIterator iter = xAccess.access(x)) {
104103
if (multiple) {
@@ -124,7 +123,7 @@ protected Object rawToChar(RAbstractRawVector x, boolean multiple,
124123

125124
@Specialization(replaces = "rawToChar")
126125
@TruffleBoundary
127-
protected Object rawToCharGeneric(RAbstractRawVector x, boolean multiple) {
126+
protected Object rawToCharGeneric(RRawVector x, boolean multiple) {
128127
return rawToChar(x, multiple, x.slowPathAccess());
129128
}
130129
}
@@ -134,12 +133,12 @@ public abstract static class RawShift extends RBuiltinNode.Arg2 {
134133

135134
static {
136135
Casts casts = new Casts(RawShift.class);
137-
casts.arg("x").boxPrimitive().mustBe(instanceOf(RAbstractRawVector.class), RError.Message.ARGUMENT_MUST_BE_RAW_VECTOR, "x");
136+
casts.arg("x").boxPrimitive().mustBe(instanceOf(RRawVector.class), RError.Message.ARGUMENT_MUST_BE_RAW_VECTOR, "x");
138137
casts.arg("n").defaultError(RError.Message.MUST_BE_SMALL_INT, "shift").asIntegerVector().findFirst().mustNotBeNA().mustBe(gte(-8).and(lte(8)));
139138
}
140139

141140
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
142-
protected RRawVector rawShift(RAbstractRawVector x, int n,
141+
protected RRawVector rawShift(RRawVector x, int n,
143142
@Cached("createBinaryProfile()") ConditionProfile negativeShiftProfile,
144143
@Cached("x.access()") VectorAccess xAccess) {
145144
try (SequentialIterator iter = xAccess.access(x)) {
@@ -159,7 +158,7 @@ protected RRawVector rawShift(RAbstractRawVector x, int n,
159158

160159
@Specialization(replaces = "rawShift")
161160
@TruffleBoundary
162-
protected RRawVector rawShiftGeneric(RAbstractRawVector x, int n,
161+
protected RRawVector rawShiftGeneric(RRawVector x, int n,
163162
@Cached("createBinaryProfile()") ConditionProfile negativeShiftProfile) {
164163
return rawShift(x, n, negativeShiftProfile, x.slowPathAccess());
165164
}

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RawToBits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.oracle.truffle.r.runtime.RError;
3434
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
3535
import com.oracle.truffle.r.runtime.data.RDataFactory;
36-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
36+
import com.oracle.truffle.r.runtime.data.RRawVector;
3737
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
3838
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess.SequentialIterator;
3939

@@ -46,7 +46,7 @@ public abstract class RawToBits extends RBuiltinNode.Arg1 {
4646
}
4747

4848
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
49-
protected RAbstractRawVector rawToBits(RAbstractRawVector x,
49+
protected RRawVector rawToBits(RRawVector x,
5050
@Cached("x.access()") VectorAccess xAccess) {
5151
try (SequentialIterator iter = xAccess.access(x)) {
5252
byte[] result = new byte[8 * x.getLength()];
@@ -64,7 +64,7 @@ protected RAbstractRawVector rawToBits(RAbstractRawVector x,
6464

6565
@Specialization(replaces = "rawToBits")
6666
@TruffleBoundary
67-
protected RAbstractRawVector rawToBitsGeneric(RAbstractRawVector x) {
67+
protected RRawVector rawToBitsGeneric(RRawVector x) {
6868
return rawToBits(x, x.slowPathAccess());
6969
}
7070
}

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unique.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@
5151
import com.oracle.truffle.r.runtime.data.RList;
5252
import com.oracle.truffle.r.runtime.data.RLogicalVector;
5353
import com.oracle.truffle.r.runtime.data.RNull;
54-
import com.oracle.truffle.r.runtime.data.RRawVector;
5554
import com.oracle.truffle.r.runtime.data.RStringVector;
5655
import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector;
5756
import com.oracle.truffle.r.runtime.data.RIntVector;
5857
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
59-
import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector;
58+
import com.oracle.truffle.r.runtime.data.RRawVector;
6059
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
6160

6261
@RBuiltin(name = "unique", kind = INTERNAL, parameterNames = {"x", "incomparables", "fromLast", "nmax"}, behavior = PURE)
@@ -461,7 +460,7 @@ protected RComplexVector doUnique(RAbstractComplexVector vec, byte incomparables
461460

462461
@SuppressWarnings("unused")
463462
@Specialization
464-
protected RRawVector doUnique(RAbstractRawVector vec, byte incomparables, byte fromLast, int nmax,
463+
protected RRawVector doUnique(RRawVector vec, byte incomparables, byte fromLast, int nmax,
465464
@Cached("createBinaryProfile()") ConditionProfile needsCopyProfile) {
466465
reportWork(vec.getLength());
467466
BitSet bitset = new BitSet(256);

0 commit comments

Comments
 (0)