Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cff40b3f4a16
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3827161d0261
Choose a head ref
  • 7 commits
  • 18 files changed
  • 1 contributor

Commits on May 6, 2015

  1. Copy the full SHA
    6c3c8ce View commit details
  2. Copy the full SHA
    c3adbd4 View commit details
  3. Copy the full SHA
    a679852 View commit details
  4. Copy the full SHA
    974ddce View commit details
  5. Remove usage ofr block.arity()

    enebo committed May 6, 2015
    Copy the full SHA
    aea099d View commit details
  6. Whoops forgot @Deprecations

    enebo committed May 6, 2015
    Copy the full SHA
    c3fe1a2 View commit details
  7. Copy the full SHA
    3827161 View commit details
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -1586,7 +1586,8 @@ public IRubyObject eachSlice(ThreadContext context, int size, Block block) {
makeShared();

// don't expose shared array to ruby
final boolean specificArity = (block.arity().isFixed()) && (block.arity().required() != 1);
Signature signature = block.getSignature();
final boolean specificArity = signature.isFixed() && signature.required() != 1;

for (; localRealLength >= size; localRealLength -= size) {
block.yield(context, window);
24 changes: 18 additions & 6 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -106,6 +106,13 @@ public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObj
arity, callback, context));
}

public static IRubyObject callEach19(Ruby runtime, ThreadContext context, IRubyObject self,
Signature signature, BlockCallback callback) {
return Helpers.invoke(context, self, "each", CallBlock19.newCallClosure(self, runtime.getEnumerable(),
signature, callback, context));
}

