Skip to content

Commit c75cfad

Browse files
committed
[GR-10710] Configure more DSL limits.
PullRequest: fastr/1712
2 parents e554905 + e3c5a40 commit c75cfad

File tree

28 files changed

+1797
-42
lines changed

28 files changed

+1797
-42
lines changed

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/PPSum.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
package com.oracle.truffle.r.library.stats;
2424

2525
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.ImportStatic;
2627
import com.oracle.truffle.api.dsl.Specialization;
2728
import com.oracle.truffle.api.profiles.ValueProfile;
2829
import com.oracle.truffle.r.library.stats.PPSumFactory.IntgrtVecNodeGen;
2930
import com.oracle.truffle.r.library.stats.PPSumFactory.PPSumExternalNodeGen;
3031
import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
32+
import com.oracle.truffle.r.runtime.DSLConfig;
3133
import com.oracle.truffle.r.runtime.data.RDataFactory.VectorFactory;
3234
import com.oracle.truffle.r.runtime.data.RDoubleVector;
3335
import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector;
@@ -36,14 +38,15 @@
3638

3739
public abstract class PPSum {
3840

41+
@ImportStatic(DSLConfig.class)
3942
public abstract static class PPSumExternal extends RExternalBuiltinNode.Arg2 {
4043
static {
4144
Casts casts = new Casts(PPSumExternal.class);
4245
casts.arg(0).asDoubleVector();
4346
casts.arg(1).asIntegerVector().findFirst();
4447
}
4548

46-
@Specialization(guards = "uAccess.supports(u)")
49+
@Specialization(guards = "uAccess.supports(u)", limit = "getVectorAccessCacheSize()")
4750
protected RDoubleVector doPPSum(RAbstractDoubleVector u, int sl,
4851
@Cached("create()") VectorFactory factory,
4952
@Cached("u.access()") VectorAccess uAccess) {

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMultinomNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import static com.oracle.truffle.r.runtime.RError.Message.NO_POSITIVE_PROBABILITIES;
3030

3131
import com.oracle.truffle.api.dsl.Cached;
32+
import com.oracle.truffle.api.dsl.ImportStatic;
3233
import com.oracle.truffle.api.dsl.Specialization;
3334
import com.oracle.truffle.api.profiles.ConditionProfile;
3435
import com.oracle.truffle.api.profiles.ValueProfile;
3536
import com.oracle.truffle.r.nodes.attributes.GetFixedAttributeNode;
3637
import com.oracle.truffle.r.nodes.attributes.SetFixedAttributeNode;
3738
import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
3839
import com.oracle.truffle.r.nodes.function.opt.UpdateShareableChildValueNode;
40+
import com.oracle.truffle.r.runtime.DSLConfig;
3941
import com.oracle.truffle.r.runtime.RError;
4042
import com.oracle.truffle.r.runtime.RError.Message;
4143
import com.oracle.truffle.r.runtime.data.RDataFactory;
@@ -52,6 +54,7 @@
5254
/**
5355
* Implements the vectorization of {@link RMultinomNode}.
5456
*/
57+
@ImportStatic(DSLConfig.class)
5558
public abstract class RMultinomNode extends RExternalBuiltinNode.Arg3 {
5659

5760
private final Rbinom rbinom = new Rbinom();
@@ -78,7 +81,7 @@ public RBaseNode getErrorContext() {
7881
return RError.SHOW_CALLER;
7982
}
8083

81-
@Specialization(guards = "probsAccess.supports(probs)")
84+
@Specialization(guards = "probsAccess.supports(probs)", limit = "getVectorAccessCacheSize()")
8285
protected RIntVector doMultinom(int n, int size, RAbstractDoubleVector probs,
8386
@Cached("probs.access()") VectorAccess probsAccess) {
8487
try (SequentialIterator probsIter = probsAccess.access(probs)) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929

3030
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3131
import com.oracle.truffle.api.dsl.Cached;
32+
import com.oracle.truffle.api.dsl.ImportStatic;
3233
import com.oracle.truffle.api.dsl.Specialization;
3334
import com.oracle.truffle.api.profiles.ValueProfile;
3435
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
3536
import com.oracle.truffle.r.nodes.control.RLengthNode;
37+
import com.oracle.truffle.r.runtime.DSLConfig;
3638
import com.oracle.truffle.r.runtime.RRuntime;
3739
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
3840
import com.oracle.truffle.r.runtime.data.RComplex;
@@ -44,6 +46,7 @@
4446
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
4547
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess.SequentialIterator;
4648

49+
@ImportStatic(DSLConfig.class)
4750
@RBuiltin(name = "anyNA", kind = PRIMITIVE, parameterNames = {"x", "recursive"}, dispatch = INTERNAL_GENERIC, behavior = PURE_SUMMARY)
4851
public abstract class AnyNA extends RBuiltinNode.Arg2 {
4952

@@ -106,7 +109,7 @@ protected byte isNA(@SuppressWarnings("unused") RNull value, @SuppressWarnings("
106109
return RRuntime.LOGICAL_FALSE;
107110
}
108111

109-
@Specialization(guards = "xAccess.supports(x)")
112+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
110113
protected byte anyNACached(RAbstractAtomicVector x, @SuppressWarnings("unused") boolean recursive,
111114
@Cached("x.access()") VectorAccess xAccess) {
112115
switch (xAccess.getType()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static CharTr create() {
5454
return CharTrNodeGen.create();
5555
}
5656

57-
@Specialization(guards = "vectorReuse.supports(values)")
57+
@Specialization(guards = "vectorReuse.supports(values)", limit = "getVectorAccessCacheSize()")
5858
RAbstractStringVector doIt(String oldStr, String newStr, RAbstractStringVector values,
5959
@Cached("createTemporary(values)") VectorReuse vectorReuse,
6060
@Cached("create()") RemoveRegAttributesNode removeRegAttributesNode) {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public static RNode special(ArgumentsSignature signature, RNode[] arguments, boo
8585
@Child private ColonCastNode rightCast = ColonCastNodeGen.create();
8686
@Child private ColonInternal internal = ColonInternalNodeGen.create();
8787

88+
private static final double FLT_EPSILON = 1.19209290e-7;
89+
8890
static {
8991
Casts.noCasts(Colon.class);
9092
}
@@ -161,7 +163,7 @@ protected RSequence colonAscending(int left, double right,
161163
if (isDouble.profile(right > Integer.MAX_VALUE)) {
162164
return RDataFactory.createAscendingRange(left, right);
163165
} else {
164-
return RDataFactory.createAscendingRange(left, (int) right);
166+
return RDataFactory.createIntSequence(left, 1, effectiveLength(left, right));
165167
}
166168
}
167169

@@ -174,7 +176,7 @@ protected RSequence colonDescending(int left, double right,
174176
if (isDouble.profile(right <= Integer.MIN_VALUE)) {
175177
return RDataFactory.createDescendingRange(left, right);
176178
} else {
177-
return RDataFactory.createDescendingRange(left, (int) right);
179+
return RDataFactory.createIntSequence(left, -1, effectiveLength(left, right));
178180
}
179181
}
180182

@@ -214,6 +216,11 @@ private void checkVecLength(double from, double to) {
214216
throw error(RError.Message.TOO_LONG_VECTOR);
215217
}
216218
}
219+
220+
private static int effectiveLength(double start, double end) {
221+
double r = Math.abs(end - start);
222+
return (int) (r + 1 + FLT_EPSILON);
223+
}
217224
}
218225

219226
@NodeInfo(cost = NodeCost.NONE)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@
6565
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6666
import com.oracle.truffle.api.TruffleLanguage;
6767
import com.oracle.truffle.api.dsl.Cached;
68+
import com.oracle.truffle.api.dsl.ImportStatic;
6869
import com.oracle.truffle.api.dsl.Specialization;
6970
import com.oracle.truffle.api.dsl.TypeSystemReference;
7071
import com.oracle.truffle.api.interop.TruffleObject;
7172
import com.oracle.truffle.r.nodes.builtin.NodeWithArgumentCasts.Casts;
7273
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
7374
import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.WriteDataNodeGen;
7475
import com.oracle.truffle.r.nodes.builtin.casts.fluent.HeadPhaseBuilder;
76+
import com.oracle.truffle.r.runtime.DSLConfig;
7577
import com.oracle.truffle.r.runtime.RCompression;
7678
import com.oracle.truffle.r.runtime.RError;
7779
import com.oracle.truffle.r.runtime.RError.Message;
@@ -1048,6 +1050,7 @@ private static RLogicalVector readLogical(RConnection con, int n, boolean swap)
10481050
}
10491051
}
10501052

1053+
@ImportStatic(DSLConfig.class)
10511054
@TypeSystemReference(RTypes.class)
10521055
public abstract static class WriteDataNode extends RBaseNode {
10531056

@@ -1069,7 +1072,7 @@ private static byte[] encodeString(String s) {
10691072
return s.getBytes(StandardCharsets.UTF_8);
10701073
}
10711074

1072-
@Specialization(guards = "objectAccess.supports(object)")
1075+
@Specialization(guards = "objectAccess.supports(object)", limit = "getVectorAccessCacheSize()")
10731076
protected ByteBuffer write(RAbstractVector object, @SuppressWarnings("unused") int size, boolean swap, @SuppressWarnings("unused") boolean useBytes,
10741077
@Cached("object.access()") VectorAccess objectAccess) {
10751078
try (SequentialIterator iter = objectAccess.access(object)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected RDoubleVector cumNull(@SuppressWarnings("unused") RNull x) {
6868
return RDataFactory.createEmptyDoubleVector();
6969
}
7070

71-
@Specialization(guards = "xAccess.supports(x)")
71+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
7272
protected RDoubleVector cumprodDouble(RAbstractDoubleVector x,
7373
@Cached("x.access()") VectorAccess xAccess) {
7474
try (SequentialIterator iter = xAccess.access(x)) {
@@ -97,7 +97,7 @@ protected RDoubleVector cumprodDoubleGeneric(RAbstractDoubleVector x) {
9797
return cumprodDouble(x, x.slowPathAccess());
9898
}
9999

100-
@Specialization(guards = "xAccess.supports(x)")
100+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
101101
protected RComplexVector cumprodComplex(RAbstractComplexVector x,
102102
@Cached("x.access()") VectorAccess xAccess) {
103103
try (SequentialIterator iter = xAccess.access(x)) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected RAbstractVector cumEmpty(RAbstractIntVector x) {
9999
return RDataFactory.createIntVector(new int[0], true, extractNamesNode.execute(x));
100100
}
101101

102-
@Specialization(guards = "xAccess.supports(x)")
102+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
103103
protected RIntVector cumsumInt(RAbstractIntVector x,
104104
@Cached("x.access()") VectorAccess xAccess) {
105105
try (SequentialIterator iter = xAccess.access(x)) {
@@ -128,7 +128,7 @@ protected RIntVector cumsumIntGeneric(RAbstractIntVector x) {
128128
return cumsumInt(x, x.slowPathAccess());
129129
}
130130

131-
@Specialization(guards = "xAccess.supports(x)")
131+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
132132
protected RDoubleVector cumsumDouble(RAbstractDoubleVector x,
133133
@Cached("x.access()") VectorAccess xAccess) {
134134
try (SequentialIterator iter = xAccess.access(x)) {
@@ -157,7 +157,7 @@ protected RDoubleVector cumsumDoubleGeneric(RAbstractDoubleVector x) {
157157
return cumsumDouble(x, x.slowPathAccess());
158158
}
159159

160-
@Specialization(guards = "xAccess.supports(x)")
160+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
161161
protected RComplexVector cumsumComplex(RAbstractComplexVector x,
162162
@Cached("x.access()") VectorAccess xAccess) {
163163
try (SequentialIterator iter = xAccess.access(x)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected Object diag(double x, int nrow, int ncol) {
8181
return RDataFactory.createDoubleVector(data, !RRuntime.isNA(x), new int[]{nrow, ncol});
8282
}
8383

84-
@Specialization(guards = "xAccess.supports(x)")
84+
@Specialization(guards = "xAccess.supports(x)", limit = "getVectorAccessCacheSize()")
8585
protected RAbstractVector diagCached(RAbstractVector x, int nrow, int ncol,
8686
@Cached("x.access()") VectorAccess xAccess,
8787
@Cached("createNew(xAccess.getType())") VectorAccess resultAccess,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected int doString(String s, @SuppressWarnings("unused") int digits, @Suppre
7070
return s.length();
7171
}
7272

73-
@Specialization(guards = "vAccess.supports(v)")
73+
@Specialization(guards = "vAccess.supports(v)", limit = "getVectorAccessCacheSize()")
7474
protected Object doVector(RAbstractVector v, int digits, int nsmall,
7575
@Cached("v.access()") VectorAccess vAccess,
7676
@Cached("create()") VectorFactory factory) {

0 commit comments

Comments
 (0)