From fb3bf33d3e626421a01e2b2c26cb24fe77753eca Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Mon, 7 Aug 2017 13:53:42 +0200 Subject: [PATCH] cleanups (no frame needed in length node) --- .../truffle/r/engine/interop/ListMR.java | 24 +++++----- .../interop/RAbstractVectorAccessFactory.java | 24 +++++----- .../r/engine/interop/REnvironmentMR.java | 2 +- .../library/methods/MethodsListDispatch.java | 1 - .../truffle/r/nodes/builtin/base/AnyNA.java | 9 ++-- .../truffle/r/nodes/builtin/base/Length.java | 3 -- .../truffle/r/nodes/builtin/base/Mapply.java | 10 ++--- .../r/nodes/builtin/base/SeqFunctions.java | 32 ++++--------- .../truffle/r/nodes/builtin/base/Unlist.java | 45 ++++++++++--------- .../builtin/base/foreign/LookupAdapter.java | 2 +- .../nodes/builtin/base/infix/AccessField.java | 3 +- .../r/nodes/builtin/base/infix/Subscript.java | 2 +- .../oracle/truffle/r/nodes/RASTBuilder.java | 1 - .../truffle/r/nodes/control/RLengthNode.java | 12 ++--- .../r/nodes/function/RMissingHelper.java | 1 - 15 files changed, 70 insertions(+), 101 deletions(-) diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ListMR.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ListMR.java index feaff8795f..7f302a4482 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ListMR.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/ListMR.java @@ -80,7 +80,7 @@ public class ListMR { public abstract static class RListGetSizeNode extends Node { @Child private RLengthNode lengthNode = RLengthNode.create(); - protected Object access(VirtualFrame frame, RList receiver) { + protected Object access(RList receiver) { return getSize(receiver, lengthNode); } } @@ -105,7 +105,7 @@ public class ListMR { public abstract static class RListWriteNode extends Node { @Child private ListWriteImplNode writeNode = ListWriteImplNodeGen.create(); - protected Object access(VirtualFrame frame, RList receiver, Object identifier, Object valueObj) { + protected Object access(RList receiver, Object identifier, Object valueObj) { return writeNode.execute(receiver, identifier, valueObj); } } @@ -123,7 +123,7 @@ public class ListMR { public abstract static class RListKeyInfoNode extends Node { @Child private ListKeyInfoImplNode keyInfoNode = ListKeyInfoImplNodeGen.create(); - protected Object access(VirtualFrame frame, TruffleObject receiver, Object idx) { + protected Object access(TruffleObject receiver, Object idx) { return keyInfoNode.execute(receiver, idx); } } @@ -164,7 +164,7 @@ public class ListMR { public abstract static class RPairListGetSizeNode extends Node { @Child private RLengthNode lengthNode = RLengthNode.create(); - protected Object access(VirtualFrame frame, RPairList receiver) { + protected Object access(RPairList receiver) { return getSize(receiver, lengthNode); } } @@ -196,7 +196,7 @@ public class ListMR { public abstract static class RPairListWriteNode extends Node { @Child private ListWriteImplNode writeNode = ListWriteImplNodeGen.create(); - protected Object access(VirtualFrame frame, RPairList receiver, Object identifier, Object valueObj) { + protected Object access(RPairList receiver, Object identifier, Object valueObj) { return writeNode.execute(receiver, identifier, valueObj); } } @@ -214,7 +214,7 @@ public class ListMR { public abstract static class RPairListKeyInfoNode extends Node { @Child private ListKeyInfoImplNode keyInfoNode = ListKeyInfoImplNodeGen.create(); - protected Object access(VirtualFrame frame, TruffleObject receiver, Object idx) { + protected Object access(TruffleObject receiver, Object idx) { return keyInfoNode.execute(receiver, idx); } } @@ -243,19 +243,19 @@ public class ListMR { protected abstract Object execute(VirtualFrame frame, TruffleObject receiver, Object idx); @Specialization - protected Object read(VirtualFrame frame, TruffleObject receiver, double idx, + protected Object read(TruffleObject receiver, double idx, @Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) { - return read(frame, receiver, (int) idx, keyInfo); + return read(receiver, (int) idx, keyInfo); } @Specialization - protected Object read(VirtualFrame frame, TruffleObject receiver, long idx, + protected Object read(TruffleObject receiver, long idx, @Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) { - return read(frame, receiver, (int) idx, keyInfo); + return read(receiver, (int) idx, keyInfo); } @Specialization - protected Object read(VirtualFrame frame, TruffleObject receiver, int idx, + protected Object read(TruffleObject receiver, int idx, @Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) { int info = keyInfo.execute(receiver, idx); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { @@ -269,7 +269,7 @@ public class ListMR { } @Specialization - protected Object read(VirtualFrame frame, TruffleObject receiver, String field, + protected Object read(TruffleObject receiver, String field, @Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) { // reading by an unknown name returns null, // reading by an unknown index returns subscript out of bounds; diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java index 3bb2437cd3..3b9d9624bc 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RAbstractVectorAccessFactory.java @@ -72,16 +72,6 @@ abstract class InteropRootNode extends RootNode { public final class RAbstractVectorAccessFactory implements Factory26 { - static class VectorSizeNode extends InteropRootNode { - - @Child private RLengthNode lengthNode = RLengthNode.create(); - - @Override - public Object execute(VirtualFrame frame) { - return lengthNode.executeInteger(ForeignAccess.getReceiver(frame)); - } - } - abstract static class VectorReadImplNode extends InteropRootNode { @Child private ExtractVectorNode extract; @@ -155,13 +145,13 @@ public final class RAbstractVectorAccessFactory implements Factory26 { protected abstract Object execute(VirtualFrame frame, Object receiver, Object identifier, Object valueObj); @Specialization - protected Object write(VirtualFrame frame, TruffleObject receiver, int idx, Object valueObj) { + protected Object write(TruffleObject receiver, int idx, Object valueObj) { // idx + 1 R is indexing from 1 return write(receiver, new Object[]{idx + 1}, valueObj); } @Specialization - protected Object write(VirtualFrame frame, TruffleObject receiver, long idx, Object valueObj) { + protected Object write(TruffleObject receiver, long idx, Object valueObj) { // idx + 1 R is indexing from 1 return write(receiver, new Object[]{idx + 1}, valueObj); } @@ -273,7 +263,15 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Override public CallTarget accessGetSize() { - return Truffle.getRuntime().createCallTarget(new VectorSizeNode()); + return Truffle.getRuntime().createCallTarget(new InteropRootNode() { + + @Child private RLengthNode lengthNode = RLengthNode.create(); + + @Override + public Object execute(VirtualFrame frame) { + return lengthNode.executeInteger(ForeignAccess.getReceiver(frame)); + } + }); } @Override diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/REnvironmentMR.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/REnvironmentMR.java index 6a8ba5a555..d2dae219f4 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/REnvironmentMR.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/REnvironmentMR.java @@ -135,7 +135,7 @@ public class REnvironmentMR { protected abstract Object execute(VirtualFrame frame, TruffleObject receiver, Object identifier); @Specialization - protected Object access(VirtualFrame frame, REnvironment receiver, String identifier, + protected Object access(REnvironment receiver, String identifier, @Cached("createKeyInfoNode()") REnvironmentKeyInfoImplNode keyInfo) { int info = keyInfo.execute(receiver, identifier); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/methods/MethodsListDispatch.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/methods/MethodsListDispatch.java index af54167a56..65d3767af0 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/methods/MethodsListDispatch.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/methods/MethodsListDispatch.java @@ -31,7 +31,6 @@ import com.oracle.truffle.r.library.methods.MethodsListDispatchFactory.GetGeneri import com.oracle.truffle.r.nodes.access.AccessSlotNode; import com.oracle.truffle.r.nodes.access.AccessSlotNodeGen; import com.oracle.truffle.r.nodes.access.variables.LocalReadVariableNode; -import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.nodes.attributes.GetFixedAttributeNode; import com.oracle.truffle.r.nodes.builtin.NodeWithArgumentCasts.Casts; import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AnyNA.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AnyNA.java index 07e5400d2b..515d57eec9 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AnyNA.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AnyNA.java @@ -29,7 +29,6 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.control.RLengthNode; @@ -54,7 +53,7 @@ public abstract class AnyNA extends RBuiltinNode.Arg2 { private final NACheck naCheck = NACheck.create(); - public abstract byte execute(VirtualFrame frame, Object value, boolean recursive); + public abstract byte execute(Object value, boolean recursive); static { Casts casts = new Casts(AnyNA.class); @@ -157,7 +156,7 @@ public abstract class AnyNA extends RBuiltinNode.Arg2 { } @Specialization(guards = "recursive") - protected byte isNA(VirtualFrame frame, RList list, boolean recursive, + protected byte isNA(RList list, boolean recursive, @Cached("createRecursive()") AnyNA recursiveNode, @Cached("createClassProfile()") ValueProfile elementProfile, @Cached("create()") RLengthNode length) { @@ -165,7 +164,7 @@ public abstract class AnyNA extends RBuiltinNode.Arg2 { for (int i = 0; i < list.getLength(); i++) { Object value = elementProfile.profile(list.getDataAt(i)); if (length.executeInteger(value) > 0) { - byte result = recursiveNode.execute(frame, value, recursive); + byte result = recursiveNode.execute(value, recursive); if (result == RRuntime.LOGICAL_TRUE) { return RRuntime.LOGICAL_TRUE; } @@ -176,7 +175,7 @@ public abstract class AnyNA extends RBuiltinNode.Arg2 { @Specialization(guards = "!recursive") @SuppressWarnings("unused") - protected byte isNA(VirtualFrame frame, RList list, boolean recursive) { + protected byte isNA(RList list, boolean recursive) { return RRuntime.LOGICAL_FALSE; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Length.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Length.java index 6e4ed78a61..6d9d8b5c16 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Length.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Length.java @@ -28,7 +28,6 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.control.RLengthNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -36,8 +35,6 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin; @RBuiltin(name = "length", kind = PRIMITIVE, dispatch = INTERNAL_GENERIC, parameterNames = {"x"}, behavior = PURE) public abstract class Length extends RBuiltinNode.Arg1 { - public abstract int executeInt(VirtualFrame frame, Object vector); - static { Casts.noCasts(Length.class); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java index 11d115c517..dc3a03b8f5 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Mapply.java @@ -79,7 +79,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { } protected static final class ElementNode extends Node { - @Child private Length lengthNode; + @Child private RLengthNode lengthNode; @Child private ExtractVectorNode extractNode; @Child private WriteVariableNode writeVectorElementNode; private final String vectorElementName; @@ -88,7 +88,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { private ElementNode(String vectorElementName, String argName) { // the name is a hack to treat ReadVariableNode-s as syntax nodes this.vectorElementName = "*" + AnonymousFrameVariable.create(vectorElementName); - this.lengthNode = insert(LengthNodeGen.create()); + this.lengthNode = insert(RLengthNode.create()); this.extractNode = insert(ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, false)); this.writeVectorElementNode = insert(WriteVariableNode.createAnonymous(this.vectorElementName, Mode.REGULAR, null)); this.argName = argName; @@ -142,7 +142,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { @Cached("createElementNodeArray(dotsLength, moreArgsLength, cachedDotsNames, cachedMoreArgsNames)") ElementNode[] cachedElementNodeArray, @Cached("createCallNode(cachedElementNodeArray)") RCallBaseNode callNode) { int[] lengths = new int[dotsLength]; - int maxLength = getDotsLengths(frame, dots, dotsLength, cachedElementNodeArray, lengths); + int maxLength = getDotsLengths(dots, dotsLength, cachedElementNodeArray, lengths); storeAdditionalArguments(frame, moreArgs, dotsLength, moreArgsLength, cachedElementNodeArray); Object[] result = new Object[maxLength]; for (int i = 0; i < maxLength; i++) { @@ -171,10 +171,10 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { } @ExplodeLoop - private static int getDotsLengths(VirtualFrame frame, RAbstractListVector dots, int dotsLength, ElementNode[] cachedElementNodeArray, int[] lengths) { + private static int getDotsLengths(RAbstractListVector dots, int dotsLength, ElementNode[] cachedElementNodeArray, int[] lengths) { int maxLength = -1; for (int i = 0; i < dotsLength; i++) { - int length = cachedElementNodeArray[i].lengthNode.executeInt(frame, dots.getDataAt(i)); + int length = cachedElementNodeArray[i].lengthNode.executeInteger(dots.getDataAt(i)); if (length > maxLength) { maxLength = length; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java index 1dc1547d22..fc804c04e3 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SeqFunctions.java @@ -29,7 +29,6 @@ import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.dsl.TypeSystemReference; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.ffi.impl.nodes.AsRealNode; import com.oracle.truffle.r.ffi.impl.nodes.AsRealNodeGen; @@ -401,12 +400,11 @@ public final class SeqFunctions { * * N.B. javac gives error "cannot find symbol" on plain "@RBuiltin". */ - @SuppressWarnings("unused") @ImportStatic({AsRealNodeGen.class, SeqFunctions.class}) + @SuppressWarnings("unused") @com.oracle.truffle.r.runtime.builtins.RBuiltin(name = "seq.int", kind = PRIMITIVE, parameterNames = {"from", "to", "by", "length.out", "along.with", "..."}, dispatch = INTERNAL_GENERIC, genericName = "seq", behavior = PURE) public abstract static class SeqInt extends RBuiltinNode.Arg6 { - private final BranchProfile error = BranchProfile.create(); private final boolean seqFastPath; /** @@ -529,8 +527,7 @@ public final class SeqFunctions { */ @Specialization(guards = "validDoubleParams(fromVec, toVec)") - protected RAbstractVector seqLengthByMissingDouble(RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, - Object dotdotdot, + protected RAbstractVector seqLengthByMissingDouble(RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { double from = fromVec.getDataAt(0); double to = toVec.getDataAt(0); @@ -570,8 +567,7 @@ public final class SeqFunctions { validateLength(toObj, "to"); double to = asRealTo.execute(toObj); validateDoubleParam(to, toObj, "to"); - RAbstractVector result = createRSequence(from, to, directionProfile); - return result; + return createRSequence(from, to, directionProfile); } /* @@ -589,8 +585,7 @@ public final class SeqFunctions { } @Specialization(guards = {"validIntParams(fromVec, toVec)", "validIntParam(byVec)", "byVec.getDataAt(0) != 0"}) - protected RAbstractVector seqLengthMissing(RAbstractIntVector fromVec, RAbstractIntVector toVec, RAbstractIntVector byVec, RMissing lengthOut, RMissing alongWith, - Object dotdotdot, + protected RAbstractVector seqLengthMissing(RAbstractIntVector fromVec, RAbstractIntVector toVec, RAbstractIntVector byVec, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { int by = byVec.getDataAt(0); int from = fromVec.getDataAt(0); @@ -598,7 +593,6 @@ public final class SeqFunctions { RIntSequence result; if (directionProfile.profile(from < to)) { if (by < 0) { - error.enter(); throw error(RError.Message.WRONG_SIGN_IN_BY); } result = RDataFactory.createIntSequence(from, by, (to - from) / by + 1); @@ -607,7 +601,6 @@ public final class SeqFunctions { return RDataFactory.createIntVectorFromScalar(from); } if (by > 0) { - error.enter(); throw error(RError.Message.WRONG_SIGN_IN_BY); } result = RDataFactory.createIntSequence(from, by, (from - to) / (-by) + 1); @@ -640,7 +633,7 @@ public final class SeqFunctions { allInt = false; } else { validateLength(toObj, "to"); - to = asRealFrom.execute(toObj); + to = asRealTo.execute(toObj); validateDoubleParam(to, toObj, "to"); allInt &= isInt(toObj); } @@ -663,7 +656,6 @@ public final class SeqFunctions { // N.B. GNU R returns the original "from" argument (which might be missing) return RDataFactory.createDoubleVectorFromScalar(from); } else { - error.enter(); // This should go away in an upcoming GNU R release throw error(seqFastPath ? RError.Message.INVALID_TFB_SD : RError.Message.INVALID_TFB); } @@ -674,11 +666,9 @@ public final class SeqFunctions { return RDataFactory.createDoubleVectorFromScalar(from); } if (n > Integer.MAX_VALUE) { - error.enter(); throw error(RError.Message.BY_TOO_SMALL); } if (n < -FEPS) { - error.enter(); throw error(RError.Message.WRONG_SIGN_IN_BY); } RAbstractVector result; @@ -761,7 +751,7 @@ public final class SeqFunctions { } @Specialization - protected boolean isIntegralNumericNode(Integer obj) { + protected boolean isIntegralNumericNode(int obj) { if (checkLength) { return obj >= 0; } else { @@ -775,7 +765,7 @@ public final class SeqFunctions { } @Specialization - protected boolean isIntegralNumericNode(Double obj) { + protected boolean isIntegralNumericNode(double obj) { double d = obj; return d == (int) d && (checkLength ? d >= 0 : true); } @@ -824,7 +814,7 @@ public final class SeqFunctions { boolean fromMissing = isMissing(fromObj); boolean toMissing = isMissing(toObj); double from = asRealFrom.execute(fromObj); - double to = asRealFrom.execute(toObj); + double to = asRealTo.execute(toObj); if (toMissing) { to = from + lout - 1; } @@ -916,7 +906,6 @@ public final class SeqFunctions { @Fallback protected RAbstractVector seqFallback(Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot) { - error.enter(); throw error(RError.Message.TOO_MANY_ARGS); } @@ -967,7 +956,6 @@ public final class SeqFunctions { private int validateIntParam(int v, String vName) { if (RRuntime.isNA(v)) { - error.enter(); throw error(RError.Message.CANNOT_BE_INVALID, vName); } return v; @@ -980,7 +968,6 @@ public final class SeqFunctions { private double validateDoubleParam(double v, Object vObj, String vName) { if (vObj != RMissing.instance) { if (!isFinite(v)) { - error.enter(); throw error(RError.Message.CANNOT_BE_INVALID, vName); } } @@ -993,7 +980,6 @@ public final class SeqFunctions { private void validateLength(Object obj, String vName) { if (obj != RMissing.instance) { if (getLength(obj) != 1) { - error.enter(); throw error(RError.Message.MUST_BE_SCALAR, vName); } } @@ -1002,7 +988,6 @@ public final class SeqFunctions { private int checkLength(Object lengthOut, AsRealNode asRealLen) { double len = asRealLen.execute(lengthOut); if (RRuntime.isNAorNaN(len) || len <= -0.5) { - error.enter(); throw error(seqFastPath ? RError.Message.MUST_BE_POSITIVE_SD : RError.Message.MUST_BE_POSITIVE, seqFastPath ? "length" : "length.out"); } if (getLength(lengthOut) != 1) { @@ -1037,7 +1022,6 @@ public final class SeqFunctions { private int checkVecLength(double from, double to) { double r = Math.abs(to - from); if (r > Integer.MAX_VALUE) { - error.enter(); throw error(RError.Message.TOO_LONG_VECTOR); } int length = (int) (r + 1 + FLT_EPSILON); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java index d792c70c41..626821a38a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Unlist.java @@ -35,6 +35,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetNamesAttributeNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.base.UnlistNodeGen.RecursiveLengthNodeGen; +import com.oracle.truffle.r.nodes.control.RLengthNode; import com.oracle.truffle.r.nodes.unary.PrecedenceNode; import com.oracle.truffle.r.nodes.unary.PrecedenceNodeGen; import com.oracle.truffle.r.runtime.RDispatch; @@ -74,7 +75,7 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } @Child private PrecedenceNode precedenceNode = PrecedenceNodeGen.create(); - @Child private Length lengthNode; + @Child private RLengthNode lengthNode; @Child private RecursiveLength recursiveLengthNode; @Child private GetNamesAttributeNode getNames = GetNamesAttributeNode.create(); @Child private Node hasSizeNode; @@ -84,13 +85,13 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { @TypeSystemReference(RTypes.class) protected abstract static class RecursiveLength extends Node { - public abstract int executeInt(VirtualFrame frame, Object vector); + public abstract int execute(Object vector); @Child private RecursiveLength recursiveLengthNode; - private int getRecursiveLength(VirtualFrame frame, Object operand) { + private int getRecursiveLength(Object operand) { initRecursiveLengthNode(); - return recursiveLengthNode.executeInt(frame, operand); + return recursiveLengthNode.execute(operand); } private void initRecursiveLengthNode() { @@ -128,11 +129,11 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } @Specialization(guards = "isVectorList(vector)") - protected int getLengthList(VirtualFrame frame, RAbstractVector vector) { + protected int getLengthList(RAbstractVector vector) { int totalSize = 0; for (int i = 0; i < vector.getLength(); i++) { Object data = vector.getDataAtAsObject(i); - totalSize += getRecursiveLength(frame, data); + totalSize += getRecursiveLength(data); } return totalSize; } @@ -142,16 +143,16 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } @Specialization - protected int getLengthPairList(VirtualFrame frame, RPairList list) { + protected int getLengthPairList(RPairList list) { int totalSize = 0; for (RPairList item : list) { - totalSize += getRecursiveLength(frame, item.car()); + totalSize += getRecursiveLength(item.car()); } return totalSize; } @Specialization(guards = {"isForeignArray(obj, hasSize)"}) - protected int getForeignArrayLength(VirtualFrame frame, TruffleObject obj, + protected int getForeignArrayLength(TruffleObject obj, @Cached("READ.createNode()") Node read, @SuppressWarnings("unused") @Cached("HAS_SIZE.createNode()") Node hasSize, @Cached("GET_SIZE.createNode()") Node getSize, @@ -175,7 +176,7 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { for (int i = 0; i < size; i++) { Object element = ForeignAccess.sendRead(read, obj, i); element = foreign2R.execute(element); - totalSize += getRecursiveLength(frame, element); + totalSize += getRecursiveLength(element); } } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw RError.interopError(RError.findParentRBase(this), ex, obj); @@ -184,7 +185,7 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } @Specialization(guards = {"isJavaIterable(obj)"}) - protected int getJavaIterableLength(VirtualFrame frame, TruffleObject obj, + protected int getJavaIterableLength(TruffleObject obj, @Cached("READ.createNode()") Node read, @Cached("createExecute(0).createNode()") Node execute, @Cached("createForeign2R()") Foreign2R foreign2R) { @@ -198,7 +199,7 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { TruffleObject nextFunction = (TruffleObject) ForeignAccess.sendRead(read, it, "next"); Object element = ForeignAccess.sendExecute(execute, nextFunction); element = foreign2R.execute(element); - totalSize += getRecursiveLength(frame, element); + totalSize += getRecursiveLength(element); } } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException | UnknownIdentifierException ex) { throw RError.interopError(RError.findParentRBase(this), ex, obj); @@ -213,21 +214,21 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } } - private int getLength(VirtualFrame frame, Object operand) { + private int getLength(Object operand) { initLengthNode(); - return lengthNode.executeInt(frame, operand); + return lengthNode.executeInteger(operand); } private void initLengthNode() { if (lengthNode == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); - lengthNode = insert(LengthNodeGen.create()); + lengthNode = insert(RLengthNode.create()); } } - private int getRecursiveLength(VirtualFrame frame, Object operand) { + private int getRecursiveLength(Object operand) { initRecursiveLengthNode(); - return recursiveLengthNode.executeInt(frame, operand); + return recursiveLengthNode.execute(operand); } private void initRecursiveLengthNode() { @@ -258,16 +259,16 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { // TODO: initially unlist was on the slow path - hence initial recursive implementation is on // the slow path as well; ultimately we may consider (non-recursive) optimization @Specialization(guards = "!isEmpty(list)") - protected Object unlistList(VirtualFrame frame, RList list, boolean recursive, boolean useNames) { + protected Object unlistList(RList list, boolean recursive, boolean useNames) { int precedence = PrecedenceNode.NO_PRECEDENCE; int totalSize = 0; for (int i = 0; i < list.getLength(); i++) { Object data = list.getDataAt(i); precedence = Math.max(precedence, precedenceNode.executeInteger(data, recursive)); if (recursive) { - totalSize += getRecursiveLength(frame, data); + totalSize += getRecursiveLength(data); } else { - totalSize += getLength(frame, data); + totalSize += getLength(data); } } // If the precedence is still NO_PRECEDENCE the result is RNull.instance @@ -279,11 +280,11 @@ public abstract class Unlist extends RBuiltinNode.Arg3 { } @Specialization(guards = "!isEmpty(list)") - protected Object unlistPairList(VirtualFrame frame, RPairList list, boolean recursive, boolean useNames) { + protected Object unlistPairList(RPairList list, boolean recursive, boolean useNames) { // TODO: unlist((pairlist(pairlist(1)), recursive=FALSE), see unit tests // Note: currently, we convert to list any pair-list that we encounter along the way, this // is sub-optimal, but the assumption is that pair-lists do not show up a lot - return unlistList(frame, list.toRList(), recursive, useNames); + return unlistList(list.toRList(), recursive, useNames); } @Specialization(guards = {"isForeignArray(obj)"}) diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/LookupAdapter.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/LookupAdapter.java index 56f021ee76..40e7c89190 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/LookupAdapter.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/LookupAdapter.java @@ -149,7 +149,7 @@ abstract class LookupAdapter extends RBuiltinNode.Arg3 implements Lookup { protected abstract NativeCallInfo execute(VirtualFrame frame, RList symbol); @Specialization - protected NativeCallInfo extractNativeCallInfo(VirtualFrame frame, RList symbol) { + protected NativeCallInfo extractNativeCallInfo(RList symbol) { if (nameExtract == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); nameExtract = insert(ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java index 3830f6954a..1663b1ff5a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/AccessField.java @@ -31,7 +31,6 @@ 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.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; @@ -100,7 +99,7 @@ public abstract class AccessField extends RBuiltinNode.Arg2 { } @Specialization - protected Object access(VirtualFrame frame, Object container, String field) { + protected Object access(Object container, String field) { if (!invalidAtomicVector.profile(container instanceof RAbstractListVector) && container instanceof RAbstractVector) { error.enter(); throw error(RError.Message.DOLLAR_ATOMIC_VECTORS); 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 c6a855d169..1cf7227181 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 @@ -146,7 +146,7 @@ abstract class SubscriptSpecial extends SubscriptSpecialBase { } @Specialization(guards = {"simpleVector(vector)", "!inReplacement"}) - protected static Object access(VirtualFrame frame, RAbstractVector vector, Object index, + protected static Object access(RAbstractVector vector, Object index, @Cached("createAccess()") ExtractVectorNode extract) { return extract.apply(vector, new Object[]{index}, RRuntime.LOGICAL_TRUE, RLogical.TRUE); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java index c5bb93fb1c..9804249bf4 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RASTBuilder.java @@ -54,7 +54,6 @@ import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.FastROptions; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.FastPathFactory; -import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.context.TruffleRLanguage; import com.oracle.truffle.r.runtime.data.REmpty; import com.oracle.truffle.r.runtime.data.RShareable; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/RLengthNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/RLengthNode.java index 71db0a9b50..f1e7dce2b6 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/RLengthNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/RLengthNode.java @@ -24,9 +24,7 @@ package com.oracle.truffle.r.nodes.control; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.NodeChild; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.ArityException; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.InteropException; @@ -47,24 +45,20 @@ import com.oracle.truffle.r.runtime.data.RSymbol; import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.interop.ForeignArray2R; -import com.oracle.truffle.r.runtime.nodes.RNode; +import com.oracle.truffle.r.runtime.nodes.RBaseNode; /** * Gets length of given container. Does not actually dispatch to the 'length' function, which may be * overridden for some S3/S4 classes. Check if you need to get actual length, or what the 'length' * function returns, like in {@code seq_along}. */ -@NodeChild("operand") @ImportStatic({Message.class, ForeignArray2R.class}) -public abstract class RLengthNode extends RNode { - - @Override - public abstract int executeInteger(VirtualFrame frame); +public abstract class RLengthNode extends RBaseNode { public abstract int executeInteger(Object value); public static RLengthNode create() { - return RLengthNodeGen.create(null); + return RLengthNodeGen.create(); } @Specialization diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RMissingHelper.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RMissingHelper.java index e6af350bbf..d3d4f63a89 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RMissingHelper.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RMissingHelper.java @@ -27,7 +27,6 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.frame.FrameSlot; import com.oracle.truffle.api.frame.FrameSlotTypeException; -import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.REmpty; import com.oracle.truffle.r.runtime.data.RMissing; -- GitLab