From e256ece0df6087c9c6da4b00504c805cea30ec95 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Fri, 10 Feb 2017 13:07:22 +0100
Subject: [PATCH] remove unnecessary usages of NodeFields and NodeChildren

---
 .../builtin/base/BaseGammaFunctions.java      | 11 +++----
 .../builtin/base/infix/SpecialsUtils.java     |  3 +-
 .../r/nodes/builtin/base/infix/Subscript.java |  8 +++--
 .../builtin/base/infix/UpdateSubscript.java   | 11 ++++---
 .../truffle/r/nodes/binary/BinaryNode.java    |  4 +--
 .../r/nodes/unary/CastToVectorNode.java       | 18 +++++++----
 .../r/nodes/unary/ConvertBooleanNode.java     |  3 +-
 .../truffle/r/nodes/unary/FirstIntNode.java   | 31 ++++++++++---------
 .../r/nodes/unary/FirstStringNode.java        | 16 +++++-----
 9 files changed, 57 insertions(+), 48 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java
index e883fc44c5..005d49ee57 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java
@@ -28,9 +28,8 @@ import static com.oracle.truffle.r.runtime.nmath.RMath.fmax2;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
 import com.oracle.truffle.r.nodes.builtin.base.BaseGammaFunctionsFactory.DpsiFnCalcNodeGen;
 import com.oracle.truffle.r.runtime.RError;
@@ -44,7 +43,6 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
 import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
 import com.oracle.truffle.r.runtime.nmath.GammaFunctions;
 import com.oracle.truffle.r.runtime.nmath.RMath;
