From b993cfdbc55c6f3513df627435efd341babd348d Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Tue, 15 Nov 2016 09:13:33 -0800
Subject: [PATCH] fix limitation in RASTUtils.createCall causing Matrix package
 to fail when codetools installed

---
 .../Makefile                                  |  2 +-
 .../com/oracle/truffle/r/nodes/RASTUtils.java | 30 +++++--------------
 .../rpackages/TestRecommendedPackages.java    |  6 ++--
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/com.oracle.truffle.r.native.recommended/Makefile b/com.oracle.truffle.r.native.recommended/Makefile
index 69f34bb47d..a7c94081ef 100644
--- a/com.oracle.truffle.r.native.recommended/Makefile
+++ b/com.oracle.truffle.r.native.recommended/Makefile
@@ -34,7 +34,7 @@ NATIVE_PROJECT := $(subst native.recommended,native,$(CURDIR))
 R_VERSION := $(notdir $(wildcard $(NATIVE_PROJECT)/gnur/R-*))
 GNUR_HOME := $(NATIVE_PROJECT)/gnur/$(R_VERSION)
 # order matters due to inter-package dependencies
-GNUR_RECOMMENDED_PKGNAMES := MASS boot class cluster lattice nnet spatial Matrix survival KernSmooth foreign nlme rpart codetools
+GNUR_RECOMMENDED_PKGNAMES := codetools MASS boot class cluster lattice nnet spatial Matrix survival KernSmooth foreign nlme rpart
 GNUR_RECOMMENDED_TARS := $(foreach pkg, $(GNUR_RECOMMENDED_PKGNAMES),$(GNUR_HOME)/src/library/Recommended/$(pkg).tgz)
 #$(info GNUR_RECOMMENDED_TARS=$(GNUR_RECOMMENDED_TARS))
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTUtils.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTUtils.java
index 6177e70fc4..0c3db22a7d 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTUtils.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTUtils.java
@@ -212,33 +212,19 @@ public class RASTUtils {
      * Create an {@link RCallNode}. Where {@code fn} is either a:
      * <ul>
      * <li>{@link RFunction}\
-     * <li>{@code ConstantFunctionNode}</li>
-     * <li>{@code ConstantStringNode}</li>
-     * <li>{@link ReadVariableNode}</li>
-     * <li>{@link RCallNode}</li>
-     * <li>GroupDispatchNode</li>
+     * <li>{@code RNode}</li>
      * </ul>
      */
     @TruffleBoundary
-    public static RSyntaxNode createCall(Object fna, boolean sourceUnavailable, ArgumentsSignature signature, RSyntaxNode... arguments) {
-        Object fn = fna;
-        if (fn instanceof Node) {
-            fn = unwrap(fn);
-        }
-        if (fn instanceof ConstantNode) {
-            fn = ((ConstantNode) fn).getValue();
-        }
-        SourceSection sourceSection = sourceUnavailable ? RSyntaxNode.SOURCE_UNAVAILABLE : RSyntaxNode.EAGER_DEPARSE;
-        if (fn instanceof ReadVariableNode) {
-            return RCallSpecialNode.createCall(sourceSection, (ReadVariableNode) fn, signature, arguments);
-        } else if (fn instanceof RCallBaseNode) {
-            return RCallSpecialNode.createCall(sourceSection, (RCallBaseNode) fn, signature, arguments);
+    public static RSyntaxNode createCall(Object fn, boolean sourceUnavailable, ArgumentsSignature signature, RSyntaxNode... arguments) {
+        RNode fnNode;
+        if (fn instanceof RFunction) {
+            fnNode = ConstantNode.create(fn);
         } else {
-            // apart from RFunction, this of course would not make much sense if trying to evaluate
-            // this call, yet it's syntactically possible, for example as a result of:
-            // f<-function(x,y) sys.call(); x<-f(7, 42); x[c(2,3)]
-            return RCallSpecialNode.createCall(sourceSection, ConstantNode.create(fn), signature, arguments);
+            fnNode = (RNode) unwrap(fn);
         }
+        SourceSection sourceSection = sourceUnavailable ? RSyntaxNode.SOURCE_UNAVAILABLE : RSyntaxNode.EAGER_DEPARSE;
+        return RCallSpecialNode.createCall(sourceSection, fnNode, signature, arguments);
     }
 
     @TruffleBoundary
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java
index d132889ce7..53d8d460cc 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java
@@ -40,14 +40,12 @@ import com.oracle.truffle.r.test.TestBase;
  * directory by the com.oracle.truffle.r.test.native Makefile. to allow them to be packaged into a
  * distribution and avoid any dependency on source paths.
  *
- * FIXME {@codetools} is installed last because when it is installed, some of the other packages use
- * it and it currently provokes a bug.
  */
 public class TestRecommendedPackages extends TestRPackages {
     // order matters due to dependencies
-    private static final String[] DEFAULT_PACKAGES = new String[]{"MASS", "boot", "class", "cluster",
+    private static final String[] DEFAULT_PACKAGES = new String[]{"codetools", "MASS", "boot", "class", "cluster",
                     "lattice", "nnet", "spatial", "Matrix", "survival", "KernSmooth", "foreign", "nlme",
-                    "rpart", "codetools"};
+                    "rpart"};
     private static String[] packages = DEFAULT_PACKAGES;
 
     /**
-- 
GitLab