diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRContext.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRContext.java index afe6563893bb3378fd0cad02e00a5fc4316aa962..de95794b29df7c8fab0b73edfcef5d5aaf1ddec3 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRContext.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRContext.java @@ -40,12 +40,10 @@ import com.oracle.truffle.api.vm.PolyglotEngine; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RChannel; -import com.oracle.truffle.r.runtime.RCmdOptions; import com.oracle.truffle.r.runtime.RCmdOptions.Client; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RSource; -import com.oracle.truffle.r.runtime.RStartParams; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.context.ContextInfo; import com.oracle.truffle.r.runtime.context.RContext; @@ -295,9 +293,7 @@ public class FastRContext { } private static ContextInfo createContextInfo(RContext.ContextKind contextKind) { - RStartParams startParams = new RStartParams(RCmdOptions.parseArguments(Client.RSCRIPT, EMPTY, false), false); - ContextInfo info = ContextInfo.create(startParams, null, contextKind, RContext.getInstance(), RContext.getInstance().getConsoleHandler()); - return info; + return ContextInfo.createNoRestore(Client.RSCRIPT, null, contextKind, RContext.getInstance(), RContext.getInstance().getConsoleHandler()); } @RBuiltin(name = ".fastr.channel.create", kind = PRIMITIVE, parameterNames = {"key"}, behavior = COMPLEX) diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java index 781156ff27b2b2ae3d7d66fc72940b0d0c19f42a..80eac3a8cb051298b12c601ef57f862a35238c62 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, 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 @@ -28,6 +28,8 @@ import java.util.concurrent.atomic.AtomicInteger; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.vm.PolyglotEngine; +import com.oracle.truffle.r.runtime.RCmdOptions; +import com.oracle.truffle.r.runtime.RCmdOptions.Client; import com.oracle.truffle.r.runtime.RStartParams; import com.oracle.truffle.r.runtime.context.RContext.ContextKind; @@ -98,6 +100,21 @@ public final class ContextInfo implements TruffleObject { return create(startParams, env, kind, parent, consoleHandler, TimeZone.getDefault()); } + /** + * Create a context configuration object such that FastR does not restore previously stored + * sessions on startup. + * + * @param env TODO + * @param kind defines the degree to which this context shares base and package environments + * with its parent + * @param parent if non-null {@code null}, the parent creating the context + * @param consoleHandler a {@link ConsoleHandler} for output + */ + public static ContextInfo createNoRestore(Client client, String[] env, ContextKind kind, RContext parent, ConsoleHandler consoleHandler) { + RStartParams params = new RStartParams(RCmdOptions.parseArguments(client, new String[]{"--no-restore"}, false), false); + return create(params, env, kind, parent, consoleHandler); + } + public static ContextInfo getContextInfo(PolyglotEngine vm) { return (ContextInfo) vm.findGlobalSymbol(ContextInfo.GLOBAL_SYMBOL).get(); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java index 22e721f0d76898a79b42ec0ac576392ec3949b50..36710352d1f4c42523d13b44bc9907903cbc7c6e 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java @@ -448,13 +448,15 @@ public final class RContext extends ExecutionContext implements TruffleObject { if (initialInfo == null) { /* * This implies that FastR is being invoked initially from another Truffle language and - * not via RCommand/RscriptCommand. + * not via RCommand/RscriptCommand. In this case, we also assume that no previously + * stored session should be restored. */ - this.info = ContextInfo.create(new RStartParams(RCmdOptions.parseArguments(Client.R, new String[0], false), false), null, + this.info = ContextInfo.create(new RStartParams(RCmdOptions.parseArguments(Client.R, new String[]{"--no-restore"}, false), false), null, ContextKind.SHARE_NOTHING, null, new DefaultConsoleHandler(env.in(), env.out())); } else { this.info = initialInfo; } + this.initial = isInitial; this.env = env; this.stateREnvVars = REnvVars.newContextState(); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java index cbc3b17563ffd31b4c45dc886852c5b05d273ad0..9cc6074db227a50b6d0c63322a786944de7dedfe 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java @@ -156,7 +156,7 @@ public final class FastRSession implements RSession { } public ContextInfo createContextInfo(ContextKind contextKind) { - RStartParams params = new RStartParams(RCmdOptions.parseArguments(Client.RSCRIPT, new String[0], false), false); + RStartParams params = new RStartParams(RCmdOptions.parseArguments(Client.RSCRIPT, new String[]{"--no-restore"}, false), false); return ContextInfo.create(params, null, contextKind, mainContext, consoleHandler, TimeZone.getTimeZone("GMT")); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java index 3601a1216d95331d537b24c89cb3a1132a7c0d4f..5771c2814c844a5c8bc20b1fcc0a35393c59b397 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/GnuROneShotRSession.java @@ -46,7 +46,7 @@ import com.oracle.truffle.r.test.TestBase; */ public class GnuROneShotRSession implements RSession { - private static final String[] GNUR_COMMANDLINE = new String[]{"<R>", "--vanilla", "--slave", "--silent"}; + private static final String[] GNUR_COMMANDLINE = new String[]{"<R>", "--vanilla", "--slave", "--silent", "--no-restore"}; private static final String FASTR_TESTGEN_GNUR = "FASTR_TESTGEN_GNUR"; private static final String NATIVE_PROJECT = "com.oracle.truffle.r.native"; private static final int DEFAULT_TIMEOUT_MINS = 5; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRDebugTest.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRDebugTest.java index a9575f0c0777b680a44efaf2b6b1533a212ef4ea..0016b0ebc3e6108885c8411d5277b69fa1d4109f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRDebugTest.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRDebugTest.java @@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; import java.util.LinkedList; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.After; import org.junit.Assert; @@ -48,6 +48,11 @@ import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.vm.PolyglotEngine; import com.oracle.truffle.api.vm.PolyglotEngine.Value; import com.oracle.truffle.r.runtime.RSource; +import com.oracle.truffle.r.runtime.RCmdOptions.Client; +import com.oracle.truffle.r.runtime.context.ConsoleHandler; +import com.oracle.truffle.r.runtime.context.ContextInfo; +import com.oracle.truffle.r.runtime.context.DefaultConsoleHandler; +import com.oracle.truffle.r.runtime.context.RContext.ContextKind; import com.oracle.truffle.r.runtime.data.RPromise.EagerPromiseBase; public class FastRDebugTest { @@ -64,7 +69,9 @@ public class FastRDebugTest { public void before() { suspendedEvent = null; - engine = PolyglotEngine.newBuilder().setOut(out).setErr(err).build(); + ConsoleHandler consoleHandler = new DefaultConsoleHandler(System.in, out); + ContextInfo info = ContextInfo.createNoRestore(Client.R, null, ContextKind.SHARE_NOTHING, null, consoleHandler); + engine = info.createVM(PolyglotEngine.newBuilder().setOut(out).setErr(err)); debugger = Debugger.find(engine); debuggerSession = debugger.startSession(event -> { suspendedEvent = event; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java index 29c8ec9c317b0c17b0e369be5c82d641b65340a9..1d79ee857fc804394e83d3bd71097fbca34f8cbd 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/tck/FastRTckTest.java @@ -29,13 +29,19 @@ import org.junit.Test; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.vm.PolyglotEngine; import com.oracle.truffle.api.vm.PolyglotEngine.Builder; +import com.oracle.truffle.r.runtime.RCmdOptions.Client; import com.oracle.truffle.r.runtime.RSource; +import com.oracle.truffle.r.runtime.context.ConsoleHandler; +import com.oracle.truffle.r.runtime.context.ContextInfo; +import com.oracle.truffle.r.runtime.context.RContext.ContextKind; +import com.oracle.truffle.r.test.generate.FastRSession.TestConsoleHandler; import com.oracle.truffle.tck.TruffleTCK; public class FastRTckTest extends TruffleTCK { @Test public void testVerifyPresence() { - PolyglotEngine vm = PolyglotEngine.newBuilder().build(); + PolyglotEngine vm = PolyglotEngine.newBuilder().globalSymbol(ContextInfo.GLOBAL_SYMBOL, + null).build(); assertTrue("Our language is present", vm.getLanguages().containsKey("text/x-r")); } @@ -154,7 +160,9 @@ public class FastRTckTest extends TruffleTCK { @Override protected PolyglotEngine prepareVM(Builder builder) throws Exception { - PolyglotEngine vm = builder.build(); + ConsoleHandler consoleHandler = new TestConsoleHandler(); + ContextInfo info = ContextInfo.createNoRestore(Client.R, null, ContextKind.SHARE_NOTHING, null, consoleHandler); + PolyglotEngine vm = info.createVM(builder); vm.eval(INITIALIZATION); return vm; }