Skip to content

Commit

Permalink
procs performing arg count checks when they shouldn't
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Apr 8, 2015
1 parent 2ad273a commit 40a4707
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Expand Up @@ -8,6 +8,7 @@
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.InlineCloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;

public class CheckArityInstr extends Instr implements FixedArityInstr {
Expand Down Expand Up @@ -64,8 +65,8 @@ public static CheckArityInstr decode(IRReaderDecoder d) {
return new CheckArityInstr(d.decodeInt(), d.decodeInt(), d.decodeInt(), d.decodeBoolean(), d.decodeInt());
}

public void checkArity(ThreadContext context, Object[] args) {
IRRuntimeHelpers.checkArity(context, args, required, opt, rest, receivesKeywords, restKey);
public void checkArity(ThreadContext context, Object[] args, Block.Type blockType) {
IRRuntimeHelpers.checkArity(context, args, required, opt, rest, receivesKeywords, restKey, blockType);
}

@Override
Expand Down
Expand Up @@ -170,7 +170,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, implClass, null);
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, null);
}
break;
case OTHER_OP:
Expand Down Expand Up @@ -328,7 +328,7 @@ protected static void processCall(ThreadContext context, Instr instr, Operation

protected static void processBookKeepingOp(ThreadContext context, Instr instr, Operation operation,
String name, IRubyObject[] args, IRubyObject self, Block block,
RubyModule implClass, Stack<Integer> rescuePCs) {
Block.Type blockType, RubyModule implClass, Stack<Integer> rescuePCs) {
switch(operation) {
case LABEL:
break;
Expand Down Expand Up @@ -356,7 +356,7 @@ protected static void processBookKeepingOp(ThreadContext context, Instr instr, O
context.callThreadPoll();
break;
case CHECK_ARITY:
((CheckArityInstr)instr).checkArity(context, args);
((CheckArityInstr)instr).checkArity(context, args, blockType);
break;
case LINE_NUM:
context.setLine(((LineNumberInstr)instr).lineNumber);
Expand Down
Expand Up @@ -91,7 +91,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, implClass, rescuePCs);
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, rescuePCs);
}
break;
case OTHER_OP:
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Expand Up @@ -507,16 +507,16 @@ public static Block getBlockFromObject(ThreadContext context, Object value) {
}

public static void checkArity(ThreadContext context, Object[] args, int required, int opt, int rest,
boolean receivesKwargs, int restKey) {
boolean receivesKwargs, int restKey, Block.Type blockType) {
int argsLength = args.length;
RubyHash keywordArgs = (RubyHash) extractKwargsHash(args, required, receivesKwargs);
RubyHash keywordArgs = extractKwargsHash(args, required, receivesKwargs);

if (restKey == -1 && keywordArgs != null) checkForExtraUnwantedKeywordArgs(context, keywordArgs);

// keyword arguments value is not used for arity checking.
if (keywordArgs != null) argsLength -= 1;

if (argsLength < required || (rest == -1 && argsLength > (required + opt))) {
if ((blockType == null || blockType.checkArity) && (argsLength < required || (rest == -1 && argsLength > (required + opt)))) {
// System.out.println("NUMARGS: " + argsLength + ", REQUIRED: " + required + ", OPT: " + opt + ", AL: " + args.length + ",RKW: " + receivesKwargs );
// System.out.println("ARGS[0]: " + args[0]);

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Expand Up @@ -848,7 +848,8 @@ public void CheckArityInstr(CheckArityInstr checkarityinstr) {
jvmAdapter().ldc(checkarityinstr.rest);
jvmAdapter().ldc(checkarityinstr.receivesKeywords);
jvmAdapter().ldc(checkarityinstr.restKey);
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, Object[].class, int.class, int.class, int.class, boolean.class, int.class));
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, Object[].class, int.class, int.class, int.class, boolean.class, int.class, Block.Type.class));
}
}

Expand Down
5 changes: 2 additions & 3 deletions test/mri/excludes/TestKeywordArguments.rb
@@ -1,7 +1,6 @@
exclude :test_block_required_keyword, "needs investigation"
exclude :test_implicit_hash_conversion, "needs investigation"
exclude :test_p1, "needs investigation"
exclude :test_p3, "needs investigation"
exclude :test_p6, "needs investigation"
exclude :test_lambda, "JIT-only"
exclude :test_p6, "JIT-only"
exclude :test_required_keyword_with_reserved, "needs investigation"
exclude :test_rest_keyrest, "needs investigation"

0 comments on commit 40a4707

Please sign in to comment.