@Deprecated
public static IRubyObject callEach19(Ruby runtime, ThreadContext context, IRubyObject self,
Arity arity, BlockCallback callback) {
return Helpers.invoke(context, self, "each", CallBlock19.newCallClosure(self, runtime.getEnumerable(),
@@ -140,10 +147,10 @@ public static IRubyObject count18(ThreadContext context, IRubyObject self, final

@JRubyMethod(name = "count")
public static IRubyObject count(ThreadContext context, IRubyObject self, final Block block) {
return countCommon(context, self, block, block.arity());
return countCommon(context, self, block);
}

private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;
final int result[] = new int[] { 0 };

@@ -802,7 +809,7 @@ private static IRubyObject collectCommon19(ThreadContext context, IRubyObject se
if (block.isGiven()) {
final RubyArray result = runtime.newArray();

callEach19(runtime, context, self, block.arity(), new BlockCallback() {
callEach19(runtime, context, self, block.getSignature(), new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg;
boolean newAry = false;
@@ -1593,10 +1600,15 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {

@JRubyMethod(name = "any?")
public static IRubyObject any_p(ThreadContext context, IRubyObject self, final Block block) {
return any_pCommon(context, self, block, block.arity());
return any_pCommon(context, self, block);
}


@Deprecated
public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
return any_pCommon(context, self, block);
}

public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, final Block block) {
final Ruby runtime = context.runtime;

try {
@@ -1942,7 +1954,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject packedArgs = packEnumValues(runtime, largs);
IRubyObject v;
if(arg.state.isNil()) {
if (arg.categorize.getBlock().arity().getValue() == 1) {
if (arg.categorize.getBlock().getSignature().arityValue() == 1) {
// if chunk's categorize block has arity one, we pass it the packed args
v = arg.categorize.callMethod(ctx, "call", packedArgs);
} else {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.compiler.Constantizable;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.UnmarshalStream;
@@ -287,7 +287,7 @@ public IRubyObject times(ThreadContext context, Block block) {
boolean checkArity = block.type.checkArity;

if (block.getBody().getArgumentType() == BlockBody.ZERO_ARGS ||
block.arity() == Arity.NO_ARGUMENTS) {
block.getSignature() == Signature.NO_ARGUMENTS) {
if (checkArity) {
// must pass arg
IRubyObject nil = runtime.getNil();
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.invokedynamic.MethodNames;
@@ -742,7 +743,7 @@ public IRubyObject default_proc() {
*
*/
private void checkDefaultProcArity(IRubyObject proc) {
int n = ((RubyProc)proc).getBlock().arity().getValue();
int n = ((RubyProc)proc).getBlock().getSignature().arityValue();

if(((RubyProc)proc).getBlock().type == Block.Type.LAMBDA && n != 2 && (n >= 0 || n < -3)) {
if(n < 0) n = -n-1;
@@ -1325,7 +1326,7 @@ private void iteratorVisitAll(Visitor visitor) {
*
*/
public RubyHash eachCommon(final ThreadContext context, final Block block) {
if (block.arity() == Arity.TWO_ARGUMENTS) {
if (block.getSignature() == Signature.TWO_ARGUMENTS) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
@@ -1879,7 +1880,7 @@ public IRubyObject any_p(ThreadContext context, Block block) {

if (!block.isGiven()) return context.runtime.getTrue();

if (block.arity().getValue() > 1)
if (block.getSignature().arityValue() > 1)
return any_p_i_fast(context, block);

return any_p_i(context, block);
17 changes: 9 additions & 8 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.SimpleSourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockBody;
@@ -48,6 +47,7 @@
import org.jruby.runtime.IRBlockBody;
import org.jruby.runtime.MethodBlock;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.DataType;
@@ -239,25 +239,26 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args) {
* arity of one, etc.)
*/
public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type, BlockBody blockBody, IRubyObject[] args) {
// FIXME: Arity marked for death
Arity arity = blockBody.arity();
if (arity == null) return args;
Signature signature = blockBody.getSignature();

// FIXME: which blocks have no signature (and no arity before that?)
if (signature == null) return args;

if (args == null) return IRubyObject.NULL_ARRAY;

if (type == Block.Type.LAMBDA) {
blockBody.getSignature().checkArity(context.runtime, args);
signature.checkArity(context.runtime, args);
return args;
}

boolean isFixed = arity.isFixed();
int required = arity.required();
boolean isFixed = signature.isFixed();
int required = signature.required();
int actual = args.length;
boolean restKwargs = blockBody instanceof IRBlockBody && ((IRBlockBody) blockBody).getSignature().hasKwargs();

// FIXME: This is a hot mess. restkwargs factors into destructing a single element array as well. I just weaved it into this logic.
// for procs and blocks, single array passed to multi-arg must be spread
if ((arity != Arity.ONE_ARGUMENT && required != 0 && (isFixed || arity != Arity.OPTIONAL) || restKwargs) &&
if ((signature != Signature.ONE_ARGUMENT && required != 0 && (isFixed || signature != Signature.OPTIONAL) || restKwargs) &&
actual == 1 && args[0].respondsTo("to_ary")) {
args = args[0].convertToArray().toJavaArray();
actual = args.length;
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public boolean isSame(DynamicMethod method) {

@Override
public Arity getArity() {
return proc.getBlock().arity();
return proc.getBlock().getSignature().arity();
}

public String getFile() {
Original file line number Diff line number Diff line change
@@ -265,7 +265,7 @@ private void inlineClosureAtYieldSite(InlineCloneInfo ii, IRClosure cl, BasicBlo

// Allocate new inliner object to reset variable and label rename maps
ii = ii.cloneForInliningClosure(cl);
ii.setupYieldArgsAndYieldResult(yield, yieldBB, cl.getBlockBody().arity());
ii.setupYieldArgsAndYieldResult(yield, yieldBB, cl.getBlockBody().getSignature().arityValue());

// 2. Merge closure cfg into the current cfg
CFG closureCFG = cl.getCFG();
Original file line number Diff line number Diff line change
@@ -181,8 +181,7 @@ public void recordYieldSite(BasicBlock bb, YieldInstr i) {
yieldSites.add(new Tuple<BasicBlock, YieldInstr>(bb, i));
}

public void setupYieldArgsAndYieldResult(YieldInstr yi, BasicBlock yieldBB, Arity blockArity) {
int blockArityValue = blockArity.getValue();
public void setupYieldArgsAndYieldResult(YieldInstr yi, BasicBlock yieldBB, int blockArityValue) {
Operand yieldInstrArg = yi.getYieldArg();

if ((yieldInstrArg == UndefinedValue.UNDEFINED) || (blockArityValue == 0)) {
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/runtime/Block.java
Original file line number Diff line number Diff line change
@@ -204,8 +204,9 @@ public Block cloneBlockForEval(IRubyObject self, EvalType evalType) {
*
* @return the arity
*/
@Deprecated
public Arity arity() {
return body.arity();
return body.getSignature().arity();
}

public Signature getSignature() {
18 changes: 12 additions & 6 deletions core/src/main/java/org/jruby/runtime/BlockBody.java
Original file line number Diff line number Diff line change
@@ -53,13 +53,16 @@ public abstract class BlockBody {
public static final String[] EMPTY_PARAMETER_LIST = new String[0];

protected final int argumentType;
protected final Signature signature;

public BlockBody(int argumentType) {
public BlockBody(int argumentType, Signature signature) {
this.argumentType = argumentType;
this.signature = signature;
}

// FIXME: Push all impls down so this is single concrete impl
public abstract Signature getSignature();
public Signature getSignature() {
return signature;
}

public void setEvalType(EvalType evalType) {
System.err.println("setEvalType unimplemented in " + this.getClass().getName());
@@ -189,7 +192,10 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyO
*
* @return the arity
*/
public abstract Arity arity();
@Deprecated
public Arity arity() {
return signature.arity();
}

/**
* Is the current block a real yield'able block instead a null one
@@ -231,14 +237,14 @@ public IRubyObject[] prepareArgumentsForCall(ThreadContext context, IRubyObject[
}
case LAMBDA:
if (argumentType == ARRAY && args.length != 1) {
context.runtime.getWarnings().warn(ID.MULTIPLE_VALUES_FOR_BLOCK, "multiple values for a block parameter (" + args.length + " for " + arity().getValue() + ")");
context.runtime.getWarnings().warn(ID.MULTIPLE_VALUES_FOR_BLOCK, "multiple values for a block parameter (" + args.length + " for " + getSignature().arityValue() + ")");
if (args.length == 0) {
args = context.runtime.getSingleNilArray();
} else {
args = new IRubyObject[] {context.runtime.newArrayNoCopy(args)};
}
} else {
arity().checkArity(context.runtime, args);
getSignature().checkArity(context.runtime, args);
}
break;
}
12 changes: 1 addition & 11 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@
* lightweight block logic within Java code.
*/
public class CallBlock extends BlockBody {
private final Signature signature;
private final BlockCallback callback;
private final StaticScope dummyScope;

@@ -56,8 +55,7 @@ public static Block newCallClosure(IRubyObject self, RubyModule imClass, Arity a
}

private CallBlock(Signature signature, BlockCallback callback, ThreadContext context) {
super(BlockBody.SINGLE_RESTARG);
this.signature = signature;
super(BlockBody.SINGLE_RESTARG, signature);
this.callback = callback;
this.dummyScope = context.runtime.getStaticScopeFactory().getDummyScope();
}
@@ -102,14 +100,6 @@ public void setStaticScope(StaticScope newScope) {
// ignore
}

public Signature getSignature() {
return signature;
}

public Arity arity() {
return signature.arity();
}

public String getFile() {
return "(internal)";
}
12 changes: 1 addition & 11 deletions core/src/main/java/org/jruby/runtime/CallBlock19.java
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@
* lightweight block logic within Java code.
*/
public class CallBlock19 extends BlockBody {
private final Signature signature;
private final BlockCallback callback;
private final StaticScope dummy;

@@ -58,8 +57,7 @@ public static Block newCallClosure(IRubyObject self, RubyModule imClass, Arity a
}

public CallBlock19(Signature signature, BlockCallback callback, ThreadContext context) {
super(BlockBody.SINGLE_RESTARG);
this.signature = signature;
super(BlockBody.SINGLE_RESTARG, signature);
this.callback = callback;
this.dummy = context.runtime.getStaticScopeFactory().getDummyScope();
}
@@ -122,14 +120,6 @@ public void setStaticScope(StaticScope newScope) {
// ignore
}

public Signature getSignature() {
return signature;
}

public Arity arity() {
return signature.arity();
}

public String getFile() {
return "(internal)";
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/runtime/CompiledBlock19.java
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ public CompiledBlock19(Signature signature, StaticScope scope, CompiledBlockCall
this.callback = callback;
this.hasMultipleArgsHead = hasMultipleArgsHead;
this.parameterList = parameterList;
this.needsSplat = Helpers.needsSplat19(arity().required(), !arity().isFixed());
this.needsSplat = Helpers.needsSplat19(signature.required(), !signature.isFixed());
}

@Deprecated
@@ -181,7 +181,7 @@ private IRubyObject[] setupBlockArg(Ruby ruby, IRubyObject value, IRubyObject se
}

private IRubyObject[] setupBlockArgs(IRubyObject value, Block.Type type, boolean alreadyArray) {
return Helpers.restructureBlockArgs19(value, arity(), type, needsSplat, alreadyArray);
return Helpers.restructureBlockArgs19(value, getSignature(), type, needsSplat, alreadyArray);
}

public String getFile() {
14 changes: 1 addition & 13 deletions core/src/main/java/org/jruby/runtime/ContextAwareBlockBody.java
Original file line number Diff line number Diff line change
@@ -9,14 +9,10 @@ public abstract class ContextAwareBlockBody extends BlockBody {
/** The static scope for the block body */
protected StaticScope scope;

/** The 'Arity' of the block */
protected final Signature signature;

public ContextAwareBlockBody(StaticScope scope, Signature signature, int argumentType) {
super(argumentType);
super(argumentType, signature);

this.scope = scope;
this.signature = signature;
}

public ContextAwareBlockBody(StaticScope scope, Arity arity, int argumentType) {
@@ -39,12 +35,4 @@ public StaticScope getStaticScope() {
public void setStaticScope(StaticScope newScope) {
this.scope = newScope;
}

public Signature getSignature() {
return signature;
}

public Arity arity() {
return signature.arity();
}
}
9 changes: 2 additions & 7 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -1823,11 +1823,6 @@ public static IRubyObject unsplatValue19(IRubyObject argsResult) {
return argsResult;
}

public static IRubyObject unsplatValue19IfArityOne(IRubyObject argsResult, Block block) {
if (block.isGiven() && block.arity().getValue() > 1) argsResult = Helpers.unsplatValue19(argsResult);
return argsResult;
}

public static IRubyObject[] splatToArguments(IRubyObject value) {
Ruby runtime = value.getRuntime();

@@ -2748,8 +2743,8 @@ public static boolean needsSplat19(int requiredCount, boolean isRest) {
// . Array with multiple values and NO rest should extract args if there are more than one argument
// Note: In 1.9 alreadyArray is only relevent from our internal Java code in core libs. We never use it
// from interpreter or JIT. FIXME: Change core lib consumers to stop using alreadyArray param.
public static IRubyObject[] restructureBlockArgs19(IRubyObject value, Arity arity, Block.Type type, boolean needsSplat, boolean alreadyArray) {
if (!type.checkArity && arity == Arity.NO_ARGUMENTS) return IRubyObject.NULL_ARRAY;
public static IRubyObject[] restructureBlockArgs19(IRubyObject value, Signature signature, Block.Type type, boolean needsSplat, boolean alreadyArray) {
if (!type.checkArity && signature == Signature.NO_ARGUMENTS) return IRubyObject.NULL_ARRAY;

if (value != null && !(value instanceof RubyArray) && needsSplat) value = Helpers.aryToAry(value);

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Bindin
}

private IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] args, Binding binding, Type type) {
int blockArity = arity().getValue();
int blockArity = getSignature().arityValue();
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
} else if (blockArity == 1) {
@@ -119,7 +119,7 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyO
public IRubyObject doYield(ThreadContext context, IRubyObject value, Binding binding, Type type) {
IRubyObject[] args;

int blockArity = arity().getValue();
int blockArity = getSignature().arityValue();

// For lambdas, independent of whether there is a REST arg or not, if # required args is 1,
// the value is passed through unmodified even when it is an array!
@@ -164,7 +164,7 @@ public IRubyObject[] prepareArgumentsForCall(ThreadContext context, IRubyObject[
if (args.length == 1) {
// Convert value to arg-array, unwrapping where necessary
args = IRRuntimeHelpers.convertValueIntoArgArray(context, args[0], signature.arity(), (type == Type.NORMAL) && (args[0] instanceof RubyArray));
} else if (arity().getValue() == 1 && !getSignature().restKwargs()) {
} else if (getSignature().arityValue() == 1 && !getSignature().restKwargs()) {
// discard excess arguments
args = (args.length == 0) ? context.runtime.getSingleNilArray() : new IRubyObject[] { args[0] };
}
13 changes: 1 addition & 12 deletions core/src/main/java/org/jruby/runtime/JavaInternalBlockBody.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
* Represents a special Java implementation of a block.
*/
public abstract class JavaInternalBlockBody extends BlockBody {
private final Signature signature;
private final ThreadContext originalContext;
private final String methodName;
private final StaticScope dummyScope;
@@ -29,9 +28,8 @@ public JavaInternalBlockBody(Ruby runtime, Signature signature) {
* For blocks which cannot be executed in parallel.
*/
public JavaInternalBlockBody(Ruby runtime, ThreadContext originalContext, String methodName, Signature signature) {
super(BlockBody.SINGLE_RESTARG);
super(BlockBody.SINGLE_RESTARG, signature);

this.signature = signature;
this.originalContext = originalContext;
this.methodName = methodName;
this.dummyScope = runtime.getStaticScopeFactory().getDummyScope();
@@ -80,15 +78,6 @@ public StaticScope getStaticScope() {
public void setStaticScope(StaticScope newScope) {
}

public Signature getSignature() {
return signature;
}

@Override
public Arity arity() {
return signature.arity();
}

@Override
public String getFile() {
return "(internal)";
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/runtime/NullBlockBody.java
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

public class NullBlockBody extends BlockBody {
public NullBlockBody() {
super(ZERO_ARGS);
super(ZERO_ARGS, null);
}

@Override
@@ -66,10 +66,6 @@ public StaticScope getStaticScope() {
public void setStaticScope(StaticScope newScope) {
}

public Signature getSignature() {
return null;
}

@Override
public Arity arity() {
return null;