Skip to content

Commit 1ada1e5

Browse files
zslajchrtsteve-s
authored andcommitted
Miscelaneous fixes
(cherry picked from commit 935bba9)
1 parent 3d0a8ad commit 1ada1e5

File tree

13 files changed

+74
-34
lines changed

13 files changed

+74
-34
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static final class TruffleLLVMInitNode extends RNGNode implements InitNo
6464
@Override
6565
public void execute(VirtualFrame frame, int seed) {
6666
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
67-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.LLVM);
67+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.LLVM);
6868
try {
6969
userFunctionInterop.execute(userFunctionTarget, seed);
7070
} catch (InteropException ex) {
@@ -84,7 +84,7 @@ private static final class TruffleLLVM_RandNode extends RNGNode implements RandN
8484
@Override
8585
public double execute(VirtualFrame frame) {
8686
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
87-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.LLVM);
87+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.LLVM);
8888
try {
8989
Object address = userFunctionInterop.execute(userFunctionTarget);
9090
return (double) readPointerInterop.execute(readPointerTarget, address);
@@ -105,7 +105,7 @@ private static final class TruffleLLVM_NSeedNode extends RNGNode implements NSee
105105
@Override
106106
public int execute(VirtualFrame frame) {
107107
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
108-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.LLVM);
108+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.LLVM);
109109
try {
110110
Object address = userFunctionInterop.execute(userFunctionTarget);
111111
return (int) readPointerInterop.execute(readPointerTarget, address);
@@ -126,7 +126,7 @@ private static final class TruffleLLVM_SeedsNode extends RNGNode implements Seed
126126
@Override
127127
public void execute(VirtualFrame frame, int[] n) {
128128
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
129-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.LLVM);
129+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.LLVM);
130130
try {
131131
Object address = userFunctionInterop.execute(userFunctionTarget);
132132
for (int i = 0; i < n.length; i++) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/mixed/TruffleMixed_Context.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package com.oracle.truffle.r.ffi.impl.mixed;
2424

25-
import com.oracle.truffle.api.frame.VirtualFrame;
25+
import com.oracle.truffle.api.frame.MaterializedFrame;
2626
import com.oracle.truffle.api.interop.TruffleObject;
2727
import com.oracle.truffle.r.ffi.impl.llvm.TruffleLLVM_Context;
2828
import com.oracle.truffle.r.ffi.impl.llvm.TruffleLLVM_DLL.LLVM_Handle;
@@ -137,7 +137,7 @@ public void afterUpcall(boolean canRunGc, Type rffiType) {
137137
}
138138

139139
@Override
140-
public Object beforeDowncall(VirtualFrame frame, Type rffiType) {
140+
public Object beforeDowncall(MaterializedFrame frame, Type rffiType) {
141141
Type actualRffiType = rffiType == null ? Type.LLVM : rffiType;
142142
assert rffiType != null;
143143
switch (rffiType) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.oracle.truffle.api.CompilerDirectives;
3636
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3737
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
38-
import com.oracle.truffle.api.frame.VirtualFrame;
38+
import com.oracle.truffle.api.frame.MaterializedFrame;
3939
import com.oracle.truffle.api.interop.InteropException;
4040
import com.oracle.truffle.api.interop.InteropLibrary;
4141
import com.oracle.truffle.api.interop.TruffleObject;
@@ -399,7 +399,7 @@ public void beforeDispose(RContext context) {
399399
}
400400

401401
@Override
402-
public Object beforeDowncall(VirtualFrame frame, RFFIFactory.Type rffiType) {
402+
public Object beforeDowncall(MaterializedFrame frame, RFFIFactory.Type rffiType) {
403403
Object tokenFromSuper = super.beforeDowncall(frame, RFFIFactory.Type.NFI);
404404
transientAllocations.push(new ArrayList<>());
405405
if (hasAccessLock) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_UserRng.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static final class TruffleNFI_InitNode extends RNGNode implements InitNo
6363
@Override
6464
public void execute(VirtualFrame frame, int seed) {
6565
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
66-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.NFI);
66+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.NFI);
6767
try {
6868
userFunctionInterop.execute(userFunctionTarget, seed);
6969
} catch (InteropException ex) {
@@ -83,7 +83,7 @@ private static final class TruffleNFI_RandNode extends RNGNode implements RandNo
8383
@Override
8484
public double execute(VirtualFrame frame) {
8585
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
86-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.NFI);
86+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.NFI);
8787
try {
8888
Object address = userFunctionInterop.execute(userFunctionTarget);
8989
return (double) readPointerInterop.execute(readPointerTarget, address);
@@ -104,7 +104,7 @@ private static final class TruffleNFI_NSeedNode extends RNGNode implements NSeed
104104
@Override
105105
public int execute(VirtualFrame frame) {
106106
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
107-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.NFI);
107+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.NFI);
108108
try {
109109
Object address = userFunctionInterop.execute(userFunctionTarget);
110110
return (int) readPointerInterop.execute(readPointerTarget, address);
@@ -125,7 +125,7 @@ private static final class TruffleNFI_SeedsNode extends RNGNode implements Seeds
125125
@Override
126126
public void execute(VirtualFrame frame, int[] n) {
127127
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
128-
Object before = stateRFFI.beforeDowncall(frame, RFFIFactory.Type.NFI);
128+
Object before = stateRFFI.beforeDowncall(frame.materialize(), RFFIFactory.Type.NFI);
129129
try {
130130
Object address = userFunctionInterop.execute(userFunctionTarget);
131131
for (int i = 0; i < n.length; i++) {

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RForceAndCallNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private static RArgsValuesAndNames createArgsAndNames(List<Object> argValues, RA
180180
}
181181

182182
private void flattenFirstArgs(VirtualFrame frame, int n, RArgsValuesAndNames args, PromiseHelperNode promiseHelper) {
183+
// In GnuR there appears to be no error checks on n > args.length
183184
if (args.getLength() < n) {
184185
CompilerDirectives.transferToInterpreter();
185186
throw RError.nyi(this, "forceAndCall with insufficient arguments");

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
import com.oracle.truffle.r.nodes.attributes.SetFixedAttributeNode;
5050
import com.oracle.truffle.r.nodes.builtin.NodeWithArgumentCasts.Casts;
5151
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
52-
import com.oracle.truffle.r.runtime.RError;
5352
import com.oracle.truffle.r.runtime.Collections.ArrayListObj;
53+
import com.oracle.truffle.r.runtime.RError;
5454
import com.oracle.truffle.r.runtime.RError.Message;
5555
import com.oracle.truffle.r.runtime.RInternalError;
5656
import com.oracle.truffle.r.runtime.RRuntime;
@@ -1977,6 +1977,9 @@ private static RIntVector convertFirstMatchedRangeToRIndex(HaystackDescriptor ha
19771977
protected Object grepFixedNoInvert(RRawVector pattern, RRawVector x, int offset, @SuppressWarnings("unused") Object ignoreCase, @SuppressWarnings("unused") boolean fixed, boolean value,
19781978
boolean all,
19791979
@SuppressWarnings("unused") boolean invert) {
1980+
if (x.getLength() == 0) {
1981+
return RDataFactory.createEmptyIntVector();
1982+
}
19801983
HaystackDescriptor haystackDescriptor = null;
19811984
if (all) {
19821985
haystackDescriptor = findAllOccurrences(pattern, x, offset);
@@ -2011,6 +2014,9 @@ protected Object grepFixedNoInvert(RRawVector pattern, RRawVector x, int offset,
20112014
protected Object grepFixedInvert(RRawVector pattern, RRawVector x, int offset, @SuppressWarnings("unused") Object ignoreCase, @SuppressWarnings("unused") boolean fixed,
20122015
@SuppressWarnings("unused") boolean value, boolean all,
20132016
@SuppressWarnings("unused") boolean invert) {
2017+
if (x.getLength() == 0) {
2018+
return RDataFactory.createEmptyIntVector();
2019+
}
20142020
HaystackDescriptor haystackDescriptor = null;
20152021
if (all) {
20162022
haystackDescriptor = findAllOccurrences(pattern, x, offset);
@@ -2029,6 +2035,9 @@ protected Object grepFixedInvert(RRawVector pattern, RRawVector x, int offset, @
20292035
protected Object grepFixedIgnoreInvert(RRawVector pattern, RRawVector x, int offset, @SuppressWarnings("unused") Object ignoreCase, boolean fixed, boolean value, boolean all,
20302036
boolean invert) {
20312037
warning(Message.ARGUMENT_IGNORED, "invert = TRUE");
2038+
if (x.getLength() == 0) {
2039+
return RDataFactory.createEmptyIntVector();
2040+
}
20322041
return grepFixedNoInvert(pattern, x, offset, ignoreCase, fixed, value, all, invert);
20332042
}
20342043

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/FortranAndCFunctions.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import java.util.Arrays;
2727

2828
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
29+
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
2930
import com.oracle.truffle.api.dsl.Cached;
31+
import com.oracle.truffle.api.dsl.CachedContext;
3032
import com.oracle.truffle.api.dsl.Fallback;
3133
import com.oracle.truffle.api.dsl.Specialization;
3234
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -42,6 +44,8 @@
4244
import com.oracle.truffle.r.runtime.RError;
4345
import com.oracle.truffle.r.runtime.RRuntime;
4446
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
47+
import com.oracle.truffle.r.runtime.context.RContext;
48+
import com.oracle.truffle.r.runtime.context.TruffleRLanguage;
4549
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
4650
import com.oracle.truffle.r.runtime.data.RAttributable;
4751
import com.oracle.truffle.r.runtime.data.RDataFactory;
@@ -109,7 +113,8 @@ protected Object doFortran(VirtualFrame frame, RList symbol, RArgsValuesAndNames
109113
protected RList doFortran(VirtualFrame frame, RList symbol, RArgsValuesAndNames args, byte naok, byte dup, @SuppressWarnings("unused") Object rPackage,
110114
@SuppressWarnings("unused") RMissing encoding,
111115
@Cached("new()") ExtractNativeCallInfoNode extractSymbolInfo,
112-
@Cached("createBinaryProfile()") ConditionProfile registeredProfile) {
116+
@Cached("createBinaryProfile()") ConditionProfile registeredProfile,
117+
@CachedContext(TruffleRLanguage.class) ContextReference<RContext> ctxRef) {
113118
NativeCallInfo nativeCallInfo = extractSymbolInfo.execute(symbol);
114119
if (registeredProfile.profile(isRegisteredRFunction(nativeCallInfo))) {
115120
if (explicitCall == null) {
@@ -120,14 +125,15 @@ protected RList doFortran(VirtualFrame frame, RList symbol, RArgsValuesAndNames
120125
Object result = explicitCall.call(frame, function, args);
121126
return RDataFactory.createList(new Object[]{result});
122127
} else {
123-
return invokeCNode.dispatch(frame, nativeCallInfo, naok, dup, args);
128+
return invokeCNode.dispatch(frame, nativeCallInfo, naok, dup, args, ctxRef.get());
124129
}
125130
}
126131

127132
@Specialization
128133
protected RList doFortran(VirtualFrame frame, RAbstractStringVector symbol, RArgsValuesAndNames args, byte naok, byte dup, Object rPackage, @SuppressWarnings("unused") RMissing encoding,
129134
@Cached("create()") DLL.RFindSymbolNode findSymbolNode,
130-
@Cached("createBinaryProfile()") ConditionProfile registeredProfile) {
135+
@Cached("createBinaryProfile()") ConditionProfile registeredProfile,
136+
@CachedContext(TruffleRLanguage.class) ContextReference<RContext> ctxRef) {
131137
String libName = LookupAdapter.checkPackageArg(rPackage);
132138
DLL.RegisteredNativeSymbol rns = new DLL.RegisteredNativeSymbol(DLL.NativeSymbolType.Fortran, null, null);
133139
DLL.SymbolHandle func = findSymbolNode.execute(symbol.getDataAt(0), libName, rns);
@@ -143,7 +149,7 @@ protected RList doFortran(VirtualFrame frame, RAbstractStringVector symbol, RArg
143149
Object result = explicitCall.call(frame, function, args);
144150
return RDataFactory.createList(new Object[]{result});
145151
} else {
146-
return invokeCNode.dispatch(frame, new NativeCallInfo(symbol.getDataAt(0), func, rns.getDllInfo()), naok, dup, args);
152+
return invokeCNode.dispatch(frame, new NativeCallInfo(symbol.getDataAt(0), func, rns.getDllInfo()), naok, dup, args, ctxRef.get());
147153
}
148154
}
149155

@@ -212,7 +218,8 @@ public abstract static class DotC extends CRFFIAdapter {
212218
@Specialization
213219
protected RList c(VirtualFrame frame, RList symbol, RArgsValuesAndNames args, byte naok, byte dup, @SuppressWarnings("unused") Object rPackage, @SuppressWarnings("unused") RMissing encoding,
214220
@Cached("new()") ExtractNativeCallInfoNode extractSymbolInfo,
215-
@Cached("createBinaryProfile()") ConditionProfile registeredProfile) {
221+
@Cached("createBinaryProfile()") ConditionProfile registeredProfile,
222+
@CachedContext(TruffleRLanguage.class) ContextReference<RContext> ctxRef) {
216223
NativeCallInfo nativeCallInfo = extractSymbolInfo.execute(symbol);
217224
if (registeredProfile.profile(isRegisteredRFunction(nativeCallInfo))) {
218225
if (explicitCall == null) {
@@ -223,14 +230,15 @@ protected RList c(VirtualFrame frame, RList symbol, RArgsValuesAndNames args, by
223230
Object result = explicitCall.call(frame, function, args);
224231
return RDataFactory.createList(new Object[]{result});
225232
} else {
226-
return invokeCNode.dispatch(frame, nativeCallInfo, naok, dup, args);
233+
return invokeCNode.dispatch(frame, nativeCallInfo, naok, dup, args, ctxRef.get());
227234
}
228235
}
229236

230237
@Specialization
231238
protected RList c(VirtualFrame frame, RAbstractStringVector symbol, RArgsValuesAndNames args, byte naok, byte dup, Object rPackage, @SuppressWarnings("unused") RMissing encoding,
232239
@Cached("create()") DLL.RFindSymbolNode findSymbolNode,
233-
@Cached("createBinaryProfile()") ConditionProfile registeredProfile) {
240+
@Cached("createBinaryProfile()") ConditionProfile registeredProfile,
241+
@CachedContext(TruffleRLanguage.class) ContextReference<RContext> ctxRef) {
234242
String libName = null;
235243
if (!(rPackage instanceof RMissing)) {
236244
libName = RRuntime.asString(rPackage);
@@ -253,7 +261,7 @@ protected RList c(VirtualFrame frame, RAbstractStringVector symbol, RArgsValuesA
253261
Object result = explicitCall.call(frame, function, args);
254262
return RDataFactory.createList(new Object[]{result});
255263
} else {
256-
return invokeCNode.dispatch(frame, new NativeCallInfo(symbol.getDataAt(0), func, rns.getDllInfo()), naok, dup, args);
264+
return invokeCNode.dispatch(frame, new NativeCallInfo(symbol.getDataAt(0), func, rns.getDllInfo()), naok, dup, args, ctxRef.get());
257265
}
258266
}
259267

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RInteropNA.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,28 @@ public class RInteropNA implements RTruffleObject {
3737
public static final RInteropNA INT = new RInteropNA(RRuntime.INT_NA);
3838
public static final RInteropNA DOUBLE = new RInteropNA(RRuntime.DOUBLE_NA);
3939
public static final RInteropNA STRING = new RInteropNA(RRuntime.STRING_NA);
40-
public static final RInteropNA LOGICAL = new RInteropNA(RRuntime.LOGICAL_NA);
40+
public static final RInteropNA LOGICAL = new RInteropNA(RRuntime.LOGICAL_NA, RRuntime.INT_NA);
4141

4242
private final Object value;
43+
private final Object nativeValue;
4344

4445
protected RInteropNA(Object value) {
46+
this(value, value);
47+
}
48+
49+
protected RInteropNA(Object value, Object nativeValue) {
4550
this.value = value;
51+
this.nativeValue = nativeValue;
4652
}
4753

4854
public Object getValue() {
4955
return value;
5056
}
5157

58+
public Object getNativeValue() {
59+
return nativeValue;
60+
}
61+
5262
@SuppressWarnings("static-method")
5363
@ExportMessage
5464
boolean isNull() {
@@ -74,5 +84,4 @@ public int hashCode() {
7484
return getValue().hashCode();
7585
}
7686
}
77-
7887
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/CallRFFI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ default Object dispatch(VirtualFrame frame, NativeCallInfo nativeCallInfo, Objec
4242
DLLInfo dllInfo = nativeCallInfo.dllInfo;
4343
LibHandle handle = dllInfo == null ? null : dllInfo.handle;
4444
Type rffiType = handle == null ? stateRFFI.getDefaultRFFIType() : handle.getRFFIType();
45-
Object before = stateRFFI.beforeDowncall(frame, rffiType);
45+
Object before = stateRFFI.beforeDowncall(frame == null ? null : frame.materialize(), rffiType);
4646
try {
4747
return execute(nativeCallInfo, args);
4848
} finally {
@@ -61,7 +61,7 @@ default Object dispatch(VirtualFrame frame, NativeCallInfo nativeCallInfo, Objec
6161
interface InvokeVoidCallNode extends NodeInterface {
6262
default void dispatch(VirtualFrame frame, NativeCallInfo nativeCallInfo, Object[] args) {
6363
RFFIContext stateRFFI = RContext.getInstance().getStateRFFI();
64-
Object before = stateRFFI.beforeDowncall(frame, nativeCallInfo.dllInfo.handle.getRFFIType());
64+
Object before = stateRFFI.beforeDowncall(frame == null ? null : frame.materialize(), nativeCallInfo.dllInfo.handle.getRFFIType());
6565
try {
6666
execute(frame, nativeCallInfo, args);
6767
} finally {

0 commit comments

Comments
 (0)