Skip to content

Commit

Permalink
No need for second field to store callName
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 27, 2024
1 parent 35068f0 commit 42af56f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@
* A call to block_given? which can be optimized like defined?(yield) or a regular call.
*/
public class BlockGivenCallInstr extends OneOperandResultBaseInstr implements FixedArityInstr {
private final String callName;
private final FunctionalCachingCallSite blockGivenSite;

public BlockGivenCallInstr(Variable result, Operand block, String callName) {
public BlockGivenCallInstr(Variable result, Operand block, String methodName) {
super(Operation.BLOCK_GIVEN_CALL, Objects.requireNonNull(result, "BlockGivenCallInstr result is null"), block);

this.callName = Objects.requireNonNull(callName, "BlockGivenCallInstr callName is null");
this.blockGivenSite = new FunctionalCachingCallSite(callName);
this.blockGivenSite =
new FunctionalCachingCallSite(Objects.requireNonNull(methodName, "BlockGivenCallInstr methodName is null"));
}

public Operand getBlockArg() {
return getOperand1();
}

public String getCallName() {
return callName;
public String getMethodName() {
return blockGivenSite.getMethodName();
}

@Override
public Instr clone(CloneInfo ii) {
return new BlockGivenCallInstr(ii.getRenamedVariable(result), getBlockArg().cloneForInlining(ii), callName);
return new BlockGivenCallInstr(ii.getRenamedVariable(result), getBlockArg().cloneForInlining(ii), blockGivenSite.getMethodName());
}

public static BlockGivenCallInstr decode(IRReaderDecoder d) {
Expand All @@ -50,7 +49,7 @@ public static BlockGivenCallInstr decode(IRReaderDecoder d) {
@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(callName);
e.encode(blockGivenSite.getMethodName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ public interface InvocationCompiler {
/**
* Invoke block_given? or iterator? with awareness of any built-in methods.
*/
void invokeBlockGiven(String callName, String file);
void invokeBlockGiven(String methodName, String file);
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ public void BlockGivenInstr(BlockGivenInstr blockGivenInstr) {

@Override
public void BlockGivenCallInstr(BlockGivenCallInstr blockGivenCallInstr) {
String callName = blockGivenCallInstr.getCallName();
String methodName = blockGivenCallInstr.getMethodName();
IRBytecodeAdapter m = jvmMethod();
m.getInvocationCompiler().invokeBlockGiven(callName, file);
m.getInvocationCompiler().invokeBlockGiven(methodName, file);
handleCallResult(m, blockGivenCallInstr.getResult());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public static CallSite blockGivenBootstrap(MethodHandles.Lookup lookup, String n
}

public IRubyObject blockGivenFallback(String name, ThreadContext context, IRubyObject self, Block block) throws Throwable {
String callName = name.split(":")[1];
String methodName = name.split(":")[1];

CacheEntry entry = self.getMetaClass().searchWithCache(callName);
CacheEntry entry = self.getMetaClass().searchWithCache(methodName);
MethodHandle target;

if (entry.method.isBuiltin()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ public void setCallInfo(int flags) {
}

@Override
public void invokeBlockGiven(String callName, String file) {
invokeBlockGiven(compiler, callName, file);
public void invokeBlockGiven(String methodName, String file) {
invokeBlockGiven(compiler, methodName, file);
}

// shared with normal for now
public static void invokeBlockGiven(IRBytecodeAdapter compiler, String callName, String file) {
public static void invokeBlockGiven(IRBytecodeAdapter compiler, String methodName, String file) {
compiler.loadContext();
compiler.loadSelf();
compiler.loadBlock();
compiler.adapter.invokedynamic(IndyInvocationCompiler.constructIndyCallName("callFunctional", callName), sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, Block.class), BlockGivenSite.BLOCK_GIVEN_BOOTSTRAP, file, compiler.getLastLine());
compiler.adapter.invokedynamic(IndyInvocationCompiler.constructIndyCallName("callFunctional", methodName), sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, Block.class), BlockGivenSite.BLOCK_GIVEN_BOOTSTRAP, file, compiler.getLastLine());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ public void setCallInfo(int flags) {
}

@Override
public void invokeBlockGiven(String callName, String file) {
public void invokeBlockGiven(String methodName, String file) {
// direct block_given? calls always use indy
IndyInvocationCompiler.invokeBlockGiven(compiler, callName, file);
IndyInvocationCompiler.invokeBlockGiven(compiler, methodName, file);
}
}

0 comments on commit 42af56f

Please sign in to comment.