diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java index 976df1b8bdfcc31b5c44f41c1c6c90e1ebc398e7..272c1ea4e83234bd361da44fc135b4fff3bb44de 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java @@ -70,7 +70,6 @@ import com.oracle.truffle.r.nodes.builtin.NodeWithArgumentCasts.Casts; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.WriteDataNodeGen; import com.oracle.truffle.r.nodes.builtin.casts.fluent.HeadPhaseBuilder; -import com.oracle.truffle.r.nodes.builtin.casts.fluent.InitialPhaseBuilder; import com.oracle.truffle.r.runtime.RCompression; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; @@ -153,15 +152,7 @@ public abstract class ConnectionFunctions { public static final class CastsHelper { private static HeadPhaseBuilder<String> description(Casts casts) { - return descriptionInternal(casts.arg("description")); - } - - private static HeadPhaseBuilder<String> descriptionNull(Casts casts) { - return descriptionInternal(casts.arg("description").allowNull()); - } - - private static HeadPhaseBuilder<String> descriptionInternal(InitialPhaseBuilder<Object> casts) { - return casts.mustBe(stringValue()).asStringVector().shouldBe(singleElement(), RError.Message.ARGUMENT_ONLY_FIRST_1, "description").findFirst().mustNotBeNA(); + return casts.arg("description").mustBe(stringValue()).asStringVector().shouldBe(singleElement(), RError.Message.ARGUMENT_ONLY_FIRST_1, "description").findFirst().mustNotBeNA(); } private static HeadPhaseBuilder<String> open(Casts casts) { @@ -351,7 +342,7 @@ public abstract class ConnectionFunctions { static { Casts casts = new Casts(TextConnection.class); - CastsHelper.descriptionNull(casts); + CastsHelper.description(casts); casts.arg("text").allowNull().mustBe(stringValue()); CastsHelper.open(casts).mustBe(equalTo("").or(equalTo("r").or(equalTo("w").or(equalTo("a")))), RError.Message.UNSUPPORTED_MODE); casts.arg("env").mustNotBeNull(RError.Message.USE_NULL_ENV_DEFUNCT).mustBe(instanceOf(REnvironment.class)); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java index 0840afea592db74df19061744e370cac39c22301..d1515e966da7dcce1c09cd5c630367d32a2f5a78 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java @@ -13,11 +13,14 @@ package com.oracle.truffle.r.nodes.builtin.base; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.dimEq; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.dimGt; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.emptyDoubleVector; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.gt; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.matrix; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.missingValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.not; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.notEmpty; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.or; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.squareMatrix; @@ -571,7 +574,8 @@ public class LaFunctions { casts.arg("a").mustBe(numericValue()).asVector().mustBe(matrix(), Message.MUST_BE_NUMERIC_MATRIX, "a").mustBe(not(dimEq(0, 0)), Message.GENERIC, "'a' is 0-diml").mustBe(squareMatrix(), Message.MUST_BE_SQUARE_MATRIX_SPEC, "a", getDimVal(0), getDimVal(1)); - casts.arg("bin").asDoubleVector(false, true, false).mustBe(or(not(matrix()), not(dimEq(1, 0))), Message.GENERIC, "no right-hand side in 'b'"); + casts.arg("bin").returnIf(missingValue().or(nullValue()), emptyDoubleVector()).asDoubleVector(false, true, false).mustBe(or(not(matrix()), not(dimEq(1, 0))), Message.GENERIC, + "no right-hand side in 'b'"); casts.arg("tolin").asDoubleVector().findFirst(RRuntime.DOUBLE_NA); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java index 80c1bfd838c372c48d4a538664f8dc94754f0224..bc951e221bd5010a19ddf800a1ce22ed3663291c 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java @@ -197,9 +197,9 @@ public final class SeqFunctions { @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck) { if (isNumericProfile.profile(fromCheck.execute(args.getArgument(0)))) { if (args.getLength() == 1) { - return seqInt.execute(frame, RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance); + return seqInt.execute(frame, RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance, RMissing.instance); } else { - return seqInt.execute(frame, args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance); + return seqInt.execute(frame, args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance, RMissing.instance); } } else { return null; @@ -217,7 +217,7 @@ public final class SeqFunctions { @Cached("createIsMissingOrNumericNode()") @SuppressWarnings("unused") IsMissingOrNumericNode byCheck) { Object[] rargs = reorderedArguments(args, seqIntFunction); if (isNumericProfile.profile(fromCheck.execute(rargs[0]) && toCheck.execute(rargs[1]) && toCheck.execute(rargs[2]))) { - return seqInt.execute(frame, rargs[0], rargs[1], rargs[2], rargs[3], rargs[4]); + return seqInt.execute(frame, rargs[0], rargs[1], rargs[2], rargs[3], rargs[4], RMissing.instance); } else { return null; } @@ -309,7 +309,7 @@ public final class SeqFunctions { @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck, @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode toCheck, @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode byCheck) { - return seqInt.execute(frame, fromObj, toObj, byObj, lengthOut, alongWith); + return seqInt.execute(frame, fromObj, toObj, byObj, lengthOut, alongWith, RMissing.instance); } /** @@ -407,7 +407,7 @@ public final class SeqFunctions { @ImportStatic({AsRealNodeGen.class, SeqFunctions.class}) @com.oracle.truffle.r.runtime.builtins.RBuiltin(name = "seq.int", kind = PRIMITIVE, parameterNames = {"from", "to", "by", "length.out", "along.with", "..."}, dispatch = INTERNAL_GENERIC, genericName = "seq", behavior = PURE) - public abstract static class SeqInt extends RBuiltinNode.Arg5 { + public abstract static class SeqInt extends RBuiltinNode.Arg6 { private final BranchProfile error = BranchProfile.create(); private final boolean seqFastPath; @@ -426,7 +426,7 @@ public final class SeqFunctions { } @Override - public abstract Object execute(VirtualFrame frame, Object start, Object to, Object by, Object lengthOut, Object alongWith); + public abstract Object execute(VirtualFrame frame, Object start, Object to, Object by, Object lengthOut, Object alongWith, Object dotdotdot); protected SeqInt(boolean seqFastPath) { this.seqFastPath = seqFastPath; @@ -447,7 +447,7 @@ public final class SeqFunctions { // No matching args (special case) @Specialization - protected RIntSequence allMissing(RMissing from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RIntSequence allMissing(RMissing from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { // GNU R allows this and returns 1 return RDataFactory.createIntSequence(1, 1, 1); } @@ -462,7 +462,7 @@ public final class SeqFunctions { * Irrespective of the R type, if the length is zero the result is an empty sequence. */ @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) == 0"}) - protected RIntVector emptySeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RIntVector emptySeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { return RDataFactory.createEmptyIntVector(); } @@ -473,7 +473,7 @@ public final class SeqFunctions { * but the value likely could not be coerced. */ @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) > 1"}) - protected RIntSequence lenSeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RIntSequence lenSeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { return RDataFactory.createIntSequence(1, 1, getLength(frame, from)); } @@ -481,7 +481,7 @@ public final class SeqFunctions { * A length-1 REAL. Return "1:(int) from" where from is positive integral */ @Specialization(guards = {"fromVec.getLength() == 1", "isPositiveIntegralDouble(fromVec.getDataAt(0))"}) - protected RAbstractVector seqFromOneArgIntDouble(RAbstractDoubleVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RAbstractVector seqFromOneArgIntDouble(RAbstractDoubleVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { int len = (int) fromVec.getDataAt(0); return RDataFactory.createIntSequence(1, 1, len); } @@ -491,7 +491,7 @@ public final class SeqFunctions { * {@code seq(0.2)} is NOT the same as {@code seq(0.0)} (according to GNU R) */ @Specialization(guards = "fromVec.getLength() == 1") - protected RAbstractVector seqFromOneArgDouble(RAbstractDoubleVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RAbstractVector seqFromOneArgDouble(RAbstractDoubleVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { double from = validateDoubleParam(fromVec.getDataAt(0), fromVec, "from"); int len = effectiveLength(1, from); return RDataFactory.createIntSequence(1, from > 0 ? 1 : -1, len); @@ -501,7 +501,7 @@ public final class SeqFunctions { * A length-1 INT. Return "1:from" (N.B. from may be negative) */ @Specialization(guards = "fromVec.getLength() == 1") - protected RIntSequence seqFromOneArgInt(RAbstractIntVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RIntSequence seqFromOneArgInt(RAbstractIntVector fromVec, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { int from = validateIntParam(fromVec.getDataAt(0), "from"); int len = from > 0 ? from : 2 - from; return RDataFactory.createIntSequence(1, from > 0 ? 1 : -1, len); @@ -514,19 +514,10 @@ public final class SeqFunctions { * which would be incorrect as the result is different. */ @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) == 1", "!isNumeric(from)"}) - protected RIntSequence seqFromOneArgObj(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith) { + protected RIntSequence seqFromOneArgObj(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { return RDataFactory.createIntSequence(1, 1, 1); } - /** - * Treat {@code lengthOut==NULL} as {@link RMissing}. - */ - @Specialization - protected RAbstractVector seqLengthByMissing(VirtualFrame frame, Object from, Object to, Object by, RNull lengthOut, RMissing alongWith, - @Cached("createSeqInt()") SeqInt seqIntNodeRecursive) { - return (RAbstractVector) seqIntNodeRecursive.execute(frame, from, to, by, RMissing.instance, alongWith); - } - /* * seq(from,to) but either could be missing. "along.with" is missing and "length.out" is * missing (or NULL), and "by" (by) is missing. N.B. we are only interested in the cases @@ -539,6 +530,7 @@ public final class SeqFunctions { @Specialization(guards = "validDoubleParams(fromVec, toVec)") protected RAbstractVector seqLengthByMissingDouble(VirtualFrame frame, RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, + Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { double from = fromVec.getDataAt(0); double to = toVec.getDataAt(0); @@ -547,7 +539,7 @@ public final class SeqFunctions { } @Specialization(guards = "validIntParams(fromVec, toVec)") - protected RAbstractVector seqLengthByMissingInt(VirtualFrame frame, RAbstractIntVector fromVec, RAbstractIntVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, + protected RAbstractVector seqLengthByMissingInt(VirtualFrame frame, RAbstractIntVector fromVec, RAbstractIntVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { int from = fromVec.getDataAt(0); int to = toVec.getDataAt(0); @@ -563,7 +555,7 @@ public final class SeqFunctions { * previous specializations. */ @Specialization(guards = {"!isMissing(toObj)"}) - protected RAbstractVector seqLengthByMissing(VirtualFrame frame, Object fromObj, Object toObj, RMissing by, RMissing lengthOut, RMissing alongWith, + protected RAbstractVector seqLengthByMissing(VirtualFrame frame, Object fromObj, Object toObj, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { @@ -589,7 +581,7 @@ public final class SeqFunctions { */ @Specialization(guards = {"validDoubleParams(fromVec, toVec)", "!isMissing(byObj)"}) - protected Object seqLengthMissing(VirtualFrame frame, RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, Object byObj, RMissing lengthOut, RMissing alongWith, + protected Object seqLengthMissing(VirtualFrame frame, RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealby) { validateLength(frame, byObj, "by"); double by = asRealby.execute(byObj); @@ -598,6 +590,7 @@ public final class SeqFunctions { @Specialization(guards = {"validIntParams(fromVec, toVec)", "validIntParam(byVec)", "byVec.getDataAt(0) != 0"}) protected RAbstractVector seqLengthMissing(VirtualFrame frame, RAbstractIntVector fromVec, RAbstractIntVector toVec, RAbstractIntVector byVec, RMissing lengthOut, RMissing alongWith, + Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { int by = byVec.getDataAt(0); int from = fromVec.getDataAt(0); @@ -626,7 +619,7 @@ public final class SeqFunctions { * See comment in {@link #seqLengthByMissing}. */ @Specialization(guards = {"!isMissing(byObj)"}) - protected Object seqLengthMissing(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, RMissing lengthOut, RMissing alongWith, + protected Object seqLengthMissing(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealby) { @@ -722,7 +715,7 @@ public final class SeqFunctions { */ @Specialization(guards = "!isMissing(lengthOut)") - protected RAbstractVector seqJustLength(VirtualFrame frame, RMissing from, RMissing to, RMissing by, Object lengthOut, RMissing alongWith, + protected RAbstractVector seqJustLength(VirtualFrame frame, RMissing from, RMissing to, RMissing by, Object lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealLen) { int n = checkLength(frame, lengthOut, asRealLen); return n == 0 ? RDataFactory.createEmptyIntVector() : RDataFactory.createIntSequence(1, 1, n); @@ -731,7 +724,7 @@ public final class SeqFunctions { // seq(along,with=) @Specialization(guards = "!isMissing(alongWith)") - protected RAbstractVector seqFromJustAlong(VirtualFrame frame, RMissing from, RMissing to, RMissing by, RMissing lengthOut, Object alongWith) { + protected RAbstractVector seqFromJustAlong(VirtualFrame frame, RMissing from, RMissing to, RMissing by, RMissing lengthOut, Object alongWith, Object dotdotdot) { int len = getLength(frame, alongWith); return len == 0 ? RDataFactory.createEmptyIntVector() : RDataFactory.createIntSequence(1, 1, len); } @@ -805,7 +798,7 @@ public final class SeqFunctions { // common idiom @Specialization(guards = {"fromCheck.execute(fromObj)", "lengthCheck.execute(lengthOut)"}) - protected RAbstractVector seqWithFromLengthIntegralNumeric(VirtualFrame frame, Object fromObj, RMissing toObj, RMissing byObj, Object lengthOut, RMissing alongWith, + protected RAbstractVector seqWithFromLengthIntegralNumeric(VirtualFrame frame, Object fromObj, RMissing toObj, RMissing byObj, Object lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createGetIntegralNumericNode()") GetIntegralNumericNode getIntegralNumericNode, @Cached("createIsIntegralNumericNodeNoLengthCheck()") IsIntegralNumericNode fromCheck, @Cached("createIsIntegralNumericNodeLengthCheck()") IsIntegralNumericNode lengthCheck) { @@ -820,7 +813,7 @@ public final class SeqFunctions { // "by" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(fromObj, toObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, Object toObj, RMissing byObj, Object lengthOut, Object alongWith, + protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, Object toObj, RMissing byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealLen) { @@ -874,7 +867,7 @@ public final class SeqFunctions { // "to" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(fromObj, byObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, RMissing toObj, Object byObj, Object lengthOut, Object alongWith, + protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, RMissing toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealby, @Cached("create()") AsRealNode asRealLen) { @@ -901,7 +894,7 @@ public final class SeqFunctions { // "from" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(toObj, byObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, RMissing fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, + protected RAbstractVector seqWithLength(VirtualFrame frame, RMissing fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealby, @Cached("create()") AsRealNode asRealLen) { @@ -922,7 +915,7 @@ public final class SeqFunctions { } @Fallback - protected RAbstractVector seqFallback(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith) { + protected RAbstractVector seqFallback(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot) { error.enter(); throw error(RError.Message.TOO_MANY_ARGS); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java index e403219f5fd7feb30c88c57bb5e020a8fc7e94b8..e266bceac2765ababb0878140efd737a41bff344 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java @@ -21,7 +21,6 @@ import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; -import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.profiles.BranchProfile; @@ -39,7 +38,6 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RExpression; import com.oracle.truffle.r.runtime.data.RList; -import com.oracle.truffle.r.runtime.data.RMissing; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RPromise; @@ -70,6 +68,7 @@ public abstract class Switch extends RBuiltinNode.Arg2 { Casts casts = new Casts(Switch.class); // first argument must be list or expression or vector of size 1, if it is not String, cast it to integer casts.arg("EXPR").defaultError(RError.Message.EXPR_NOT_LENGTH_ONE). + mustNotBeMissing(RError.Message.EXPR_MISSING). returnIf(atomicIntegerValue().or(instanceOf(String.class)).or(instanceOf(RExpression.class))). mustBe(abstractVectorValue()).boxPrimitive().mustBe(size(1)). returnIf(stringValue(), findFirst().stringElement()). @@ -176,13 +175,6 @@ public abstract class Switch extends RBuiltinNode.Arg2 { return prepareResult(frame, doSwitchInt(frame, x, optionalArgs)); } - @SuppressWarnings("unused") - @Specialization - protected Object doSwitch(RMissing x, RMissing optionalArgs) { - CompilerDirectives.transferToInterpreter(); - throw error(RError.Message.EXPR_MISSING); - } - private Object doSwitchInt(VirtualFrame frame, int index, RArgsValuesAndNames optionalArgs) { if (noAlternativesProfile.profile(optionalArgs.getLength() == 0)) { warning(RError.Message.NO_ALTERNATIVES_IN_SWITCH); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TrigExpFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TrigExpFunctions.java index b7b963b1e95d5eaf482c3ecb506a0fa922bb610a..62eb8e262084a42cbc86ff7471bc9eafb87fdd00 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TrigExpFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TrigExpFunctions.java @@ -565,7 +565,7 @@ public class TrigExpFunctions { profile); } - @Fallback + @Specialization(guards = {"!isDouble(x) || !isDouble(y)"}) @TruffleBoundary protected Object atan2(Object x, Object y) { if (x instanceof RAbstractComplexVector || y instanceof RAbstractComplexVector) { @@ -573,5 +573,9 @@ public class TrigExpFunctions { } throw error(RError.Message.NON_NUMERIC_MATH); } + + protected static boolean isDouble(Object x) { + return x instanceof Double || x instanceof RAbstractDoubleVector; + } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastrDqrls.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastrDqrls.java index 5dc87230fce0d367c56e55cf628c758d4dabb94e..043cfb754430f72f058c3e9b69e9990ea807fee0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastrDqrls.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastrDqrls.java @@ -11,6 +11,8 @@ */ package com.oracle.truffle.r.nodes.builtin.fastr; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.missingValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; import static com.oracle.truffle.r.runtime.RVisibility.OFF; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; @@ -44,13 +46,13 @@ public abstract class FastrDqrls extends RBuiltinNode.Arg7 { static { Casts casts = new Casts(FastrDqrls.class); - casts.arg("x").asDoubleVector(true, true, true); + casts.arg("x").mustNotBeMissing().mustNotBeNull().asDoubleVector(true, true, true); casts.arg("n").asIntegerVector().findFirst(); casts.arg("p").asIntegerVector().findFirst(); - casts.arg("y").asDoubleVector(true, true, true); + casts.arg("y").mustNotBeMissing().mustNotBeNull().asDoubleVector(true, true, true); casts.arg("ny").asIntegerVector().findFirst(); casts.arg("tol").asDoubleVector().findFirst(); - casts.arg("coeff").asDoubleVector(true, true, true); + casts.arg("coeff").mustNotBeMissing().mustNotBeNull().asDoubleVector(true, true, true); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java index 745cb3980a6575aa301543d2fb592e89ca88246e..79d3635e48cbea9dd3adc96bb69d3959cf3a7bcc 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java @@ -182,11 +182,6 @@ public abstract class CastLogicalNode extends CastLogicalBaseNode { return ret; } - @Specialization - protected RArgsValuesAndNames doArgsValueAndNames(RArgsValuesAndNames values) { - return values; - } - @Specialization protected RMissing doMissing(RMissing missing) { return missing; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java index e31111eb6fe6c5813d651697f70f4dd6578140e7..8583792a6fa9bac94b31a98244a5b83cacf22be6 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java @@ -320,7 +320,7 @@ public final class RError extends RuntimeException { MUST_BE_POSITIVE_INT("'%s' must be a positive integer"), MUST_BE_POSITIVE_SD("%s must be non-negative number"), MUST_BE_SQUARE("'%s' (%d x %d) must be square"), - MUST_BE_SQUARE_COMPATIBLE("'%s' (%d x %d) must be compatible with '%' (%d x %d)"), + MUST_BE_SQUARE_COMPATIBLE("'%s' (%d x %d) must be compatible with '%s' (%d x %d)"), INVALID_TFB_SD("invalid (to - from)/by in seq(.)"), INVALID_TFB("invalid '(to - from)/by' in 'seq'"), WRONG_SIGN_IN_BY("wrong sign in 'by' argument"),