Skip to content

Commit dd18d93

Browse files
committed
[GR-11189] Upgrade R to 3.5.1.
PullRequest: fastr/1853
2 parents f848d2b + 4faf190 commit dd18d93

File tree

186 files changed

+7605
-2902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+7605
-2902
lines changed

3rd_party_licenses.txt

Lines changed: 1620 additions & 68 deletions
Large diffs are not rendered by default.

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
*/
2323
package com.oracle.truffle.r.engine;
2424

25-
import java.io.BufferedReader;
26-
import java.io.IOException;
27-
import java.net.URI;
28-
import java.util.ArrayList;
29-
import java.util.Arrays;
30-
import java.util.List;
31-
import java.util.stream.Collectors;
32-
3325
import com.oracle.truffle.api.CallTarget;
3426
import com.oracle.truffle.api.CompilerAsserts;
3527
import com.oracle.truffle.api.CompilerDirectives;
@@ -63,6 +55,7 @@
6355
import com.oracle.truffle.r.nodes.function.RCallerHelper;
6456
import com.oracle.truffle.r.nodes.function.call.CallRFunctionNode;
6557
import com.oracle.truffle.r.nodes.function.opt.ShareObjectNode;
58+
import com.oracle.truffle.r.nodes.function.opt.UnShareObjectNode;
6659
import com.oracle.truffle.r.nodes.function.visibility.GetVisibilityNode;
6760
import com.oracle.truffle.r.nodes.function.visibility.SetVisibilityNode;
6861
import com.oracle.truffle.r.nodes.instrumentation.RInstrumentation;
@@ -103,6 +96,14 @@
10396
import com.oracle.truffle.r.runtime.nodes.RNode;
10497
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
10598

