diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java index 6e568a59be33fe0180fbcdf9d9144a7b885e4ddc..7589fcf8a876b1e29552a48df8e27e5fb4ddd724 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java @@ -429,8 +429,7 @@ final class REngine implements Engine, Engine.Timings { } } RArgsValuesAndNames reorderedArgs = CallMatcherGenericNode.reorderArguments(args, func, - names == null ? ArgumentsSignature.empty(args.length) : ArgumentsSignature.get(names.getDataWithoutCopying()), false, - RError.NO_CALLER); + names == null ? ArgumentsSignature.empty(args.length) : ArgumentsSignature.get(names.getDataWithoutCopying()), RError.NO_CALLER); Object[] newArgs = reorderedArgs.getArguments(); for (int i = 0; i < newArgs.length; i++) { Object arg = newArgs[i]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/S3DispatchFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/S3DispatchFunctions.java index 21f5256c1b6aa582ccc8433452afcb65fc4c0d5b..91aa642cb77db7cde6343807f75c40d3cd2de3af 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/S3DispatchFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/S3DispatchFunctions.java @@ -65,7 +65,7 @@ public abstract class S3DispatchFunctions extends RBuiltinNode { protected S3DispatchFunctions(boolean nextMethod) { methodLookup = S3FunctionLookupNode.create(true, nextMethod); - callMatcher = CallMatcherNode.create(nextMethod, false); + callMatcher = CallMatcherNode.create(false); } protected MaterializedFrame getCallerFrame(VirtualFrame frame) { 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 0151d99d910b40d7313c630e7684cc1c3a429a20..05ae3e1145805f119885ef2523049106a5f55d26 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 @@ -123,7 +123,7 @@ abstract class SubscriptSpecial extends SubscriptSpecialBase { } } -@RBuiltin(name = "[[", kind = PRIMITIVE, parameterNames = {"", "...", "exact", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) +@RBuiltin(name = "[[", kind = PRIMITIVE, parameterNames = {"x", "...", "exact", "drop"}, dispatch = INTERNAL_GENERIC, behavior = PURE) public abstract class Subscript extends RBuiltinNode { @RBuiltin(name = ".subset2", kind = PRIMITIVE, parameterNames = {"x", "...", "exact", "drop"}, behavior = PURE) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RInternalCodeBuiltinNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RInternalCodeBuiltinNode.java index 6099c04dfecf655d59ff6d3a77b9e66864e4ba08..78914ee9313f30da5b6375abe5aac790555c4695 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RInternalCodeBuiltinNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RInternalCodeBuiltinNode.java @@ -45,7 +45,7 @@ public final class RInternalCodeBuiltinNode extends RExternalBuiltinNode { private final Source code; private final String functionName; - @Child private CallMatcherNode call = CallMatcherNode.create(false, true); + @Child private CallMatcherNode call = CallMatcherNode.create(true); @CompilationFinal private RFunction function; public RInternalCodeBuiltinNode(RContext context, String basePackage, Source code, String functionName) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java index a56caa191cadd1e6ac3cde0064ab64bd3d226668..177b16a70499c1366fcb1fef5c3640acbb72a669 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java @@ -42,13 +42,13 @@ import com.oracle.truffle.r.runtime.Arguments; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RArguments; import com.oracle.truffle.r.runtime.RArguments.S3DefaultArguments; -import com.oracle.truffle.r.runtime.builtins.FastPathFactory; -import com.oracle.truffle.r.runtime.builtins.RBuiltinDescriptor; -import com.oracle.truffle.r.runtime.builtins.RBuiltinKind; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.Utils; +import com.oracle.truffle.r.runtime.builtins.FastPathFactory; +import com.oracle.truffle.r.runtime.builtins.RBuiltinDescriptor; +import com.oracle.truffle.r.runtime.builtins.RBuiltinKind; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.REmpty; import com.oracle.truffle.r.runtime.data.RFunction; @@ -67,7 +67,7 @@ import com.oracle.truffle.r.runtime.nodes.RNode; * {@link #matchArguments(RRootNode, CallArgumentsNode, ArgumentsSignature, S3DefaultArguments, RBaseNode, boolean)} * . The other match functions are used for special cases, where builtins make it necessary to * re-match parameters, e.g.: - * {@link #matchArgumentsEvaluated(RRootNode, RArgsValuesAndNames, S3DefaultArguments, boolean, RBaseNode)} + * {@link #matchArgumentsEvaluated(RRootNode, RArgsValuesAndNames, S3DefaultArguments, RBaseNode)} * for 'UseMethod'. * </p> * @@ -157,9 +157,9 @@ public class ArgumentMatcher { return ArgumentMatcher.matchNodes(target, argNodes, signature, s3DefaultArguments, callingNode, arguments, noOpt); } - public static MatchPermutation matchArguments(ArgumentsSignature supplied, ArgumentsSignature formal, RBaseNode callingNode, boolean forNextMethod, RBuiltinDescriptor builtin) { + public static MatchPermutation matchArguments(ArgumentsSignature supplied, ArgumentsSignature formal, RBaseNode callingNode, RBuiltinDescriptor builtin) { CompilerAsserts.neverPartOfCompilation(); - return permuteArguments(supplied, formal, callingNode, forNextMethod, index -> false, index -> supplied.getName(index) == null ? "" : supplied.getName(index), builtin); + return permuteArguments(supplied, formal, callingNode, index -> false, index -> supplied.getName(index) == null ? "" : supplied.getName(index), builtin); } public static ArgumentsSignature getFunctionSignature(RFunction function) { @@ -219,15 +219,13 @@ public class ArgumentMatcher { * taken from the stack) * @param s3DefaultArguments default values carried over from S3 group dispatch method (e.g. * from max to Summary.factor). {@code null} if there are no such arguments. - * @param forNextMethod matching when evaluating NextMethod * @param callingNode The {@link Node} invoking the match * @return A Fresh {@link RArgsValuesAndNames} containing the arguments rearranged and stuffed * with default values (in the form of {@link RPromise}s where needed) */ - public static RArgsValuesAndNames matchArgumentsEvaluated(RRootNode target, RArgsValuesAndNames evaluatedArgs, S3DefaultArguments s3DefaultArguments, boolean forNextMethod, - RBaseNode callingNode) { + public static RArgsValuesAndNames matchArgumentsEvaluated(RRootNode target, RArgsValuesAndNames evaluatedArgs, S3DefaultArguments s3DefaultArguments, RBaseNode callingNode) { FormalArguments formals = target.getFormalArguments(); - MatchPermutation match = permuteArguments(evaluatedArgs.getSignature(), formals.getSignature(), callingNode, forNextMethod, index -> { + MatchPermutation match = permuteArguments(evaluatedArgs.getSignature(), formals.getSignature(), callingNode, index -> { throw RInternalError.unimplemented("S3Dispatch should not have arg length mismatch"); }, index -> evaluatedArgs.getSignature().getName(index), null); @@ -310,7 +308,7 @@ public class ArgumentMatcher { FormalArguments formals = target.getFormalArguments(); // Rearrange arguments - MatchPermutation match = permuteArguments(suppliedSignature, formals.getSignature(), callingNode, false, + MatchPermutation match = permuteArguments(suppliedSignature, formals.getSignature(), callingNode, index -> RASTUtils.isLookup(suppliedArgs[index], ArgumentsSignature.VARARG_NAME), index -> getErrorForArgument(suppliedArgs, suppliedSignature, index), target.getBuiltin()); @@ -491,12 +489,11 @@ public class ArgumentMatcher { * @param signature The signature (==names) of the supplied arguments * @param formalSignature The signature (==names) of the formal arguments * @param callingNode The {@link Node} invoking the match - * @param forNextMethod matching when evaluating NextMethod * @param builtin builtin function descriptor (or null if not a builtin) * @return An array of type <T> with the supplied arguments in the correct order */ @TruffleBoundary - private static MatchPermutation permuteArguments(ArgumentsSignature signature, ArgumentsSignature formalSignature, RBaseNode callingNode, boolean forNextMethod, IntPredicate isVarSuppliedVarargs, + private static MatchPermutation permuteArguments(ArgumentsSignature signature, ArgumentsSignature formalSignature, RBaseNode callingNode, IntPredicate isVarSuppliedVarargs, IntFunction<String> errorString, RBuiltinDescriptor builtin) { // assert Arrays.stream(suppliedNames).allMatch(name -> name == null || !name.isEmpty()); @@ -517,8 +514,7 @@ public class ArgumentMatcher { } // Search for argument name inside formal arguments - int formalIndex = findParameterPosition(formalSignature, signature.getName(suppliedIndex), resultPermutation, suppliedIndex, hasVarArgs, callingNode, varArgIndex, forNextMethod, - errorString, builtin); + int formalIndex = findParameterPosition(formalSignature, signature.getName(suppliedIndex), resultPermutation, suppliedIndex, hasVarArgs, callingNode, varArgIndex, errorString, builtin); if (formalIndex != MatchPermutation.UNMATCHED) { resultPermutation[formalIndex] = suppliedIndex; resultSignature[formalIndex] = signature.getName(suppliedIndex); @@ -541,10 +537,6 @@ public class ArgumentMatcher { break outer; } if (!matchedSuppliedArgs[suppliedIndex]) { - if (forNextMethod) { - // for NextMethod, unused parameters are matched even when named - break; - } if (signature.getName(suppliedIndex) == null || signature.getName(suppliedIndex).isEmpty()) { // unnamed parameter, match by position break; @@ -638,7 +630,7 @@ public class ArgumentMatcher { * argument has been matched before */ private static <T> int findParameterPosition(ArgumentsSignature formalsSignature, String suppliedName, int[] resultPermutation, int suppliedIndex, boolean hasVarArgs, RBaseNode callingNode, - int varArgIndex, boolean forNextMethod, IntFunction<String> errorString, RBuiltinDescriptor builtin) { + int varArgIndex, IntFunction<String> errorString, RBuiltinDescriptor builtin) { int found = MatchPermutation.UNMATCHED; for (int i = 0; i < formalsSignature.getLength(); i++) { String formalName = formalsSignature.getName(i); @@ -672,7 +664,7 @@ public class ArgumentMatcher { } } } - if (found >= 0 || hasVarArgs || forNextMethod) { + if (found >= 0 || hasVarArgs) { return found; } throw RError.error(callingNode, RError.Message.UNUSED_ARGUMENT, errorString.apply(suppliedIndex)); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java index 06d899fec812551590a9d15b134af69cbe86b136..9454d1b46b985707c8c836d1c714a9b1b86936e3 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallMatcherNode.java @@ -46,7 +46,6 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; public abstract class CallMatcherNode extends RBaseNode { - protected final boolean forNextMethod; protected final boolean argsAreEvaluated; @Child private PromiseHelperNode promiseHelper; @@ -54,15 +53,14 @@ public abstract class CallMatcherNode extends RBaseNode { protected final ConditionProfile missingArgProfile = ConditionProfile.createBinaryProfile(); protected final ConditionProfile emptyArgProfile = ConditionProfile.createBinaryProfile(); - private CallMatcherNode(boolean forNextMethod, boolean argsAreEvaluated) { - this.forNextMethod = forNextMethod; + private CallMatcherNode(boolean argsAreEvaluated) { this.argsAreEvaluated = argsAreEvaluated; } private static final int MAX_CACHE_DEPTH = 3; - public static CallMatcherNode create(boolean forNextMethod, boolean argsAreEvaluated) { - return new CallMatcherUninitializedNode(forNextMethod, argsAreEvaluated); + public static CallMatcherNode create(boolean argsAreEvaluated) { + return new CallMatcherUninitializedNode(argsAreEvaluated); } public abstract Object execute(VirtualFrame frame, ArgumentsSignature suppliedSignature, Object[] suppliedArguments, RFunction function, String functionName, DispatchArgs dispatchArgs); @@ -110,9 +108,9 @@ public abstract class CallMatcherNode extends RBaseNode { assert resultSignature != null; ArgumentsSignature formalSignature = ArgumentMatcher.getFunctionSignature(function); - MatchPermutation permutation = ArgumentMatcher.matchArguments(resultSignature, formalSignature, this, forNextMethod, function.getRBuiltin()); + MatchPermutation permutation = ArgumentMatcher.matchArguments(resultSignature, formalSignature, this, function.getRBuiltin()); - return new CallMatcherCachedNode(suppliedSignature, varArgsInfo.getVarArgsSignatures(), function, preparePermutation, permutation, forNextMethod, argsAreEvaluated, next); + return new CallMatcherCachedNode(suppliedSignature, varArgsInfo.getVarArgsSignatures(), function, preparePermutation, permutation, argsAreEvaluated, next); } protected final void evaluatePromises(VirtualFrame frame, RFunction function, Object[] args, int varArgIndex) { @@ -153,8 +151,8 @@ public abstract class CallMatcherNode extends RBaseNode { @NodeInfo(cost = NodeCost.UNINITIALIZED) private static final class CallMatcherUninitializedNode extends CallMatcherNode { - CallMatcherUninitializedNode(boolean forNextMethod, boolean argsAreEvaluated) { - super(forNextMethod, argsAreEvaluated); + CallMatcherUninitializedNode(boolean argsAreEvaluated) { + super(argsAreEvaluated); } private int depth; @@ -163,7 +161,7 @@ public abstract class CallMatcherNode extends RBaseNode { public Object execute(VirtualFrame frame, ArgumentsSignature suppliedSignature, Object[] suppliedArguments, RFunction function, String functionName, DispatchArgs dispatchArgs) { CompilerDirectives.transferToInterpreterAndInvalidate(); if (++depth > MAX_CACHE_DEPTH) { - return replace(new CallMatcherGenericNode(forNextMethod, argsAreEvaluated)).execute(frame, suppliedSignature, suppliedArguments, function, functionName, dispatchArgs); + return replace(new CallMatcherGenericNode(argsAreEvaluated)).execute(frame, suppliedSignature, suppliedArguments, function, functionName, dispatchArgs); } else { CallMatcherCachedNode cachedNode = replace(specialize(suppliedSignature, suppliedArguments, function, this)); // for splitting if necessary @@ -201,8 +199,8 @@ public abstract class CallMatcherNode extends RBaseNode { private final FormalArguments formals; CallMatcherCachedNode(ArgumentsSignature suppliedSignature, ArgumentsSignature[] varArgSignatures, RFunction function, long[] preparePermutation, MatchPermutation permutation, - boolean forNextMethod, boolean argsAreEvaluated, CallMatcherNode next) { - super(forNextMethod, argsAreEvaluated); + boolean argsAreEvaluated, CallMatcherNode next) { + super(argsAreEvaluated); this.cachedSuppliedSignature = suppliedSignature; this.cachedVarArgSignatures = varArgSignatures; this.cachedFunction = function; @@ -315,8 +313,8 @@ public abstract class CallMatcherNode extends RBaseNode { public static final class CallMatcherGenericNode extends CallMatcherNode { - CallMatcherGenericNode(boolean forNextMethod, boolean argsAreEvaluated) { - super(forNextMethod, argsAreEvaluated); + CallMatcherGenericNode(boolean argsAreEvaluated) { + super(argsAreEvaluated); } @Child private CallRFunctionCachedNode call = CallRFunctionCachedNodeGen.create(0); @@ -324,7 +322,7 @@ public abstract class CallMatcherNode extends RBaseNode { @Override public Object execute(VirtualFrame frame, ArgumentsSignature suppliedSignature, Object[] suppliedArguments, RFunction function, String functionName, DispatchArgs dispatchArgs) { - RArgsValuesAndNames reorderedArgs = reorderArguments(suppliedArguments, function, suppliedSignature, forNextMethod, this); + RArgsValuesAndNames reorderedArgs = reorderArguments(suppliedArguments, function, suppliedSignature, this); evaluatePromises(frame, function, reorderedArgs.getArguments(), reorderedArgs.getSignature().getVarArgIndex()); RCaller parent = RArguments.getCall(frame).getParent(); @@ -351,7 +349,7 @@ public abstract class CallMatcherNode extends RBaseNode { } @TruffleBoundary - public static RArgsValuesAndNames reorderArguments(Object[] args, RFunction function, ArgumentsSignature paramSignature, boolean forNextMethod, RBaseNode callingNode) { + public static RArgsValuesAndNames reorderArguments(Object[] args, RFunction function, ArgumentsSignature paramSignature, RBaseNode callingNode) { assert paramSignature.getLength() == args.length; int argCount = args.length; @@ -412,7 +410,7 @@ public abstract class CallMatcherNode extends RBaseNode { RArgsValuesAndNames evaledArgs = new RArgsValuesAndNames(argValues, signature); // ...to match them against the chosen function's formal arguments - RArgsValuesAndNames evaluated = ArgumentMatcher.matchArgumentsEvaluated((RRootNode) function.getRootNode(), evaledArgs, null, forNextMethod, callingNode); + RArgsValuesAndNames evaluated = ArgumentMatcher.matchArgumentsEvaluated((RRootNode) function.getRootNode(), evaledArgs, null, callingNode); return evaluated; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UseMethodInternalNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UseMethodInternalNode.java index 284b6b0c0825045733416846ed73b1ab1641f761..739931976e6def1f5933a27c1c92806339e413c4 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UseMethodInternalNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UseMethodInternalNode.java @@ -24,7 +24,7 @@ public final class UseMethodInternalNode extends RNode { @Child private ClassHierarchyNode classHierarchyNode = ClassHierarchyNodeGen.create(true, true); @Child private S3FunctionLookupNode lookup = S3FunctionLookupNode.create(false, false); - @Child private CallMatcherNode callMatcher = CallMatcherNode.create(false, false); + @Child private CallMatcherNode callMatcher = CallMatcherNode.create(false); @Child private PreProcessArgumentsNode argPreProcess; private final String generic; 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 ee7c56dace3c2fb6fc13e9ff516535ec2344587d..60218f9968d1610f1a04a6f303e88eb16bbd1e53 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 @@ -183,7 +183,7 @@ public abstract class PrepareArguments extends Node { CachedExplicitPrepareArguments(PrepareArguments next, RRootNode target, RCallNode call, ArgumentsSignature explicitArgSignature) { this.next = next; formals = target.getFormalArguments(); - permutation = ArgumentMatcher.matchArguments(explicitArgSignature, formals.getSignature(), call, false, target.getBuiltin()); + permutation = ArgumentMatcher.matchArguments(explicitArgSignature, formals.getSignature(), call, target.getBuiltin()); cachedExplicitArgSignature = explicitArgSignature; } @@ -208,7 +208,7 @@ public abstract class PrepareArguments extends Node { public RArgsValuesAndNames execute(VirtualFrame frame, RArgsValuesAndNames explicitArgs, S3DefaultArguments s3DefaultArguments, RCallNode call) { CompilerDirectives.transferToInterpreter(); // Function and arguments may change every call: Flatt'n'Match on SlowPath! :-/ - return ArgumentMatcher.matchArgumentsEvaluated(target, explicitArgs, s3DefaultArguments, false, RError.ROOTNODE); + return ArgumentMatcher.matchArgumentsEvaluated(target, explicitArgs, s3DefaultArguments, RError.ROOTNODE); } } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/objects/ExecuteMethod.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/objects/ExecuteMethod.java index a486be7101ff3eb27da17ed9a59ad0f3c320ef5c..4619df7873767cf57eb2f9b2b0a24c3512e4f14e 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/objects/ExecuteMethod.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/objects/ExecuteMethod.java @@ -42,7 +42,7 @@ final class ExecuteMethod extends RBaseNode { if (collectArgs == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); collectArgs = insert(CollectArgumentsNodeGen.create()); - callMatcher = insert(CallMatcherNode.create(false, false)); + callMatcher = insert(CallMatcherNode.create(false)); } FormalArguments formals = ((RRootNode) fdef.getRootNode()).getFormalArguments();