diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java index aebfa378cdb8983e83189c69939bde8bddc5bdb4..64a35769dfca90ad558e2c7187dc5f3a35f905d6 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java @@ -176,21 +176,27 @@ public final class CoerceNodes { } // Note: caches should cover all valid possibilities - @Specialization(guards = {"!isS4Object(value)", "isNotList(value)", "isValidMode(mode)", "cachedMode == mode"}, limit = "99") - Object doCached(Object value, @SuppressWarnings("unused") int mode, + @Specialization(guards = {"!isS4Object(value)", "cachedMode == mode", "isValidMode(cachedMode)", "isNotList(value)"}, limit = "99") + Object doCachedNotList(Object value, @SuppressWarnings("unused") int mode, @Cached("mode") @SuppressWarnings("unused") int cachedMode, @Cached("createCastNode(cachedMode)") CastNode castNode) { return castNode.doCast(value); } // Lists are coerced with only preserved names unlike other types - @Specialization(guards = {"!isS4Object(value)", "isValidMode(mode)", "cachedMode == mode"}, limit = "99") + @Specialization(guards = {"!isS4Object(value)", "cachedMode == mode", "isValidMode(cachedMode)"}, limit = "99") Object doCached(RList value, @SuppressWarnings("unused") int mode, @Cached("mode") @SuppressWarnings("unused") int cachedMode, @Cached("createCastNodeForList(cachedMode)") CastNode castNode) { return castNode.doCast(value); } + @Specialization(replaces = {"doCachedNotList", "doCached"}, guards = {"!isS4Object(value)", "isValidMode(mode)"}) + Object doCached(Object value, int mode) { + String type = value != null ? value.getClass().getSimpleName() : "null"; + throw RInternalError.unimplemented(String.format("Rf_coerceVector unimplemented for type %s or mode %s.", type, mode)); + } + @Fallback @TruffleBoundary Object doFallback(Object value, Object mode) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CharTr.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CharTr.java index 6c81776bedc9f22a2ed489768891dce428f84897..b354a949115daff2c94b7805669ed7d95393eb29 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CharTr.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CharTr.java @@ -94,9 +94,10 @@ public abstract class CharTr extends RBuiltinNode.Arg3 { if (newEnd - newStart < oldEnd - oldStart) { throw error(X_LONGER_THAN_Y, "old", "new"); } + String replacedValue = value; for (int rangeIdx = 0; rangeIdx <= oldEnd - oldStart; rangeIdx++) { - value = value.replace((char) (oldStart + rangeIdx), (char) (newStart + rangeIdx)); + replacedValue = value.replace((char) (oldStart + rangeIdx), (char) (newStart + rangeIdx)); } - return value; + return replacedValue; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompileFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompileFunctions.java index 383554e3ac42e46081f99ee0ccdb061ce7a5d32a..bf269cdd993347017074d3eefc8641571ae845e0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompileFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompileFunctions.java @@ -69,6 +69,7 @@ public class CompileFunctions { } @RBuiltin(name = "mkCode", kind = INTERNAL, parameterNames = {"bytes", "consts"}, behavior = PURE) + @SuppressWarnings("unused") public abstract static class MkCode extends RBuiltinNode.Arg2 { static { @@ -96,7 +97,8 @@ public class CompileFunctions { } @Specialization - protected Object bcClose(@SuppressWarnings("unused") Object forms, Object body, @SuppressWarnings("unused") Object env) { + @SuppressWarnings("unused") + protected Object bcClose(Object forms, Object body, Object env) { return RNull.instance; // Body } } @@ -130,6 +132,7 @@ public class CompileFunctions { } @RBuiltin(name = "bcVersion", kind = INTERNAL, parameterNames = {}, behavior = PURE) + @SuppressWarnings("unused") public abstract static class BcVersion extends RBuiltinNode.Arg0 { static { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/EncodeString.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/EncodeString.java index 3feb26bd40ed44046a9738be0352a6de7c17342e..9fe3d1452275081b70e808f932655b1cde53ab51 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/EncodeString.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/EncodeString.java @@ -24,7 +24,6 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; 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.nodes.attributes.UnaryCopyAttributesNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; @@ -47,7 +46,6 @@ public abstract class EncodeString extends RBuiltinNode.Arg5 { } private final NACheck na = NACheck.create(); - private final BranchProfile everSeenNA = BranchProfile.create(); static { Casts casts = new Casts(EncodeString.class); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsListFactor.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsListFactor.java index dd4dab9a055702a74f81034f690083ba3f4096d6..9dbf01f18ce98069a69e0e3e4e9bc35ba8009638 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsListFactor.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsListFactor.java @@ -78,7 +78,7 @@ public abstract class IsListFactor extends RBuiltinNode.Arg2 { return IsListFactorInternalNodeGen.create(recursive); } - @Specialization(guards = "recursive == node.recursive") + @Specialization(guards = "recursive == node.recursive", limit = "2") protected byte isListFactor(Object value, @SuppressWarnings("unused") boolean recursive, @Cached("createNode(recursive)") IsListFactorInternal node) { return RRuntime.asLogical(node.execute(value)); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchArg.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchArg.java index 4abcb6b98d96cc80801bdb9c72b0ce3e11265ff2..748b85555f953729c12da0abc4c48ce5f2f51b41 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchArg.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchArg.java @@ -206,12 +206,22 @@ public abstract class MatchArg extends RBuiltinNode.Arg3 { return MatchArgInternalNodeGen.create(); } - @Specialization(limit = "3", guards = "choicesValue.isSupported(frame, arg)") + @Specialization(limit = "1", guards = "cache.choicesValue.isSupported(frame, arg)") protected Object matchArg(VirtualFrame frame, RPromise arg, @SuppressWarnings("unused") RMissing choices, Object severalOK, - @Cached("new(frame, arg)") MatchArgChoices choicesValue, - @Cached("createInternal()") MatchArgInternal internal, - @Cached("new()") PromiseHelperNode promiseHelper) { - return internal.castAndExecute(promiseHelper.evaluate(frame, arg), choicesValue.execute(frame), severalOK); + @Cached("new(frame, arg)") MatchArgNode cache) { + return cache.internal.castAndExecute(cache.promiseHelper.evaluate(frame, arg), cache.choicesValue.execute(frame), severalOK); + } + + public static final class MatchArgNode extends Node { + @Child public MatchArgChoices choicesValue; + @Child public MatchArgInternal internal; + @Child public PromiseHelperNode promiseHelper; + + public MatchArgNode(VirtualFrame frame, RPromise arg) { + this.choicesValue = new MatchArgChoices(frame, arg); + this.internal = MatchArgInternalNodeGen.create(); + this.promiseHelper = new PromiseHelperNode(); + } } protected static boolean isRMissing(Object value) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NChar.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NChar.java index 8c6b7d81d146cc79ab669752db13765b6742b111..a9b767a2be16d0c3bfe87321b1dedbf798b052bf 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NChar.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NChar.java @@ -53,9 +53,6 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = "nchar", kind = INTERNAL, parameterNames = {"x", "type", "allowNA", "keepNA"}, behavior = PURE) public abstract class NChar extends RBuiltinNode.Arg4 { private static final String[] TYPES = new String[]{"bytes", "chars", "width"}; - private static final int TYPE_BYTES = 0; - private static final int TYPE_CHARS = 1; - private static final int TYPE_WIDTH = 2; static { Casts casts = new Casts(NChar.class); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PMatch.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PMatch.java index 56edbde21bfcb951cc63a5704dfa59951b95d8a1..23c393d948b3e9cf83ccbbbf0f14ad0af659fcc1 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PMatch.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PMatch.java @@ -40,6 +40,7 @@ import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = "pmatch", kind = INTERNAL, parameterNames = {"x", "table", "nomatch", "duplicates.ok"}, behavior = PURE) +@SuppressWarnings("unused") public abstract class PMatch extends RBuiltinNode.Arg4 { private final ConditionProfile nomatchNA = ConditionProfile.createBinaryProfile(); 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 7fdcb9628a28f74d4d9b74794c8ee1ea0155caf1..48edb3ccebcf38aca2e3ed8b9ba86c8d4abdea4e 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 @@ -184,42 +184,61 @@ public final class SeqFunctions { @TypeSystemReference(RTypes.class) @ImportStatic(SeqFunctions.class) public abstract static class SeqFastPath extends FastPathAdapter { - @Specialization(guards = {"!hasClass(args, getClassAttributeNode)", "lengthSpecials(args)"}) - @SuppressWarnings("unused") + + @Specialization(guards = {"!hasClass(args, cache.getClassAttributeNode)", "lengthSpecials(args)"}, limit = "1") protected Object seqNoClassFromAndLength(RArgsValuesAndNames args, // - @Cached("createSeqIntForFastPath()") SeqInt seqInt, - @Cached("lookupSeqInt()") RFunction seqIntFunction, - @Cached("createBinaryProfile()") ConditionProfile isNumericProfile, - @Cached("createGetClassAttributeNode()") GetClassAttributeNode getClassAttributeNode, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck) { - if (isNumericProfile.profile(fromCheck.execute(args.getArgument(0)))) { + @Cached("new()") SeqNoClassFromAndLengthNode cache) { + if (cache.isNumericProfile.profile(cache.fromCheck.execute(args.getArgument(0)))) { if (args.getLength() == 1) { - return seqInt.execute(RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance, RMissing.instance); + return cache.seqInt.execute(RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance, RMissing.instance); } else { - return seqInt.execute(args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance, RMissing.instance); + return cache.seqInt.execute(args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance, RMissing.instance); } } else { return null; } } - @Specialization(guards = {"!hasClass(args, getClassAttributeNode)"}) + public static class SeqNoClassFromAndLengthNode { + + final SeqInt seqInt; + final RFunction seqIntFunction; + final ConditionProfile isNumericProfile; + @Child public GetClassAttributeNode getClassAttributeNode; + @Child IsMissingOrNumericNode fromCheck; + + public SeqNoClassFromAndLengthNode() { + this.seqInt = SeqInt.createSeqIntForFastPath(); + this.seqIntFunction = lookupSeqInt(); + this.isNumericProfile = ConditionProfile.createBinaryProfile(); + this.getClassAttributeNode = createGetClassAttributeNode(); + this.fromCheck = createIsMissingOrNumericNode(); + } + + } + + @Specialization(guards = {"!hasClass(args, cache.getClassAttributeNode)"}, limit = "1") protected Object seqNoClassAndNumeric(RArgsValuesAndNames args, - @Cached("createSeqIntForFastPath()") SeqInt seqInt, - @Cached("lookupSeqInt()") RFunction seqIntFunction, - @Cached("createBinaryProfile()") ConditionProfile isNumericProfile, - @Cached("createGetClassAttributeNode()") @SuppressWarnings("unused") GetClassAttributeNode getClassAttributeNode, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode toCheck, - @Cached("createIsMissingOrNumericNode()") @SuppressWarnings("unused") IsMissingOrNumericNode byCheck) { - Object[] rargs = reorderedArguments(args, seqIntFunction); - if (isNumericProfile.profile(fromCheck.execute(rargs[0]) && toCheck.execute(rargs[1]) && toCheck.execute(rargs[2]))) { - return seqInt.execute(rargs[0], rargs[1], rargs[2], rargs[3], rargs[4], RMissing.instance); + @Cached("new()") SeqNoClassAndNumericNode cache) { + Object[] rargs = reorderedArguments(args, cache.seqIntFunction); + if (cache.isNumericProfile.profile(cache.fromCheck.execute(rargs[0]) && cache.toCheck.execute(rargs[1]) && cache.toCheck.execute(rargs[2]))) { + return cache.seqInt.execute(rargs[0], rargs[1], rargs[2], rargs[3], rargs[4], RMissing.instance); } else { return null; } } + public static class SeqNoClassAndNumericNode extends SeqNoClassFromAndLengthNode { + @Child IsMissingOrNumericNode toCheck; + @Child IsMissingOrNumericNode byCheck; + + public SeqNoClassAndNumericNode() { + this.toCheck = createIsMissingOrNumericNode(); + this.byCheck = createIsMissingOrNumericNode(); + } + + } + @Fallback protected Object seqFallback(@SuppressWarnings("unused") Object args) { return null; @@ -299,14 +318,24 @@ public final class SeqFunctions { */ @TypeSystemReference(RTypes.class) public abstract static class SeqDefaultFastPath extends FastPathAdapter { - @SuppressWarnings("unused") - @Specialization(guards = {"fromCheck.execute(fromObj)", "toCheck.execute(toObj)", "byCheck.execute(byObj)"}) + @Specialization(guards = {"cache.fromCheck.execute(fromObj)", "cache.toCheck.execute(toObj)", "cache.byCheck.execute(byObj)"}, limit = "1") protected Object seqDefaultNumeric(Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, - @Cached("createSeqIntForFastPath()") SeqInt seqInt, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode toCheck, - @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode byCheck) { - return seqInt.execute(fromObj, toObj, byObj, lengthOut, alongWith, RMissing.instance); + @Cached("new()") SeqDefaultNumericNode cache) { + return cache.seqInt.execute(fromObj, toObj, byObj, lengthOut, alongWith, RMissing.instance); + } + + public class SeqDefaultNumericNode extends Node { + @Child SeqInt seqInt; + @Child public IsMissingOrNumericNode fromCheck; + @Child public IsMissingOrNumericNode toCheck; + @Child public IsMissingOrNumericNode byCheck; + + public SeqDefaultNumericNode() { + seqInt = SeqInt.createSeqIntForFastPath(); + fromCheck = createIsMissingOrNumericNode(); + toCheck = createIsMissingOrNumericNode(); + byCheck = createIsMissingOrNumericNode(); + } } /** @@ -787,18 +816,27 @@ public final class SeqFunctions { } // common idiom - @Specialization(guards = {"fromCheck.execute(fromObj)", "lengthCheck.execute(lengthOut)"}) + @Specialization(guards = {"cached.fromCheck.execute(fromObj)", "cached.lengthCheck.execute(lengthOut)"}, limit = "1") protected RAbstractVector seqWithFromLengthIntegralNumeric(Object fromObj, RMissing toObj, RMissing byObj, Object lengthOut, RMissing alongWith, Object dotdotdot, - @Cached("createGetIntegralNumericNode()") GetIntegralNumericNode getIntegralNumericNode, - @Cached("createIsIntegralNumericNodeNoLengthCheck()") IsIntegralNumericNode fromCheck, - @Cached("createIsIntegralNumericNodeLengthCheck()") IsIntegralNumericNode lengthCheck) { - int from = getIntegralNumericNode.execute(fromObj); - int lout = getIntegralNumericNode.execute(lengthOut); + @Cached("new()") SeqWithFromLengthIntegralNumericNode cached) { + int from = cached.getIntegralNumericNode.execute(fromObj); + int lout = cached.getIntegralNumericNode.execute(lengthOut); if (lout == 0) { return RDataFactory.createEmptyIntVector(); } return RDataFactory.createDoubleSequence(from, 1, lout); + } + public class SeqWithFromLengthIntegralNumericNode extends Node { + @Child GetIntegralNumericNode getIntegralNumericNode; + @Child public IsIntegralNumericNode fromCheck; + @Child public IsIntegralNumericNode lengthCheck; + + public SeqWithFromLengthIntegralNumericNode() { + getIntegralNumericNode = createGetIntegralNumericNode(); + fromCheck = createIsIntegralNumericNodeNoLengthCheck(); + lengthCheck = createIsIntegralNumericNodeLengthCheck(); + } } // "by" missing diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Strrep.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Strrep.java index 43dd6c789ac6620c2c3d9d76ee27d188606bbd4c..3b6723a2e2c6484921ae9e4b423055e90d8689ee 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Strrep.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Strrep.java @@ -91,12 +91,14 @@ public abstract class Strrep extends RBuiltinNode.Arg2 { } @Specialization + @SuppressWarnings("unused") protected Object strrep(RNull xVec, RAbstractIntVector timesVec) { return RDataFactory.createEmptyStringVector(); // GnuR fails with segfault; return value // adheres to non-internal strrep() result } @Specialization + @SuppressWarnings("unused") protected Object strrep(RAbstractStringVector xVec, RNull timesVec) { return RDataFactory.createEmptyStringVector(); // GnuR - infinite loop; return value adheres // to non-internal strrep() result diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java index e266bceac2765ababb0878140efd737a41bff344..dbcc505daa559df10188669a5aac0e9035bd35f0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Switch.java @@ -81,7 +81,8 @@ public abstract class Switch extends RBuiltinNode.Arg2 { // could be interpreted as integer @Specialization - protected Object doSwitchList(VirtualFrame frame, RList list, @SuppressWarnings("unused") RArgsValuesAndNames optionalArgs) { + @SuppressWarnings("unused") + protected Object doSwitchList(VirtualFrame frame, RList list, RArgsValuesAndNames optionalArgs) { return prepareResult(frame, null); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IntersectFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IntersectFastPath.java index 5d746b49b97ac9dce9232dc5b695e56cf22ad10e..268ab3930cf3bfe67e43687abff84475d145e3b3 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IntersectFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IntersectFastPath.java @@ -39,8 +39,6 @@ import com.oracle.truffle.r.runtime.nodes.RFastPathNode; public abstract class IntersectFastPath extends RFastPathNode { - protected static final int TYPE_LIMIT = 2; - private static final int[] EMPTY_INT_ARRAY = new int[0]; protected static final class IntersectSortedNode extends Node { @@ -140,47 +138,53 @@ public abstract class IntersectFastPath extends RFastPathNode { return new IntersectSortedNode(false); } - @Specialization(limit = "TYPE_LIMIT", guards = {"x.getClass() == xClass", "y.getClass() == yClass", "length(x, xClass) > 0", "length(y, yClass) > 0"}, rewriteOn = IllegalArgumentException.class) + @Specialization(limit = "1", guards = {"x.getClass() == cached.xClass", "y.getClass() == cached.yClass", "length(x, cached.xClass) > 0", + "length(y, cached.yClass) > 0"}, rewriteOn = IllegalArgumentException.class) protected RAbstractIntVector intersectMaybeSorted(RAbstractIntVector x, RAbstractIntVector y, - @Cached("x.getClass()") Class<? extends RAbstractIntVector> xClass, - @Cached("y.getClass()") Class<? extends RAbstractIntVector> yClass, - @Cached("createMaybeSorted()") IntersectSortedNode intersect) { + @Cached("new(x.getClass(), y.getClass())") IntersectMaybeSortedNode cached) { // apply the type profiles: - RAbstractIntVector profiledX = xClass.cast(x); - RAbstractIntVector profiledY = yClass.cast(y); + RAbstractIntVector profiledX = cached.xClass.cast(x); + RAbstractIntVector profiledY = cached.yClass.cast(y); int xLength = profiledX.getLength(); int yLength = profiledY.getLength(); RBaseNode.reportWork(this, xLength + yLength); - int[] result = intersect.execute(profiledX, xLength, yLength, profiledY); + int[] result = cached.intersect.execute(profiledX, xLength, yLength, profiledY); return RDataFactory.createIntVector(result, profiledX.isComplete() | profiledY.isComplete()); } + public static class IntersectMaybeSortedNode extends Node { + public final Class<? extends RAbstractIntVector> xClass; + public final Class<? extends RAbstractIntVector> yClass; + @Child IntersectSortedNode intersect; + + public IntersectMaybeSortedNode(Class<? extends RAbstractIntVector> xClass, Class<? extends RAbstractIntVector> yClass) { + this.xClass = xClass; + this.yClass = yClass; + this.intersect = createMaybeSorted(); + } + } + protected static IntersectSortedNode createSorted() { return new IntersectSortedNode(true); } - @Specialization(limit = "TYPE_LIMIT", guards = {"x.getClass() == xClass", "y.getClass() == yClass", "length(x, xClass) > 0", "length(y, yClass) > 0"}) + @Specialization(limit = "1", guards = {"x.getClass() == cached.xClass", "y.getClass() == cached.yClass", "length(x, cached.xClass) > 0", "length(y, cached.yClass) > 0"}) protected RAbstractIntVector intersect(RAbstractIntVector x, RAbstractIntVector y, - @Cached("x.getClass()") Class<? extends RAbstractIntVector> xClass, - @Cached("y.getClass()") Class<? extends RAbstractIntVector> yClass, - @Cached("createBinaryProfile()") ConditionProfile isXSortedProfile, - @Cached("createBinaryProfile()") ConditionProfile isYSortedProfile, - @Cached("createBinaryProfile()") ConditionProfile resultLengthMatchProfile, - @Cached("createSorted()") IntersectSortedNode intersect) { + @Cached("new(x.getClass(), y.getClass())") IntersectNode cached) { // apply the type profiles: - RAbstractIntVector profiledX = xClass.cast(x); - RAbstractIntVector profiledY = yClass.cast(y); + RAbstractIntVector profiledX = cached.xClass.cast(x); + RAbstractIntVector profiledY = cached.yClass.cast(y); int xLength = profiledX.getLength(); int yLength = profiledY.getLength(); RBaseNode.reportWork(this, xLength + yLength); int[] result; - if (isXSortedProfile.profile(isSorted(profiledX))) { + if (cached.isXSortedProfile.profile(isSorted(profiledX))) { RAbstractIntVector tempY; - if (isYSortedProfile.profile(isSorted(profiledY))) { + if (cached.isYSortedProfile.profile(isSorted(profiledY))) { tempY = profiledY; } else { int[] temp = new int[yLength]; @@ -190,7 +194,7 @@ public abstract class IntersectFastPath extends RFastPathNode { sort(temp); tempY = RDataFactory.createIntVector(temp, profiledY.isComplete()); } - result = intersect.execute(profiledX, xLength, yLength, tempY); + result = cached.intersect.execute(profiledX, xLength, yLength, tempY); } else { result = EMPTY_INT_ARRAY; int maxResultLength = Math.min(xLength, yLength); @@ -213,11 +217,26 @@ public abstract class IntersectFastPath extends RFastPathNode { result[count++] = value; } } - result = resultLengthMatchProfile.profile(count == result.length) ? result : Arrays.copyOf(result, count); + result = cached.resultLengthMatchProfile.profile(count == result.length) ? result : Arrays.copyOf(result, count); } return RDataFactory.createIntVector(result, profiledX.isComplete() | profiledY.isComplete()); } + public static class IntersectNode extends Node { + public final Class<? extends RAbstractIntVector> xClass; + public final Class<? extends RAbstractIntVector> yClass; + final ConditionProfile isXSortedProfile = ConditionProfile.createBinaryProfile(); + final ConditionProfile isYSortedProfile = ConditionProfile.createBinaryProfile(); + final ConditionProfile resultLengthMatchProfile = ConditionProfile.createBinaryProfile(); + @Child IntersectSortedNode intersect; + + public IntersectNode(Class<? extends RAbstractIntVector> xClass, Class<? extends RAbstractIntVector> yClass) { + this.xClass = xClass; + this.yClass = yClass; + this.intersect = createMaybeSorted(); + } + } + private static boolean isSorted(RAbstractIntVector vector) { int length = vector.getLength(); int lastValue = vector.getDataAt(0); @@ -240,4 +259,5 @@ public abstract class IntersectFastPath extends RFastPathNode { protected Object fallback(@SuppressWarnings("unused") Object x, @SuppressWarnings("unused") Object y) { return null; } + } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SetDiffFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SetDiffFastPath.java index 637b427b173dbbe5eb6c400fca5a6c73a7b6cc32..28d3f45c916b4ffa6f36bff66d379023717afe06 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SetDiffFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SetDiffFastPath.java @@ -32,8 +32,8 @@ import com.oracle.truffle.r.runtime.nodes.RFastPathNode; public abstract class SetDiffFastPath extends RFastPathNode { - @Specialization(guards = {"x.getStride() == 1", "y.getClass() == yClass"}) - protected Object setdiff(RIntSequence x, RAbstractIntVector y, + @Specialization(guards = {"x.getStride() == 1", "y.getClass() == yClass"}, limit = "3") + protected static Object cached(RIntSequence x, RAbstractIntVector y, @Cached("y.getClass()") Class<? extends RAbstractIntVector> yClass) { RAbstractIntVector profiledY = yClass.cast(y); int xLength = x.getLength(); @@ -64,9 +64,14 @@ public abstract class SetDiffFastPath extends RFastPathNode { return RDataFactory.createIntVector(result, true); } + @Specialization(guards = {"x.getStride() == 1"}, replaces = "cached") + protected static Object generic(RIntSequence x, RAbstractIntVector y) { + return cached(x, y, y.getClass()); + } + @Fallback @SuppressWarnings("unused") - protected Object fallback(Object x, Object y) { + protected static Object fallback(Object x, Object y) { return null; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java index eefdeb44aadb7a314f371af24035b6fb4845ffc3..fa7bd093468a50b2f7af32a0ba00d1f728d75522 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java @@ -22,6 +22,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.nodes.Node; import com.oracle.truffle.r.library.fastrGrid.FastRGridExternalLookup; import com.oracle.truffle.r.library.methods.MethodsListDispatchFactory.R_M_setPrimitiveMethodsNodeGen; import com.oracle.truffle.r.library.methods.MethodsListDispatchFactory.R_externalPtrPrototypeObjectNodeGen; @@ -73,6 +74,7 @@ import com.oracle.truffle.r.library.utils.TypeConvertNodeGen; import com.oracle.truffle.r.library.utils.UnzipNodeGen; import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode; import com.oracle.truffle.r.nodes.builtin.RInternalCodeBuiltinNode; +import com.oracle.truffle.r.nodes.builtin.base.foreign.CallAndExternalFunctions.DotExternal.CallNamedFunctionNode; import com.oracle.truffle.r.nodes.helpers.MaterializeNode; import com.oracle.truffle.r.nodes.objects.GetPrimNameNodeGen; import com.oracle.truffle.r.nodes.objects.NewObjectNodeGen; @@ -80,7 +82,9 @@ import com.oracle.truffle.r.runtime.FastROptions; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalCode; import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.builtins.RBehavior; import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.builtins.RBuiltinKind; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RDataFactory; @@ -733,7 +737,7 @@ public class CallAndExternalFunctions { * The interpretation of the {@code .NAME} and {code .PACKAGE} arguments as are for * {@link DotCall}. */ - @RBuiltin(name = ".External", kind = PRIMITIVE, parameterNames = {".NAME", "...", "PACKAGE"}, behavior = COMPLEX) + @com.oracle.truffle.r.runtime.builtins.RBuiltin(name = ".External", kind = RBuiltinKind.PRIMITIVE, parameterNames = {".NAME", "...", "PACKAGE"}, behavior = RBehavior.COMPLEX) public abstract static class DotExternal extends LookupAdapter { @Child private CallRFFI.InvokeCallNode callRFFINode = RFFIFactory.getCallRFFI().createInvokeCallNode(); @@ -802,13 +806,22 @@ public class CallAndExternalFunctions { } @SuppressWarnings("unused") - @Specialization(limit = "2", guards = {"cached == symbol"})// limit="2" because of DSL bug + @Specialization(limit = "1", guards = {"cached.symbol == symbol"}) protected Object callNamedFunction(RList symbol, RArgsValuesAndNames args, Object packageName, - @Cached("symbol") RList cached, - @Cached("new()") ExtractNativeCallInfoNode extractSymbolInfo, - @Cached("extractSymbolInfo.execute(symbol)") NativeCallInfo nativeCallInfo) { - Object list = encodeArgumentPairList(args, nativeCallInfo.name); - return callRFFINode.dispatch(nativeCallInfo, new Object[]{list}); + @Cached("new(symbol)") CallNamedFunctionNode cached) { + Object list = encodeArgumentPairList(args, cached.nativeCallInfo.name); + return callRFFINode.dispatch(cached.nativeCallInfo, new Object[]{list}); + } + + public static class CallNamedFunctionNode extends Node { + public final RList symbol; + final NativeCallInfo nativeCallInfo; + + public CallNamedFunctionNode(RList symbol) { + this.symbol = symbol; + this.nativeCallInfo = new ExtractNativeCallInfoNode().execute(symbol); + } + } @Specialization @@ -899,13 +912,11 @@ public class CallAndExternalFunctions { } @SuppressWarnings("unused") - @Specialization(limit = "2", guards = {"cached == symbol"}) // limit="2" because of DSL bug + @Specialization(limit = "1", guards = {"cached.symbol == symbol"}) protected Object callNamedFunction(RList symbol, RArgsValuesAndNames args, Object packageName, - @Cached("symbol") RList cached, - @Cached("new()") ExtractNativeCallInfoNode extractSymbolInfo, - @Cached("extractSymbolInfo.execute(symbol)") NativeCallInfo nativeCallInfo) { - Object list = encodeArgumentPairList(args, nativeCallInfo.name); - return callRFFINode.dispatch(nativeCallInfo, new Object[]{CALL, getOp(), list, RHO}); + @Cached("new(symbol)") CallNamedFunctionNode cached) { + Object list = encodeArgumentPairList(args, cached.nativeCallInfo.name); + return callRFFINode.dispatch(cached.nativeCallInfo, new Object[]{CALL, getOp(), list, RHO}); } @Specialization diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ListPrinter.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ListPrinter.java index 344a27d78998400ac0dd6cf9d31d386994d762b2..7c84d1caf7a79c2145c6ad528bd222ee4e6ed597 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ListPrinter.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ListPrinter.java @@ -30,7 +30,6 @@ import com.oracle.truffle.r.runtime.data.RLanguage; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractListVector; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java index 98a1c486ef10f89e416b6a7daa1282334b64dd22..65a38e8148ec40896a988c3f9e4267e95c857cb0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java @@ -798,11 +798,10 @@ public class FastRInterop { Casts.noCasts(InteropNew.class); } - @Specialization(limit = "99", guards = {"isForeignObject(clazz)", "length == args.getLength()"}) + @Specialization(guards = {"isForeignObject(clazz)"}) @TruffleBoundary public Object interopNew(TruffleObject clazz, RArgsValuesAndNames args, - @SuppressWarnings("unused") @Cached("args.getLength()") int length, - @Cached("createNew(length).createNode()") Node sendNew, + @Cached("createNew(0).createNode()") Node sendNew, @Cached("create()") R2Foreign r2Foreign, @Cached("create()") Foreign2R foreign2R) { try { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java index 6cdcdf89e23d866f2e90d45aeb77a8a9854067d7..c3c7bcbd3519ee7244320a1c1d471a046e007950 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java @@ -94,18 +94,12 @@ public abstract class ExtractVectorNode extends RBaseNode { protected abstract Object execute(Object vector, Object[] positions, Object exact, Object dropDimensions); - @Specialization(guards = {"cached != null", "cached.isSupported(vector, positions)"}) + @Specialization(guards = {"cached != null", "cached.isSupported(vector, positions)"}, limit = "3") protected Object doExtractSameDimensions(RAbstractVector vector, Object[] positions, Object exact, Object dropDimensions, // @Cached("createRecursiveCache(vector, positions)") RecursiveExtractSubscriptNode cached) { return cached.apply(vector, positions, exact, dropDimensions); } - @Specialization(guards = {"cached != null", "cached.isSupported(vector, positions)"}) - protected Object doExtractRecursive(RAbstractListVector vector, Object[] positions, Object exact, Object dropDimensions, // - @Cached("createRecursiveCache(vector, positions)") RecursiveExtractSubscriptNode cached) { - return cached.apply(vector, positions, exact, dropDimensions); - } - protected RecursiveExtractSubscriptNode createRecursiveCache(Object vector, Object[] positions) { if (isRecursiveSubscript(vector, positions)) { return RecursiveExtractSubscriptNode.create((RAbstractListVector) vector, positions[0]); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java index 814b3c6f6e324ee9af106229a09be0c709778256..2e6c5c264963c3b02f1eb8209d60905983f46399 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java @@ -897,7 +897,6 @@ public final class SpecialAttributesFunctions { public abstract static class InitDimsNamesDimNamesNode extends RBaseNode { - private final ConditionProfile oldAttrsNullProfile = ConditionProfile.createBinaryProfile(); private final ConditionProfile doAnythingProfile = ConditionProfile.createBinaryProfile(); @Child private GetDimAttributeNode getDimNode; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java index 62c6f044fb95cda2d7c6063b6c7fda748e579bca..45f7c7172620825a5482dbbe39ec42b100ae6d1d 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java @@ -25,7 +25,6 @@ package com.oracle.truffle.r.nodes.function.call; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; @@ -180,7 +179,7 @@ public abstract class PrepareArguments extends Node { return ArgumentMatcher.matchArgumentsEvaluated(permutation, explicitArgs.getArguments(), s3DefaultArguments, formals); } - @Fallback + @Specialization @TruffleBoundary public RArgsValuesAndNames prepareGeneric(RArgsValuesAndNames explicitArgs, S3DefaultArguments s3DefaultArguments, @SuppressWarnings("unused") RCallNode call) { // Function and arguments may change every call: Flatt'n'Match on SlowPath! :-/ diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareMatchInternalArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareMatchInternalArguments.java index 23b150ba129ea609c0df36c851469658e5b813ef..ced89a756a2fc3f9a2744196a5dc3af5a02e8b89 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareMatchInternalArguments.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareMatchInternalArguments.java @@ -26,7 +26,6 @@ import java.util.Objects; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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.nodes.Node; import com.oracle.truffle.r.nodes.function.ArgumentMatcher; @@ -66,8 +65,8 @@ public abstract class PrepareMatchInternalArguments extends Node { return ArgumentMatcher.matchArgumentsEvaluated(permutation, explicitArgs.getArguments(), s3DefaultArguments, formals); } - @Fallback @TruffleBoundary + @Specialization public RArgsValuesAndNames prepareGeneric(RArgsValuesAndNames evaluatedArgs, S3DefaultArguments s3DefaultArguments) { return ArgumentMatcher.matchArgumentsEvaluated(formals, evaluatedArgs, s3DefaultArguments, callingNode); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseNonSharedNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseNonSharedNode.java index 09ef7a3fc56c1c0f0474bb0b4947012ffbb12f00..54da9d9c5f26fd7ee94866aaad57908c1cd3f06c 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseNonSharedNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseNonSharedNode.java @@ -24,7 +24,6 @@ package com.oracle.truffle.r.nodes.function.opt; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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.nodes.Node; import com.oracle.truffle.api.profiles.ConditionProfile; @@ -73,7 +72,7 @@ public abstract class ReuseNonSharedNode extends Node { } } - @Fallback + @Specialization @TruffleBoundary public static RVector<?> reuseSlow(RAbstractVector value) { RSharingAttributeStorage.verify(value); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java index ff7a98dceb7fc19d46b402fb85303f40c382607a..65b4d0f0a086a19af810217eb9c26a1de63fe01c 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/opt/ReuseTemporaryNode.java @@ -24,7 +24,6 @@ package com.oracle.truffle.r.nodes.function.opt; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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.nodes.Node; import com.oracle.truffle.api.profiles.ConditionProfile; @@ -64,7 +63,7 @@ public abstract class ReuseTemporaryNode extends Node { } } - @Fallback + @Specialization @TruffleBoundary public static RVector<?> reuseSlow(RAbstractVector value) { RSharingAttributeStorage.verify(value); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCleanUp.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCleanUp.java index d33648e88f25646b17a93d579f973f4e91c46b12..37065d16a16fe7a968856635a928b9ceace872c6 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCleanUp.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RCleanUp.java @@ -82,7 +82,6 @@ public class RCleanUp { * we save always */ RContext.getEngine().checkAndRunStartupShutdownFunction("sys.save.image", new String[]{"\".RData\""}); - String history = RContext.getInstance().getConsole().getHistory(); // TODO: write out history break; case NOSAVE: diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ChildContextInfo.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ChildContextInfo.java index a40ce96e9b708b299c5697038600e8ca607a74ae..931b59fd2ad37b18af07cefc88851216fa83cc45 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ChildContextInfo.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ChildContextInfo.java @@ -119,7 +119,7 @@ public final class ChildContextInfo { return this.truffleContext; } - public TruffleContext createVM(ChildContextInfo childContextInfo) { + public TruffleContext createVM(@SuppressWarnings("unused") ChildContextInfo childContextInfo) { this.truffleContext = RContext.getInstance().getEnv().newContextBuilder().config("parentContext", parent.getVM()).config(CONFIG_KEY, this).build(); return this.truffleContext; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/EnableNACheckNode.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/EnableNACheckNode.java index 63fd9a46ad164623671bbc371b8546643d7d846e..d9884dc6260054d5f0cca9fcb034a26bd53f4457 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/EnableNACheckNode.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/EnableNACheckNode.java @@ -23,7 +23,6 @@ package com.oracle.truffle.r.runtime.data.nodes; 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.nodes.Node; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @@ -42,8 +41,8 @@ public abstract class EnableNACheckNode extends Node { check.enable(clazz.cast(vector)); } - @Fallback - public void doEnable(NACheck check, RAbstractVector vector) { + @Specialization(replaces = "doEnable") + public void doEnableGeneric(NACheck check, RAbstractVector vector) { check.enable(vector); } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataAt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataAt.java index 72827019f4ab86f92e5087bc710fcf845dd38a4e..e85b37ebc48af203afdc4afb8bb653f1a103da2e 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataAt.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataAt.java @@ -60,6 +60,7 @@ public abstract class GetDataAt extends Node { public abstract Object getAsObject(RAbstractVector vector, Object store, int index); @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Int extends GetDataAt { public static Int create() { @@ -92,14 +93,19 @@ public abstract class GetDataAt extends Node { } // This accounts for other vector types, like closures - @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}) - protected int doDoubleClosure(RAbstractIntVector vector, Object store, int index, + @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}, limit = "3") + protected int doGenericCached(RAbstractIntVector vector, Object store, int index, @Cached("vector.getClass()") Class<? extends RAbstractIntVector> cachedClass) { return cachedClass.cast(vector).getDataAt(store, index); } + @Specialization(guards = {"isGenericVector(vector)"}, replaces = "doGenericCached") + protected int doGeneric(RAbstractIntVector vector, Object store, int index) { + return vector.getDataAt(store, index); + } + @Fallback - protected int doDoubleClosure(RAbstractIntVector vector, Object store, int index) { + protected int doFallback(RAbstractIntVector vector, Object store, int index) { return vector.getDataAt(store, index); } @@ -109,6 +115,7 @@ public abstract class GetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Double extends GetDataAt { public static Double create() { @@ -142,13 +149,18 @@ public abstract class GetDataAt extends Node { } @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}, limit = "3") - protected double doDoubleClosure(RAbstractDoubleVector vector, Object store, int index, + protected double doGenericCached(RAbstractDoubleVector vector, Object store, int index, @Cached("vector.getClass()") Class<?> cachedClass) { return ((RAbstractDoubleVector) cachedClass.cast(vector)).getDataAt(store, index); } + @Specialization(guards = "isGenericVector(vector)", replaces = "doGenericCached") + protected double doGeneric(RAbstractDoubleVector vector, Object store, int index) { + return vector.getDataAt(store, index); + } + @Fallback - protected double doDoubleClosure(RAbstractDoubleVector vector, Object store, int index) { + protected double doFallback(RAbstractDoubleVector vector, Object store, int index) { return vector.getDataAt(store, index); } @@ -158,6 +170,7 @@ public abstract class GetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Logical extends GetDataAt { public static Logical create() { @@ -185,14 +198,19 @@ public abstract class GetDataAt extends Node { } // This accounts for other vector types, like closures - @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}) - protected byte doDoubleClosure(RAbstractLogicalVector vector, Object store, int index, + @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}, limit = "3") + protected byte doGenericCached(RAbstractLogicalVector vector, Object store, int index, @Cached("vector.getClass()") Class<? extends RAbstractLogicalVector> cachedClass) { return cachedClass.cast(vector).getDataAt(store, index); } + @Specialization(guards = {"isGenericVector(vector)"}, replaces = "doGenericCached") + protected byte doGeneric(RAbstractLogicalVector vector, Object store, int index) { + return vector.getDataAt(store, index); + } + @Fallback - protected byte doDoubleClosure(RAbstractLogicalVector vector, Object store, int index) { + protected byte doFallback(RAbstractLogicalVector vector, Object store, int index) { return vector.getDataAt(store, index); } @@ -202,6 +220,7 @@ public abstract class GetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Raw extends GetDataAt { public static Raw create() { @@ -229,14 +248,19 @@ public abstract class GetDataAt extends Node { } // This accounts for other vector types, like closures - @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}) - protected byte doDoubleClosure(RAbstractRawVector vector, Object store, int index, + @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}, limit = "3") + protected byte doGenericCached(RAbstractRawVector vector, Object store, int index, @Cached("vector.getClass()") Class<? extends RAbstractRawVector> cachedClass) { return cachedClass.cast(vector).getRawDataAt(store, index); } + @Specialization(guards = {"isGenericVector(vector)"}, replaces = "doGenericCached") + protected byte doGeneric(RAbstractRawVector vector, Object store, int index) { + return vector.getRawDataAt(store, index); + } + @Fallback - protected byte doDoubleClosure(RAbstractRawVector vector, Object store, int index) { + protected byte doFallback(RAbstractRawVector vector, Object store, int index) { return vector.getRawDataAt(store, index); } @@ -263,7 +287,7 @@ public abstract class GetDataAt extends Node { public abstract RComplex execute(RAbstractComplexVector vector, Object store, int index); - protected RComplex doRVector(RComplexVector vector, double[] store, int index) { + protected RComplex doRVector(@SuppressWarnings("unused") RComplexVector vector, double[] store, int index) { return RComplex.valueOf(store[index * 2], store[index * 2 + 1]); } @@ -273,14 +297,19 @@ public abstract class GetDataAt extends Node { throw RInternalError.unimplemented(); } - @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}) - protected RComplex doDoubleClosure(RAbstractComplexVector vector, Object store, int index, + @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}, limit = "3") + protected RComplex doGenericCached(RAbstractComplexVector vector, Object store, int index, @Cached("vector.getClass()") Class<? extends RAbstractComplexVector> cachedClass) { return cachedClass.cast(vector).getDataAt(store, index); } + @Specialization(guards = {"isGenericVector(vector)"}, replaces = "doGenericCached") + protected RComplex doGeneric(RAbstractComplexVector vector, Object store, int index) { + return vector.getDataAt(store, index); + } + @Fallback - protected RComplex doDoubleClosure(RAbstractComplexVector vector, Object store, int index) { + protected RComplex doFallback(RAbstractComplexVector vector, Object store, int index) { return vector.getDataAt(store, index); } @@ -307,7 +336,7 @@ public abstract class GetDataAt extends Node { public abstract java.lang.String execute(RAbstractStringVector vector, Object store, int index); - protected java.lang.String doRVector(RStringVector vector, java.lang.String[] store, int index) { + protected java.lang.String doRVector(@SuppressWarnings("unused") RStringVector vector, java.lang.String[] store, int index) { return store[index]; } @@ -318,13 +347,18 @@ public abstract class GetDataAt extends Node { } @Specialization(guards = {"isGenericVector(vector)", "cachedClass == vector.getClass()"}) - protected java.lang.String doDoubleClosure(RAbstractStringVector vector, Object store, int index, + protected java.lang.String doGenericCached(RAbstractStringVector vector, Object store, int index, @Cached("vector.getClass()") Class<? extends RAbstractStringVector> cachedClass) { return cachedClass.cast(vector).getDataAt(store, index); } + @Specialization(guards = {"isGenericVector(vector)"}, replaces = "doGenericCached") + protected java.lang.String doGeneric(RAbstractStringVector vector, Object store, int index) { + return vector.getDataAt(store, index); + } + @Fallback - protected java.lang.String doDoubleClosure(RAbstractStringVector vector, Object store, int index) { + protected java.lang.String doFallback(RAbstractStringVector vector, Object store, int index) { return vector.getDataAt(store, index); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataCopy.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataCopy.java index f5b86c65dd6a62a1516f8a386f9af4ef2d544776..ebd66da59d1822a94aeefb09136854dd9f081673 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataCopy.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataCopy.java @@ -83,7 +83,7 @@ public abstract class GetDataCopy { } @Specialization(guards = "vec.hasNativeMemoryData()") - protected java.lang.String[] doManagedRVector(RStringVector vec) { + protected java.lang.String[] doManagedRVector(@SuppressWarnings("unused") RStringVector vec) { throw RInternalError.unimplemented("string vectors backed by native memory"); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataStore.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataStore.java index 2d07058cbdd0aa0ec50d217f5544e440a8c69f00..a9baa4b4177c2b71b86db8754ceb76113a8e924f 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataStore.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/GetDataStore.java @@ -45,7 +45,7 @@ public abstract class GetDataStore extends Node { } @Specialization(guards = {"noNativeMemoryData(vector)", "vector.getClass() == vectorClass"}, limit = "CACHE_LIMIT") - protected Object doGeneric(RAbstractVector vector, + protected Object doCached(RAbstractVector vector, @Cached("vector.getClass()") Class<? extends RAbstractVector> vectorClass, @Cached("getStoreClass(vector)") Class<?> storeClass) { Object store = vectorClass.cast(vector).getInternalStore(); @@ -53,6 +53,12 @@ public abstract class GetDataStore extends Node { return storeClass.cast(store); } + @Specialization(replaces = "doCached", guards = {"noNativeMemoryData(vector)"}) + protected Object doGeneric(RAbstractVector vector) { + Object store = vector.getInternalStore(); + return store; + } + @Fallback protected Object doFallback(RAbstractVector vector) { if (noNativeMemoryData(vector)) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SetDataAt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SetDataAt.java index 46f7a849bc3efd49e51de9ea55b635ff53891a7d..297b29b932ac9b31d16537c4dc78d3c7f2a9d1d8 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SetDataAt.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SetDataAt.java @@ -41,6 +41,7 @@ public abstract class SetDataAt extends Node { public abstract void setDataAtAsObject(RVector<?> vector, Object store, int index, Object value); @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Double extends SetDataAt { @Override @@ -70,6 +71,7 @@ public abstract class SetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Int extends SetDataAt { @Override @@ -99,6 +101,7 @@ public abstract class SetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Logical extends SetDataAt { @Override @@ -128,6 +131,7 @@ public abstract class SetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Raw extends SetDataAt { @Override @@ -157,6 +161,7 @@ public abstract class SetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class Complex extends SetDataAt { @Override @@ -188,6 +193,7 @@ public abstract class SetDataAt extends Node { } @ImportStatic(NativeDataAccess.class) + @SuppressWarnings("unused") public abstract static class String extends SetDataAt { @Override diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorIterator.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorIterator.java index f2ffc6e80be0be8bb4e4c0e5e6056f15d3f91d51..ebb528ff5b3ccd8372e846f4a9f0f33f6b06e57a 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorIterator.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorIterator.java @@ -68,18 +68,25 @@ abstract class GetIteratorNode extends VectorIteratorNodeAdapter { } @Specialization(guards = {"vectorClass == vector.getClass()", "hasNoNativeMemoryData(vector, vectorClass)"}, limit = "10") - protected IteratorData<?> generic(RAbstractVector vector, + protected IteratorData<?> cached(RAbstractVector vector, @Cached("vector.getClass()") Class<? extends RAbstractVector> vectorClass) { RAbstractVector profiledVec = vectorClass.cast(vector); return new IteratorData<>(profiledVec.getInternalStore(), profiledVec.getLength()); } - @Fallback + @Specialization(replaces = "cached", guards = {"hasNoNativeMemoryData(vector, vector.getClass())"}) protected IteratorData<?> generic(RAbstractVector vector) { + RAbstractVector profiledVec = vector; + return new IteratorData<>(profiledVec.getInternalStore(), profiledVec.getLength()); + } + + @Fallback + protected IteratorData<?> fallback(RAbstractVector vector) { return new IteratorData<>(vector.getInternalStore(), vector.getLength()); } } +@SuppressWarnings("unused") abstract class HasNextNode extends VectorIteratorNodeAdapter { public abstract boolean execute(RAbstractVector vector, IteratorData<?> iterator); @@ -115,12 +122,13 @@ abstract class HasNextNode extends VectorIteratorNodeAdapter { return iter.index < profiledVec.getLength(); } - @Fallback + @Specialization protected boolean generic(RAbstractVector vector, IteratorData<?> iter) { return iter.index < vector.getLength(); } } +@SuppressWarnings("unused") abstract class GetNextNode extends VectorIteratorNodeAdapter { public abstract Object execute(RAbstractVector vector, IteratorData<?> iterator); @@ -254,10 +262,10 @@ abstract class GetNextNode extends VectorIteratorNodeAdapter { * This node wraps 3 nodes needed to sequentially iterate a given vector and provides convenience * methods to invoke those nodes: {@link #init(RAbstractVector)}, * {@link #next(RAbstractVector, Object)} and {@link #hasNext(RAbstractVector, Object)}. - * + * * To construct use factory methods from type specialized inner classes, e.g. {@link Int#create()}, * or generic version if the iterated vector could be of any type {@link Generic#create()}. - * + * * Iterator can wrap around, i.e. once the iteration ends, it starts again from the first element. */ public abstract class VectorIterator<T> extends Node { @@ -277,9 +285,8 @@ public abstract class VectorIterator<T> extends Node { } } - @SuppressWarnings("unchecked") public Object init(RAbstractVector vector) { - return (IteratorData<T>) getIteratorNode.execute(vector); + return getIteratorNode.execute(vector); } public boolean hasNext(RAbstractVector vector, Object iterator) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java index 7549bbc4924ea6a7b4401d9d53bca33fb6c39555..d6250e1f5b191c1ebb0c236d77a9bd7db617efb1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/SNorm.java @@ -111,6 +111,7 @@ public final class SNorm { // only static members } + @SuppressWarnings("unused") public static double normRand(RandomNumberGenerator rand, NormKind normKind) { double s; double u1; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/interop/AbstractMRTest.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/interop/AbstractMRTest.java index 3454f3d7ba20a1cf4e18f8cd0aff8b9712811f65..c44cfb173ad9a76f1d0dcf4434f580da03e22822 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/interop/AbstractMRTest.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/interop/AbstractMRTest.java @@ -91,7 +91,7 @@ public abstract class AbstractMRTest { return false; } - protected boolean testToNative(TruffleObject obj) { + protected boolean testToNative(@SuppressWarnings("unused") TruffleObject obj) { return true; } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java index ad80239ab65b27287f05fd591b93272cae55e0a4..58f375d43e239a8579c514272dc81fe6f2b8a0e8 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java @@ -913,7 +913,7 @@ public class TestJavaInterop extends TestBase { } } - private String getRLikeCoordinates(final List<Integer> dims) { + private static String getRLikeCoordinates(final List<Integer> dims) { StringBuilder cor = new StringBuilder(); cor.append("["); for (int i = 0; i < dims.size(); i++) { @@ -926,7 +926,7 @@ public class TestJavaInterop extends TestBase { return cor.toString(); } - private String getJavaLikeCoordinates(final List<Integer> dims) { + private static String getJavaLikeCoordinates(final List<Integer> dims) { StringBuilder cor = new StringBuilder(); for (int i = 0; i < dims.size(); i++) { cor.append("["); @@ -1565,7 +1565,7 @@ public class TestJavaInterop extends TestBase { return sb.toString(); } - private String errorIn(String left, String right) { + private static String errorIn(String left, String right) { String errorIn = "Error in "; String delim = " :";