99+
import java.io.BufferedReader;
100+
import java.io.IOException;
101+
import java.net.URI;
102+
import java.util.ArrayList;
103+
import java.util.Arrays;
104+
import java.util.List;
105+
import java.util.stream.Collectors;
106+
106107
/**
107108
* The engine for the FastR implementation. Handles parsing and evaluation. There is one instance of
108109
* this class per {@link RContext}.
@@ -672,7 +673,7 @@ private static void printValue(RContext ctx, MaterializedFrame callingFrame, Obj
672673
RFunction function = (RFunction) evaluatePromise(printMethod);
673674
CallRFunctionNode.executeSlowpath(function, RCaller.createInvalid(callingFrame), callingFrame, new Object[]{resultValue, RArgsValuesAndNames.EMPTY}, null);
674675
}
675-
ShareObjectNode.unshare(resultValue);
676+
UnShareObjectNode.unshare(resultValue);
676677
} else {
677678
// this supports printing of non-R values (via toString for now)
678679
String str;

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,20 +352,20 @@ public boolean disableDebug(RFunction func) {
352352
}
353353

354354
@Override
355-
public Object rcommandMain(String[] args, String[] env, boolean intern) {
355+
public Object rcommandMain(String[] args, String[] env, boolean intern, int timeoutSecs) {
356356
IORedirect redirect = handleIORedirect(args, intern);
357357
assert env == null : "re-enable env arguments";
358-
int result = RMain.runR(redirect.args, redirect.in, redirect.out, redirect.err);
358+
int result = RMain.runR(redirect.args, redirect.in, redirect.out, redirect.err, timeoutSecs);
359359
return redirect.getInternResult(result);
360360
}
361361

362362
@Override
363-
public Object rscriptMain(String[] args, String[] env, boolean intern) {
363+
public Object rscriptMain(String[] args, String[] env, boolean intern, int timeoutSecs) {
364364
IORedirect redirect = handleIORedirect(args, intern);
365365
// TODO argument parsing can fail with ExitException, which needs to be handled correctly in
366366
// nested context
367367
assert env == null : "re-enable env arguments";
368-
int result = RMain.runRscript(redirect.args, redirect.in, redirect.out, redirect.err);
368+
int result = RMain.runRscript(redirect.args, redirect.in, redirect.out, redirect.err, timeoutSecs);
369369
return redirect.getInternResult(result);
370370
}
371371

com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/REPL.java

Lines changed: 123 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.io.EOFException;
2626
import java.io.File;
2727
import java.io.FileInputStream;
28+
import java.io.FileOutputStream;
29+
import java.io.FileWriter;
2830
import java.io.IOException;
2931
import java.io.OutputStream;
3032
import java.util.ArrayList;
@@ -77,11 +79,13 @@ public static int readEvalPrint(Context context, ConsoleHandler consoleHandler,
7779
*/
7880
public static int readEvalPrint(Context context, ConsoleHandler consoleHandler, File srcFile, boolean useExecutor, OutputStream errStream) {
7981
final ExecutorService executor;
82+
final EventLoopThread eventLoopThread;
8083
if (useExecutor) {
8184
executor = context.eval(GET_EXECUTOR).asHostObject();
82-
initializeNativeEventLoop(context, executor);
85+
eventLoopThread = initializeNativeEventLoop(context, executor);
8386
} else {
8487
executor = null;
88+
eventLoopThread = null;
8589
}
8690
run(executor, () -> context.eval(SET_CONSOLE_PROMPT_HANDLER).execute(consoleHandler.getPolyglotWrapper()));
8791
int lastStatus = 0;
@@ -178,6 +182,117 @@ public static int readEvalPrint(Context context, ConsoleHandler consoleHandler,
178182
System.err.println("Unexpected error in REPL");
179183
ex.printStackTrace();
180184
return 1;
185+
} finally {
186+
if (eventLoopThread != null) {
187+
eventLoopThread.stopLoop();
188+
}
189+
190+
traceEventLoopLogger.close();
191+
}
192+
}
193+
194+
/**
195+
* This is a temporary class facilitating catching an occasional hanging attributed to the
196+
* native event loop mechanism.
197+
*/
198+
static class SimpleTraceEventLoopLogger {
199+
private FileWriter traceEventLoopLogWriter;
200+
private long timestamp = System.currentTimeMillis();
201+
202+
{
203+
try {
204+
if ("true".equalsIgnoreCase(System.getenv("TRACE_EVENT_LOOP"))) {
205+
traceEventLoopLogWriter = new FileWriter("traceEventLoop.log", true);
206+
}
207+
} catch (IOException e) {
208+
}
209+
}
210+
211+
void log(String msg) {
212+
if (traceEventLoopLogWriter != null) {
213+
try {
214+
traceEventLoopLogWriter.append(String.format("DEBUG[%d]: traceEventLoop: %s\n", timestamp, msg));
215+
traceEventLoopLogWriter.flush();
216+
} catch (IOException e) {
217+
}
218+
}
219+
}
220+
221+
void close() {
222+
if (traceEventLoopLogWriter != null) {
223+
try {
224+
traceEventLoopLogWriter.close();
225+
} catch (IOException e) {
226+
}
227+
}
228+
}
229+
}
230+
231+
private static SimpleTraceEventLoopLogger traceEventLoopLogger = new SimpleTraceEventLoopLogger();
232+
233+
static class EventLoopThread extends Thread {
234+
235+
private final File fifoInFile;
236+
private final File fifoOutFile;
237+
private final Context context;
238+
private final ExecutorService executor;
239+
240+
EventLoopThread(String fifoInPath, String fifoOutPath, Context context, ExecutorService executor) {
241+
this.fifoInFile = new File(fifoInPath);
242+
this.fifoOutFile = new File(fifoOutPath);
243+
this.context = context;
244+
this.executor = executor;
245+
}
246+
247+
void stopLoop() {
248+
try {
249+
interrupt();
250+
final FileOutputStream fis = new FileOutputStream(fifoInFile);
251+
fis.write(66);
252+
fis.flush();
253+
fis.close();
254+
join(8000);
255+
} catch (Exception e) {
256+
e.printStackTrace();
257+
}
258+
}
259+
260+
void releaseFifoOut() {
261+
try {
262+
final FileOutputStream fis = new FileOutputStream(fifoOutFile);
263+
fis.write(65);
264+
fis.flush();
265+
fis.close();
266+
} catch (Exception e) {
267+
e.printStackTrace();
268+
}
269+
}
270+
271+
@Override
272+
public void run() {
273+
while (!isInterrupted()) {
274+
try {
275+
final FileInputStream fis = new FileInputStream(fifoInFile);
276+
fis.read();
277+
if (isInterrupted()) {
278+
break;
279+
}
280+
fis.close();
281+
} catch (IOException e) {
282+
e.printStackTrace();
283+
}
284+
executor.submit(() -> {
285+
traceEventLoopLogger.log("before dispatching request");
286+
try {
287+
int res = context.eval(Source.newBuilder("R", ".fastr.dispatchNativeHandlers", "<dispatch-native-handlers>").internal(true).buildLiteral()).execute().asInt();
288+
traceEventLoopLogger.log("after dispatching request, res=" + res);
289+
} catch (Throwable ex) {
290+
releaseFifoOut();
291+
traceEventLoopLogger.log("error in dispatching request");
292+
ex.printStackTrace();
293+
}
294+
});
295+
}
181296
}
182297
}
183298

