From 1f8713c1b17afb8143f2ebb0b88c54721e1ab6c5 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Tue, 21 Nov 2017 16:42:44 +0100
Subject: [PATCH] remove unnecessary implicit Raw/Complex casts from RTypes and
 ensure wrapping of scalar vectors in FFIWrapNode

---
 .../r/ffi/impl/upcalls/FFIWrapNode.java       |  7 +++-
 .../oracle/truffle/r/runtime/data/RTypes.java | 40 -------------------
 2 files changed, 6 insertions(+), 41 deletions(-)

diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java
index 6c7e397ee8..2693615f50 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FFIWrapNode.java
@@ -36,6 +36,7 @@ import com.oracle.truffle.r.runtime.data.RLogical;
 import com.oracle.truffle.r.runtime.data.RObject;
 import com.oracle.truffle.r.runtime.data.RRaw;
 import com.oracle.truffle.r.runtime.data.RScalarList;
+import com.oracle.truffle.r.runtime.data.RScalarVector;
 import com.oracle.truffle.r.runtime.data.RSequence;
 
 public abstract class FFIWrapNode extends Node {
@@ -92,7 +93,11 @@ public abstract class FFIWrapNode extends Node {
         return wrap(RDataFactory.createComplexVectorFromScalar(value));
     }
 
-    @Specialization
+    protected static boolean isRScalarVector(RObject value) {
+        return value instanceof RScalarVector;
+    }
+
+    @Specialization(guards = "!isRScalarVector(value)")
     protected static Object wrap(RObject value) {
         return value;
     }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RTypes.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RTypes.java
index f11da3d123..582b9366c7 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RTypes.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RTypes.java
@@ -109,21 +109,11 @@ public class RTypes {
         return RDataFactory.createDoubleVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractContainer toAbstractContainer(RRaw value) {
-        return RDataFactory.createRawVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractContainer toAbstractContainer(byte value) {
         return RDataFactory.createLogicalVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractContainer toAbstractContainer(RComplex value) {
-        return RDataFactory.createComplexVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractContainer toAbstractContainer(String value) {
         return RDataFactory.createStringVectorFromScalar(value);
@@ -139,21 +129,11 @@ public class RTypes {
         return RDataFactory.createDoubleVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractVector toAbstractVector(RRaw value) {
-        return RDataFactory.createRawVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractVector toAbstractVector(byte value) {
         return RDataFactory.createLogicalVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractVector toAbstractVector(RComplex value) {
-        return RDataFactory.createComplexVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractVector toAbstractVector(String value) {
         return RDataFactory.createStringVectorFromScalar(value);
@@ -169,21 +149,11 @@ public class RTypes {
         return RDataFactory.createDoubleVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractComplexVector toAbstractComplexVector(RComplex vector) {
-        return RDataFactory.createComplexVectorFromScalar(vector);
-    }
-
     @ImplicitCast
     public static RAbstractLogicalVector toAbstractLogicalVector(byte vector) {
         return RDataFactory.createLogicalVectorFromScalar(vector);
     }
 
-    @ImplicitCast
-    public static RAbstractRawVector toAbstractRawVector(RRaw vector) {
-        return RDataFactory.createRawVectorFromScalar(vector);
-    }
-
     @ImplicitCast
     public static RAbstractStringVector toAbstractStringVector(String vector) {
         return RDataFactory.createStringVectorFromScalar(vector);
@@ -199,21 +169,11 @@ public class RTypes {
         return RDataFactory.createDoubleVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractAtomicVector toAbstractAtomicVector(RRaw value) {
-        return RDataFactory.createRawVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractAtomicVector toAbstractAtomicVector(byte value) {
         return RDataFactory.createLogicalVectorFromScalar(value);
     }
 
-    @ImplicitCast
-    public static RAbstractAtomicVector toAbstractAtomicVector(RComplex value) {
-        return RDataFactory.createComplexVectorFromScalar(value);
-    }
-
     @ImplicitCast
     public static RAbstractAtomicVector toAbstractAtomicVector(String value) {
         return RDataFactory.createStringVectorFromScalar(value);
-- 
GitLab