Skip to content

Commit

Permalink
Merge pull request jruby#6585 from enebo/remove_block_stuff
Browse files Browse the repository at this point in the history
Kill all use of Arity+
  • Loading branch information
enebo authored Mar 3, 2021
2 parents 6199049 + ede9382 commit bb5a9ab
Show file tree
Hide file tree
Showing 31 changed files with 302 additions and 418 deletions.
13 changes: 3 additions & 10 deletions core/src/main/java/org/jruby/AbstractRubyMethod.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/***** BEGIN LICENSE BLOCK *****
/*
**** BEGIN LICENSE BLOCK *****
* Version: EPL 2.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
Expand Down Expand Up @@ -35,7 +36,6 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.internal.runtime.methods.AliasMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.PositionAware;
Expand Down Expand Up @@ -71,14 +71,7 @@ public DynamicMethod getMethod() {
*/
@JRubyMethod(name = "arity")
public RubyFixnum arity() {
int value;
if (method instanceof IRMethodArgs) {
value = ((IRMethodArgs) method).getSignature().arityValue();
} else {
value = method.getArity().getValue();
}

return getRuntime().newFixnum(value);
return getRuntime().newFixnum(method.getSignature().arityValue());
}

@Deprecated
Expand Down
19 changes: 3 additions & 16 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.BasicObjectSites;
import org.jruby.runtime.Signature;
import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.runtime.ivars.VariableAccessor;
import java.io.IOException;
Expand Down Expand Up @@ -602,23 +603,9 @@ public final boolean respondsTo(String name) {
// respond_to? or respond_to_missing? is not defined, so we must dispatch to trigger method_missing
if ( respondTo.isUndefined() ) {
return sites(context).respond_to.call(context, this, this, mname).isTrue();
} else {
return respondTo.callRespondTo(context, this, "respond_to?", entry.sourceModule, mname);
}

// respond_to? is defined, invoke already-retrieved method object
final String respondName = "respond_to?";

// We have to check and enforce arity
final Arity arity = respondTo.getArity();
if ( arity.isFixed() ) {
if ( arity.required() == 1 ) {
return respondTo.call(context, this, entry.sourceModule, respondName, mname).isTrue();
}
if ( arity.required() != 2 ) {
throw runtime.newArgumentError(str(runtime, ids(runtime, respondName), " must accept 1 or 2 arguments (requires " + arity.getValue() + ")"));
}
}

return respondTo.call(context, this, entry.sourceModule, respondName, mname, runtime.getTrue()).isTrue();
}