@@ -229,37 +344,24 @@ public static void printPolyglotStackTrace(PolyglotException e, OutputStream out
229344
*
230345
* @param context
231346
* @param executor
347+
* @return the event loop thread
232348
*/
233-
private static void initializeNativeEventLoop(Context context, final ExecutorService executor) {
349+
private static EventLoopThread initializeNativeEventLoop(Context context, final ExecutorService executor) {
234350
Source initEventLoopSource = Source.newBuilder("R", ".fastr.initEventLoop", "<init-event-loop>").internal(true).buildLiteral();
235351
Value result = context.eval(initEventLoopSource).execute();
236352
if (result.isNull()) {
237-
return; // event loop is not configured to be run
353+
return null; // event loop is not configured to be run
238354
} else if (result.getMember("result").asInt() != 0) {
239355
// TODO: it breaks pkgtest when parsing output
240356
// System.err.println("WARNING: Native event loop unavailable. Error code: " +
241357
// result.getMember("result").asInt());
358+
return null;
242359
} else {
243360
final String fifoInPath = result.getMember("fifoInPath").asString();
244-
Thread t = new Thread() {
245-
@Override
246-
public void run() {
247-
final File fifoFile = new File(fifoInPath);
248-
while (!Thread.currentThread().isInterrupted()) {
249-
try {
250-
final FileInputStream fis = new FileInputStream(fifoFile);
251-
fis.read();
252-
fis.close();
253-
} catch (IOException e) {
254-
e.printStackTrace();
255-
}
256-
executor.submit(() -> {
257-
context.eval(Source.newBuilder("R", ".fastr.dispatchNativeHandlers", "<dispatch-native-handlers>").internal(true).buildLiteral()).execute().asInt();
258-
});
259-
}
260-
}
261-
};
361+
final String fifoOutPath = result.getMember("fifoOutPath").asString();
362+
EventLoopThread t = new EventLoopThread(fifoInPath, fifoOutPath, context, executor);
262363
t.start();
364+
return t;
263365
}
264366
}
265367

com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RMain.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ public static void main(String[] args) {
5353
new RMain().launch(args);
5454
}
5555

56-
public static int runR(String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream) {
57-
return runROrRScript("R", args, inStream, outStream, errStream);
56+
public static int runR(String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream, int timeoutSecs) {
57+
return runROrRScript("R", args, inStream, outStream, errStream, timeoutSecs);
5858
}
5959

60-
public static int runRscript(String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream) {
61-
return runROrRScript("Rscript", args, inStream, outStream, errStream);
60+
public static int runRscript(String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream, int timeoutSecs) {
61+
return runROrRScript("Rscript", args, inStream, outStream, errStream, timeoutSecs);
6262
}
6363

64-
private static int runROrRScript(String command, String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream) {
64+
private static int runROrRScript(String command, String[] args, InputStream inStream, OutputStream outStream, OutputStream errStream, int timeoutSecs) {
6565
String[] newArgs = new String[args.length + 1];
6666
System.arraycopy(args, 0, newArgs, 1, args.length);
6767
newArgs[0] = command;
68-
try (RMain cmd = new RMain(false, inStream, outStream, errStream)) {
68+
try (RMain cmd = new RMain(false, inStream, outStream, errStream, timeoutSecs)) {
6969
cmd.launch(newArgs);
7070
return cmd.execute();
7171
}
@@ -82,6 +82,7 @@ private static int runROrRScript(String command, String[] args, InputStream inSt
8282
protected final InputStream inStream;
8383
protected final OutputStream outStream;
8484
protected final OutputStream errStream;
85+
protected final int timeoutSecs;
8586

8687
/**
8788
* In launcher mode {@link #launch(String[])} runs the command and uses {@link System#exit(int)}
@@ -98,18 +99,20 @@ private static int runROrRScript(String command, String[] args, InputStream inSt
9899
private boolean useJVM;
99100
private Context preparedContext; // to transfer between launch and execute when !launcherMode
100101

101-
private RMain(boolean launcherMode, InputStream inStream, OutputStream outStream, OutputStream errStream) {
102+
private RMain(boolean launcherMode, InputStream inStream, OutputStream outStream, OutputStream errStream, int timeoutSecs) {
102103
this.launcherMode = launcherMode;
103104
this.inStream = inStream;
104105
this.outStream = outStream;
105106
this.errStream = errStream;
107+
this.timeoutSecs = timeoutSecs;
106108
}
107109

108110
private RMain() {
109111
this.launcherMode = true;
110112
this.inStream = System.in;
111113
this.outStream = System.out;
112114
this.errStream = System.err;
115+
this.timeoutSecs = 0;
113116
}
114117

115118
@Override
@@ -194,8 +197,6 @@ protected void launch(Builder contextBuilder) {
194197
}
195198

196199
this.consoleHandler.setContext(context);
197-
Source src = Source.newBuilder("R", ".fastr.set.consoleHandler", "<set-console-handler>").internal(true).buildLiteral();
198-
context.eval(src).execute(consoleHandler.getPolyglotWrapper());
199200
if (launcherMode) {
200201
try {
201202
System.exit(execute(context));

com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RVersionNumber.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
*/
3333
public class RVersionNumber {
3434
public static final String MAJOR = "3";
35-
public static final String MINOR = "4";
36-
public static final String PATCH = "0";
35+
public static final String MINOR = "5";
36+
public static final String PATCH = "1";
3737

38-
public static final int R_VERSION = (3 << 16) + (4 << 8) + 0;
38+
public static final int R_VERSION = (3 << 16) + (5 << 8) + 1;
3939

4040
public static final String MAJOR_MINOR = MAJOR + "." + MINOR;
4141
public static final String MINOR_PATCH = MINOR + "." + PATCH;
4242
public static final String FULL = MAJOR + "." + MINOR + "." + PATCH;
4343
public static final String R_HYPHEN_FULL = "R-" + FULL;
4444

45-
public static final String RELEASE_YEAR = "2017";
46-
public static final String RELEASE_MONTH = "04";
47-
public static final String RELEASE_DAY = "21";
45+
public static final String RELEASE_YEAR = "2018";
46+
public static final String RELEASE_MONTH = "07";
47+
public static final String RELEASE_DAY = "02";
4848

4949
public static final String RELEASE_DATE = " (" + RELEASE_YEAR + "-" + RELEASE_MONTH + "-" + RELEASE_DAY + ")";
5050

@@ -53,7 +53,7 @@ public class RVersionNumber {
5353
/**
5454
* From {@code Rinternals.h} and {@code library.R}.
5555
*/
56-
public static final String INTERNALS_UID = "0310d4b8-ccb1-4bb8-ba94-d36a55f60262";
56+
public static final String INTERNALS_UID = "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327";
5757

5858
public static void main(String[] args) {
5959
System.out.printf("R version %s", FULL);

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/TypeConvert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public RBaseNode getErrorContext() {
7272

7373
private static boolean isNA(String s, RAbstractStringVector naStrings) {
7474
// naStrings are in addition to NA_character_
75-
if (RRuntime.isNA(s)) {
75+
if (RRuntime.isNA(s) || s.isEmpty()) { // Blank treated as NA too
7676
return true;
7777
}
7878
for (int i = 0; i < naStrings.getLength(); i++) {

com.oracle.truffle.r.native/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export TOPDIR = $(CURDIR)
2727
export FASTR_R_HOME=$(abspath $(TOPDIR)/..)
2828
export FASTR_LIB_DIR=$(FASTR_R_HOME)/lib
2929
export FASTR_NATIVE_DIR = $(TOPDIR)
30-
export R_VERSION = 3.4.0
30+
export R_VERSION = 3.5.1
3131
export DEFAULT_CRAN_MIRROR = "https://mran.microsoft.com/snapshot/2018-11-18"
3232
export GNUR_HOME = $(TOPDIR)/gnur/patch-build
3333

0 commit comments

Comments
 (0)