diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsVector.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsVector.java index 4a03881ca6309d7ad3de0b2c1c42af1bf2b41d23..bfafef9b2994b2da85401568e313c6d0008ecd56 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsVector.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsVector.java @@ -284,9 +284,9 @@ public abstract class AsVector extends RBuiltinNode.Arg2 { } @Fallback + @TruffleBoundary protected Object castPairlist(Object x) { - String name = x instanceof RTypedValue ? ((RTypedValue) x).getRType().getName() : x.getClass().getSimpleName(); - throw error(Message.CANNOT_COERCE, name, RType.PairList.getName()); + throw error(Message.CANNOT_COERCE, RRuntime.getRTypeName(x), RType.PairList.getName()); } @TruffleBoundary 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 72241c43e5f262fab618a0efefa7b816bdcdc1da..b6b9c9d509bcc0cb769c2b4814d181b332b7a08d 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 @@ -35,12 +35,12 @@ import com.oracle.truffle.r.nodes.binary.CastTypeNodeGen; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.unary.TypeofNode; import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RLogicalVector; -import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.nodes.DuplicationHelper; @@ -107,12 +107,10 @@ public class DuplicatedFunctions { @SuppressWarnings("unused") @Specialization(guards = {"!isRAbstractVector(incomparables)", "x.getLength() != 0"}) + @TruffleBoundary protected RLogicalVector duplicatedTrueIncomparables(RAbstractVector x, Object incomparables, byte fromLast, int nmax, @Cached("createTypeof()") TypeofNode typeof) { - RType xType = typeof.execute(x); - // TODO: this is not quite correct, as passing expression generated some obscure error - // message, but is it worth fixing - throw error(RError.Message.CANNOT_COERCE, ((RTypedValue) incomparables).getRType().getName(), xType.getName()); + throw error(Message.CANNOT_COERCE, RRuntime.getRTypeName(incomparables), RRuntime.getRTypeName(x)); } @SuppressWarnings("unused") @@ -165,9 +163,8 @@ public class DuplicatedFunctions { @Specialization(guards = {"!isRAbstractVector(incomparables)", "x.getLength() != 0"}) @TruffleBoundary protected int anyDuplicatedTrueIncomparables(RAbstractVector x, Object incomparables, @SuppressWarnings("unused") byte fromLast) { - // TODO: this is not quite correct, as passing expression generated some obscure error - // message, but is it worth fixing - throw error(RError.Message.CANNOT_COERCE, TypeofNode.getTypeof(incomparables).getName(), TypeofNode.getTypeof(x).getName()); + // this is not quite correct, as passing expression generates some obscure error message + throw error(Message.CANNOT_COERCE, RRuntime.getRTypeName(incomparables), RRuntime.getRTypeName(x)); } @SuppressWarnings("unused") diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastBaseNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastBaseNode.java index deff01be84efd6b48203cf340a384fa44fa328b9..2e74d0bb7758b3bfec75a63332ad089f90283648 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastBaseNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastBaseNode.java @@ -25,7 +25,6 @@ package com.oracle.truffle.r.nodes.unary; 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.interop.TruffleObject; import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.api.profiles.ValueProfile; @@ -36,7 +35,6 @@ import com.oracle.truffle.r.runtime.NullProfile; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.ErrorContext; import com.oracle.truffle.r.runtime.RError.Message; -import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.data.RDataFactory.VectorFactory; @@ -46,7 +44,6 @@ import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; -import com.oracle.truffle.r.runtime.env.REnvironment; public abstract class CastBaseNode extends CastNode { @@ -182,27 +179,14 @@ public abstract class CastBaseNode extends CastNode { @TruffleBoundary protected Object doOther(Object value) { Object mappedValue = RRuntime.asAbstractVector(value); - return forRFFI ? doOtherRFFI(mappedValue) : doOtherDefault(mappedValue); - } - - protected Object doOtherDefault(Object mappedValue) { - if (mappedValue instanceof REnvironment) { - throw error(RError.Message.ENVIRONMENTS_COERCE); - } else if (mappedValue instanceof RTypedValue) { - throw error(RError.Message.CANNOT_COERCE, ((RTypedValue) mappedValue).getRType().getName(), getTargetType().getName()); - } else if (mappedValue instanceof TruffleObject) { - throw error(RError.Message.CANNOT_COERCE, "truffleobject", getTargetType().getName()); - } else { - throw RInternalError.shouldNotReachHere("unexpected value of type " + (mappedValue == null ? "null" : mappedValue.getClass())); + if (forRFFI && mappedValue instanceof RTypedValue) { + return doOtherRFFI(mappedValue); } + throw error(Message.CANNOT_COERCE, RRuntime.getRTypeName(mappedValue), getTargetType().getName()); } protected Object doOtherRFFI(Object mappedValue) { - if (mappedValue instanceof RTypedValue) { - warning(Message.CANNOT_COERCE_RFFI, ((RTypedValue) mappedValue).getRType().getName(), getTargetType().getName()); - } else if (mappedValue instanceof TruffleObject) { - throw error(RError.Message.CANNOT_COERCE, "truffleobject", getTargetType().getName()); - } + warning(Message.CANNOT_COERCE_RFFI, ((RTypedValue) mappedValue).getRType().getName(), getTargetType().getName()); return RNull.instance; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java index baa12172fa4a3b549440f2a53d35f6c459e13283..03921521b5e1801f027d64446e78de340f0bd18f 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ToStringNode.java @@ -27,10 +27,12 @@ import java.util.EnumMap; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; +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.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; +import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; @@ -197,4 +199,10 @@ public abstract class ToStringNode extends RBaseNode { protected String toString(REnvironment env, String separator) { return env.toString(); } + + @Fallback + @TruffleBoundary + protected String toStringFallback(Object value, @SuppressWarnings("unused") String separator) { + throw error(Message.CANNOT_COERCE, RRuntime.getRTypeName(value), RType.Character.getName()); + } } 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 1729d773c0d972a5734c30d7c20ec423fa81ddfd..fd8870115834e8e6c40dab38fe2de518a4b15e0d 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 @@ -16787,7 +16787,7 @@ logical(0) #{ complex(3) } [1] 0+0i 0+0i 0+0i -##com.oracle.truffle.r.test.builtins.TestBuiltin_complex.testComplex# +##com.oracle.truffle.r.test.builtins.TestBuiltin_complex.testComplex#Output.IgnoreErrorMessage# #{ complex(3, 3, new.env()) } Error in complex(3, 3, new.env()) : environments cannot be coerced to other types @@ -16804,7 +16804,7 @@ Error in complex(3, 3, new.env()) : #{ complex(3, c(1,2,3), c(4,5,6)) } [1] 1+4i 2+5i 3+6i -##com.oracle.truffle.r.test.builtins.TestBuiltin_complex.testComplex# +##com.oracle.truffle.r.test.builtins.TestBuiltin_complex.testComplex#Output.IgnoreErrorMessage# #{ complex(3, new.env()) } Error in complex(3, new.env()) : environments cannot be coerced to other types @@ -31361,7 +31361,7 @@ raw(0) Error in intToBits(list(c(5, 5, 7, 8), 88, 6L)) : (list) object cannot be coerced to type 'integer' -##com.oracle.truffle.r.test.builtins.TestBuiltin_intToBits.testintToBits# +##com.oracle.truffle.r.test.builtins.TestBuiltin_intToBits.testintToBits#Output.IgnoreErrorMessage# #intToBits(new.env()) Error in intToBits(new.env()) : environments cannot be coerced to other types @@ -146388,9 +146388,9 @@ Error in as.character(to) : no method for coercing this polyglot value to a vector ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testAsXXX# -#if (!any(R.version$engine == "FastR")) { cat('Error in as.complex(to) :', '<<<NEWLINE>>>', ' cannot coerce type \'truffleobject\' to vector of type \'complex\'', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.complex(to); } +#if (!any(R.version$engine == "FastR")) { cat('Error in as.complex(to) :', '<<<NEWLINE>>>', ' cannot coerce type \'polyglot.value\' to vector of type \'complex\'', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.complex(to); } Error in as.complex(to) : - cannot coerce type 'truffleobject' to vector of type 'complex' + cannot coerce type 'polyglot.value' to vector of type 'complex' ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testAsXXX# #if (!any(R.version$engine == "FastR")) { cat('Error in as.double(to) :', '<<<NEWLINE>>>', ' no method for coercing this polyglot value to a vector', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.double(to); } @@ -146413,9 +146413,9 @@ Error in as.logical(to) : no method for coercing this polyglot value to a vector ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testAsXXX# -#if (!any(R.version$engine == "FastR")) { cat('Error in as.raw(to) :', '<<<NEWLINE>>>', ' cannot coerce type \'truffleobject\' to vector of type \'raw\'', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.raw(to); } +#if (!any(R.version$engine == "FastR")) { cat('Error in as.raw(to) :', '<<<NEWLINE>>>', ' cannot coerce type \'polyglot.value\' to vector of type \'raw\'', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.raw(to); } Error in as.raw(to) : - cannot coerce type 'truffleobject' to vector of type 'raw' + cannot coerce type 'polyglot.value' to vector of type 'raw' ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testAsXXX# #if (!any(R.version$engine == "FastR")) { cat('Error in as.symbol(to) :', '<<<NEWLINE>>>', ' no method for coercing this polyglot value to a vector', '<<<NEWLINE>>>') } else { to <- .fastr.interop.new(java.type('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'));as.symbol(to); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_complex.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_complex.java index 5068d1ad6f99480eb197aa4690a9194bb4927338..46f448f1f67056fcf6846a6ca1b864daacef7f97 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_complex.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_complex.java @@ -68,8 +68,8 @@ public class TestBuiltin_complex extends TestBase { assertEval("{ complex(real=1,imag=2) }"); assertEval("{ complex(3) }"); assertEval(Output.IgnoreErrorMessage, "{ complex(new.env()) }"); - assertEval("{ complex(3, new.env()) }"); - assertEval("{ complex(3, 3, new.env()) }"); + assertEval(Output.IgnoreErrorMessage, "{ complex(3, new.env()) }"); + assertEval(Output.IgnoreErrorMessage, "{ complex(3, 3, new.env()) }"); assertEval("{ complex(3, c(1,2,3), c(4,5,6)) }"); assertEval("{ complex(3, c(1,2,3), c(4,5)) }"); assertEval("{ complex(3, c(1,2), c(4,5,6)) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_intToBits.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_intToBits.java index 0a87483ae829dfb8136772449067ad0062a48b12..7685cd1f7b01f51cef6f2caf6af557c5b78ef9b1 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_intToBits.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_intToBits.java @@ -56,7 +56,7 @@ public class TestBuiltin_intToBits extends TestBase { assertEval("intToBits(double(0))"); assertEval("intToBits(6:9)"); assertEval("intToBits('23rrff')"); - assertEval("intToBits(new.env())"); + assertEval(Output.IgnoreErrorMessage, "intToBits(new.env())"); assertEval("intToBits(environment)"); assertEval("intToBits(stdout())"); assertEval("intToBits(list(c(5,5,7,8),88,6L))"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java index 0c765ee621c368083deeabf0850b649487d3586a..0c7cbb906542ba4c1d198ad67bb894c7e08e2539 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java @@ -1057,7 +1057,7 @@ public class TestJavaInterop extends TestBase { if (asXXX.equals("as.expression")) { assertEvalFastR(Output.IgnoreErrorContext, CREATE_TRUFFLE_OBJECT + asXXX + "(to);", errorIn(asXXX + "(to)", "no method for coercing this polyglot value to a vector")); } else if (asXXX.equals("as.raw") || asXXX.equals("as.complex")) { - assertEvalFastR(CREATE_TRUFFLE_OBJECT + asXXX + "(to);", errorIn(asXXX + "(to)", "cannot coerce type 'truffleobject' to vector of type '" + type + "'")); + assertEvalFastR(CREATE_TRUFFLE_OBJECT + asXXX + "(to);", errorIn(asXXX + "(to)", "cannot coerce type 'polyglot.value' to vector of type '" + type + "'")); } else { assertEvalFastR(CREATE_TRUFFLE_OBJECT + asXXX + "(to);", errorIn(asXXX + "(to)", "no method for coercing this polyglot value to a vector")); }