Skip to content

Commit ee11fce

Browse files
committed
[GR-5611] Changes to FastR as required by data.table (mostly bug fixes of FastR found from intergrating data.table).
PullRequest: fastr/1800
2 parents a04629e + df5a7e9 commit ee11fce

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
import com.oracle.truffle.r.runtime.data.RTypedValue;
9797
import com.oracle.truffle.r.runtime.data.RUnboundValue;
9898
import com.oracle.truffle.r.runtime.data.RVector;
99+
import com.oracle.truffle.r.runtime.data.model.RAbstractAtomicVector;
100+
import com.oracle.truffle.r.runtime.data.model.RAbstractListBaseVector;
99101
import com.oracle.truffle.r.runtime.data.model.RAbstractListVector;
100102
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
101103
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
@@ -739,7 +741,7 @@ public Object PRINTNAME(Object x) {
739741
return x;
740742
}
741743
guaranteeInstanceOf(x, RSymbol.class);
742-
return CharSXPWrapper.create(((RSymbol) x).getName());
744+
return ((RSymbol) x).getWrappedName();
743745
}
744746

745747
@Override
@@ -2410,8 +2412,12 @@ public Object LOGICAL(Object x) {
24102412
}
24112413

24122414
@Override
2415+
@TruffleBoundary
24132416
public Object REAL(Object x) {
2414-
return VectorRFFIWrapper.get(guaranteeVectorOrNull(x, RDoubleVector.class));
2417+
if ((x instanceof RAbstractStringVector) || (x instanceof RAbstractListBaseVector)) {
2418+
RFFIUtils.unimplemented("REAL is being called for type " + Utils.getTypeName(x));
2419+
}
2420+
return VectorRFFIWrapper.get(guaranteeVectorOrNull(x, RAbstractAtomicVector.class));
24152421
}
24162422

