Skip to content

Commit 4c77ff7

Browse files
committed
Merge commit 'fad3548f2d036fc81b9bccb3d0b557448e56a4d3' into release/graal-vm/1.0
2 parents 1d674b1 + fad3548 commit 4c77ff7

File tree

225 files changed

+22557
-3010
lines changed

Some content is hidden

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

225 files changed

+22557
-3010
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
# 1.0 RC 12
2+
3+
New Features:
4+
5+
* the implementation of the `TruffleLanguage#toString` method uses R function `print`
6+
* for example: the console in Chrome DevTools will print data.frames formatted like R would
7+
8+
Added missing R builtins and C API
9+
10+
* FastR provides GNU-R compatible `parseData` for expressions parsed via `parse(...,keep.source=T)`
11+
* `format.POSIXlt` supports following formats: %z, %Z, %x, %X.
12+
* dummy implementation of the ALTREP framework to avoid linking problems. Most of the functions fail at runtime. #48
13+
14+
Bug fixes:
15+
16+
* `sys.calls` gives wrong result when `eval` with `envir` argument is on the call stack
17+
* `is.na` was not correctly handling lists, for example: `is.na(list(function() 42))`
18+
* transfer `srcref` attribute to the result of `.subset` and `[`
19+
* `matrix(1,nrow=NULL,ncol=NULL)` caused internal FastR error instead of R user level error
20+
* option `--polyglot` works with the native image of FastR
21+
* added native functions optim() and optimness()
22+
* fixed various race conditions in parallel package
23+
* `strsplit(...,perl=T)` does not end up in an infinite loop if the pattern is not found by `pcre_exec`
24+
* `as.character.factor` error for levels containing NAs
25+
* `env2list` error for environments containing pairlists
26+
* `body<-` error for non-scalar values
27+
* `unlink` error for paths containing wildcard(s) but no path separator
28+
* dims attribute errorneously set to RDoubleVector; exception when retrieving the dims #49
29+
* issues with the dplyr's `mutate` and `transmute`: #50 and #51
30+
131
# 1.0 RC 11
232