/**
Expand Down
194 changes: 83 additions & 111 deletions core/src/main/java/org/jruby/RubyClass.java

Large diffs are not rendered by default.

161 changes: 0 additions & 161 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2241,118 +2241,11 @@ public static IRubyObject none_p19(ThreadContext context, IRubyObject self, fina
return none_p(context, self, null, block);
}

@Deprecated
public static IRubyObject none_p(final ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
try {
if (block.isGiven()) {
callEach(context.runtime, context, self, callbackArity, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "none?");
IRubyObject larg = packEnumValues(ctx, largs);
if (block.yield(ctx, larg).isTrue()) throw JumpException.SPECIAL_JUMP;
return ctx.nil;
}
@Override
public IRubyObject call(ThreadContext ctx, IRubyObject larg) {
checkContext(context, ctx, "none?");
if (block.yield(ctx, larg).isTrue()) throw JumpException.SPECIAL_JUMP;
return ctx.nil;
}
});
} else {
callEach(context, eachSite(context), self, Signature.ONE_REQUIRED, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "none?");
IRubyObject larg = packEnumValues(ctx, largs);
if (larg.isTrue()) throw JumpException.SPECIAL_JUMP;
return ctx.nil;
}
@Override
public IRubyObject call(ThreadContext ctx, IRubyObject larg) {
checkContext(context, ctx, "none?");
if (larg.isTrue()) throw JumpException.SPECIAL_JUMP;
return ctx.nil;
}
});
}
} catch (JumpException.SpecialJump sj) {
return context.fals;
}
return context.tru;
}

@Deprecated
public static IRubyObject one_p19(ThreadContext context, IRubyObject self, final Block block) {
return one_p(context, self, null, block);
}

@Deprecated
public static IRubyObject one_p(final ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
final Ruby runtime = context.runtime;
final boolean[] result = new boolean[] { false };

try {
if (block.isGiven()) {
callEach(runtime, context, self, callbackArity, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "one?");
IRubyObject larg = packEnumValues(ctx, largs);
if (block.yield(ctx, larg).isTrue()) {
if (result[0]) {
throw JumpException.SPECIAL_JUMP;
} else {
result[0] = true;
}
}
return ctx.nil;
}
@Override
public IRubyObject call(ThreadContext ctx, IRubyObject larg) {
checkContext(context, ctx, "one?");
if (block.yield(ctx, larg).isTrue()) {
if (result[0]) {
throw JumpException.SPECIAL_JUMP;
} else {
result[0] = true;
}
}
return ctx.nil;
}
});
} else {
callEach(context, eachSite(context), self, Signature.ONE_REQUIRED, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
checkContext(context, ctx, "one?");
IRubyObject larg = packEnumValues(ctx, largs);
if (larg.isTrue()) {
if (result[0]) {
throw JumpException.SPECIAL_JUMP;
} else {
result[0] = true;
}
}
return ctx.nil;
}
@Override
public IRubyObject call(ThreadContext ctx, IRubyObject larg) {
checkContext(context, ctx, "one?");
if (larg.isTrue()) {
if (result[0]) {
throw JumpException.SPECIAL_JUMP;
} else {
result[0] = true;
}
}
return ctx.nil;
}
});
}
} catch (JumpException.SpecialJump sj) {
return runtime.getFalse();
}
return result[0] ? runtime.getTrue() : runtime.getFalse();
}

protected static CachingCallSite eachSite(ThreadContext context) {
return sites(context).each;
}
Expand All @@ -2379,33 +2272,13 @@ public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObj
return Helpers.invoke(context, self, "each", args, CallBlock.newCallClosure(self, runtime.getEnumerable(), Signature.OPTIONAL, 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(),
arity, callback, context));
}

@Deprecated
public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject[] args,
Arity arity, BlockCallback callback) {
return Helpers.invoke(context, self, "each", args, CallBlock.newCallClosure(self, runtime.getEnumerable(), arity, callback, context));
}

@Deprecated
public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject[] args,
Signature signature, BlockCallback callback) {
return Helpers.invoke(context, self, "each", args,
CallBlock.newCallClosure(context, self, signature, callback));
}

@Deprecated
public static IRubyObject callEach(Ruby runtime, ThreadContext context, IRubyObject self,
Arity arity, BlockCallback callback) {
return Helpers.invoke(context, self, "each", CallBlock.newCallClosure(self, runtime.getEnumerable(),
arity, callback, context));
}

@Deprecated
public static IRubyObject callEach19(Ruby runtime, ThreadContext context, IRubyObject self,
Signature signature, BlockCallback callback) {
Expand Down Expand Up @@ -2447,45 +2320,11 @@ public static IRubyObject find_index19(ThreadContext context, IRubyObject self,
return find_index(context, self, block);
}

@Deprecated
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
boolean blockGiven = block.isGiven();

if (self instanceof RubyArray && blockGiven) return ((RubyArray) self).find_index(context, block);

return blockGiven ? find_indexCommon(context, self, block, callbackArity) :
enumeratorize(context.runtime, self, "find_index");
}

@Deprecated
public static IRubyObject find_index19(ThreadContext context, IRubyObject self, final IRubyObject cond, final Block block) {
return find_index(context, self, cond, block);
}

@Deprecated
public static IRubyObject find_indexCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
final Ruby runtime = context.runtime;
final long result[] = new long[] {0};

try {
callEach(runtime, context, self, callbackArity, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return call(ctx, packEnumValues(ctx, largs), blk);
}
@Override
public IRubyObject call(ThreadContext ctx, IRubyObject larg, Block blk) {
if (block.yield(ctx, larg).isTrue()) throw JumpException.SPECIAL_JUMP;
result[0]++;
return ctx.nil;
}
});
} catch (JumpException.SpecialJump sj) {
return RubyFixnum.newFixnum(runtime, result[0]);
}

return context.nil;
}

@Deprecated
public static IRubyObject collect19(ThreadContext context, IRubyObject self, final Block block) {
return collect(context, self, block);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ public static IRubyObject write(ThreadContext context, IRubyObject maybeIO, IRub
CachingCallSite write = sites(context).write;

// In MRI this is used for all multi-arg puts calls to write. Here, we just do it for two
if (write.retrieveCache(maybeIO.getMetaClass()).method.getArity() == Arity.ONE_ARGUMENT) {
if (write.retrieveCache(maybeIO.getMetaClass()).method.getSignature().isOneArgument()) {
Ruby runtime = context.runtime;
if (runtime.isVerbose() && maybeIO != runtime.getGlobalVariables().get("$stderr")) {
warnWrite(runtime, maybeIO);
Expand Down
13 changes: 2 additions & 11 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,7 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
*/
@JRubyMethod
public RubyFixnum arity() {
int value;
if (method instanceof IRMethodArgs) {
value = ((IRMethodArgs) method).getSignature().arityValue();
} else {
value = method.getArity().getValue();
}

return getRuntime().newFixnum(value);
return getRuntime().newFixnum(method.getSignature().arityValue());
}