24172423
@Override

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public interface StdUpCallsRFFI {
203203
/**
204204
* WARNING: argument order reversed from Rf_findVarInFrame!
205205
*/
206-
Object Rf_findVar(Object symbolArg, Object envArg);
206+
Object Rf_findVar(Object symbolArg, @RFFIResultOwner Object envArg);
207207

208208
Object Rf_findVarInFrame(@RFFIResultOwner Object envArg, Object symbolArg);
209209

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ private RSyntaxNode createCall(SourceSection source, RSyntaxNode lhs, List<Argum
132132
// switch the args if needed
133133
RSyntaxNode lhsArg = args.get(switchArgs ? 1 : 0).value;
134134
RSyntaxNode rhsArg = args.get(switchArgs ? 0 : 1).value;
135-
return new ReplacementDispatchNode(source, lhsLookup, lhsArg, rhsArg, isSuper, context.getReplacementVarsStartIndex());
135+
String lhsName = args.get(0).name;
136+
String rhsName = args.get(1).name;
137+
ArgumentsSignature names;
138+
if (lhsName == null && rhsName == null) {
139+
names = ArgumentsSignature.empty(2);
140+
} else {
141+
names = ArgumentsSignature.get(lhsName, rhsName);
142+
}
143+
return new ReplacementDispatchNode(source, lhsLookup, lhsArg, rhsArg, isSuper, context.getReplacementVarsStartIndex(), names);
136144
}
137145
} else if (args.size() == 3) {
138146
switch (symbol) {

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementDispatchNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ public final class ReplacementDispatchNode extends OperatorNode {
6161

6262
private final boolean isSuper;
6363
private final int tempNamesStartIndex;
64+
private final ArgumentsSignature names;
6465

65-
public ReplacementDispatchNode(SourceSection src, RSyntaxLookup operator, RSyntaxNode lhs, RSyntaxNode rhs, boolean isSuper, int tempNamesStartIndex) {
66+
public ReplacementDispatchNode(SourceSection src, RSyntaxLookup operator, RSyntaxNode lhs, RSyntaxNode rhs, boolean isSuper, int tempNamesStartIndex, ArgumentsSignature names) {
6667
super(src, operator);
6768
assert lhs != null && rhs != null;
6869
this.lhs = lhs.asRNode();
6970
this.rhs = rhs.asRNode();
7071
this.isSuper = isSuper;
7172
this.tempNamesStartIndex = tempNamesStartIndex;
73+
this.names = names;
7274
}
7375

7476
@Override
@@ -123,7 +125,7 @@ private RNode createWriteVariableNode(RSyntaxNode lhsSyntax) {
123125

124126
@Override
125127
public ArgumentsSignature getSyntaxSignature() {
126-
return ArgumentsSignature.empty(2);
128+
return names;
127129
}
128130

129131
@Override

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static RNode createFunctionUpdate(SourceSection source, RSyntaxNode newL
154154
newArgs[1] = builder.lookup(oldArgs[1].getLazySourceSection(), ((RSyntaxLookup) oldArgs[1]).getIdentifier() + "<-", true);
155155
newSyntaxLHS = RCallSpecialNode.createCall(callLHS.getLazySourceSection(), builder.process(callLHS.getSyntaxLHS(), codeBuilderContext).asRNode(), callLHS.getSyntaxSignature(), newArgs);
156156
}
157-
return RCallSpecialNode.createCallInReplace(source, newSyntaxLHS.asRNode(), ArgumentsSignature.get(names), argNodes, 0, argNodes.length - 1).asRNode();
157+
return RCallSpecialNode.createCallInReplace(source, newSyntaxLHS.asRNode(), ArgumentsSignature.get(names), argNodes, argNodes.length - 1).asRNode();
158158
}
159159

160160
static RPairList getLanguage(WriteVariableNode wvn) {
@@ -169,11 +169,11 @@ private static RSyntaxNode createLookup(SourceSection source, String idenifier)
169169
return RContext.getASTBuilder().lookup(source, idenifier, false);
170170
}
171171

172-
private static RNode createReplacementTarget(RSyntaxLookup variable, boolean isSuper, boolean localPeek) {
172+
private static RNode createReplacementTarget(RSyntaxLookup variable, boolean isSuper, boolean isSpecial) {
173173
if (isSuper) {
174174
return ReadVariableNode.wrap(variable.getLazySourceSection(), ReadVariableNode.createSuperLookup(variable.getIdentifier())).asRNode();
175175
} else {
176-
return localPeek ? new PeekLocalVariableNode(variable.getIdentifier())
176+
return isSpecial ? new PeekLocalVariableNode(variable.getIdentifier())
177177
: ReadVariableNode.wrap(variable.getLazySourceSection(), ReadVariableNode.create(variable.getIdentifier(), true)).asRNode();
178178
}
179179
}

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/helpers/MaterializeNode.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,12 @@ protected Object doGeneric(Object o) {
9898
}
9999

100100
private RList materializeContents(RList list) {
101-
boolean changed = false;
102-
RList materializedContents = null;
103101
for (int i = 0; i < list.getLength(); i++) {
104102
Object element = list.getDataAt(i);
105103
Object materializedElem = doGenericSlowPath(element);
106104
if (materializedElem != element) {
107-
materializedContents = (RList) list.copy();
108-
changed = true;
105+
list.setDataAt(i, materializedElem);
109106
}
110-
if (changed && materializedElem != element) {
111-
materializedContents.setDataAt(i, materializedElem);
112-
}
113-
}
114-
if (changed) {
115-
return materializedContents;
116107
}
117108
return list;
118109
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ public final class RSymbol extends RAttributeStorage {
4747

4848
public static final RSymbol MISSING = RDataFactory.createSymbol("");
4949

50-
private final String name;
5150
private CharSXPWrapper nameWrapper;
5251

5352
private RSymbol(String name) {
54-
this.name = name;
53+
this.nameWrapper = CharSXPWrapper.createInterned(name);
5554
}
5655

5756
@TruffleBoundary
@@ -70,13 +69,10 @@ public RType getRType() {
7069
}
7170

7271
public String getName() {
73-
return name;
72+
return nameWrapper.getContents();
7473
}
7574

7675
public CharSXPWrapper getWrappedName() {
77-
if (nameWrapper == null) {
78-
nameWrapper = CharSXPWrapper.createInterned(name);
79-
}
8076
return nameWrapper;
8177
}
8278

@@ -99,7 +95,7 @@ public boolean equals(Object obj) {
9995
if (obj == this) {
10096
return true;
10197
} else if (obj instanceof RSymbol) {
102-
return ((RSymbol) obj).getName() == this.name;
98+
return ((RSymbol) obj).getName() == this.nameWrapper.getContents();
10399
}
104100
return false;
105101
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nodes/RSyntaxLookup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ default boolean isPromiseLookup() {
8282
* section.
8383
*/
8484
static RSyntaxLookup createDummyLookup(SourceSection source, String identifier, boolean isFunctionLookup) {
85+
assert Utils.isInterned(identifier);
8586
return new RSyntaxLookup() {
8687
@Override
8788
public SourceSection getLazySourceSection() {

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77254,6 +77254,10 @@ Error in substitute(1, NA) : invalid environment specified
7725477254
#substitute(1, list(list(1)))
7725577255
[1] 1
7725677256

77257+
##com.oracle.truffle.r.test.builtins.TestBuiltin_substitute.testSubstitute#
77258+
#substitute(`:=`(a=3,b=3))
77259+
`:=`(a = 3, b = 3)
77260+
7725777261
##com.oracle.truffle.r.test.builtins.TestBuiltin_substitute.testSubstitute#
7725877262
#substitute(expr=1, env=1)
7725977263
Error in substitute(expr = 1, env = 1) : invalid environment specified

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_substitute.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ public void testSubstitute() {
150150
assertEval("{ foo <- function(...) bar(3+2); bar <- function(...) { list(...); substitute(list(...)); }; foo(1+2); }");
151151

152152
assertEval("typeof(substitute())");
153+
assertEval("substitute(`:=`(a=3,b=3))");
153154
}
154155
}

0 commit comments

Comments
 (0)