333
* upgraded the R version to R-3.5.1

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -275,17 +275,19 @@ public Object parseAndEval(Source source, MaterializedFrame frame, boolean print
275275

276276
private List<RSyntaxNode> parseSource(Source source) throws ParseException {
277277
RParserFactory.Parser<RSyntaxNode> parser = RParserFactory.getParser();
278-
return parser.script(source, new RASTBuilder(), context.getLanguage());
278+
return parser.script(source, new RASTBuilder(true), context.getLanguage());
279279
}
280280

281281
@Override
282-
public RExpression parse(Source source) throws ParseException {
283-
List<RSyntaxNode> list = parseSource(source);
284-
Object[] data = new Object[list.size()];
285-
for (int i = 0; i < data.length; i++) {
286-
data[i] = RASTUtils.createLanguageElement(list.get(i));
282+
public ParsedExpression parse(Source source, boolean keepSource) throws ParseException {
283+
RParserFactory.Parser<RSyntaxNode> parser = RParserFactory.getParser();
284+
RASTBuilder builder = new RASTBuilder(true);
285+
List<RSyntaxNode> script = parser.script(source, builder, context.getLanguage());
286+
Object[] data = new Object[script.size()];
287+
for (int i = 0; i < script.size(); i++) {
288+
data[i] = RASTUtils.createLanguageElement(script.get(i));
287289
}
288-
return RDataFactory.createExpression(data);
290+
return new ParsedExpression(RDataFactory.createExpression(data), builder.getParseData());
289291
}
290292

291293
@Override
@@ -387,7 +389,7 @@ private EngineRootNode createRScriptRoot(Source fullSource, MaterializedFrame fr
387389
List<RSyntaxNode> currentStmts = null;
388390
try {
389391
RParserFactory.Parser<RSyntaxNode> parser = RParserFactory.getParser();
390-
currentStmts = parser.statements(src, fullSource, startLine, new RASTBuilder(), context.getLanguage());
392+
currentStmts = parser.statements(src, fullSource, startLine, new RASTBuilder(true), context.getLanguage());
391393
} catch (IncompleteSourceException e) {
392394
lastParseException = e;
393395
if (nextLineInput != null) {

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

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,31 +29,41 @@
2929
import com.oracle.truffle.api.Scope;
3030
import com.oracle.truffle.api.TruffleLanguage;
3131
import com.oracle.truffle.api.frame.Frame;
32+
import com.oracle.truffle.api.frame.MaterializedFrame;
3233
import com.oracle.truffle.api.instrumentation.Instrumenter;
3334
import com.oracle.truffle.api.instrumentation.ProvidedTags;
3435
import com.oracle.truffle.api.instrumentation.StandardTags;
36+
import com.oracle.truffle.api.interop.TruffleObject;
3537
import com.oracle.truffle.api.nodes.ExecutableNode;
3638
import com.oracle.truffle.api.nodes.Node;
3739
import com.oracle.truffle.api.source.Source;
3840
import com.oracle.truffle.api.source.SourceSection;
3941
import com.oracle.truffle.r.engine.interop.RForeignAccessFactoryImpl;
4042
import com.oracle.truffle.r.nodes.RASTBuilder;
4143
import com.oracle.truffle.r.nodes.builtin.RBuiltinPackages;
44+
import com.oracle.truffle.r.nodes.function.PromiseHelperNode;
45+
import com.oracle.truffle.r.nodes.function.RMissingHelper;
4246
import com.oracle.truffle.r.nodes.instrumentation.RSyntaxTags;
4347
import com.oracle.truffle.r.nodes.instrumentation.RSyntaxTags.FunctionBodyBlockTag;
48+
import com.oracle.truffle.r.runtime.ArgumentsSignature;
4449
import com.oracle.truffle.r.runtime.ExitException;
4550
import com.oracle.truffle.r.runtime.FastROptions;
4651
import com.oracle.truffle.r.runtime.RAccuracyInfo;
52+
import com.oracle.truffle.r.runtime.RCaller;
4753
import com.oracle.truffle.r.runtime.RDeparse;
54+
import com.oracle.truffle.r.runtime.RError;
55+
import com.oracle.truffle.r.runtime.RError.Message;
4856
import com.oracle.truffle.r.runtime.RRuntime;
4957
import com.oracle.truffle.r.runtime.RSuicide;
58+
import com.oracle.truffle.r.runtime.conn.StdConnections.ContextStateImpl;
5059
import com.oracle.truffle.r.runtime.context.Engine.IncompleteSourceException;
5160
import com.oracle.truffle.r.runtime.context.Engine.ParseException;
5261
import com.oracle.truffle.r.runtime.context.RContext;
5362
import com.oracle.truffle.r.runtime.context.TruffleRLanguage;
5463
import com.oracle.truffle.r.runtime.data.RFunction;
5564
import com.oracle.truffle.r.runtime.data.RPromise;
5665
import com.oracle.truffle.r.runtime.data.RTypedValue;
66+
import com.oracle.truffle.r.runtime.env.REnvironment;
5767
import com.oracle.truffle.r.runtime.env.RScope;
5868
import com.oracle.truffle.r.runtime.ffi.RFFIFactory;
5969
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
@@ -113,10 +123,9 @@ protected void initializeContext(RContext context) throws Exception {
113123
protected RContext createContext(Env env) {
114124
boolean initialContext = !systemInitialized;
115125
if (initialContext) {
116-
RContext.initializeGlobalState(new RASTBuilder(), new RRuntimeASTAccessImpl(), RBuiltinPackages.getInstance(), new RForeignAccessFactoryImpl());
126+
RContext.initializeGlobalState(new RASTBuilder(false), new RRuntimeASTAccessImpl(), RBuiltinPackages.getInstance(), new RForeignAccessFactoryImpl());
117127
}
118-
RContext result = RContext.create(this, env, env.lookup(Instrumenter.class), initialContext);
119-
return result;
128+
return RContext.create(this, env, env.lookup(Instrumenter.class), initialContext);
120129
}
121130

122131
@Override
@@ -128,19 +137,44 @@ protected void disposeContext(RContext context) {
128137
protected String toString(RContext context, Object value) {
129138
// the debugger also passes result of TruffleRLanguage.findMetaObject() to this method
130139
Object unwrapped = value;
140+
// print promises by other means than the "print" function to avoid evaluating them
131141
if (unwrapped instanceof RPromise) {
132142
RPromise promise = (RPromise) unwrapped;
133-
if (promise.isEvaluated()) {
134-
unwrapped = RRuntime.asAbstractVector(promise.getValue());
143+
if (promise.isEvaluated() || promise.isOptimized()) {
144+
unwrapped = promise.getValue();
145+
} else {
146+
return RDeparse.deparse(unwrapped, RDeparse.MAX_CUTOFF, true, RDeparse.KEEPINTEGER, -1, 1024 * 1024);
135147
}
136148
}
137-
if (unwrapped instanceof String) {
138-
return (String) unwrapped;
149+
// print missing explicitly, because "print" would report missing argument
150+
if (RMissingHelper.isMissing(unwrapped)) {
151+
return "missing";
152+
}
153+
Object asVector = RRuntime.asAbstractVector(unwrapped);
154+
if (!(asVector instanceof TruffleObject)) {
155+
throw RError.error(RError.NO_CALLER, Message.GENERIC, String.format("Printing value of type '%s' is not supported by the R language.", unwrapped.getClass().getSimpleName()));
156+
}
157+
Object printObj = REnvironment.baseEnv(context).get("print");
158+
if (printObj instanceof RPromise) {
159+
printObj = PromiseHelperNode.evaluateSlowPath((RPromise) printObj);
139160
}
140-
if (unwrapped instanceof RTypedValue) {
141-
return RDeparse.deparse(unwrapped, RDeparse.MAX_CUTOFF, true, RDeparse.KEEPINTEGER, -1, 1024 * 1024);
161+
if (!(printObj instanceof RFunction)) {
162+
throw RError.error(RError.NO_CALLER, Message.GENERIC, "Cannot retrieve the 'print' function from the base package.");
163+
}
164+
MaterializedFrame callingFrame = REnvironment.globalEnv(context).getFrame();
165+
ContextStateImpl stateStdConnections = context.stateStdConnections;
166+
try {
167+
StringBuilder buffer = new StringBuilder();
168+
stateStdConnections.setBuffer(buffer);
169+
RContext.getEngine().evalFunction((RFunction) printObj, callingFrame, RCaller.topLevel, false, ArgumentsSignature.empty(1), asVector);
170+
// remove the last "\n", which is useful for REPL, but not here
171+
if (buffer.charAt(buffer.length() - 1) == '\n') {
172+
buffer.setLength(buffer.length() - 1);
173+
}
174+
return buffer.toString();
175+
} finally {
176+
stateStdConnections.resetBuffer();
142177
}
143-
return RRuntime.toString(unwrapped);
144178
}
145179

146180
@Override

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,18 @@ public RootNode get() {
484484

485485
private static final class Check extends RootNode {
486486

487+
private final ConditionProfile profile = ConditionProfile.createBinaryProfile();
488+
487489
Check() {
488490
super(null);
489491
}
490492

491493
@Override
492494
public Object execute(VirtualFrame frame) {
493495
final Object receiver = ForeignAccess.getReceiver(frame);
494-
return receiver instanceof RAbstractAtomicVector && !(receiver instanceof RScalar);
496+
return profile.profile(receiver instanceof RAbstractAtomicVector && !(receiver instanceof RScalar));
495497
}
498+
496499
}
500+
497501
}

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RInteropNAMR.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,4 +44,5 @@ protected static boolean test(TruffleObject receiver) {
4444
return receiver instanceof RInteropNA;
4545
}
4646
}
47+
4748
}

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -72,7 +72,7 @@ public class REmbedded {
7272
private static void initializeR(String[] args, boolean initMainLoop) {
7373
assert context == null;
7474
RContext.setEmbedded();
75-
RCmdOptions options = RCmdOptions.parseArguments(RCmdOptions.Client.R, args, false);
75+
RCmdOptions options = RCmdOptions.parseArguments(args, false);
7676

7777
EmbeddedConsoleHandler embeddedConsoleHandler = new EmbeddedConsoleHandler();
7878

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
import com.oracle.truffle.r.runtime.data.RUnboundValue;
9999
import com.oracle.truffle.r.runtime.data.RVector;
100100
import com.oracle.truffle.r.runtime.data.model.RAbstractAtomicVector;
101-
import com.oracle.truffle.r.runtime.data.model.RAbstractListVector;
102101
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
103102
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
104103
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
@@ -552,12 +551,7 @@ public void SETLENGTH(Object x, int l) {
552551

553552
@Override
554553
public void SET_TRUELENGTH(Object x, int l) {
555-
if (x instanceof CharSXPWrapper) {
556-
((CharSXPWrapper) x).setTruelength(l);
557-
return;
558-
}
559-
RAbstractVector vec = (RAbstractVector) RRuntime.asAbstractVector(x);
560-
vec.setTrueLength(l);
554+
throw implementedAsNode();
561555
}
562556

563557
@Override
@@ -619,18 +613,7 @@ public Object STRING_ELT(Object x, long i) {
619613

620614
@Override
621615
public Object VECTOR_ELT(Object x, long i) {
622-
Object vec = x;
623-
if (vec instanceof RExpression) {
624-
return ((RExpression) vec).getDataAt((int) i);
625-
}
626-
RAbstractListVector list = guaranteeInstanceOf(RRuntime.asAbstractVector(vec), RAbstractListVector.class);
627-
if (list.getLength() == i) {
628-
// Some packages abuse that there seems to be no bounds checking and the
629-
// one-after-the-last element returns NULL, which they use to find out if they reached
630-
// the end of the list...
631-
return RNull.instance;
632-
}
633-
return list.getDataAt((int) i);
616+
throw implementedAsNode();
634617
}
635618

636619
@Override
@@ -1116,7 +1099,7 @@ public Object R_ParseVector(Object text, int n, Object srcFile) {
11161099
Object[] resultData = new Object[2];
11171100
try {
11181101
Source source = RSource.fromTextInternal(textString, RSource.Internal.R_PARSEVECTOR);
1119-
RExpression exprs = RContext.getEngine().parse(source);
1102+
RExpression exprs = RContext.getEngine().parse(source, false).getExpression();
11201103
resultData[0] = RDataFactory.createIntVectorFromScalar(ParseStatus.PARSE_OK.ordinal());
11211104
resultData[1] = exprs;
11221105
} catch (IncompleteSourceException ex) {
@@ -1404,9 +1387,8 @@ public Object R_ExternalPtrProtected(Object x) {
14041387
}
14051388

14061389
@Override
1407-
public void R_SetExternalPtrAddr(Object x, long addr) {
1408-
RExternalPtr p = guaranteeInstanceOf(x, RExternalPtr.class);
1409-
p.setAddr(new SymbolHandle(addr));
1390+
public void R_SetExternalPtrAddr(Object x, Object addr) {
1391+
throw implementedAsNode();
14101392
}
14111393

14121394
@Override
@@ -1558,7 +1540,7 @@ public Object R_MethodsNamespace() {
15581540
@TruffleBoundary
15591541
public void R_PreserveObject(Object obj) {
15601542
guaranteeInstanceOf(obj, RObject.class);
1561-
IdentityHashMap<RObject, AtomicInteger> preserveList = getContext().preserveList;
1543+
IdentityHashMap<RObject, AtomicInteger> preserveList = getContext().rffiContextState.preserveList;
15621544
AtomicInteger prevCnt = preserveList.putIfAbsent((RObject) obj, new AtomicInteger(1));
15631545
if (prevCnt != null) {
15641546
prevCnt.incrementAndGet();
@@ -1570,7 +1552,7 @@ public void R_PreserveObject(Object obj) {
15701552
public void R_ReleaseObject(Object obj) {
15711553
guaranteeInstanceOf(obj, RObject.class);
15721554
RFFIContext context = getContext();
1573-
IdentityHashMap<RObject, AtomicInteger> preserveList = context.preserveList;
1555+
IdentityHashMap<RObject, AtomicInteger> preserveList = context.rffiContextState.preserveList;
15741556
AtomicInteger atomicInteger = preserveList.get(obj);
15751557
if (atomicInteger != null) {
15761558
int decrementAndGet = atomicInteger.decrementAndGet();
@@ -1587,15 +1569,15 @@ public void R_ReleaseObject(Object obj) {
15871569
@Override
15881570
@TruffleBoundary
15891571
public Object Rf_protect(Object x) {
1590-
getContext().protectStack.add(guaranteeInstanceOf(x, RObject.class));
1572+
getContext().rffiContextState.protectStack.add(guaranteeInstanceOf(x, RObject.class));
15911573
return x;
15921574
}
15931575

15941576
@Override
15951577
@TruffleBoundary
15961578
public void Rf_unprotect(int x) {
15971579
RFFIContext context = getContext();
1598-
ArrayList<RObject> stack = context.protectStack;
1580+
ArrayList<RObject> stack = context.rffiContextState.protectStack;
15991581
for (int i = 0; i < x; i++) {
16001582
context.registerReferenceUsedInNative(stack.remove(stack.size() - 1));
16011583
}
@@ -1604,23 +1586,23 @@ public void Rf_unprotect(int x) {
16041586
@Override
16051587
@TruffleBoundary
16061588
public int R_ProtectWithIndex(Object x) {
1607-
ArrayList<RObject> stack = getContext().protectStack;
1589+
ArrayList<RObject> stack = getContext().rffiContextState.protectStack;
16081590
stack.add(guaranteeInstanceOf(x, RObject.class));
16091591
return stack.size() - 1;
16101592
}
16111593

16121594
@Override
16131595
@TruffleBoundary
16141596
public void R_Reprotect(Object x, int y) {
1615-
ArrayList<RObject> stack = getContext().protectStack;
1597+
ArrayList<RObject> stack = getContext().rffiContextState.protectStack;
16161598
stack.set(y, guaranteeInstanceOf(x, RObject.class));
16171599
}
16181600

16191601
@Override
16201602
@TruffleBoundary
16211603
public void Rf_unprotect_ptr(Object x) {
16221604
RFFIContext context = getContext();
1623-
ArrayList<RObject> stack = context.protectStack;
1605+
ArrayList<RObject> stack = context.rffiContextState.protectStack;
16241606
for (int i = stack.size() - 1; i >= 0; i--) {
16251607
if (stack.get(i) == x) {
16261608
context.registerReferenceUsedInNative(stack.remove(i));

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/HandleLLVMUpCallExceptionNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,9 @@
2424

2525
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2626
import com.oracle.truffle.api.nodes.Node;
27-
import com.oracle.truffle.r.runtime.ffi.CallRFFI.HandleUpCallExceptionNode;
27+
import com.oracle.truffle.r.ffi.impl.upcalls.UpCallsRFFI;
2828

29-
public class HandleLLVMUpCallExceptionNode extends Node implements HandleUpCallExceptionNode {
29+
public class HandleLLVMUpCallExceptionNode extends Node implements UpCallsRFFI.HandleUpCallExceptionNode {
3030
@Override
3131
@TruffleBoundary
3232
public void execute(Throwable ex) {

0 commit comments

Comments
 (0)