diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java index 52adbf3a11dea8a445eb6363720156f718f2a1e5..1d6e7c0216b1f24f7c0f5b7e558329c11e8bba30 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java @@ -45,8 +45,6 @@ import com.oracle.truffle.r.nodes.builtin.base.foreign.ForeignFunctions; import com.oracle.truffle.r.nodes.builtin.base.foreign.ForeignFunctionsFactory; import com.oracle.truffle.r.nodes.builtin.fastr.FastRCallCounting; import com.oracle.truffle.r.nodes.builtin.fastr.FastRCallCountingFactory; -import com.oracle.truffle.r.nodes.builtin.fastr.FastRCompile; -import com.oracle.truffle.r.nodes.builtin.fastr.FastRCompileNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRContext; import com.oracle.truffle.r.nodes.builtin.fastr.FastRContextFactory; import com.oracle.truffle.r.nodes.builtin.fastr.FastRDebug; @@ -277,7 +275,6 @@ public class BasePackage extends RBuiltinPackage { add(Expression.class, ExpressionNodeGen::create); add(FastRCallCounting.CreateCallCounter.class, FastRCallCountingFactory.CreateCallCounterNodeGen::create); add(FastRCallCounting.GetCallCounter.class, FastRCallCountingFactory.GetCallCounterNodeGen::create); - add(FastRCompile.class, FastRCompileNodeGen::create); add(FastRContext.CloseChannel.class, FastRContextFactory.CloseChannelNodeGen::create); add(FastRContext.Create.class, FastRContextFactory.CreateNodeGen::create); add(FastRContext.CreateChannel.class, FastRContextFactory.CreateChannelNodeGen::create); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRCompile.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRCompile.java deleted file mode 100644 index 5b8b725e6e32e02c83676aca334a22d06e3c60b2..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRCompile.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2013, 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.nodes.builtin.fastr; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.concurrent.Future; - -import com.oracle.truffle.api.CallTarget; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.runtime.RBuiltin; -import com.oracle.truffle.r.runtime.RBuiltinKind; -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.data.RFunction; -import com.oracle.truffle.r.runtime.data.RMissing; - -@RBuiltin(name = ".fastr.compile", kind = RBuiltinKind.PRIMITIVE, parameterNames = {"func", "background"}) -public abstract class FastRCompile extends RBuiltinNode { - - private static final class Compiler { - private final Class<?> optimizedCallTarget; - private final Class<?> graalTruffleRuntime; - private final Method submitForCompilationMethod; - private final Method finishCompilationMethod; - - private Compiler() { - try { - optimizedCallTarget = Class.forName("com.oracle.graal.truffle.OptimizedCallTarget", false, Truffle.getRuntime().getClass().getClassLoader()); - graalTruffleRuntime = Class.forName("com.oracle.graal.truffle.GraalTruffleRuntime", false, Truffle.getRuntime().getClass().getClassLoader()); - submitForCompilationMethod = graalTruffleRuntime.getDeclaredMethod("submitForCompilation", optimizedCallTarget); - finishCompilationMethod = graalTruffleRuntime.getDeclaredMethod("finishCompilation", optimizedCallTarget, Future.class, boolean.class); - } catch (ClassNotFoundException | IllegalArgumentException | NoSuchMethodException | SecurityException e) { - throw Utils.fail("fastr.compile: failed to find 'compile' method"); - } - } - - static Compiler getCompiler() { - if (System.getProperty("fastr.truffle.compile", "true").equals("true") && Truffle.getRuntime().getName().contains("Graal")) { - return new Compiler(); - } else { - return null; - } - } - - boolean compile(CallTarget callTarget, boolean background) throws InvocationTargetException, IllegalAccessException { - if (optimizedCallTarget.isInstance(callTarget)) { - Future<?> submitted = (Future<?>) submitForCompilationMethod.invoke(Truffle.getRuntime(), callTarget); - finishCompilationMethod.invoke(Truffle.getRuntime(), callTarget, submitted, background); - return true; - } else { - return false; - } - } - } - - private static final Compiler compiler = Compiler.getCompiler(); - - @Override - public Object[] getDefaultParameterValues() { - return new Object[]{RMissing.instance, RRuntime.LOGICAL_FALSE}; - } - - @Specialization - protected byte compileFunction(RFunction function, byte background) { - controlVisibility(); - if (compiler != null) { - try { - if (compiler.compile(function.getTarget(), background == RRuntime.LOGICAL_TRUE)) { - return RRuntime.LOGICAL_TRUE; - } - } catch (InvocationTargetException | IllegalAccessException e) { - throw RError.error(this, RError.Message.GENERIC, e.toString()); - } - } else { - throw RError.error(this, RError.Message.GENERIC, "fastr.compile not supported in this environment"); - } - return RRuntime.LOGICAL_FALSE; - } - - @SuppressWarnings("unused") - @Fallback - protected Object fallback(Object a1, Object a2) { - throw RError.error(this, RError.Message.INVALID_OR_UNIMPLEMENTED_ARGUMENTS); - } -} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java index d7383de899da867de3a815ae9a7c125849030626..1418ab39e90504bb45fd8867c7bec30ed9562d02 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java @@ -170,7 +170,7 @@ public class TraceHandling { if (!disabled()) { int depth = RArguments.getDepth(frame); try { - for (int i = 0; i < depth; i++) { + for (int i = 0; i < depth - 1; i++) { outputHandler.writeString(" ", false); } String callString = getCallSource(frame); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java index 54d84b5f5407537fca68ece6be99ee43face700d..da6c3c3242a5235a27cb6416132d5626e25bf949 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java @@ -437,8 +437,6 @@ public final class RASTBuilder implements RCodeBuilder<RSyntaxNode> { @Override public RSyntaxNode constant(SourceSection source, Object value) { - assert value instanceof Byte || value instanceof Integer || value instanceof Double || value instanceof RComplex || value instanceof String || value instanceof RNull || - value instanceof REmpty || value instanceof RSymbol || value instanceof RAbstractVector || value instanceof RFunction : value.getClass(); if (value instanceof String && !RRuntime.isNA((String) value)) { return ConstantNode.create(source, ((String) value).intern()); } else { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java index 598e597811d5c1bac3ed67fc399fb53f6702befd..093c75a0a7bb3d22d77c450bedb03e80695fb3d6 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java @@ -80,12 +80,25 @@ public enum FastROptions { public boolean getBooleanValue() { assert isBoolean; - return (Boolean) value; + if (value instanceof Boolean) { + return (Boolean) value; + } else { + System.out.println("boolean option value expected with " + name() + " - forgot +/- ?"); + System.exit(2); + return false; + } + } public String getStringValue() { assert !isBoolean; - return (String) value; + if (value == null || value instanceof String) { + return (String) value; + } else { + System.out.println("string option value expected with " + name()); + System.exit(2); + return ""; + } } private static FastROptions[] VALUES = values(); 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 be36e61f8d8844183a60d73bd9911547f991b278..9804e42bacde3c0ce7462627471866f6b82744e7 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 @@ -106354,6 +106354,110 @@ debug at #4: t exiting from: f(5) [1] 6 +##com.oracle.truffle.r.test.library.utils.TestTrace.testCondTrace +#f <- function(x) {}; (if (exists('.fastr.trace')) .fastr.trace else trace)(f, tracer=quote(if (x == 3 || x == 7) print(x))); g <- function() for (i in 1:10) f(i); g() +[1] "f" +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +[1] 3 +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +[1] 7 +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry + +##com.oracle.truffle.r.test.library.utils.TestTrace.testCondTrace +#f <- function(x) {}; trace(f, tracer=quote(if (x == 3 || x == 7) print(x))); g <- function() for (i in 1:10) f(i); g() +[1] "f" +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +[1] 3 +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry +[1] 7 +Tracing f(i) on entry +Tracing f(i) on entry +Tracing f(i) on entry + +##com.oracle.truffle.r.test.library.utils.TestTrace.testMultiTrace +#f <- function(x) {}; (if (exists('.fastr.trace')) .fastr.trace else trace)(f, tracer=quote(print(x))); g <- function() for (i in 1:10) f(i); g() +[1] "f" +Tracing f(i) on entry +[1] 1 +Tracing f(i) on entry +[1] 2 +Tracing f(i) on entry +[1] 3 +Tracing f(i) on entry +[1] 4 +Tracing f(i) on entry +[1] 5 +Tracing f(i) on entry +[1] 6 +Tracing f(i) on entry +[1] 7 +Tracing f(i) on entry +[1] 8 +Tracing f(i) on entry +[1] 9 +Tracing f(i) on entry +[1] 10 + +##com.oracle.truffle.r.test.library.utils.TestTrace.testMultiTrace +#f <- function(x) {}; trace(f, tracer=quote(print(x))); g <- function() for (i in 1:10) f(i); g() +[1] "f" +Tracing f(i) on entry +[1] 1 +Tracing f(i) on entry +[1] 2 +Tracing f(i) on entry +[1] 3 +Tracing f(i) on entry +[1] 4 +Tracing f(i) on entry +[1] 5 +Tracing f(i) on entry +[1] 6 +Tracing f(i) on entry +[1] 7 +Tracing f(i) on entry +[1] 8 +Tracing f(i) on entry +[1] 9 +Tracing f(i) on entry +[1] 10 + +##com.oracle.truffle.r.test.library.utils.TestTrace.testSimple +#f <- function(x) {}; (if (exists('.fastr.trace')) .fastr.trace else trace)(f); f() +trace: f() +NULL + +##com.oracle.truffle.r.test.library.utils.TestTrace.testSimple +#f <- function(x) {}; trace(f); f() +trace: f() +NULL + +##com.oracle.truffle.r.test.library.utils.TestTrace.testSimpleTrace +#f <- function(x) {}; (if (exists('.fastr.trace')) .fastr.trace else trace)(f, tracer=quote(print(x))); f(100) +[1] "f" +Tracing f(100) on entry +[1] 100 +NULL + +##com.oracle.truffle.r.test.library.utils.TestTrace.testSimpleTrace +#f <- function(x) {}; trace(f, tracer=quote(print(x))); f(100) +[1] "f" +Tracing f(100) on entry +[1] 100 +NULL + ##com.oracle.truffle.r.test.library.utils.TestUtils.testHeadNTail #{head(letters)} [1] "a" "b" "c" "d" "e" "f" diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/utils/TestTrace.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/utils/TestTrace.java new file mode 100644 index 0000000000000000000000000000000000000000..5a09217420b34d17cd213b0a9538913e0936e053 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/utils/TestTrace.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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.library.utils; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +public class TestTrace extends TestBase { + private static final String FASTR_TRACE = "(if (exists('.fastr.trace')) .fastr.trace else trace)"; + private static final String PLAIN_TRACE = "trace"; + private static final String[] TRACE_VARIANTS = new String[]{PLAIN_TRACE, FASTR_TRACE}; + + @Test + public void testSimple() { + assertEval(template("f <- function(x) {}; %0(f); f()", TRACE_VARIANTS)); + } + + @Test + public void testSimpleTrace() { + assertEval(template("f <- function(x) {}; %0(f, tracer=quote(print(x))); f(100)", TRACE_VARIANTS)); + } + + @Test + public void testMultiTrace() { + assertEval(template("f <- function(x) {}; %0(f, tracer=quote(print(x))); g <- function() for (i in 1:10) f(i); g()", TRACE_VARIANTS)); + } + + @Test + public void testCondTrace() { + assertEval(template("f <- function(x) {}; %0(f, tracer=quote(if (x == 3 || x == 7) print(x))); g <- function() for (i in 1:10) f(i); g()", TRACE_VARIANTS)); + } + +}