From 14f4373c6ccc45e48ab1f05f73cb1b68689bef66 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Tue, 8 Aug 2017 14:10:42 +0200 Subject: [PATCH] Fix copying position names in CachedReplaceVectorNode --- .../truffle/r/engine/interop/ListMR.java | 54 +++++----- .../interop/RAbstractVectorAccessFactory.java | 29 ++--- .../r/engine/interop/REnvironmentMR.java | 6 +- .../truffle/r/engine/interop/RLanguageMR.java | 4 +- .../truffle/r/nodes/builtin/base/AnyNA.java | 2 +- .../truffle/r/nodes/builtin/base/Lapply.java | 4 +- .../truffle/r/nodes/builtin/base/Length.java | 4 +- .../truffle/r/nodes/builtin/base/Lengths.java | 5 +- .../truffle/r/nodes/builtin/base/Mapply.java | 10 +- .../r/nodes/builtin/base/SeqFunctions.java | 102 +++++++++--------- .../fastpaths/SubscriptDataFrameFastPath.java | 11 +- .../fastpaths/SubsetDataFrameFastPath.java | 7 +- .../builtin/base/foreign/LookupAdapter.java | 8 +- .../nodes/builtin/base/infix/AccessField.java | 2 +- .../r/nodes/builtin/base/infix/Subscript.java | 6 +- .../r/nodes/builtin/base/infix/Subset.java | 9 +- .../nodes/builtin/base/infix/UpdateField.java | 5 +- .../builtin/base/infix/UpdateSubscript.java | 4 +- .../builtin/base/infix/UpdateSubset.java | 5 +- .../access/vector/ExtractVectorNodeTest.java | 2 +- .../access/vector/ReplaceVectorNodeTest.java | 2 +- .../vector/CachedReplaceVectorNode.java | 5 +- .../access/vector/ExtractVectorNode.java | 21 ++-- .../vector/RecursiveExtractSubscriptNode.java | 23 ++-- .../vector/RecursiveReplaceSubscriptNode.java | 29 +++-- .../access/vector/ReplaceVectorNode.java | 11 +- .../truffle/r/nodes/control/ForNode.java | 2 +- .../truffle/r/nodes/control/RLengthNode.java | 2 +- .../truffle/r/test/ExpectedTestOutput.test | 5 + .../builtins/TestBuiltin_extract_replace.java | 5 + 30 files changed, 193 insertions(+), 191 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 6a873e0868..35d1ddc69c 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 @@ -81,7 +81,7 @@ public class ListMR { @Child private RLengthNode lengthNode = RLengthNode.create(); protected Object access(VirtualFrame frame, RList receiver) { - return getSize(frame, receiver, lengthNode); + return getSize(receiver, lengthNode); } } @@ -106,7 +106,7 @@ public class ListMR { @Child private ListWriteImplNode writeNode = ListWriteImplNodeGen.create(); protected Object access(VirtualFrame frame, RList receiver, Object identifier, Object valueObj) { - return writeNode.execute(frame, receiver, identifier, valueObj); + return writeNode.execute(receiver, identifier, valueObj); } } @@ -124,7 +124,7 @@ public class ListMR { @Child private ListKeyInfoImplNode keyInfoNode = ListKeyInfoImplNodeGen.create(); protected Object access(VirtualFrame frame, TruffleObject receiver, Object idx) { - return keyInfoNode.execute(frame, receiver, idx); + return keyInfoNode.execute(receiver, idx); } } @@ -165,7 +165,7 @@ public class ListMR { @Child private RLengthNode lengthNode = RLengthNode.create(); protected Object access(VirtualFrame frame, RPairList receiver) { - return getSize(frame, receiver, lengthNode); + return getSize(receiver, lengthNode); } } @@ -197,7 +197,7 @@ public class ListMR { @Child private ListWriteImplNode writeNode = ListWriteImplNodeGen.create(); protected Object access(VirtualFrame frame, RPairList receiver, Object identifier, Object valueObj) { - return writeNode.execute(frame, receiver, identifier, valueObj); + return writeNode.execute(receiver, identifier, valueObj); } } @@ -215,7 +215,7 @@ public class ListMR { @Child private ListKeyInfoImplNode keyInfoNode = ListKeyInfoImplNodeGen.create(); protected Object access(VirtualFrame frame, TruffleObject receiver, Object idx) { - return keyInfoNode.execute(frame, receiver, idx); + return keyInfoNode.execute(receiver, idx); } } @@ -245,13 +245,13 @@ public class ListMR { @Specialization protected Object read(VirtualFrame frame, TruffleObject receiver, int idx, @Cached("createKeyInfoNode()") ListKeyInfoImplNode keyInfo) { - int info = keyInfo.execute(frame, receiver, idx); + int info = keyInfo.execute(receiver, idx); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { throw UnknownIdentifierException.raise("" + idx); } initExtractNode(); // idx + 1 R is indexing from 1 - Object value = extract.apply(frame, receiver, new Object[]{idx + 1}, RLogical.valueOf(false), RMissing.instance); + Object value = extract.apply(receiver, new Object[]{idx + 1}, RLogical.valueOf(false), RMissing.instance); initR2ForeignNode(); return r2Foreign.execute(value); } @@ -262,12 +262,12 @@ public class ListMR { // reading by an unknown name returns null, // reading by an unknown index returns subscript out of bounds; // let's be consistent at this place, the name should be known to the caller anyway - int info = keyInfo.execute(frame, receiver, field); + int info = keyInfo.execute(receiver, field); if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { throw UnknownIdentifierException.raise("" + field); } initExtractNode(); - Object value = extract.applyAccessField(frame, receiver, field); + Object value = extract.applyAccessField(receiver, field); initR2ForeignNode(); return r2Foreign.execute(value); } @@ -300,20 +300,20 @@ public class ListMR { @Child private ReplaceVectorNode replace; @Child private Foreign2R foreign2R; - protected abstract Object execute(VirtualFrame frame, TruffleObject receiver, Object identifier, Object valueObj); + protected abstract Object execute(TruffleObject 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(frame, receiver, new Object[]{idx + 1}, valueObj); + return write(receiver, new Object[]{idx + 1}, valueObj); } @Specialization - protected Object write(VirtualFrame frame, TruffleObject receiver, String field, Object valueObj) { - return write(frame, receiver, new Object[]{field}, valueObj); + protected Object write(TruffleObject receiver, String field, Object valueObj) { + return write(receiver, new Object[]{field}, valueObj); } - private Object write(VirtualFrame frame, TruffleObject receiver, Object[] positions, Object valueObj) { + private Object write(TruffleObject receiver, Object[] positions, Object valueObj) { if (foreign2R == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); foreign2R = insert(Foreign2RNodeGen.create()); @@ -323,7 +323,7 @@ public class ListMR { CompilerDirectives.transferToInterpreterAndInvalidate(); replace = insert(ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - return replace.apply(frame, receiver, positions, value); + return replace.apply(receiver, positions, value); } @Fallback @@ -337,28 +337,28 @@ public class ListMR { private final ConditionProfile unknownIdentifier = ConditionProfile.createBinaryProfile(); - abstract int execute(VirtualFrame frame, TruffleObject receiver, Object idx); + abstract int execute(TruffleObject receiver, Object idx); @Specialization - protected int keyInfo(VirtualFrame frame, TruffleObject receiver, int idx, + protected int keyInfo(TruffleObject receiver, int idx, @Cached("createLengthNode()") RLengthNode lenghtNode) { - return keyInfo(frame, receiver, (double) idx, lenghtNode); + return keyInfo(receiver, (double) idx, lenghtNode); } @Specialization - protected int keyInfo(VirtualFrame frame, TruffleObject receiver, double idx, + protected int keyInfo(TruffleObject receiver, double idx, @Cached("createLengthNode()") RLengthNode lengthNode) { - int length = lengthNode.executeInteger(frame, receiver); + int length = lengthNode.executeInteger(receiver); if (unknownIdentifier.profile(idx < 0 || idx >= length)) { return 0; } initExtractNode(); - return buildKeys(extractNode.apply(frame, receiver, new Object[]{idx + 1}, RLogical.valueOf(false), RMissing.instance)); + return buildKeys(extractNode.apply(receiver, new Object[]{idx + 1}, RLogical.valueOf(false), RMissing.instance)); } @Specialization - protected int keyInfo(VirtualFrame frame, TruffleObject receiver, String identifier, + protected int keyInfo(TruffleObject receiver, String identifier, @Cached("createNamesNode()") GetNamesAttributeNode namesNode) { RStringVector names = namesNode.getNames(receiver); boolean exists = false; @@ -372,7 +372,7 @@ public class ListMR { return 0; } initExtractNode(); - return buildKeys(extractNode.applyAccessField(frame, receiver, identifier)); + return buildKeys(extractNode.applyAccessField(receiver, identifier)); } protected RLengthNode createLengthNode() { @@ -414,8 +414,8 @@ public class ListMR { return true; } - private static Object getSize(VirtualFrame frame, TruffleObject receiver, RLengthNode lengthNode) { - return lengthNode.executeInteger(frame, receiver); + private static Object getSize(TruffleObject receiver, RLengthNode lengthNode) { + return lengthNode.executeInteger(receiver); } private static Object listKeys(TruffleObject receiver, GetNamesAttributeNode getNamesNode) { 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 49398a0d0b..3bb2437cd3 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 @@ -22,6 +22,8 @@ */ package com.oracle.truffle.r.engine.interop; +import java.util.List; + import com.oracle.truffle.api.CallTarget; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.Truffle; @@ -56,7 +58,6 @@ import com.oracle.truffle.r.runtime.interop.Foreign2RNodeGen; import com.oracle.truffle.r.runtime.interop.R2Foreign; import com.oracle.truffle.r.runtime.interop.R2ForeignNodeGen; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; -import java.util.List; abstract class InteropRootNode extends RootNode { InteropRootNode() { @@ -77,7 +78,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Override public Object execute(VirtualFrame frame) { - return lengthNode.executeInteger(frame, ForeignAccess.getReceiver(frame)); + return lengthNode.executeInteger(ForeignAccess.getReceiver(frame)); } } @@ -104,7 +105,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { throw UnknownIdentifierException.raise("" + idx); } - return read(frame, receiver, new Object[]{idx + 1}); + return read(receiver, new Object[]{idx + 1}); } @Specialization @@ -114,15 +115,15 @@ public final class RAbstractVectorAccessFactory implements Factory26 { if (unknownIdentifier.profile(!KeyInfo.isExisting(info))) { throw UnknownIdentifierException.raise("" + idx); } - return read(frame, receiver, new Object[]{idx + 1}); + return read(receiver, new Object[]{idx + 1}); } - private Object read(VirtualFrame frame, Object receiver, Object[] positions) { + private Object read(Object receiver, Object[] positions) { if (extract == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); extract = insert(ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - Object value = extract.apply(frame, receiver, positions, RLogical.TRUE, RLogical.TRUE); + Object value = extract.apply(receiver, positions, RLogical.TRUE, RLogical.TRUE); if (r2Foreign == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); r2Foreign = insert(R2ForeignNodeGen.create()); @@ -156,16 +157,16 @@ public final class RAbstractVectorAccessFactory implements Factory26 { @Specialization protected Object write(VirtualFrame frame, TruffleObject receiver, int idx, Object valueObj) { // idx + 1 R is indexing from 1 - return write(frame, receiver, new Object[]{idx + 1}, valueObj); + return write(receiver, new Object[]{idx + 1}, valueObj); } @Specialization protected Object write(VirtualFrame frame, TruffleObject receiver, long idx, Object valueObj) { // idx + 1 R is indexing from 1 - return write(frame, receiver, new Object[]{idx + 1}, valueObj); + return write(receiver, new Object[]{idx + 1}, valueObj); } - private Object write(VirtualFrame frame, TruffleObject receiver, Object[] positions, Object valueObj) { + private Object write(TruffleObject receiver, Object[] positions, Object valueObj) { if (foreign2R == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); foreign2R = insert(Foreign2RNodeGen.create()); @@ -175,7 +176,7 @@ public final class RAbstractVectorAccessFactory implements Factory26 { CompilerDirectives.transferToInterpreterAndInvalidate(); replace = insert(ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - return replace.apply(frame, receiver, positions, value); + return replace.apply(receiver, positions, value); } @Fallback @@ -209,13 +210,13 @@ public final class RAbstractVectorAccessFactory implements Factory26 { protected abstract int execute(VirtualFrame frame, Object reciever, Object indentifier); @Specialization - protected int keyInfo(VirtualFrame frame, Object receiver, int idx) { - return keyInfo(frame, receiver, (long) idx); + protected int keyInfo(Object receiver, int idx) { + return keyInfo(receiver, (long) idx); } @Specialization - protected int keyInfo(VirtualFrame frame, Object receiver, long idx) { - if (unknownIdentifier.profile(idx < 0 || idx >= lengthNode.executeInteger(frame, receiver))) { + protected int keyInfo(Object receiver, long idx) { + if (unknownIdentifier.profile(idx < 0 || idx >= lengthNode.executeInteger(receiver))) { return 0; } KeyInfo.Builder builder = KeyInfo.newBuilder(); 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 018acd8001..6a8ba5a555 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 @@ -143,7 +143,7 @@ public class REnvironmentMR { } initExtractNode(); - Object value = extract.applyAccessField(frame, receiver, identifier); + Object value = extract.applyAccessField(receiver, identifier); initR2ForeignNode(); return r2Foreign.execute(value); } @@ -181,7 +181,7 @@ public class REnvironmentMR { protected abstract Object execute(VirtualFrame frame, TruffleObject receiver, Object identifier, Object valueObj); @Specialization - protected Object access(VirtualFrame frame, REnvironment receiver, String identifier, Object valueObj, + protected Object access(REnvironment receiver, String identifier, Object valueObj, @Cached("createKeyInfoNode()") REnvironmentKeyInfoImplNode keyInfo) { int info = keyInfo.execute(receiver, identifier); @@ -202,7 +202,7 @@ public class REnvironmentMR { CompilerDirectives.transferToInterpreterAndInvalidate(); replace = insert(ReplaceVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - return replace.apply(frame, receiver, new Object[]{identifier}, value); + return replace.apply(receiver, new Object[]{identifier}, value); } @Fallback diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RLanguageMR.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RLanguageMR.java index aef100f31b..f92d14eab1 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RLanguageMR.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RLanguageMR.java @@ -117,7 +117,7 @@ public class RLanguageMR { abstract Object execute(VirtualFrame frame, RLanguage receiver, Object identifier); @Specialization - protected Object access(VirtualFrame frame, RLanguage receiver, int idx, + protected Object access(RLanguage receiver, int idx, @Cached("createKeyInfoNode()") KeyInfoNode keyInfo) { int info = keyInfo.execute(receiver, idx); @@ -129,7 +129,7 @@ public class RLanguageMR { CompilerDirectives.transferToInterpreterAndInvalidate(); extract = insert(ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - Object value = extract.apply(frame, receiver, new Object[]{idx + 1}, RLogical.TRUE, RLogical.TRUE); + Object value = extract.apply(receiver, new Object[]{idx + 1}, RLogical.TRUE, RLogical.TRUE); if (value == null) { return RNull.instance; } 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 1ef93f39bc..07e5400d2b 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 @@ -164,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(frame, value) > 0) { + if (length.executeInteger(value) > 0) { byte result = recursiveNode.execute(frame, value, recursive); if (result == RRuntime.LOGICAL_TRUE) { return RRuntime.LOGICAL_TRUE; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lapply.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lapply.java index 1065e130ee..6c7d0b0488 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lapply.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lapply.java @@ -111,7 +111,7 @@ public abstract class Lapply extends RBuiltinNode.Arg2 { @Override public Object execute(VirtualFrame frame) { try { - return extractElementNode.apply(frame, FrameSlotChangeMonitor.getObject(vectorSlot, frame), new Object[]{frame.getInt(indexSlot)}, RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_TRUE); + return extractElementNode.apply(FrameSlotChangeMonitor.getObject(vectorSlot, frame), new Object[]{frame.getInt(indexSlot)}, RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_TRUE); } catch (FrameSlotTypeException e) { CompilerDirectives.transferToInterpreter(); throw RInternalError.shouldNotReachHere("frame type mismatch in lapply"); @@ -159,7 +159,7 @@ public abstract class Lapply extends RBuiltinNode.Arg2 { @Cached("createCallNode(vectorSlot, indexSlot)") RCallBaseNode callNode) { // TODO: R switches to double if x.getLength() is greater than 2^31-1 FrameSlotChangeMonitor.setObject(frame, vectorSlot, vector); - int length = lengthNode.executeInteger(frame, vector); + int length = lengthNode.executeInteger(vector); Object[] result = new Object[length]; if (length > 0) { reportWork(this, length); 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 2acf888097..6e4ed78a61 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 @@ -43,8 +43,8 @@ public abstract class Length extends RBuiltinNode.Arg1 { } @Specialization - protected int getLength(VirtualFrame frame, Object vector, + protected int getLength(Object vector, @Cached("create()") RLengthNode lengthNode) { - return lengthNode.executeInteger(frame, vector); + return lengthNode.executeInteger(vector); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lengths.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lengths.java index 69e7498c34..05138ba5ce 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lengths.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Lengths.java @@ -35,7 +35,6 @@ import java.util.Arrays; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 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; @@ -64,12 +63,12 @@ public abstract class Lengths extends RBuiltinNode.Arg2 { } @Specialization - protected RIntVector doList(VirtualFrame frame, RList list, boolean useNames) { + protected RIntVector doList(RList list, boolean useNames) { initLengthNode(); int[] data = new int[list.getLength()]; for (int i = 0; i < data.length; i++) { Object elem = list.getDataAt(i); - data[i] = lengthNode.executeInteger(frame, elem); + data[i] = lengthNode.executeInteger(elem); } return createResult(list, data, useNames); } 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 76a3262d6c..11d115c517 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 @@ -128,8 +128,8 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { public abstract Object[] execute(VirtualFrame frame, RAbstractListVector dots, RFunction function, RAbstractListVector additionalArguments); - private static Object getVecElement(VirtualFrame frame, RAbstractListVector dots, int i, int listIndex, int[] lengths, ExtractVectorNode extractNode) { - return extractNode.apply(frame, dots.getDataAt(listIndex), new Object[]{i % lengths[listIndex] + 1}, RLogical.TRUE, RLogical.TRUE); + private static Object getVecElement(RAbstractListVector dots, int i, int listIndex, int[] lengths, ExtractVectorNode extractNode) { + return extractNode.apply(dots.getDataAt(listIndex), new Object[]{i % lengths[listIndex] + 1}, RLogical.TRUE, RLogical.TRUE); } @Specialization(limit = "5", guards = {"dots.getLength() == dotsLength", "moreArgs.getLength() == moreArgsLength", @@ -157,7 +157,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { @ExplodeLoop private static void prepareElements(VirtualFrame frame, RAbstractListVector dots, int dotsLength, ElementNode[] cachedElementNodeArray, int[] lengths, int i) { for (int listIndex = 0; listIndex < dotsLength; listIndex++) { - Object vecElement = getVecElement(frame, dots, i, listIndex, lengths, cachedElementNodeArray[listIndex].extractNode); + Object vecElement = getVecElement(dots, i, listIndex, lengths, cachedElementNodeArray[listIndex].extractNode); cachedElementNodeArray[listIndex].writeVectorElementNode.execute(frame, vecElement); } } @@ -199,7 +199,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { int[] lengths = new int[dotsLength]; int maxLength = -1; for (int i = 0; i < dotsLength; i++) { - int length = lengthNode.executeInteger(frame, dots.getDataAt(i)); + int length = lengthNode.executeInteger(dots.getDataAt(i)); if (length > maxLength) { maxLength = length; } @@ -223,7 +223,7 @@ public abstract class Mapply extends RBuiltinNode.Arg3 { for (int i = 0; i < maxLength; i++) { /* Evaluate and store the arguments */ for (int listIndex = 0; listIndex < dotsLength; listIndex++) { - Object vecElement = getVecElement(frame, dots, i, listIndex, lengths, extractNode); + Object vecElement = getVecElement(dots, i, listIndex, lengths, extractNode); values[listIndex] = vecElement; } /* Now call the function */ 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 fc920d2672..1dc1547d22 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 @@ -187,7 +187,7 @@ public final class SeqFunctions { public abstract static class SeqFastPath extends FastPathAdapter { @Specialization(guards = {"!hasClass(args, getClassAttributeNode)", "lengthSpecials(args)"}) @SuppressWarnings("unused") - protected Object seqNoClassFromAndLength(VirtualFrame frame, RArgsValuesAndNames args, // + protected Object seqNoClassFromAndLength(RArgsValuesAndNames args, // @Cached("createSeqIntForFastPath()") SeqInt seqInt, @Cached("lookupSeqInt()") RFunction seqIntFunction, @Cached("createBinaryProfile()") ConditionProfile isNumericProfile, @@ -195,9 +195,9 @@ public final class SeqFunctions { @Cached("createIsMissingOrNumericNode()") IsMissingOrNumericNode fromCheck) { if (isNumericProfile.profile(fromCheck.execute(args.getArgument(0)))) { if (args.getLength() == 1) { - return seqInt.execute(frame, RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance, RMissing.instance); + return seqInt.execute(RMissing.instance, RMissing.instance, RMissing.instance, args.getArgument(0), RMissing.instance, RMissing.instance); } else { - return seqInt.execute(frame, args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance, RMissing.instance); + return seqInt.execute(args.getArgument(0), RMissing.instance, RMissing.instance, args.getArgument(1), RMissing.instance, RMissing.instance); } } else { return null; @@ -205,7 +205,7 @@ public final class SeqFunctions { } @Specialization(guards = {"!hasClass(args, getClassAttributeNode)"}) - protected Object seqNoClassAndNumeric(VirtualFrame frame, RArgsValuesAndNames args, + protected Object seqNoClassAndNumeric(RArgsValuesAndNames args, @Cached("createSeqIntForFastPath()") SeqInt seqInt, @Cached("lookupSeqInt()") RFunction seqIntFunction, @Cached("createBinaryProfile()") ConditionProfile isNumericProfile, @@ -215,7 +215,7 @@ public final class SeqFunctions { @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(frame, rargs[0], rargs[1], rargs[2], rargs[3], rargs[4], RMissing.instance); + return seqInt.execute(rargs[0], rargs[1], rargs[2], rargs[3], rargs[4], RMissing.instance); } else { return null; } @@ -302,12 +302,12 @@ public final class SeqFunctions { public abstract static class SeqDefaultFastPath extends FastPathAdapter { @SuppressWarnings("unused") @Specialization(guards = {"fromCheck.execute(fromObj)", "toCheck.execute(toObj)", "byCheck.execute(byObj)"}) - protected Object seqDefaultNumeric(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, + 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(frame, fromObj, toObj, byObj, lengthOut, alongWith, RMissing.instance); + return seqInt.execute(fromObj, toObj, byObj, lengthOut, alongWith, RMissing.instance); } /** @@ -315,7 +315,7 @@ public final class SeqFunctions { */ @SuppressWarnings("unused") @Fallback - protected Object seqDefaultFallback(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith) { + protected Object seqDefaultFallback(Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith) { return null; } } @@ -330,9 +330,9 @@ public final class SeqFunctions { } @Specialization(guards = "!hasClass(value)") - protected RIntSequence seq(VirtualFrame frame, Object value, + protected RIntSequence seq(Object value, @Cached("create()") RLengthNode length) { - return RDataFactory.createIntSequence(1, 1, length.executeInteger(frame, value)); + return RDataFactory.createIntSequence(1, 1, length.executeInteger(value)); } /** @@ -426,6 +426,8 @@ public final class SeqFunctions { @Override public abstract Object execute(VirtualFrame frame, Object start, Object to, Object by, Object lengthOut, Object alongWith, Object dotdotdot); + public abstract Object execute(Object start, Object to, Object by, Object lengthOut, Object alongWith, Object dotdotdot); + protected SeqInt(boolean seqFastPath) { this.seqFastPath = seqFastPath; } @@ -459,8 +461,8 @@ public final class SeqFunctions { /** * Irrespective of the R type, if the length is zero the result is an empty sequence. */ - @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) == 0"}) - protected RIntVector emptySeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { + @Specialization(guards = {"!isMissing(from)", "getLength(from) == 0"}) + protected RIntVector emptySeqFromOneArg(Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { return RDataFactory.createEmptyIntVector(); } @@ -470,9 +472,9 @@ public final class SeqFunctions { * builtins take the </i>value</i> of the first element and warn about ignoring the rest, * but the value likely could not be coerced. */ - @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) > 1"}) - protected RIntSequence lenSeqFromOneArg(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { - return RDataFactory.createIntSequence(1, 1, getLength(frame, from)); + @Specialization(guards = {"!isMissing(from)", "getLength(from) > 1"}) + protected RIntSequence lenSeqFromOneArg(Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { + return RDataFactory.createIntSequence(1, 1, getLength(from)); } /** @@ -511,8 +513,8 @@ public final class SeqFunctions { * {@code !isNumeric(from)} guard this would "contain" the previous two specializations, * which would be incorrect as the result is different. */ - @Specialization(guards = {"!isMissing(from)", "getLength(frame, from) == 1", "!isNumeric(from)"}) - protected RIntSequence seqFromOneArgObj(VirtualFrame frame, Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { + @Specialization(guards = {"!isMissing(from)", "getLength(from) == 1", "!isNumeric(from)"}) + protected RIntSequence seqFromOneArgObj(Object from, RMissing to, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot) { return RDataFactory.createIntSequence(1, 1, 1); } @@ -527,7 +529,7 @@ public final class SeqFunctions { */ @Specialization(guards = "validDoubleParams(fromVec, toVec)") - protected RAbstractVector seqLengthByMissingDouble(VirtualFrame frame, RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, + protected RAbstractVector seqLengthByMissingDouble(RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { double from = fromVec.getDataAt(0); @@ -537,7 +539,7 @@ public final class SeqFunctions { } @Specialization(guards = "validIntParams(fromVec, toVec)") - protected RAbstractVector seqLengthByMissingInt(VirtualFrame frame, RAbstractIntVector fromVec, RAbstractIntVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, + protected RAbstractVector seqLengthByMissingInt(RAbstractIntVector fromVec, RAbstractIntVector toVec, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { int from = fromVec.getDataAt(0); int to = toVec.getDataAt(0); @@ -553,7 +555,7 @@ public final class SeqFunctions { * previous specializations. */ @Specialization(guards = {"!isMissing(toObj)"}) - protected RAbstractVector seqLengthByMissing(VirtualFrame frame, Object fromObj, Object toObj, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, + protected RAbstractVector seqLengthByMissing(Object fromObj, Object toObj, RMissing by, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { @@ -561,11 +563,11 @@ public final class SeqFunctions { if (isMissing(fromObj)) { from = 1.0; } else { - validateLength(frame, fromObj, "from"); + validateLength(fromObj, "from"); from = asRealFrom.execute(fromObj); validateDoubleParam(from, fromObj, "from"); } - validateLength(frame, toObj, "to"); + validateLength(toObj, "to"); double to = asRealTo.execute(toObj); validateDoubleParam(to, toObj, "to"); RAbstractVector result = createRSequence(from, to, directionProfile); @@ -579,15 +581,15 @@ public final class SeqFunctions { */ @Specialization(guards = {"validDoubleParams(fromVec, toVec)", "!isMissing(byObj)"}) - protected Object seqLengthMissing(VirtualFrame frame, RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, + protected Object seqLengthMissing(RAbstractDoubleVector fromVec, RAbstractDoubleVector toVec, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealby) { - validateLength(frame, byObj, "by"); + validateLength(byObj, "by"); double by = asRealby.execute(byObj); return doSeqLengthMissing(fromVec.getDataAt(0), toVec.getDataAt(0), by, false); } @Specialization(guards = {"validIntParams(fromVec, toVec)", "validIntParam(byVec)", "byVec.getDataAt(0) != 0"}) - protected RAbstractVector seqLengthMissing(VirtualFrame frame, RAbstractIntVector fromVec, RAbstractIntVector toVec, RAbstractIntVector byVec, RMissing lengthOut, RMissing alongWith, + protected RAbstractVector seqLengthMissing(RAbstractIntVector fromVec, RAbstractIntVector toVec, RAbstractIntVector byVec, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("createBinaryProfile()") ConditionProfile directionProfile) { int by = byVec.getDataAt(0); @@ -617,7 +619,7 @@ public final class SeqFunctions { * See comment in {@link #seqLengthByMissing}. */ @Specialization(guards = {"!isMissing(byObj)"}) - protected Object seqLengthMissing(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, + protected Object seqLengthMissing(Object fromObj, Object toObj, Object byObj, RMissing lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealby) { @@ -627,7 +629,7 @@ public final class SeqFunctions { from = 1.0; allInt = false; } else { - validateLength(frame, fromObj, "from"); + validateLength(fromObj, "from"); from = asRealFrom.execute(fromObj); validateDoubleParam(from, fromObj, "from"); allInt &= isInt(fromObj); @@ -637,12 +639,12 @@ public final class SeqFunctions { to = 1.0; allInt = false; } else { - validateLength(frame, toObj, "to"); + validateLength(toObj, "to"); to = asRealFrom.execute(toObj); validateDoubleParam(to, toObj, "to"); allInt &= isInt(toObj); } - validateLength(frame, byObj, "by"); + validateLength(byObj, "by"); allInt &= isInt(byObj); double by = asRealby.execute(byObj); return doSeqLengthMissing(from, to, by, allInt); @@ -713,17 +715,17 @@ public final class SeqFunctions { */ @Specialization(guards = "!isMissing(lengthOut)") - protected RAbstractVector seqJustLength(VirtualFrame frame, RMissing from, RMissing to, RMissing by, Object lengthOut, RMissing alongWith, Object dotdotdot, + protected RAbstractVector seqJustLength(RMissing from, RMissing to, RMissing by, Object lengthOut, RMissing alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealLen) { - int n = checkLength(frame, lengthOut, asRealLen); + int n = checkLength(lengthOut, asRealLen); return n == 0 ? RDataFactory.createEmptyIntVector() : RDataFactory.createIntSequence(1, 1, n); } // seq(along,with=) @Specialization(guards = "!isMissing(alongWith)") - protected RAbstractVector seqFromJustAlong(VirtualFrame frame, RMissing from, RMissing to, RMissing by, RMissing lengthOut, Object alongWith, Object dotdotdot) { - int len = getLength(frame, alongWith); + protected RAbstractVector seqFromJustAlong(RMissing from, RMissing to, RMissing by, RMissing lengthOut, Object alongWith, Object dotdotdot) { + int len = getLength(alongWith); return len == 0 ? RDataFactory.createEmptyIntVector() : RDataFactory.createIntSequence(1, 1, len); } @@ -796,7 +798,7 @@ public final class SeqFunctions { // common idiom @Specialization(guards = {"fromCheck.execute(fromObj)", "lengthCheck.execute(lengthOut)"}) - protected RAbstractVector seqWithFromLengthIntegralNumeric(VirtualFrame frame, Object fromObj, RMissing toObj, RMissing byObj, Object lengthOut, RMissing alongWith, Object dotdotdot, + 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) { @@ -811,11 +813,11 @@ public final class SeqFunctions { // "by" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(fromObj, toObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, Object toObj, RMissing byObj, Object lengthOut, Object alongWith, Object dotdotdot, + protected RAbstractVector seqWithLength(Object fromObj, Object toObj, RMissing byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealLen) { - int lout = checkLengthAlongWith(frame, lengthOut, alongWith, asRealLen); + int lout = checkLengthAlongWith(lengthOut, alongWith, asRealLen); if (lout == 0) { return RDataFactory.createEmptyIntVector(); } @@ -865,11 +867,11 @@ public final class SeqFunctions { // "to" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(fromObj, byObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, Object fromObj, RMissing toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, + protected RAbstractVector seqWithLength(Object fromObj, RMissing toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealFrom, @Cached("create()") AsRealNode asRealby, @Cached("create()") AsRealNode asRealLen) { - int lout = checkLengthAlongWith(frame, lengthOut, alongWith, asRealLen); + int lout = checkLengthAlongWith(lengthOut, alongWith, asRealLen); if (lout == 0) { return RDataFactory.createEmptyIntVector(); } @@ -892,11 +894,11 @@ public final class SeqFunctions { // "from" missing @Specialization(guards = {"oneNotMissing(alongWith, lengthOut)", "oneNotMissing(toObj, byObj)"}) - protected RAbstractVector seqWithLength(VirtualFrame frame, RMissing fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, + protected RAbstractVector seqWithLength(RMissing fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot, @Cached("create()") AsRealNode asRealTo, @Cached("create()") AsRealNode asRealby, @Cached("create()") AsRealNode asRealLen) { - int lout = checkLengthAlongWith(frame, lengthOut, alongWith, asRealLen); + int lout = checkLengthAlongWith(lengthOut, alongWith, asRealLen); if (lout == 0) { return RDataFactory.createEmptyIntVector(); } @@ -913,7 +915,7 @@ public final class SeqFunctions { } @Fallback - protected RAbstractVector seqFallback(VirtualFrame frame, Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot) { + protected RAbstractVector seqFallback(Object fromObj, Object toObj, Object byObj, Object lengthOut, Object alongWith, Object dotdotdot) { error.enter(); throw error(RError.Message.TOO_MANY_ARGS); } @@ -932,8 +934,8 @@ public final class SeqFunctions { return vec.getLength() == 1 && vec.getDataAt(0) != RRuntime.INT_NA; } - public final int getLength(VirtualFrame frame, Object obj) { - return lengthNode.executeInteger(frame, obj); + public final int getLength(Object obj) { + return lengthNode.executeInteger(obj); } public static boolean isNumeric(Object obj) { @@ -988,22 +990,22 @@ public final class SeqFunctions { /** * Unless {@code obj} is missing, check whether length is 1. */ - private void validateLength(VirtualFrame frame, Object obj, String vName) { + private void validateLength(Object obj, String vName) { if (obj != RMissing.instance) { - if (getLength(frame, obj) != 1) { + if (getLength(obj) != 1) { error.enter(); throw error(RError.Message.MUST_BE_SCALAR, vName); } } } - private int checkLength(VirtualFrame frame, Object lengthOut, AsRealNode asRealLen) { + 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(frame, lengthOut) != 1) { + if (getLength(lengthOut) != 1) { warning(RError.Message.FIRST_ELEMENT_USED, "length.out"); } return (int) Math.ceil(len); @@ -1017,11 +1019,11 @@ public final class SeqFunctions { return (int) by == by && isInIntRange(from) && isInIntRange(to); } - private int checkLengthAlongWith(VirtualFrame frame, Object lengthOut, Object alongWith, AsRealNode asRealLen) { + private int checkLengthAlongWith(Object lengthOut, Object alongWith, AsRealNode asRealLen) { if (alongWith != RMissing.instance) { - return getLength(frame, alongWith); + return getLength(alongWith); } else if (lengthOut != RMissing.instance) { - return checkLength(frame, lengthOut, asRealLen); + return checkLength(lengthOut, asRealLen); } else { throw RInternalError.shouldNotReachHere(); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubscriptDataFrameFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubscriptDataFrameFastPath.java index 230cb8046b..b4f2b8a9ba 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubscriptDataFrameFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubscriptDataFrameFastPath.java @@ -25,7 +25,6 @@ package com.oracle.truffle.r.nodes.builtin.base.fastpaths; 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.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; @@ -74,29 +73,29 @@ public abstract class SubscriptDataFrameFastPath extends RFastPathNode { @Child private ExtractVectorNode extractNode = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, false); @Specialization(guards = {"positions.getLength() == 1", "positions.getSignature().getNonNullCount() == 0"}) - protected Object subscript1(VirtualFrame frame, RAbstractListVector df, RArgsValuesAndNames positions, Object exact, + protected Object subscript1(RAbstractListVector df, RArgsValuesAndNames positions, Object exact, @Cached("create()") AsScalarNode asScalar) { Object pos = asScalar.execute(positions.getArgument(0)); if (pos == null) { return null; } - return extractNode.apply(frame, df, new Object[]{pos}, exact, RRuntime.LOGICAL_TRUE); + return extractNode.apply(df, new Object[]{pos}, exact, RRuntime.LOGICAL_TRUE); } @Specialization(guards = {"positions.getLength() == 2", "positions.getSignature().getNonNullCount() == 0"}) - protected Object subscript2(VirtualFrame frame, RAbstractListVector df, RArgsValuesAndNames positions, Object exact, + protected Object subscript2(RAbstractListVector df, RArgsValuesAndNames positions, Object exact, @Cached("create()") AsScalarNode asScalar1, @Cached("create()") AsScalarNode asScalar2) { Object pos2 = asScalar2.execute(positions.getArgument(1)); if (pos2 == null) { return null; } - Object extracted = extractNode.apply(frame, df, new Object[]{pos2}, exact, RRuntime.LOGICAL_TRUE); + Object extracted = extractNode.apply(df, new Object[]{pos2}, exact, RRuntime.LOGICAL_TRUE); Object pos1 = asScalar1.execute(positions.getArgument(0)); if (pos1 == null) { return null; } - return extractNode.apply(frame, extracted, new Object[]{pos1}, exact, RRuntime.LOGICAL_TRUE); + return extractNode.apply(extracted, new Object[]{pos1}, exact, RRuntime.LOGICAL_TRUE); } @Fallback diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubsetDataFrameFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubsetDataFrameFastPath.java index a68e960b0c..cb2f35532f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubsetDataFrameFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/SubsetDataFrameFastPath.java @@ -25,7 +25,6 @@ package com.oracle.truffle.r.nodes.builtin.base.fastpaths; 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.r.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; import com.oracle.truffle.r.runtime.RRuntime; @@ -38,19 +37,19 @@ public abstract class SubsetDataFrameFastPath extends RFastPathNode { @Child private ExtractVectorNode extractNode = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, false); @Specialization(guards = {"positions.getLength() == 2", "positions.getSignature().getNonNullCount() == 0"}) - protected Object subscript2(VirtualFrame frame, RAbstractListVector df, RArgsValuesAndNames positions, Object exact, + protected Object subscript2(RAbstractListVector df, RArgsValuesAndNames positions, Object exact, @Cached("create()") AsScalarNode asScalar1, @Cached("create()") AsScalarNode asScalar2) { Object pos2 = asScalar2.execute(positions.getArgument(1)); if (pos2 == null) { return null; } - Object extracted = extractNode.apply(frame, df, new Object[]{pos2}, exact, RRuntime.LOGICAL_TRUE); + Object extracted = extractNode.apply(df, new Object[]{pos2}, exact, RRuntime.LOGICAL_TRUE); Object pos1 = asScalar1.execute(positions.getArgument(0)); if (pos1 == null) { return null; } - return extractNode.apply(frame, extracted, new Object[]{pos1}, exact, RRuntime.LOGICAL_TRUE); + return extractNode.apply(extracted, new Object[]{pos1}, exact, RRuntime.LOGICAL_TRUE); } @Fallback 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 49bcba7882..56f021ee76 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 @@ -162,11 +162,11 @@ abstract class LookupAdapter extends RBuiltinNode.Arg3 implements Lookup { CompilerDirectives.transferToInterpreterAndInvalidate(); packageExtract = insert(ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true)); } - String name = RRuntime.asString(nameExtract.applyAccessField(frame, symbol, "name")); - SymbolHandle address = ((RExternalPtr) addressExtract.applyAccessField(frame, symbol, "address")).getAddr(); + String name = RRuntime.asString(nameExtract.applyAccessField(symbol, "name")); + SymbolHandle address = ((RExternalPtr) addressExtract.applyAccessField(symbol, "address")).getAddr(); // field name may be "package" or "dll", but always at (R) index 3 - RList packageList = (RList) packageExtract.apply(frame, symbol, new Object[]{3}, RLogical.valueOf(false), RMissing.instance); - DLLInfo dllInfo = (DLLInfo) ((RExternalPtr) addressExtract.applyAccessField(frame, packageList, "info")).getExternalObject(); + RList packageList = (RList) packageExtract.apply(symbol, new Object[]{3}, RLogical.valueOf(false), RMissing.instance); + DLLInfo dllInfo = (DLLInfo) ((RExternalPtr) addressExtract.applyAccessField(packageList, "info")).getExternalObject(); return new NativeCallInfo(name, address, dllInfo); } 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 807c734932..3830f6954a 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 @@ -105,6 +105,6 @@ public abstract class AccessField extends RBuiltinNode.Arg2 { error.enter(); throw error(RError.Message.DOLLAR_ATOMIC_VECTORS); } - return extract.applyAccessField(frame, container, field); + return extract.applyAccessField(container, field); } } 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 8662349032..c6a855d169 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 @@ -148,7 +148,7 @@ abstract class SubscriptSpecial extends SubscriptSpecialBase { @Specialization(guards = {"simpleVector(vector)", "!inReplacement"}) protected static Object access(VirtualFrame frame, RAbstractVector vector, Object index, @Cached("createAccess()") ExtractVectorNode extract) { - return extract.apply(frame, vector, new Object[]{index}, RRuntime.LOGICAL_TRUE, RLogical.TRUE); + return extract.apply(vector, new Object[]{index}, RRuntime.LOGICAL_TRUE, RLogical.TRUE); } public static RNode create(boolean inReplacement, RNode profiledVector, ConvertIndex index) { @@ -223,11 +223,11 @@ public abstract class Subscript extends RBuiltinNode.Arg4 { } @Specialization(guards = "!indexes.isEmpty()") - protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames indexes, RAbstractLogicalVector exact, @SuppressWarnings("unused") Object drop) { + protected Object get(Object x, RArgsValuesAndNames indexes, RAbstractLogicalVector exact, @SuppressWarnings("unused") Object drop) { /* * "drop" is not actually used by this builtin, but it needs to be in the argument list * (because the "drop" argument needs to be skipped). */ - return extractNode.apply(frame, x, indexes.getArguments(), exact, RLogical.TRUE); + return extractNode.apply(x, indexes.getArguments(), exact, RLogical.TRUE); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java index f463743d65..107b02ea74 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.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.r.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ExtractListElement; import com.oracle.truffle.r.nodes.access.vector.ExtractVectorNode; @@ -78,9 +77,9 @@ abstract class SubsetSpecial extends SubscriptSpecialBase { } @Specialization(guards = {"simpleVector(vector)", "!inReplacement"}) - protected Object access(VirtualFrame frame, RAbstractVector vector, Object index, + protected Object access(RAbstractVector vector, Object index, @Cached("createAccess()") ExtractVectorNode extract) { - return extract.apply(frame, vector, new Object[]{index}, RRuntime.LOGICAL_TRUE, RLogical.TRUE); + return extract.apply(vector, new Object[]{index}, RRuntime.LOGICAL_TRUE, RLogical.TRUE); } public static RNode create(boolean inReplacement, RNode vectorNode, ConvertIndex index) { @@ -162,7 +161,7 @@ public abstract class Subset extends RBuiltinNode.Arg3 { } @Specialization(guards = "!indexes.isEmpty()") - protected Object get(VirtualFrame frame, Object x, RArgsValuesAndNames indexes, Object drop) { - return extractNode.apply(frame, x, indexes.getArguments(), RLogical.TRUE, drop); + protected Object get(Object x, RArgsValuesAndNames indexes, Object drop) { + return extractNode.apply(x, indexes.getArguments(), RLogical.TRUE, drop); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java index f1145838fa..b73fcb9cc9 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateField.java @@ -32,7 +32,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.ConditionProfile; import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; @@ -131,9 +130,9 @@ public abstract class UpdateField extends RBuiltinNode.Arg3 { } @Specialization - protected Object update(VirtualFrame frame, Object container, String field, Object value) { + protected Object update(Object container, String field, Object value) { Object list = coerceList.profile(container instanceof RAbstractListVector) ? container : coerceList(container); - return update.apply(frame, list, new Object[]{field}, value); + return update.apply(list, new Object[]{field}, value); } private Object coerceList(Object vector) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java index 9bc4b7371c..36cf01ffbe 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubscript.java @@ -174,7 +174,7 @@ public abstract class UpdateSubscript extends RBuiltinNode.Arg2 { } @Specialization(guards = "!args.isEmpty()") - protected Object update(VirtualFrame frame, Object x, RArgsValuesAndNames args) { + protected Object update(Object x, RArgsValuesAndNames args) { Object value = args.getArgument(args.getLength() - 1); Object[] pos; if (argsLengthLargerThanOneProfile.profile(args.getLength() > 1)) { @@ -182,7 +182,7 @@ public abstract class UpdateSubscript extends RBuiltinNode.Arg2 { } else { pos = new Object[]{RMissing.instance}; } - return replaceNode.apply(frame, x, pos, value); + return replaceNode.apply(x, pos, value); } @Specialization(guards = "args.isEmpty()") diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java index bb734f4ae2..bf0e061a75 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/UpdateSubset.java @@ -31,7 +31,6 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.access.vector.ElementAccessMode; import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode; @@ -67,7 +66,7 @@ public abstract class UpdateSubset extends RBuiltinNode.Arg1 { } @Specialization(guards = "args.getLength() >= 2") - protected Object update(VirtualFrame frame, RArgsValuesAndNames args) { + protected Object update(RArgsValuesAndNames args) { // first argument: object to assign to Object x = args.getArgument(0); @@ -81,7 +80,7 @@ public abstract class UpdateSubset extends RBuiltinNode.Arg1 { } else { pos = new Object[]{RMissing.instance}; } - return replaceNode.apply(frame, x, pos, value); + return replaceNode.apply(x, pos, value); } @Specialization(guards = "args.getLength() < 2") diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNodeTest.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNodeTest.java index ab6890dc71..7461c2db64 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNodeTest.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNodeTest.java @@ -302,6 +302,6 @@ public class ExtractVectorNodeTest extends TestBase { private static NodeHandle<ExtractVectorNode> create(ElementAccessMode mode, boolean exact, boolean dropDimension) { return createHandle(ExtractVectorNode.create(mode, false), - (node, args) -> node.apply(null, args[0], (Object[]) args[1], RLogical.valueOf(exact), RLogical.valueOf(dropDimension))); + (node, args) -> node.apply(args[0], (Object[]) args[1], RLogical.valueOf(exact), RLogical.valueOf(dropDimension))); } } diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNodeTest.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNodeTest.java index 063a5f35ab..c24a265ce6 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNodeTest.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNodeTest.java @@ -298,6 +298,6 @@ public class ReplaceVectorNodeTest extends TestBase { private static NodeHandle<ReplaceVectorNode> create(ElementAccessMode mode) { return createHandle(ReplaceVectorNode.create(mode, false), - (node, args) -> node.apply(null, args[0], (Object[]) args[1], args[2])); + (node, args) -> node.apply(args[0], (Object[]) args[1], args[2])); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java index cccb20e157..db90dae6c5 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java @@ -98,7 +98,7 @@ final class CachedReplaceVectorNode extends CachedVectorNode { @Child private WriteIndexedVectorNode writeVectorNode; @Child private PositionsCheckNode positionsCheckNode; @Child private CastNode castVectorNode; - @Child private CachedReplaceVectorNode copyPositionNames; + @Child private ReplaceVectorNode copyPositionNames; @Child private DeleteElementsNode deleteElementsNode; @Child private SetNamesAttributeNode setNamesNode; @@ -569,9 +569,8 @@ final class CachedReplaceVectorNode extends CachedVectorNode { } if (copyPositionNames == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); - copyPositionNames = insert(new CachedReplaceVectorNode(mode, names, positions, positionNames.getClass(), positionNames.getRType(), false, recursive, positionNames.getLength() > 1)); + copyPositionNames = insert(ReplaceVectorNode.create(ElementAccessMode.SUBSET, true)); } - assert copyPositionNames.isSupported(names, positions, positionNames); RAbstractStringVector newNames = (RAbstractStringVector) copyPositionNames.apply(names, positions, positionNames); if (updateNamesProfile.profile(newNames != originalNames)) { if (setNamesNode == null) { 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 6ea4760139..2b29e8d952 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 @@ -27,7 +27,6 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.InteropException; import com.oracle.truffle.api.interop.KeyInfo; @@ -40,7 +39,6 @@ import com.oracle.truffle.r.nodes.binary.BoxPrimitiveNode; import com.oracle.truffle.r.nodes.profile.TruffleBoundaryNode; import com.oracle.truffle.r.nodes.unary.CastStringNode; import com.oracle.truffle.r.nodes.unary.FirstStringNode; -import com.oracle.truffle.r.runtime.interop.Foreign2R; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RLogical; @@ -52,6 +50,7 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractListVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; +import com.oracle.truffle.r.runtime.interop.Foreign2R; import com.oracle.truffle.r.runtime.interop.Foreign2RNodeGen; import com.oracle.truffle.r.runtime.interop.ForeignArray2R; import com.oracle.truffle.r.runtime.interop.ForeignArray2R.CollectedElements; @@ -80,12 +79,12 @@ public abstract class ExtractVectorNode extends RBaseNode { return mode; } - public final Object applyAccessField(VirtualFrame frame, Object vector, String singlePosition) { - return apply(frame, vector, new Object[]{singlePosition}, RLogical.valueOf(false), RMissing.instance); + public final Object applyAccessField(Object vector, String singlePosition) { + return apply(vector, new Object[]{singlePosition}, RLogical.valueOf(false), RMissing.instance); } - public final Object apply(VirtualFrame frame, Object vector, Object[] positions, Object exact, Object dropDimensions) { - return execute(frame, boxVector.execute(vector), positions, boxExact.execute(exact), boxDropdimensions.execute(dropDimensions)); + public final Object apply(Object vector, Object[] positions, Object exact, Object dropDimensions) { + return execute(boxVector.execute(vector), positions, boxExact.execute(exact), boxDropdimensions.execute(dropDimensions)); } public static ExtractVectorNode create(ElementAccessMode accessMode, boolean ignoreRecursive) { @@ -96,18 +95,18 @@ public abstract class ExtractVectorNode extends RBaseNode { return ExtractVectorNodeGen.create(accessMode, true, false); } - protected abstract Object execute(VirtualFrame frame, Object vector, Object[] positions, Object exact, Object dropDimensions); + protected abstract Object execute(Object vector, Object[] positions, Object exact, Object dropDimensions); @Specialization(guards = {"cached != null", "cached.isSupported(vector, positions)"}) - protected Object doExtractSameDimensions(VirtualFrame frame, RAbstractVector vector, Object[] positions, Object exact, Object dropDimensions, // + protected Object doExtractSameDimensions(RAbstractVector vector, Object[] positions, Object exact, Object dropDimensions, // @Cached("createRecursiveCache(vector, positions)") RecursiveExtractSubscriptNode cached) { - return cached.apply(frame, vector, positions, exact, dropDimensions); + return cached.apply(vector, positions, exact, dropDimensions); } @Specialization(guards = {"cached != null", "cached.isSupported(vector, positions)"}) - protected Object doExtractRecursive(VirtualFrame frame, RAbstractListVector vector, Object[] positions, Object exact, Object dropDimensions, // + protected Object doExtractRecursive(RAbstractListVector vector, Object[] positions, Object exact, Object dropDimensions, // @Cached("createRecursiveCache(vector, positions)") RecursiveExtractSubscriptNode cached) { - return cached.apply(frame, vector, positions, exact, dropDimensions); + return cached.apply(vector, positions, exact, dropDimensions); } protected RecursiveExtractSubscriptNode createRecursiveCache(Object vector, Object[] positions) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveExtractSubscriptNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveExtractSubscriptNode.java index 984805f079..559bde5617 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveExtractSubscriptNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveExtractSubscriptNode.java @@ -24,7 +24,6 @@ package com.oracle.truffle.r.nodes.access.vector; 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.runtime.RError; import com.oracle.truffle.r.runtime.data.RInteger; import com.oracle.truffle.r.runtime.data.RLogical; @@ -45,37 +44,37 @@ abstract class RecursiveExtractSubscriptNode extends RecursiveSubscriptNode { return RecursiveExtractSubscriptNodeGen.create(vector, position); } - public final Object apply(VirtualFrame frame, Object vector, Object[] positions, Object exact, Object dropDimensions) { + public final Object apply(Object vector, Object[] positions, Object exact, Object dropDimensions) { Object firstPosition = positions[0]; - int length = positionLengthNode.executeInteger(frame, firstPosition); - return execute(frame, vector, positions, firstPosition, length, exact, dropDimensions); + int length = positionLengthNode.executeInteger(firstPosition); + return execute(vector, positions, firstPosition, length, exact, dropDimensions); } - protected abstract Object execute(VirtualFrame frame, Object vector, Object[] positions, Object firstPosition, int positionLength, Object exact, Object dropDimensions); + protected abstract Object execute(Object vector, Object[] positions, Object firstPosition, int positionLength, Object exact, Object dropDimensions); @Specialization(guards = "positionLength <= 1") - protected Object doDefault(VirtualFrame frame, Object vector, Object[] positions, @SuppressWarnings("unused") Object firstPosition, @SuppressWarnings("unused") int positionLength, Object exact, + protected Object doDefault(Object vector, Object[] positions, @SuppressWarnings("unused") Object firstPosition, @SuppressWarnings("unused") int positionLength, Object exact, Object dropDimensions) { try { - return subscriptExtract.apply(frame, vector, positions, exact, dropDimensions); + return subscriptExtract.apply(vector, positions, exact, dropDimensions); } catch (RecursiveIndexNotFoundError e) { throw error(RError.Message.SUBSCRIPT_BOUNDS); } } @Specialization(replaces = "doDefault") - protected Object doRecursive(VirtualFrame frame, Object vector, @SuppressWarnings("unused") Object[] positions, Object originalFirstPosition, int positionLength, Object exact, + protected Object doRecursive(Object vector, @SuppressWarnings("unused") Object[] positions, Object originalFirstPosition, int positionLength, Object exact, Object dropDimensions, @Cached("createPositionCast()") PositionCastNode positionCast) { Object firstPosition = positionCast.execute(originalFirstPosition); Object currentVector = vector; for (int i = 1; i < positionLength; i++) { - Object selection = getPositionExtract.apply(frame, firstPosition, new Object[]{RInteger.valueOf(i)}, RLogical.TRUE, RLogical.TRUE); + Object selection = getPositionExtract.apply(firstPosition, new Object[]{RInteger.valueOf(i)}, RLogical.TRUE, RLogical.TRUE); try { if (!(currentVector instanceof RAbstractListVector)) { throw indexingFailed(i); } - currentVector = recursiveSubscriptExtract.apply(frame, currentVector, new Object[]{selection}, exact, dropDimensions); + currentVector = recursiveSubscriptExtract.apply(currentVector, new Object[]{selection}, exact, dropDimensions); if (currentVector == RNull.instance) { throw error(RError.Message.SUBSCRIPT_BOUNDS); @@ -84,9 +83,9 @@ abstract class RecursiveExtractSubscriptNode extends RecursiveSubscriptNode { throw noSuchIndex(i); } } - Object selection = getPositionExtract.apply(frame, firstPosition, new Object[]{RInteger.valueOf(positionLength)}, RLogical.TRUE, RLogical.TRUE); + Object selection = getPositionExtract.apply(firstPosition, new Object[]{RInteger.valueOf(positionLength)}, RLogical.TRUE, RLogical.TRUE); try { - return subscriptExtract.apply(frame, currentVector, new Object[]{selection}, exact, dropDimensions); + return subscriptExtract.apply(currentVector, new Object[]{selection}, exact, dropDimensions); } catch (RecursiveIndexNotFoundError e) { throw error(RError.Message.SUBSCRIPT_BOUNDS); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveReplaceSubscriptNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveReplaceSubscriptNode.java index f24cc63744..8af694da2e 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveReplaceSubscriptNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/RecursiveReplaceSubscriptNode.java @@ -24,7 +24,6 @@ package com.oracle.truffle.r.nodes.access.vector; 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.runtime.data.RInteger; import com.oracle.truffle.r.runtime.data.RLogical; import com.oracle.truffle.r.runtime.data.RNull; @@ -45,18 +44,18 @@ abstract class RecursiveReplaceSubscriptNode extends RecursiveSubscriptNode { return RecursiveReplaceSubscriptNodeGen.create(vector, position); } - public final Object apply(VirtualFrame frame, Object vector, Object[] positions, Object value) { + public final Object apply(Object vector, Object[] positions, Object value) { assert isSupported(vector, positions); Object firstPosition = positionClass.cast(positions[0]); - int length = positionLengthNode.executeInteger(frame, firstPosition); - return execute(frame, vectorClass.cast(vector), positions, firstPosition, length, value); + int length = positionLengthNode.executeInteger(firstPosition); + return execute(vectorClass.cast(vector), positions, firstPosition, length, value); } - protected abstract Object execute(VirtualFrame frame, Object vector, Object[] positions, Object firstPosition, int positionLength, Object value); + protected abstract Object execute(Object vector, Object[] positions, Object firstPosition, int positionLength, Object value); @Specialization(guards = "positionLength <= 1") - protected Object doDefault(VirtualFrame frame, Object vector, Object[] positions, @SuppressWarnings("unused") Object firstPosition, @SuppressWarnings("unused") int positionLength, Object value) { - return subscriptReplace.apply(frame, vector, positions, value); + protected Object doDefault(Object vector, Object[] positions, @SuppressWarnings("unused") Object firstPosition, @SuppressWarnings("unused") int positionLength, Object value) { + return subscriptReplace.apply(vector, positions, value); } /** @@ -82,7 +81,7 @@ abstract class RecursiveReplaceSubscriptNode extends RecursiveSubscriptNode { * </code> */ @Specialization(replaces = "doDefault") - protected Object doRecursive(VirtualFrame frame, Object vector, @SuppressWarnings("unused") Object[] positions, Object originalFirstPosition, int positionLength, Object value, + protected Object doRecursive(Object vector, @SuppressWarnings("unused") Object[] positions, Object originalFirstPosition, int positionLength, Object value, @Cached("createPositionCast()") PositionCastNode positionCast) { Object firstPosition = positionCast.execute(originalFirstPosition); Object[] positionStack = new Object[positionLength]; @@ -90,13 +89,13 @@ abstract class RecursiveReplaceSubscriptNode extends RecursiveSubscriptNode { valueStack[0] = vector; Object currentVector = vector; for (int i = 1; i < positionLength; i++) { - Object parentPosition = getPositionValue(frame, firstPosition, i - 1); + Object parentPosition = getPositionValue(firstPosition, i - 1); positionStack[i - 1] = parentPosition; try { if (!(currentVector instanceof RAbstractListVector)) { throw indexingFailed(i); } - currentVector = recursiveSubscriptExtract.apply(frame, currentVector, new Object[]{parentPosition}, RLogical.TRUE, RLogical.TRUE); + currentVector = recursiveSubscriptExtract.apply(currentVector, new Object[]{parentPosition}, RLogical.TRUE, RLogical.TRUE); if (currentVector == RNull.instance) { throw noSuchIndex(i); } @@ -106,12 +105,12 @@ abstract class RecursiveReplaceSubscriptNode extends RecursiveSubscriptNode { } } Object recursiveValue = value; - positionStack[positionLength - 1] = getPositionValue(frame, firstPosition, positionLength - 1); + positionStack[positionLength - 1] = getPositionValue(firstPosition, positionLength - 1); for (int i = positionLength - 1; i >= 1; i--) { - recursiveValue = recursiveSubscriptReplace.apply(frame, valueStack[i], new Object[]{positionStack[i]}, recursiveValue); + recursiveValue = recursiveSubscriptReplace.apply(valueStack[i], new Object[]{positionStack[i]}, recursiveValue); } // the last recursive replace need to have recursive set to false - recursiveValue = subscriptReplace.apply(frame, valueStack[0], new Object[]{positionStack[0]}, recursiveValue); + recursiveValue = subscriptReplace.apply(valueStack[0], new Object[]{positionStack[0]}, recursiveValue); return recursiveValue; } @@ -120,7 +119,7 @@ abstract class RecursiveReplaceSubscriptNode extends RecursiveSubscriptNode { return PositionCastNode.create(ElementAccessMode.SUBSCRIPT, false); } - private Object getPositionValue(VirtualFrame frame, Object firstPosition, int i) { - return getPositionExtract.apply(frame, firstPosition, new Object[]{RInteger.valueOf(i + 1)}, RLogical.TRUE, RLogical.TRUE); + private Object getPositionValue(Object firstPosition, int i) { + return getPositionExtract.apply(firstPosition, new Object[]{RInteger.valueOf(i + 1)}, RLogical.TRUE, RLogical.TRUE); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java index 190797cdd4..b769ad5a4d 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java @@ -27,7 +27,6 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.InteropException; import com.oracle.truffle.api.interop.KeyInfo; @@ -72,11 +71,11 @@ public abstract class ReplaceVectorNode extends RBaseNode { this.ignoreRecursive = ignoreRecursive; } - public final Object apply(VirtualFrame frame, Object vector, Object[] positions, Object value) { - return execute(frame, boxVector.execute(vector), positions, boxValue.execute(value)); + public final Object apply(Object vector, Object[] positions, Object value) { + return execute(boxVector.execute(vector), positions, boxValue.execute(value)); } - protected abstract Object execute(VirtualFrame frame, Object vector, Object[] positions, Object value); + protected abstract Object execute(Object vector, Object[] positions, Object value); public static ReplaceVectorNode create(ElementAccessMode mode, boolean ignoreRecursive) { return ReplaceVectorNodeGen.create(mode, false, ignoreRecursive); @@ -162,9 +161,9 @@ public abstract class ReplaceVectorNode extends RBaseNode { } @Specialization(limit = "CACHE_LIMIT", guards = {"cached != null", "cached.isSupported(vector, positions)"}) - protected Object doRecursive(VirtualFrame frame, RAbstractListVector vector, Object[] positions, Object value, // + protected Object doRecursive(RAbstractListVector vector, Object[] positions, Object value, // @Cached("createRecursiveCache(vector, positions)") RecursiveReplaceSubscriptNode cached) { - return cached.apply(frame, vector, positions, value); + return cached.apply(vector, positions, value); } protected RecursiveReplaceSubscriptNode createRecursiveCache(Object vector, Object[] positions) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ForNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ForNode.java index a027060246..1205b62c9e 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ForNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ForNode.java @@ -78,7 +78,7 @@ public final class ForNode extends AbstractLoopNode implements RSyntaxNode, RSyn Object obj = range.execute(frame); writeIndexNode.execute(frame, 1); writeRangeNode.execute(frame, obj); - writeLengthNode.execute(frame, length.executeInteger(frame, obj)); + writeLengthNode.execute(frame, length.executeInteger(obj)); loopNode.executeLoop(frame); } 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 dc4db26034..71db0a9b50 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 @@ -61,7 +61,7 @@ public abstract class RLengthNode extends RNode { @Override public abstract int executeInteger(VirtualFrame frame); - public abstract int executeInteger(VirtualFrame frame, Object value); + public abstract int executeInteger(Object value); public static RLengthNode create() { return RLengthNodeGen.create(null); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 2ef82b8378..d4e5866c55 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -24063,6 +24063,11 @@ q + b attr(,"mya") [1] 42 +##com.oracle.truffle.r.test.builtins.TestBuiltin_extract_replace.replaceWithPositionNames# +#{ foo <- function(x, idx) { x[idx] <- F; x }; foo(c(T,T,T,T), structure(c('a'), .Names = c('a'))); r <- foo(c(T,T,T,T), structure(c('a', 'b'), .Names = c('a', 'b'))); r } + a b + TRUE TRUE TRUE TRUE FALSE FALSE + ##com.oracle.truffle.r.test.builtins.TestBuiltin_factor.testFactor# #{ as.logical(factor(c("a", "b", "a"))) } [1] NA NA NA diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_extract_replace.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_extract_replace.java index 3745256f04..6ea1535f07 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_extract_replace.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_extract_replace.java @@ -48,4 +48,9 @@ public class TestBuiltin_extract_replace extends TestBase { assertEval("e1 <- expression(x^2); l1 <- quote(y^2); l1[1] <- e1; l1[[1]]==e1[[1]]"); assertEval(Ignored.OutputFormatting, "e1 <- expression(x^2); l1 <- quote(y^2); l1[1] <- e1; l1"); } + + @Test + public void replaceWithPositionNames() { + assertEval("{ foo <- function(x, idx) { x[idx] <- F; x }; foo(c(T,T,T,T), structure(c('a'), .Names = c('a'))); r <- foo(c(T,T,T,T), structure(c('a', 'b'), .Names = c('a', 'b'))); r }"); + } } -- GitLab