diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java index 03d2eb7c7da92316ad144a9ec3957f4da0245805..eea62355abc09e830a188d4c2697a12f89d725eb 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java @@ -46,8 +46,12 @@ public class DuplicatedFunctions { private final ConditionProfile incomparable = ConditionProfile.createBinaryProfile(); protected void casts(CastBuilder casts) { - casts.arg("x").mustBe(nullValue().or(abstractVectorValue()), RError.SHOW_CALLER, RError.Message.GENERIC, - "duplicated() applies only to vectors").asVector(); + // these are similar to those in DuplicatedFunctions.java + casts.arg("x").mustBe(nullValue().or(abstractVectorValue()), RError.SHOW_CALLER, RError.Message.APPLIES_TO_VECTORS, + "duplicated()").asVector(); + // not much more can be done for incomparables as it is either a vector of incomparable + // values or a (single) logical value + casts.arg("incomparables").asVector(true); casts.arg("fromLast").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } @@ -76,7 +80,7 @@ public class DuplicatedFunctions { } } - @RBuiltin(name = "duplicated", kind = INTERNAL, parameterNames = {"x", "imcomparables", "fromLast", "nmax"}, behavior = PURE) + @RBuiltin(name = "duplicated", kind = INTERNAL, parameterNames = {"x", "incomparables", "fromLast", "nmax"}, behavior = PURE) public abstract static class Duplicated extends Adapter { @Override @@ -123,7 +127,7 @@ public class DuplicatedFunctions { } } - @RBuiltin(name = "anyDuplicated", kind = INTERNAL, parameterNames = {"x", "imcomparables", "fromLast"}, behavior = PURE) + @RBuiltin(name = "anyDuplicated", kind = INTERNAL, parameterNames = {"x", "incomparables", "fromLast"}, behavior = PURE) public abstract static class AnyDuplicated extends Adapter { @Override diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Tabulate.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Tabulate.java index ef4df374403504b236c0b66efe19ef6b5c4a97c5..17cff1e7387cae9887f94e163a1a9151ca31831a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Tabulate.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Tabulate.java @@ -10,13 +10,11 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.LoopConditionProfile; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; @@ -30,22 +28,16 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; @RBuiltin(name = "tabulate", kind = INTERNAL, parameterNames = {"bin", "nbins"}, behavior = PURE) public abstract class Tabulate extends RBuiltinNode { - private final BranchProfile errorProfile = BranchProfile.create(); private final LoopConditionProfile loopProfile = LoopConditionProfile.createCountingProfile(); @Override protected void createCasts(CastBuilder casts) { - // TODO: not sure if the behavior is 100% compliant - casts.arg("bin").asIntegerVector(); - casts.arg("nbins").asIntegerVector().findFirst(); + casts.arg("bin").mustBe(integerValue(), RError.NO_CALLER, RError.Message.INVALID_INPUT).asIntegerVector(); + casts.arg("nbins").defaultError(RError.NO_CALLER, RError.Message.INVALID_ARGUMENT, "nbin").asIntegerVector().findFirst().mustBe(gte(0)); } @Specialization protected RIntVector tabulate(RAbstractIntVector bin, int nBins) { - if (RRuntime.isNA(nBins) || nBins < 0) { - errorProfile.enter(); - throw RError.error(this, RError.Message.INVALID_ARGUMENT, "nbin"); - } int[] ans = new int[nBins]; loopProfile.profileCounted(bin.getLength()); for (int i = 0; loopProfile.inject(i < bin.getLength()); i++) { @@ -57,10 +49,4 @@ public abstract class Tabulate extends RBuiltinNode { return RDataFactory.createIntVector(ans, RDataFactory.COMPLETE_VECTOR); } - @SuppressWarnings("unused") - @Fallback - @TruffleBoundary - protected RIntVector tabulate(Object bin, Object nBins) { - throw RError.error(this, RError.Message.INVALID_INPUT); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TempFile.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TempFile.java index d3318f5e976edf3e976ab543851e46e675dbb1af..070b089bb2f517578e02568d65fdd2e010ac6a42 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TempFile.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/TempFile.java @@ -22,15 +22,17 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.TempPathName; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -38,91 +40,29 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = "tempfile", kind = INTERNAL, parameterNames = {"pattern", "tempdir", "fileext"}, behavior = COMPLEX) public abstract class TempFile extends RBuiltinNode { - @CompilationFinal private int stringVectorsAmount; - private static final String INVALID_PATTERN = mkErrorMsg("filename"); - private static final String INVALID_TEMPDIR = mkErrorMsg("tempdir"); - private static final String INVALID_FILEEXT = mkErrorMsg("file extension"); - - private static String mkErrorMsg(String msg) { - return "invalid '" + msg + "'"; + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("pattern").asVector().mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.INVALID_FILENAME_PATTERN).mustBe(notEmpty(), RError.SHOW_CALLER, RError.Message.NO, "pattern"); + casts.arg("tempdir").asVector().mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.INVALID_VALUE, "tempdir").findFirst(RError.SHOW_CALLER, RError.Message.NO, "tempdir"); + casts.arg("fileext").asVector().mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.INVALID_FILE_EXT).mustBe(notEmpty(), RError.SHOW_CALLER, RError.Message.NO, "fileext"); } - @Specialization(guards = "tempDir.getLength() == 1") @TruffleBoundary - protected RStringVector tempfile(String pattern, RAbstractStringVector tempDir, String fileExt) { - return RDataFactory.createStringVector(TempPathName.createNonExistingFilePath(pattern, tempDir.getDataAt(0), fileExt)); - } - @Specialization - @TruffleBoundary - protected RStringVector tempfileGeneric(Object pattern, Object tempDir, Object fileExt) { - // Now we have RStringVectors of at least length 1 - RStringVector[] argVecs = new RStringVector[]{checkVector(pattern, INVALID_PATTERN), checkVector(tempDir, INVALID_TEMPDIR), checkVector(fileExt, INVALID_FILEEXT)}; - stringVectorsAmount = argVecs.length; - int maxL = findMaxLengthIn(argVecs); - extendVectorsToSameLength(argVecs, maxL); // Now all vectors are same length - return RDataFactory.createStringVector(createTempFilesPaths(argVecs, maxL), true); - } - - @TruffleBoundary - private int findMaxLengthIn(RStringVector[] stringVectors) { - int maxLength = 0; - for (int i = 0; i < stringVectorsAmount; i++) { - int length = stringVectors[i].getLength(); - if (length > maxLength) { - maxLength = length; - } - } - return maxLength; - } - - @TruffleBoundary - private void extendVectorsToSameLength(RStringVector[] stringVectors, int desiredLength) { - for (int i = 0; i < stringVectorsAmount; i++) { - RStringVector stringVector = stringVectors[i]; - int length = stringVector.getLength(); - if (length < desiredLength) { - stringVectors[i] = extendVector(stringVector, length, desiredLength); - } + protected RStringVector tempfile(RAbstractStringVector pattern, String tempDir, RAbstractStringVector fileExt) { + int patternLength = pattern.getLength(); + int fileExtLength = fileExt.getLength(); + int maxLength = Math.max(patternLength, fileExtLength); + String[] data = new String[maxLength]; + int patternInd = 0; + int fileExtInd = 0; + for (int i = 0; i < maxLength; i++) { + data[i] = TempPathName.createNonExistingFilePath(pattern.getDataAt(patternInd), tempDir, fileExt.getDataAt(fileExtInd)); + patternInd = Utils.incMod(patternInd, patternLength); + fileExtInd = Utils.incMod(fileExtInd, fileExtLength); } + return RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR); } - @TruffleBoundary - private static RStringVector extendVector(RStringVector vec, int vecL, int maxL) { - String[] data = new String[maxL]; - int i = 0; - while (i < vecL) { - data[i] = vec.getDataAt(i); - i++; - } - while (i < maxL) { - data[i] = vec.getDataAt(i % vecL); - i++; - } - return RDataFactory.createStringVector(data, true); - } - - @TruffleBoundary - private static String[] createTempFilesPaths(RStringVector[] stringVectors, int pathsAmount) { - // pathsAmount must be equals to length of vector. All vectors must be same length - String[] paths = new String[pathsAmount]; - for (int i = 0; i < pathsAmount; i++) { - paths[i] = TempPathName.createNonExistingFilePath(stringVectors[0].getDataAt(i), stringVectors[1].getDataAt(i), stringVectors[2].getDataAt(i)); - } - return paths; - } - - @TruffleBoundary - private RStringVector checkVector(Object obj, String msg) { - if (obj instanceof RStringVector) { - RStringVector result = (RStringVector) obj; - if (result.getLength() > 0) { - return result; - } - } else if (obj instanceof String) { - return RDataFactory.createStringVector((String) obj); - } - throw RError.error(this, RError.Message.GENERIC, msg); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UnClass.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UnClass.java index fd3f5c4be7fc1e5796af7c05099009b31363aa49..9f6d574f555cf4b776024d331357cadc9a50c460 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UnClass.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UnClass.java @@ -17,62 +17,72 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RAttributable; import com.oracle.truffle.r.runtime.data.RAttributeProfiles; -import com.oracle.truffle.r.runtime.data.RLanguage; -import com.oracle.truffle.r.runtime.data.RS4Object; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.RShareable; import com.oracle.truffle.r.runtime.data.RVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @RBuiltin(name = "unclass", kind = PRIMITIVE, parameterNames = {"x"}, behavior = PURE) public abstract class UnClass extends RBuiltinNode { private final BranchProfile objectProfile = BranchProfile.create(); + private final BranchProfile shareableProfile = BranchProfile.create(); private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").asAttributable(true, true, true); + } + @Specialization + protected RNull unClass(RNull rnull) { + return rnull; + } + @TruffleBoundary - protected Object unClass(RAbstractVector arg) { - if (arg.isObject(attrProfiles)) { - objectProfile.enter(); - RVector resultVector = arg.materialize(); - if (!resultVector.isTemporary()) { - resultVector = resultVector.copy(); - resultVector.incRefCount(); - } - return RVector.setVectorClassAttr(resultVector, null); + private static Object unClassVector(RAbstractVector arg) { + RVector resultVector = arg.materialize(); + if (!resultVector.isTemporary()) { + resultVector = resultVector.copy(); + resultVector.incRefCount(); } - return arg; + return RVector.setVectorClassAttr(resultVector, null); } + // TODO: this specialization could go away if connections were simple vectors (we wouldn't need + // special method for setting class attributes then) @Specialization - protected Object unClass(RLanguage arg) { - if (arg.getClassAttr(attrProfiles) != null) { + protected Object unClass(RAbstractVector arg) { + if (arg.isObject(attrProfiles)) { objectProfile.enter(); - RLanguage resultLang = arg; - if (!resultLang.isTemporary()) { - resultLang = resultLang.copy(); - resultLang.incRefCount(); - } - resultLang.removeAttr(attrProfiles, RRuntime.CLASS_ATTR_KEY); - return resultLang; + return unClassVector(arg); } return arg; } - @Specialization - protected Object unClass(RS4Object arg) { + @Specialization(guards = "notAbstractVector(arg)") + protected Object unClass(RAttributable arg) { if (arg.getClassAttr(attrProfiles) != null) { objectProfile.enter(); - RS4Object resultS4 = arg; - if (!resultS4.isTemporary()) { - resultS4 = resultS4.copy(); - resultS4.incRefCount(); + if (arg instanceof RShareable) { + shareableProfile.enter(); + RShareable shareable = (RShareable) arg; + if (!shareable.isTemporary()) { + shareable = shareable.copy(); + shareable.incRefCount(); + } } - resultS4.removeAttr(attrProfiles, RRuntime.CLASS_ATTR_KEY); - return resultS4; + arg.removeAttr(attrProfiles, RRuntime.CLASS_ATTR_KEY); } return arg; } + + protected boolean notAbstractVector(Object arg) { + return !(arg instanceof RAbstractVector); + } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unique.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unique.java index 74c3cda1adc2acb91fe46584ee1a18ab30fe37f3..ea894dcbba0de2e02e1f80fcdb310dda99c097ea 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unique.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unique.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -32,11 +33,12 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RComplex; import com.oracle.truffle.r.runtime.data.RComplexVector; import com.oracle.truffle.r.runtime.data.RDataFactory; @@ -54,9 +56,9 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractVector; -// Implements default S3 method -@RBuiltin(name = "unique", kind = INTERNAL, parameterNames = {"x", "incomparables", "fromLast", "nmax", "..."}, behavior = PURE) +@RBuiltin(name = "unique", kind = INTERNAL, parameterNames = {"x", "incomparables", "fromLast", "nmax"}, behavior = PURE) // TODO A more efficient implementation is in order; GNU R uses hash tables so perhaps we should // consider using one of the existing libraries that offer hash table implementations for primitive // types @@ -66,15 +68,31 @@ public abstract class Unique extends RBuiltinNode { private final ConditionProfile bigProfile = ConditionProfile.createBinaryProfile(); + @Override + protected void createCasts(CastBuilder casts) { + // these are similar to those in DuplicatedFunctions.java + casts.arg("x").mustBe(nullValue().or(abstractVectorValue()), RError.SHOW_CALLER, RError.Message.APPLIES_TO_VECTORS, + "unique()").mapIf(nullValue().not(), asVector()); + // not much more can be done for incomparables as it is either a vector of incomparable + // values or a (single) logical value + // TODO: coercion error must be handled by specialization as it depends on type of x (much + // like in duplicated) + casts.arg("incomparables").asVector(true); + casts.arg("fromLast").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); + // currently not supported and not tested, but NA is a correct value (the same for empty + // vectors) whereas 0 is not (throws an error) + casts.arg("nmax").asIntegerVector().findFirst(RRuntime.INT_NA); + } + @SuppressWarnings("unused") @Specialization - protected RNull doUnique(RNull vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RNull doUnique(RNull vec, RAbstractVector incomparables, byte fromLast, int nmax) { return vec; } @SuppressWarnings("unused") @Specialization - protected RStringVector doUnique(RAbstractStringVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RStringVector doUnique(RAbstractStringVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { if (bigProfile.profile(vec.getLength() * (long) vec.getLength() > BIG_THRESHOLD)) { Utils.NonRecursiveHashSet<String> set = new Utils.NonRecursiveHashSet<>(vec.getLength()); String[] data = new String[vec.getLength()]; @@ -230,7 +248,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization - protected RIntVector doUnique(RAbstractIntVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RIntVector doUnique(RAbstractIntVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { if (bigProfile.profile(vec.getLength() * (long) vec.getLength() > BIG_THRESHOLD)) { NonRecursiveHashSetInt set = new NonRecursiveHashSetInt(); int[] data = new int[16]; @@ -259,7 +277,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization(guards = "lengthOne(list)") - protected RList doUniqueL1(RList list, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RList doUniqueL1(RList list, RAbstractVector incomparables, byte fromLast, int nmax) { return (RList) list.copyDropAttributes(); } @@ -276,7 +294,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization(guards = "!lengthOne(list)") @TruffleBoundary - protected RList doUnique(RList list, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RList doUnique(RList list, RAbstractVector incomparables, byte fromLast, int nmax) { /* * Brute force, as manual says: Using this for lists is potentially slow, especially if the * elements are not atomic vectors (see vector) or differ only in their attributes. In the @@ -355,7 +373,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization - protected RDoubleVector doUnique(RAbstractDoubleVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RDoubleVector doUnique(RAbstractDoubleVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { if (bigProfile.profile(vec.getLength() * (long) vec.getLength() > BIG_THRESHOLD)) { Utils.NonRecursiveHashSetDouble set = new Utils.NonRecursiveHashSetDouble(vec.getLength()); double[] data = new double[vec.getLength()]; @@ -381,7 +399,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization - protected RLogicalVector doUnique(RAbstractLogicalVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RLogicalVector doUnique(RAbstractLogicalVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { ByteArray dataList = new ByteArray(vec.getLength()); for (int i = 0; i < vec.getLength(); i++) { byte val = vec.getDataAt(i); @@ -394,7 +412,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization - protected RComplexVector doUnique(RAbstractComplexVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RComplexVector doUnique(RAbstractComplexVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { if (bigProfile.profile(vec.getLength() * (long) vec.getLength() > BIG_THRESHOLD)) { Utils.NonRecursiveHashSet<RComplex> set = new Utils.NonRecursiveHashSet<>(vec.getLength()); double[] data = new double[vec.getLength() * 2]; @@ -421,7 +439,7 @@ public abstract class Unique extends RBuiltinNode { @SuppressWarnings("unused") @Specialization - protected RRawVector doUnique(RAbstractRawVector vec, byte incomparables, byte fromLast, Object nmax, RArgsValuesAndNames vararg) { + protected RRawVector doUnique(RAbstractRawVector vec, RAbstractVector incomparables, byte fromLast, int nmax) { if (bigProfile.profile(vec.getLength() * (long) vec.getLength() > BIG_THRESHOLD)) { Utils.NonRecursiveHashSet<RRaw> set = new Utils.NonRecursiveHashSet<>(vec.getLength()); byte[] data = new byte[vec.getLength()]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java index d440e5ec6417d32322adaff051b0f0dbaff3bbdb..26f0329783ba934603331515c4dad9184cf2d6b8 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java @@ -11,11 +11,13 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.dsl.TypeSystemReference; import com.oracle.truffle.api.frame.VirtualFrame; @@ -47,8 +49,8 @@ public abstract class Unlist extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.firstBoolean(1); - casts.firstBoolean(2); + casts.arg("recursive").asLogicalVector().findFirst(RRuntime.LOGICAL_TRUE).map(toBoolean()); + casts.arg("use.names").asLogicalVector().findFirst(RRuntime.LOGICAL_TRUE).map(toBoolean()); } @Child private PrecedenceNode precedenceNode = PrecedenceNodeGen.create(); @@ -143,21 +145,9 @@ public abstract class Unlist extends RBuiltinNode { return RNull.instance; } - @SuppressWarnings("unused") - @Specialization(guards = "!isVectorList(vector)") - protected RAbstractVector unlistVector(RAbstractVector vector, boolean recursive, boolean useNames) { - return vector; - } - @SuppressWarnings("unused") @Specialization(guards = "isEmpty(list)") - protected RNull unlistEmptyList(VirtualFrame frame, RList list, boolean recursive, boolean useNames) { - return RNull.instance; - } - - @SuppressWarnings("unused") - @Specialization(guards = "isOneNull(list)") - protected RNull unlistOneNullList(VirtualFrame frame, RList list, boolean recursive, boolean useNames) { + protected RNull unlistEmptyList(RList list, boolean recursive, boolean useNames) { return RNull.instance; } @@ -184,6 +174,12 @@ public abstract class Unlist extends RBuiltinNode { } } + @SuppressWarnings("unused") + @Fallback + protected Object unlist(Object o, boolean recursive, boolean useNames) { + return o; + } + @TruffleBoundary private RAbstractVector unlistHelper(RList list, boolean recursive, boolean useNames, int precedence, int totalSize) { String[] namesData = useNames ? new String[totalSize] : null; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VApply.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VApply.java index b878565580cb566b94d9b2728004d11527840110..f27617a2fd13d84181bd9e7bc97fdb0ffcea59de 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VApply.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VApply.java @@ -22,15 +22,15 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; 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; import com.oracle.truffle.api.profiles.ConditionProfile; -import com.oracle.truffle.api.profiles.ValueProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.base.Lapply.LapplyInternalNode; import com.oracle.truffle.r.nodes.builtin.base.LapplyNodeGen.LapplyInternalNodeGen; @@ -76,10 +76,8 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "vapply", kind = INTERNAL, parameterNames = {"X", "FUN", "FUN.VALUE", "USE.NAMES"}, splitCaller = true, behavior = COMPLEX) public abstract class VApply extends RBuiltinNode { - private final ValueProfile funValueProfile = ValueProfile.createClassProfile(); private final ConditionProfile useNamesProfile = ConditionProfile.createBinaryProfile(); private final ConditionProfile dimsProfile = ConditionProfile.createBinaryProfile(); - private final BranchProfile errorProfile = BranchProfile.create(); private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); private final NACheck naCheck = NACheck.create(); @@ -91,6 +89,14 @@ public abstract class VApply extends RBuiltinNode { @Child private CastLogicalNode castLogical; @Child private CastStringNode castString; + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("X").asVector(); + casts.arg("FUN").mustBe(instanceOf(RFunction.class), RError.SHOW_CALLER, RError.Message.APPLY_NON_FUNCTION); + casts.arg("FUN.VALUE").mapIf(anyValue(), chain(asVector(true)).with(mustBe(abstractVectorValue(), RError.SHOW_CALLER, true, RError.Message.MUST_BE_VECTOR, "FUN.VALUE")).end()); + casts.arg("USE.NAMES").defaultError(RError.SHOW_CALLER, RError.Message.INVALID_VALUE, "USE.NAMES").mustBe(stringValue().not()).asLogicalVector().findFirst(); + } + private Object castComplex(Object operand, boolean preserveAllAttr) { if (castComplex == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); @@ -132,25 +138,19 @@ public abstract class VApply extends RBuiltinNode { } @Specialization - protected Object vapply(VirtualFrame frame, RAbstractVector vec, RFunction fun, Object funValue, byte useNames) { + protected Object vapply(VirtualFrame frame, RAbstractVector vec, RFunction fun, RAbstractVector funValue, byte useNames) { RVector result = delegateToLapply(frame, vec, fun, funValue, useNames); // set here else it gets overridden by the iterator evaluation return result; } - private RVector delegateToLapply(VirtualFrame frame, RAbstractVector vec, RFunction fun, Object funValueArg, byte useNames) { + private RVector delegateToLapply(VirtualFrame frame, RAbstractVector vec, RFunction fun, RAbstractVector funValueVec, byte useNames) { /* * The implementation is complicated by the existence of scalar length 1 vectors (e.g. * Integer) and concrete length 1 vectors (e.g. RIntVector), as either form can occur in * both funValueArg and the result of the doApply. At a slight performance cost this code * works exclusively in terms of concrete vectors. */ - Object funValueObj = RRuntime.asAbstractVector(funValueArg); - if (!(funValueObj instanceof RAbstractVector)) { - errorProfile.enter(); - throw RError.error(this, RError.Message.MUST_BE_VECTOR, "FUN.VALUE"); - } - RAbstractVector funValueVec = funValueProfile.profile((RAbstractVector) funValueObj); int funValueVecLen = funValueVec.getLength(); RVector vecMat = vec.materialize(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Vector.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Vector.java index 5736f617e756325463f3b84daf925551432de5d6..c942eacc8a4a562af2a4749cd517b0b1cdb63e8f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Vector.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Vector.java @@ -47,7 +47,8 @@ public abstract class Vector extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.arg("length").asIntegerVector().mustBe(singleElement()).findFirst(); + casts.arg("mode").defaultError(RError.SHOW_CALLER, RError.Message.INVALID_ARGUMENT, "mode").asStringVector().mustBe(singleElement()).findFirst(); + casts.arg("length").defaultError(RError.SHOW_CALLER, RError.Message.INVALID_ARGUMENT, "length").asIntegerVector().mustBe(singleElement()).findFirst(); } protected RType modeToType(String mode) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRDebug.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRDebug.java index e58eaf4b62f6fd9328fd27a758c0052a067e6e2b..9ad0b4fcb9612dfdc2063665d27ba7ca639a0a66 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRDebug.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRDebug.java @@ -27,11 +27,10 @@ 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.TruffleBoundary; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.FastROptions; -import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @@ -39,6 +38,11 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = ".fastr.debug", visibility = OFF, kind = PRIMITIVE, parameterNames = {"values"}, behavior = COMPLEX) public abstract class FastRDebug extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("values").asStringVector(); + } + @Specialization @TruffleBoundary protected RNull debug(RAbstractStringVector vec) { @@ -48,9 +52,4 @@ public abstract class FastRDebug extends RBuiltinNode { return RNull.instance; } - @SuppressWarnings("unused") - @Fallback - protected Object fallback(Object a1) { - throw RError.error(this, RError.Message.INVALID_ARGUMENT, "element"); - } } 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 35cd80b4af5e7dd96c2554d5c5831590d52952e6..7009fb6deb44a0d9efe9bf59888f586daf673444 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,7 @@ */ package com.oracle.truffle.r.nodes.builtin.fastr; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; 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; @@ -19,6 +20,7 @@ import java.util.Arrays; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.unary.CastDoubleNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -45,6 +47,18 @@ public abstract class FastrDqrls extends RBuiltinNode { private final RAttributeProfiles xAttributeProfiles = RAttributeProfiles.create(); private final RAttributeProfiles residualsAttributesProfiles = RAttributeProfiles.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").asDoubleVector(true, true, true); + casts.arg("n").asIntegerVector().findFirst(); + casts.arg("p").asIntegerVector().findFirst(); + casts.arg("y").asDoubleVector(true, true, true); + casts.arg("ny").asIntegerVector().findFirst(); + casts.arg("tol").asDoubleVector().findFirst(); + casts.arg("coeff").asDoubleVector(true, true, true); + + } + @Specialization public RList doDouble(RAbstractDoubleVector xVec, int n, int p, RAbstractDoubleVector yVec, int ny, double tol, RAbstractDoubleVector coeffVec) { return call(xVec, xVec.materialize(), n, p, yVec, yVec.materialize(), ny, tol, coeffVec); 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 692e68ad39787190beaab5d76c4882d28ec14ca8..cfd6a8900fc15b8a855cbed33c03c730c569bbc2 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 @@ -726,7 +726,11 @@ public final class RError extends RuntimeException { ATTEMPT_TO_REPLICATE("attempt to replicate an object of type '%s'"), ATTEMPT_TO_REPLICATE_NO_VECTOR("attempt to replicate non-vector"), INCORRECT_ARG_TYPE("incorrect type for %s argument"), - INVALID_ARG_OF_LENGTH("invalid %s argument of length %d"); + INVALID_ARG_OF_LENGTH("invalid %s argument of length %d"), + INVALID_FILENAME_PATTERN("invalid filename pattern"), + INVALID_FILE_EXT("invalid file extension"), + NO("no '%s'"), + APPLIES_TO_VECTORS("%s applies only to vectors"); public final String message; final boolean hasArgs; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 01052b8dfe1ba9f565c3a206e66957d0069257cd..fc022cff4049e77656ea0eaa456bbfe9a51b1321 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -49093,6 +49093,26 @@ c 2 [,1] [,2] [,3] [1,] -2.137774 1.170455 5.851801 +##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate +#{ .Internal(tabulate(c(2,3,5), 7)) } +Error: invalid input + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate +#{ .Internal(tabulate(c(2L,3L,5L), -1)) } +Error: invalid 'nbin' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate +#{ .Internal(tabulate(c(2L,3L,5L), NA)) } +Error: invalid 'nbin' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate +#{ .Internal(tabulate(c(2L,3L,5L), c(7, 42))) } +[1] 0 1 1 0 1 0 0 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate +#{ .Internal(tabulate(c(2L,3L,5L), integer())) } +Error: invalid 'nbin' argument + ##com.oracle.truffle.r.test.builtins.TestBuiltin_tabulate.testTabulate #{tabulate(c(-2,0,2,3,3,5))} [1] 0 1 2 0 1 @@ -49825,6 +49845,42 @@ Volume 55.4 55.7 58.3 51.5 51 77.0 [4,] 0.47180794+0i -0.009784296+0i 0.08254997+0i 0.09431439+0i 0.87269229+0i [5,] -0.63291053+0i 0.283760917+0i 0.54536410+0i 0.39826963+0i 0.25072556+0i +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", 42) } +Error in tempfile("file", 42) : invalid 'tempdir' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", character()) } +Error in tempfile("file", character()) : no 'tempdir' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", integer()) } +Error in tempfile("file", integer()) : invalid 'tempdir' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", tempdir(), 42) } +Error in tempfile("file", tempdir(), 42) : invalid file extension + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", tempdir(), character()) } +Error in tempfile("file", tempdir(), character()) : no 'fileext' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile("file", tempdir(), integer()) } +Error in tempfile("file", tempdir(), integer()) : invalid file extension + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile(42) } +Error in tempfile(42) : invalid filename pattern + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile(character()) } +Error in tempfile(character()) : no 'pattern' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_tempfile.testTempfile +#{ tempfile(integer()) } +Error in tempfile(integer()) : invalid filename pattern + ##com.oracle.truffle.r.test.builtins.TestBuiltin_times_difftime.testtimes_difftime1 #argv <- structure(list(e1 = 2, e2 = structure(c(3.33333333333333, 683.25), units = 'mins', class = 'difftime')), .Names = c('e1', 'e2'));do.call('*.difftime', argv) Time differences in mins @@ -51181,6 +51237,19 @@ attr(,"row.names") "3rd Qu.: 7.75 " "3rd Qu.: 7.75 3rd Qu.:17.75 " "Max. :10.00 " "Max. :10.00 Max. :20.00 " +##com.oracle.truffle.r.test.builtins.TestBuiltin_unique.testUnique +#{ unique(c(1,2,1), incomparables=function() 42) } +Error in unique.default(c(1, 2, 1), incomparables = function() 42) : + cannot coerce type 'closure' to vector of type 'double' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_unique.testUnique +#{ x<-function() 42; unique(x) } +Error in unique.default(x) : unique() applies only to vectors + +##com.oracle.truffle.r.test.builtins.TestBuiltin_unique.testUnique +#{ x<-quote(f(7, 42)); unique(x) } +Error in unique.default(x) : unique() applies only to vectors + ##com.oracle.truffle.r.test.builtins.TestBuiltin_unique.testUnique #{x<-factor(c("a", "b", "a")); unique(x) } [1] a b @@ -52493,6 +52562,30 @@ function (x) { x } #{ iv <- integer(1); iv[[1]] = 1L; vapply(c(1L, 2L, 3L, 4L), function(x) x+5L, iv) } [1] 6 7 8 9 +##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply +#{ vapply(c("foo", "bar"), 42, c(TRUE) } +Error: unexpected '}' in "{ vapply(c("foo", "bar"), 42, c(TRUE) }" + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply +#{ vapply(c("foo", "bar"), function(x) FALSE, c(TRUE), USE.NAMES="42") } +Error in vapply(c("foo", "bar"), function(x) FALSE, c(TRUE), USE.NAMES = "42") : + invalid 'USE.NAMES' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply +#{ vapply(c("foo", "bar"), function(x) FALSE, c(TRUE), USE.NAMES=42) } + foo bar +FALSE FALSE + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply +#{ vapply(c("foo", "bar"), function(x) FALSE, c(TRUE), USE.NAMES=logical()) } +Error in vapply(c("foo", "bar"), function(x) FALSE, c(TRUE), USE.NAMES = logical()) : + invalid 'USE.NAMES' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply +#{ vapply(c("foo", "bar"), function(x) FALSE, function() 42) } +Error in vapply(c("foo", "bar"), function(x) FALSE, function() 42) : + 'FUN.VALUE' must be a vector + ##com.oracle.truffle.r.test.builtins.TestBuiltin_vapply.testVapply #{ vapply(c("hello", "goodbye", "up", "down"), function(x) x, c("a")) } hello goodbye up down @@ -52526,6 +52619,14 @@ function (x) { x } #{ vapply(c(TRUE, FALSE, TRUE), function(x) x, c(TRUE)) } [1] TRUE FALSE TRUE +##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor +#{ vector("numeric", c(7, 42)) } +Error in vector("numeric", c(7, 42)) : invalid 'length' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor +#{ vector("numeric", integer()) } +Error in vector("numeric", integer()) : invalid 'length' argument + ##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor #{ vector("integer") } integer(0) @@ -52542,6 +52643,14 @@ numeric(0) #{ vector() } logical(0) +##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor +#{ vector(c("numeric", "numeric")) } +Error in vector(c("numeric", "numeric")) : invalid 'mode' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor +#{ vector(character()) } +Error in vector(character()) : invalid 'mode' argument + ##com.oracle.truffle.r.test.builtins.TestBuiltin_vector.testVectorConstructor #{ vector(length=3) } [1] FALSE FALSE FALSE diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_duplicated.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_duplicated.java index a1eb5d73a1b0199b0680eabeb57f843bdd75477a..3040237600c6d490b85893e20465e5eec7e6755f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_duplicated.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_duplicated.java @@ -133,7 +133,7 @@ public class TestBuiltin_duplicated extends TestBase { assertEval("{ x<-quote(f(7, 42)); duplicated(x) }"); assertEval("{ x<-function() 42; duplicated(x) }"); - assertEval(Output.IgnoreErrorMessage, "{ duplicated(c(1,2,1), incomparables=function() 42) }"); + assertEval(Output.IgnoreErrorContext, "{ duplicated(c(1,2,1), incomparables=function() 42) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tabulate.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tabulate.java index 8e671d9096a3f72dd6eb57dcbe0876ed17e38e5f..edfddef077b82650e2074d6bc75fb1cadb887773 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tabulate.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tabulate.java @@ -59,5 +59,11 @@ public class TestBuiltin_tabulate extends TestBase { assertEval("{tabulate(c(-2,0,2,3,3,5))}"); assertEval("{tabulate(c(-2,0,2,3,3,5), nbins = 3)}"); assertEval("{tabulate(factor(letters[1:10]))}"); + + assertEval("{ .Internal(tabulate(c(2,3,5), 7)) }"); + assertEval("{ .Internal(tabulate(c(2L,3L,5L), c(7, 42))) }"); + assertEval("{ .Internal(tabulate(c(2L,3L,5L), integer())) }"); + assertEval("{ .Internal(tabulate(c(2L,3L,5L), -1)) }"); + assertEval("{ .Internal(tabulate(c(2L,3L,5L), NA)) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tempfile.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tempfile.java new file mode 100644 index 0000000000000000000000000000000000000000..b0b796a6c6a6b8f6c85d28edfe277641af9cc528 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tempfile.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.test.builtins; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +// Checkstyle: stop line length check +public class TestBuiltin_tempfile extends TestBase { + + @Test + public void testTempfile() { + // checking error messages; other tests not possible due to random nature of the builtin + assertEval("{ tempfile(42) }"); + assertEval("{ tempfile(integer()) }"); + assertEval("{ tempfile(character()) }"); + assertEval("{ tempfile(\"file\", 42) }"); + assertEval("{ tempfile(\"file\", character()) }"); + assertEval("{ tempfile(\"file\", integer()) }"); + assertEval("{ tempfile(\"file\", tempdir(), 42) }"); + assertEval("{ tempfile(\"file\", tempdir(), integer()) }"); + assertEval("{ tempfile(\"file\", tempdir(), character()) }"); + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unique.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unique.java index ff067fd22894b21b8987226dfe1b0a4c7b7473a5..fb84a6827c203f84b5fa831f81968fb4918e8a20 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unique.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unique.java @@ -189,5 +189,10 @@ public class TestBuiltin_unique extends TestBase { @Test public void testUnique() { assertEval("{x<-factor(c(\"a\", \"b\", \"a\")); unique(x) }"); + + assertEval("{ x<-quote(f(7, 42)); unique(x) }"); + assertEval("{ x<-function() 42; unique(x) }"); + assertEval(Ignored.Unknown, "{ unique(c(1,2,1), incomparables=function() 42) }"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vapply.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vapply.java index eb8d5dd823630843b0128c10d1b1b529da06f479..fb621527510c5967036e416d241449f044902765 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vapply.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vapply.java @@ -36,6 +36,12 @@ public class TestBuiltin_vapply extends TestBase { assertEval("{ f <- function(a, ...) vapply(a, function(.) identical(a, T, ...), NA); v <- c(1,2,3); f(v) }"); assertEval("{ f<-function(x,y) x-y; w<-c(42, 42); z<-7; vapply(w, f, as.double(NA), x=z) }"); + + assertEval("{ vapply(c(\"foo\", \"bar\"), 42, c(TRUE) }"); + assertEval(Output.IgnoreErrorContext, "{ vapply(c(\"foo\", \"bar\"), function(x) FALSE, function() 42) }"); + assertEval(Output.IgnoreErrorContext, "{ vapply(c(\"foo\", \"bar\"), function(x) FALSE, c(TRUE), USE.NAMES=logical()) }"); + assertEval(Output.IgnoreErrorContext, "{ vapply(c(\"foo\", \"bar\"), function(x) FALSE, c(TRUE), USE.NAMES=\"42\") }"); + assertEval("{ vapply(c(\"foo\", \"bar\"), function(x) FALSE, c(TRUE), USE.NAMES=42) }"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vector.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vector.java index 5e7c002f47917a4bb563a2971a52e36a7120e6d1..e218f7e8d356838608ffdff845acebc860915c12 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vector.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_vector.java @@ -65,6 +65,11 @@ public class TestBuiltin_vector extends TestBase { assertEval("{ vector(\"numeric\", length=4) }"); assertEval("{ vector(length=3) }"); assertEval("{ x<-as.vector(3); y<-vector(length=x) }"); + + assertEval("{ vector(character()) }"); + assertEval("{ vector(c(\"numeric\", \"numeric\")) }"); + assertEval("{ vector(\"numeric\", integer()) }"); + assertEval("{ vector(\"numeric\", c(7, 42)) }"); } @Test