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: 2a9e7a8ddeeb
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2f39f3e6ff4e
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 9, 2015

  1. Copy the full SHA
    3f74052 View commit details
  2. Only load implicit var for block arg if we have block arg.

    A couple oddities here wrt OptimizeTempVars:
    
    * The loop storing the definition of a variable was never actually
      updating. I'm not sure what this affected but the original code
      made no sense.
    * ReifyClosure *had to* implement simplifyOperands, even though it
      is claimed to be optional. Without it, a rename of the result of
      a previous LoadImplicitClosure did not propagate into the Reify.
    headius committed Jan 9, 2015
    Copy the full SHA
    2f39f3e View commit details
16 changes: 4 additions & 12 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1841,9 +1841,11 @@ protected void receiveBlockArg(final ArgsNode argsNode, IRScope s) {
BlockArgNode blockArg = argsNode.getBlock();
if (blockArg != null) {
String blockArgName = blockArg.getName();
Variable blockVar = s.getNewLocalVariable(blockArgName, 0);
Variable blockVar = s.getLocalVariable(blockArgName, 0);
if (s instanceof IRMethod) ((IRMethod) s).addArgDesc(IRMethodArgs.ArgType.block, blockArgName);
addInstr(s, new ReifyClosureInstr(s.getImplicitClosureVariable(), blockVar));
Variable tmp = s.createTemporaryVariable();
addInstr(s, new LoadImplicitClosureInstr(tmp));
addInstr(s, new ReifyClosureInstr(blockVar, tmp));
}
}

@@ -1857,9 +1859,6 @@ private void prepareImplicitState(IRScope s) {
// Receive self
addInstr(s, new ReceiveSelfInstr(s.getSelf()));

// used for constructing block arg; if none, this will go away
addInstr(s, new LoadImplicitClosureInstr(s.getImplicitClosureVariable()));

// used for yields; metaclass body (sclass) inherits yield var from surrounding, and accesses it as implicit
if (s instanceof IRMethod || s instanceof IRMetaClassBody) {
addInstr(s, new LoadImplicitClosureInstr(s.getYieldClosureVariable()));
@@ -2509,13 +2508,6 @@ public Operand buildIter(final IterNode iterNode, IRScope s) {
// Prepare all implicit state (self, frame block, etc)
closureBuilder.prepareImplicitState(closure);

// load block into temporary variable
if (s instanceof IRMethod) {
addInstr(s, new LoadImplicitClosureInstr(s.getYieldClosureVariable()));
} else {
addInstr(s, new LoadFrameClosureInstr(s.getYieldClosureVariable()));
}

// Build args
if (iterNode.getVarNode().getNodeType() != null) closureBuilder.receiveBlockArgs(iterNode, closure);

14 changes: 0 additions & 14 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -135,8 +135,6 @@ public abstract class IRScope implements ParseResult {

private TemporaryVariable yieldClosureVariable;

private TemporaryVariable implicitClosureVariable;

// Used by cloning code
protected IRScope(IRScope s, IRScope lexicalParent) {
this.lexicalParent = lexicalParent;
@@ -905,18 +903,6 @@ public TemporaryVariable getYieldClosureVariable() {
return yieldClosureVariable;
}

/**
* Get the variable for accessing the implicit closure in this scope (the block
* passed along the JVM stack).
*/
public TemporaryVariable getImplicitClosureVariable() {
if (implicitClosureVariable == null) {
return implicitClosureVariable = createTemporaryVariable();
}

return implicitClosureVariable;
}

public TemporaryLocalVariable getNewUnboxedVariable(Class type) {
TemporaryVariableType varType;
if (type == Float.class) {
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jruby.ir.instructions;

import org.jruby.RubyProc;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRVisitor;
@@ -18,12 +17,14 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Map;

/* Receive the closure argument (either implicit or explicit in Ruby source code) */
public class ReifyClosureInstr extends Instr implements ResultInstr, FixedArityInstr {
private final Variable source;
private Variable source;
private Variable result;

public ReifyClosureInstr(Variable source, Variable result) {
public ReifyClosureInstr(Variable result, Variable source) {
super(Operation.REIFY_CLOSURE);

assert result != null: "ReceiveClosureInstr result is null";
@@ -34,7 +35,7 @@ public ReifyClosureInstr(Variable source, Variable result) {

@Override
public String toString() {
return "reify_closure(" + source + ")";
return super.toString() + "(" + source + ")";
}

@Override
@@ -51,6 +52,11 @@ public Variable getResult() {
return result;
}

@Override
public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
source = (Variable)source.getSimplifiedOperand(valueMap, force);
}

@Override
public void updateResult(Variable v) {
this.result = v;
@@ -64,7 +70,7 @@ public boolean computeScopeFlags(IRScope scope) {

@Override
public Instr clone(CloneInfo info) {
if (info instanceof SimpleCloneInfo) return new ReifyClosureInstr(info.getRenamedVariable(source), info.getRenamedVariable(result));
if (info instanceof SimpleCloneInfo) return new ReifyClosureInstr(info.getRenamedVariable(result), info.getRenamedVariable(source));

// SSS FIXME: This code below is for inlining and is untested.

Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ private static void optimizeTmpVars(IRScope s) {
TemporaryVariable tv = (TemporaryVariable)v;
Instr defs = tmpVarDefs.get(tv);
if (defs == null) {
tmpVarDefs.put(tv, defs);
tmpVarDefs.put(tv, i);
} else if (defs != NopInstr.NOP) {
tmpVarDefs.put(tv, NopInstr.NOP);
}
@@ -204,8 +204,7 @@ else if (i instanceof CopyInstr) {
}
}

// Always make sure the implicit block variable is considered live, so we don't clobber it
lastVarUseOrDef.put(s.getImplicitClosureVariable(), iCount);
// Always make sure the yield closure variable is considered live, so we don't clobber it
lastVarUseOrDef.put(s.getYieldClosureVariable(), iCount);

// If the scope has loops, extend live range of %current-module and %current-scope