@JRubyMethod(name = "eql?", required = 1)
Expand Down Expand Up @@ -220,13 +213,11 @@ public IRubyObject to_proc(ThreadContext context) {
Ruby runtime = context.runtime;

MethodBlockBody body;
Signature signature;
Signature signature = method.getSignature();
ArgumentDescriptor[] argsDesc;
if (method instanceof IRMethodArgs) {
signature = ((IRMethodArgs) method).getSignature();
argsDesc = ((IRMethodArgs) method).getArgumentDescriptors();
} else {
signature = Signature.from(method.getArity());
argsDesc = Helpers.methodToArgumentDescriptors(method);
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/anno/TypePopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.MethodFactory;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
Expand All @@ -48,7 +49,7 @@ public abstract class TypePopulator {

public static void populateMethod(JavaMethod javaMethod, int arity, String simpleName, boolean isStatic, boolean notImplemented) {
javaMethod.setIsBuiltin(true);
javaMethod.setArity(Arity.createArity(arity));
javaMethod.setSignature(Signature.fromArityValue(arity));
javaMethod.setJavaName(simpleName);
javaMethod.setSingleton(isStatic);
javaMethod.setNotImplemented(notImplemented);
Expand All @@ -57,7 +58,7 @@ public static void populateMethod(JavaMethod javaMethod, int arity, String simpl
public static void populateMethod(JavaMethod javaMethod, int arity, String simpleName, boolean isStatic, boolean notImplemented,
Class nativeTarget, String nativeName, Class nativeReturn, Class[] nativeArguments) {
javaMethod.setIsBuiltin(true);
javaMethod.setArity(Arity.createArity(arity));
javaMethod.setSignature(Signature.fromArityValue(arity));
javaMethod.setJavaName(simpleName);
javaMethod.setSingleton(isStatic);
javaMethod.setNotImplemented(notImplemented);
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ext/ffi/jffi/DefaultMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public DynamicMethod getMethodForCaching() {
return compiledInvoker != null ? compiledInvoker : this;
}

Signature getSignature() {
return signature;
}

CallContext getCallContext() {
return function.getCallContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ private static CachingCallSite getParameterCallSite(Signature signature, int par
}
}

Signature getSignature() {
return signature;
}

CallContext getCallContext() {
return callContext;
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/main/java/org/jruby/ext/ffi/jffi/NativeInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ abstract public class NativeInvoker extends DynamicMethod {
protected final com.kenai.jffi.Function function;
private final int cbIndex;
private final NativeCallbackFactory cbFactory;
private final Signature signature;


public NativeInvoker(RubyModule implementationClass, com.kenai.jffi.Function function, Signature signature) {
super(implementationClass, Visibility.PUBLIC, "ffi"+function.getFunctionAddress());
this.arity = Arity.fixed(signature.getParameterCount());
this.function = function;
this.signature = signature;

int cbIndex = -1;
NativeCallbackFactory cbFactory = null;
Expand Down Expand Up @@ -56,10 +54,6 @@ public final boolean isNative() {
return true;
}

Signature getSignature() {
return signature;
}

CallContext getCallContext() {
return function.getCallContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Signature getSignature() {
return signature;
}

@Override
@Deprecated @Override
public Arity getArity() {
return signature.arity();
}
Expand Down
Loading

0 comments on commit bb5a9ab

Please sign in to comment.