-import com.oracle.truffle.r.runtime.nodes.RNode;
 import com.oracle.truffle.r.runtime.ops.na.NACheck;
 
 public class BaseGammaFunctions {
@@ -110,7 +108,7 @@ public class BaseGammaFunctions {
         private double dpsiFnCalc(double x, int n, int kode, double ans) {
             if (dpsiFnCalc == null) {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
-                dpsiFnCalc = insert(DpsiFnCalcNodeGen.create(null, null, null, null));
+                dpsiFnCalc = insert(DpsiFnCalcNodeGen.create());
             }
             return dpsiFnCalc.executeDouble(x, n, kode, ans);
         }
@@ -156,8 +154,7 @@ public class BaseGammaFunctions {
         }
     }
 
-    @NodeChildren({@NodeChild(value = "x"), @NodeChild(value = "n"), @NodeChild(value = "kode"), @NodeChild(value = "ans")})
-    protected abstract static class DpsiFnCalc extends RNode {
+    protected abstract static class DpsiFnCalc extends Node {
 
         // the following is transcribed from polygamma.c
 
@@ -179,7 +176,7 @@ public class BaseGammaFunctions {
         private double dpsiFnCalc(double x, int n, int kode, double ans) {
             if (dpsiFnCalc == null) {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
-                dpsiFnCalc = insert(DpsiFnCalcNodeGen.create(null, null, null, null));
+                dpsiFnCalc = insert(DpsiFnCalcNodeGen.create());
             }
             return dpsiFnCalc.executeDouble(x, n, kode, ans);
         }
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java
index 0cd7b5397c..501753254b 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java
@@ -25,7 +25,6 @@ package com.oracle.truffle.r.nodes.builtin.base.infix;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.dsl.TypeSystemReference;
 import com.oracle.truffle.api.frame.VirtualFrame;
@@ -172,7 +171,7 @@ class SpecialsUtils {
     }
 
     @NodeInfo(cost = NodeCost.NONE)
-    @NodeChildren({@NodeChild(value = "delegate", type = RNode.class)})
+    @NodeChild(value = "delegate", type = RNode.class)
     @TypeSystemReference(EmptyTypeSystemFlatLayout.class)
     public abstract static class ConvertIndex extends RNode {
 
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java
index 176b95d29c..144f70966b 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java
@@ -31,7 +31,6 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
 import com.oracle.truffle.api.dsl.Cached;
 import com.oracle.truffle.api.dsl.Fallback;
 import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.dsl.TypeSystemReference;
 import com.oracle.truffle.api.frame.VirtualFrame;
@@ -66,7 +65,8 @@ import com.oracle.truffle.r.runtime.nodes.RNode;
 /**
  * Subscript code for vectors minus list is the same as subset code, this class allows sharing it.
  */
-@NodeChildren({@NodeChild(value = "vector", type = ProfiledValue.class), @NodeChild(value = "index", type = ConvertIndex.class)})
+@NodeChild(value = "vector", type = ProfiledValue.class)
+@NodeChild(value = "index", type = ConvertIndex.class)
 abstract class SubscriptSpecialBase extends SubscriptSpecialCommon {
 
     protected SubscriptSpecialBase(boolean inReplacement) {
@@ -104,7 +104,9 @@ abstract class SubscriptSpecialBase extends SubscriptSpecialCommon {
 /**
  * Subscript code for matrices minus list is the same as subset code, this class allows sharing it.
  */
-@NodeChildren({@NodeChild(value = "vector", type = ProfiledValue.class), @NodeChild(value = "index1", type = ConvertIndex.class), @NodeChild(value = "index2", type = ConvertIndex.class)})
+@NodeChild(value = "vector", type = ProfiledValue.class)
+@NodeChild(value = "index1", type = ConvertIndex.class)
+@NodeChild(value = "index2", type = ConvertIndex.class)
 abstract class SubscriptSpecial2Base extends SubscriptSpecial2Common {
 
     protected SubscriptSpecial2Base(boolean inReplacement) {
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java
index 432d1c31a5..cfc2f94db1 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java
@@ -32,7 +32,6 @@ import java.util.Arrays;
 
 import com.oracle.truffle.api.dsl.Fallback;
 import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.dsl.TypeSystemReference;
 import com.oracle.truffle.api.frame.VirtualFrame;
@@ -60,7 +59,9 @@ import com.oracle.truffle.r.runtime.data.RStringVector;
 import com.oracle.truffle.r.runtime.nodes.RNode;
 import com.oracle.truffle.r.runtime.ops.na.NACheck;
 
-@NodeChildren({@NodeChild(value = "vector", type = ProfiledValue.class), @NodeChild(value = "index", type = ConvertIndex.class), @NodeChild(value = "value", type = RNode.class)})
+@NodeChild(value = "vector", type = ProfiledValue.class)
+@NodeChild(value = "index", type = ConvertIndex.class)
+@NodeChild(value = "value", type = RNode.class)
 abstract class UpdateSubscriptSpecial extends SubscriptSpecialCommon {
 
     protected UpdateSubscriptSpecial(boolean inReplacement) {
@@ -108,8 +109,10 @@ abstract class UpdateSubscriptSpecial extends SubscriptSpecialCommon {
     }
 }
 
-@NodeChildren({@NodeChild(value = "vector", type = ProfiledValue.class), @NodeChild(value = "index1", type = ConvertIndex.class), @NodeChild(value = "index2", type = ConvertIndex.class),
-                @NodeChild(value = "value", type = RNode.class)})
+@NodeChild(value = "vector", type = ProfiledValue.class)
+@NodeChild(value = "index1", type = ConvertIndex.class)
+@NodeChild(value = "index2", type = ConvertIndex.class)
+@NodeChild(value = "value", type = RNode.class)
 abstract class UpdateSubscriptSpecial2 extends SubscriptSpecial2Common {
 
     protected UpdateSubscriptSpecial2(boolean inReplacement) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryNode.java
index 11825aaf02..bccc9d44c5 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryNode.java
@@ -23,10 +23,10 @@
 package com.oracle.truffle.r.nodes.binary;
 
 import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.r.runtime.nodes.RNode;
 
-@NodeChildren({@NodeChild(value = "left", type = RNode.class), @NodeChild(value = "right", type = RNode.class)})
+@NodeChild(value = "left", type = RNode.class)
+@NodeChild(value = "right", type = RNode.class)
 abstract class BinaryNode extends RNode {
 
     protected abstract RNode getLeft();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastToVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastToVectorNode.java
index f4f299fa5e..ff0088f66c 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastToVectorNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastToVectorNode.java
@@ -22,7 +22,6 @@
  */
 package com.oracle.truffle.r.nodes.unary;
 
-import com.oracle.truffle.api.dsl.NodeField;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.r.runtime.data.RDataFactory;
 import com.oracle.truffle.r.runtime.data.RFunction;
@@ -30,14 +29,21 @@ import com.oracle.truffle.r.runtime.data.RMissing;
 import com.oracle.truffle.r.runtime.data.RNull;
 import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
 
-@NodeField(name = "preserveNonVector", type = boolean.class)
 public abstract class CastToVectorNode extends CastNode {
 
-    public abstract boolean isPreserveNonVector();
+    private final boolean preserveNonVector;
+
+    protected CastToVectorNode(boolean preserveNonVector) {
+        this.preserveNonVector = preserveNonVector;
+    }
+
+    public final boolean isPreserveNonVector() {
+        return preserveNonVector;
+    }
 
     @Specialization
     protected Object castNull(@SuppressWarnings("unused") RNull rnull) {
-        if (isPreserveNonVector()) {
+        if (preserveNonVector) {
             return RNull.instance;
         } else {
             return RDataFactory.createList();
@@ -46,7 +52,7 @@ public abstract class CastToVectorNode extends CastNode {
 
     @Specialization
     protected Object castMissing(@SuppressWarnings("unused") RMissing missing) {
-        if (isPreserveNonVector()) {
+        if (preserveNonVector) {
             return RMissing.instance;
         } else {
             return RDataFactory.createList();
@@ -55,7 +61,7 @@ public abstract class CastToVectorNode extends CastNode {
 
     @Specialization
     protected Object castFunction(RFunction f) {
-        if (isPreserveNonVector()) {
+        if (preserveNonVector) {
             return f;
         } else {
             return RDataFactory.createList();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ConvertBooleanNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ConvertBooleanNode.java
index 82b940252a..df64052e58 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ConvertBooleanNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ConvertBooleanNode.java
@@ -23,7 +23,6 @@
 package com.oracle.truffle.r.nodes.unary;
 
 import com.oracle.truffle.api.dsl.NodeChild;
-import com.oracle.truffle.api.dsl.NodeChildren;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.frame.VirtualFrame;
 import com.oracle.truffle.api.profiles.BranchProfile;
@@ -44,7 +43,7 @@ import com.oracle.truffle.r.runtime.nodes.RNode;
 import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
 import com.oracle.truffle.r.runtime.ops.na.NAProfile;
 
-@NodeChildren({@NodeChild("operand")})
+@NodeChild("operand")
 public abstract class ConvertBooleanNode extends RNode {
 
     private final NAProfile naProfile = NAProfile.create();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstIntNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstIntNode.java
index 4b20e6deda..54d04e8c92 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstIntNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstIntNode.java
@@ -22,25 +22,26 @@
  */
 package com.oracle.truffle.r.nodes.unary;
 
-import com.oracle.truffle.api.dsl.NodeField;
-import com.oracle.truffle.api.dsl.NodeFields;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.profiles.BranchProfile;
 import com.oracle.truffle.api.profiles.ConditionProfile;
 import com.oracle.truffle.r.runtime.RError;
+import com.oracle.truffle.r.runtime.RError.Message;
 import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
 
-@NodeFields({@NodeField(name = "emptyError", type = RError.Message.class), @NodeField(name = "sizeWarning", type = RError.Message.class), @NodeField(name = "argumentName", type = String.class),
-                @NodeField(name = "defaultValue", type = int.class)})
 public abstract class FirstIntNode extends CastNode {
 
-    protected abstract RError.Message getEmptyError();
+    private final RError.Message emptyError;
+    private final RError.Message sizeWarning;
+    private final String argumentName;
+    private final int defaultValue;
 
-    protected abstract RError.Message getSizeWarning();
-
-    protected abstract String getArgumentName();
-
-    protected abstract int getDefaultValue();
+    protected FirstIntNode(Message emptyError, Message sizeWarning, String argumentName, int defaultValue) {
+        this.emptyError = emptyError;
+        this.sizeWarning = sizeWarning;
+        this.argumentName = argumentName;
+        this.defaultValue = defaultValue;
+    }
 
     public abstract int executeInt(Object value);
 
@@ -55,14 +56,14 @@ public abstract class FirstIntNode extends CastNode {
     @Specialization(replaces = "firstScalar")
     protected int firstVector(RAbstractIntVector argument) {
         if (!lengthOneProfile.profile(argument.getLength() == 1)) {
-            if (getSizeWarning() != null) {
-                RError.warning(this, getSizeWarning(), getArgumentName());
+            if (sizeWarning != null) {
+                RError.warning(this, sizeWarning, argumentName);
                 if (argument.getLength() == 0) {
-                    return getDefaultValue();
+                    return defaultValue;
                 }
-            } else if (getEmptyError() != null && argument.getLength() == 0) {
+            } else if (emptyError != null && argument.getLength() == 0) {
                 errorProfile.enter();
-                throw RError.error(this, getEmptyError(), getArgumentName());
+                throw RError.error(this, emptyError, argumentName);
             }
         }
         return argument.getDataAt(0);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstStringNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstStringNode.java
index ef7bb5c6dd..a1672bbea1 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstStringNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/FirstStringNode.java
@@ -23,20 +23,22 @@
 package com.oracle.truffle.r.nodes.unary;
 
 import com.oracle.truffle.api.dsl.Fallback;
-import com.oracle.truffle.api.dsl.NodeField;
-import com.oracle.truffle.api.dsl.NodeFields;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.profiles.BranchProfile;
 import com.oracle.truffle.api.profiles.ConditionProfile;
 import com.oracle.truffle.r.runtime.RError;
+import com.oracle.truffle.r.runtime.RError.Message;
 import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
 
-@NodeFields({@NodeField(name = "emptyError", type = RError.Message.class), @NodeField(name = "argumentName", type = String.class)})
 public abstract class FirstStringNode extends CastNode {
 
-    protected abstract RError.Message getEmptyError();
+    private final RError.Message emptyError;
+    private final String argumentName;
 
-    protected abstract String getArgumentName();
+    protected FirstStringNode(Message emptyError, String argumentName) {
+        this.emptyError = emptyError;
+        this.argumentName = argumentName;
+    }
 
     private final ConditionProfile lengthOneProfile = ConditionProfile.createBinaryProfile();
     private final BranchProfile errorProfile = BranchProfile.create();
@@ -54,14 +56,14 @@ public abstract class FirstStringNode extends CastNode {
     protected String firstVector(RAbstractStringVector argument) {
         if (!lengthOneProfile.profile(argument.getLength() == 1)) {
             errorProfile.enter();
-            throw RError.error(RError.SHOW_CALLER, getEmptyError(), getArgumentName());
+            throw RError.error(RError.SHOW_CALLER, emptyError, argumentName);
         }
         return argument.getDataAt(0);
     }
 
     @Fallback
     protected String firstVectorFallback(@SuppressWarnings("unused") Object argument) {
-        throw RError.error(RError.SHOW_CALLER, getEmptyError(), getArgumentName());
+        throw RError.error(RError.SHOW_CALLER, emptyError, argumentName);
     }
 
     public static FirstStringNode createWithError(RError.Message emptyError, String argumentName) {
-- 
GitLab