Skip to content
Snippets Groups Projects
Commit fc96c256 authored by Tomas Stupka's avatar Tomas Stupka
Browse files

fixed UnsupportedSpecializationException in BinaryBooleanNode if list contains NULL

parent 798c13d2
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.r.nodes.attributes.CopyAttributesNode;
import com.oracle.truffle.r.nodes.attributes.CopyAttributesNodeGen;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
......@@ -45,6 +46,7 @@ import com.oracle.truffle.r.runtime.data.RDoubleVector;
import com.oracle.truffle.r.runtime.data.RIntVector;
import com.oracle.truffle.r.runtime.data.RPairList;
import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RRaw;
import com.oracle.truffle.r.runtime.data.RRawVector;
import com.oracle.truffle.r.runtime.data.RString;
......@@ -174,7 +176,8 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 {
@Specialization(guards = {"isOneList(left, right)"})
protected Object doList(VirtualFrame frame, RAbstractVector left, RAbstractVector right,
@Cached("create()") CastTypeNode cast,
@Cached("createRecursive()") BinaryBooleanNode recursive) {
@Cached("createRecursive()") BinaryBooleanNode recursive,
@Cached("create()") BranchProfile listCoercionErrorBranch) {
Object recursiveLeft = left;
if (isRAbstractListVector(left)) {
if (copyAttributes == null) {
......@@ -182,6 +185,10 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 {
copyAttributes = insert(CopyAttributesNodeGen.create(true));
}
recursiveLeft = castListToAtomic((RAbstractListBaseVector) left, cast, right.getRType(), copyAttributes);
if (recursiveLeft == null) {
listCoercionErrorBranch.enter();
throw RError.error(RError.NO_CALLER, RError.Message.LIST_COERCION, right.getRType().getName());
}
}
Object recursiveRight = right;
if (isRAbstractListVector(right)) {
......@@ -190,6 +197,10 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 {
copyAttributes = insert(CopyAttributesNodeGen.create(true));
}
recursiveRight = castListToAtomic((RAbstractListBaseVector) right, cast, left.getRType(), copyAttributes);
if (recursiveRight == null) {
listCoercionErrorBranch.enter();
throw RError.error(RError.NO_CALLER, RError.Message.LIST_COERCION, left.getRType().getName());
}
}
return recursive.execute(frame, recursiveLeft, recursiveRight);
}
......@@ -200,6 +211,9 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 {
Object store = result.getInternalStore();
for (int i = 0; i < source.getLength(); i++) {
Object value = source.getDataAt(i);
if (value == RNull.instance) {
return null;
}
if (type == RType.Character) {
if (!(value instanceof String)) {
value = RDeparse.deparse(value);
......
......@@ -43348,6 +43348,18 @@ Error in Ops.factor(factor(c("a", "b", "c")), factor(c(1, 2, 3))) :
#{ c(1,2,3,4,5) %in% c(1,2,1,2) }
[1] TRUE TRUE FALSE FALSE FALSE
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testListWithNull#
#{ c(1, 1) < list(1, NULL) }
Error: (list) object cannot be coerced to type 'double'
##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testListWithNull#
#{ list(1, NULL) < c(1, 1) }
Error: (list) object cannot be coerced to type 'double'
##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testListWithNull#
#{ list(NULL) < 1 }
Error: (list) object cannot be coerced to type 'double'
##com.oracle.truffle.r.test.builtins.TestBuiltin_operators.testMatMult#
#{ as.vector(c(1,2,3)) %*% t(as.vector(c(1,2))) }
[,1] [,2]
......@@ -2079,4 +2079,11 @@ public class TestBuiltin_operators extends TestBase {
assertEval("{ l <- list(an=T, bn=F, T, F); l == T }");
assertEval("{ l <- list(an=T, bn=F, T, F); T == l }");
}
@Test
public void testListWithNull() {
assertEval("{ list(NULL) < 1 }");
assertEval("{ list(1, NULL) < c(1, 1) }");
assertEval("{ c(1, 1) < list(1, NULL) }");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment