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

Commits on Oct 20, 2016

  1. Copy the full SHA
    4253b8e View commit details
  2. Be more precise about identifying undefined lvars in nested scopes

    I was checking for lvar.getScopeDepth() < expectedScopeDepth
    instead of lvar.getScopeDepth() == expectedScopeDepth.
    
    This caused unexpected initializations to be added in multi-level
    nesting scenarios like this:
    
    def foo
      x = 1
      loop do
        loop do
          ...
          p x
          ...
        end
      end
    end
    
    The old code was trying add an initialize of 'x' in the outer loop
    which was the bug.
    subbuss committed Oct 20, 2016
    Copy the full SHA
    192ca18 View commit details
Original file line number Diff line number Diff line change
@@ -85,8 +85,8 @@ public void applyTransferFunction(Instr i) {
}
}

private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int minDepth) {
int clBaseDepth = minDepth + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1);
private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int nestingLevel) {
int clBaseDepth = nestingLevel + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1);
cl.setUpUseDefLocalVarMaps();
for (LocalVariable lv: cl.getUsedLocalVariables()) {
// This can happen where an outer scope variable
@@ -96,13 +96,8 @@ private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosu
continue;
}

// Variables with scope depth lesser than this couldn't have
// been defined in problem's scope and we aren't concerned with them.
if (lv.getScopeDepth() < clBaseDepth) {
continue;
}

if (!tmp.get(problem.getDFVar(lv))) {
// Find variables which belong to the problem.getScope()
if (lv.getScopeDepth() == clBaseDepth && !tmp.get(problem.getDFVar(lv))) {
// We want lv suitable for initializing in this scope
undefinedVars.add(lv.getScopeDepth() == 0 ? lv : lv.cloneForDepth(0));
tmp.set(problem.getDFVar(lv));
@@ -111,7 +106,7 @@ private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosu

// Recurse
for (IRClosure nestedCl: cl.getClosures()) {
identifyUndefinedVarsInClosure(undefinedVars, nestedCl, clBaseDepth);
identifyUndefinedVarsInClosure(undefinedVars, nestedCl, nestingLevel + 1);
}
}

@@ -136,7 +131,6 @@ public void identifyInits(Set<Variable> undefinedVars) {
}
}

/*
if (i instanceof ClosureAcceptingInstr) {
// Find all variables used in the closure and
// figure out if they are defined are not.
@@ -145,7 +139,6 @@ public void identifyInits(Set<Variable> undefinedVars) {
identifyUndefinedVarsInClosure(undefinedVars, ((WrappedIRClosure)o).getClosure(), 0);
}
}
*/

// v is defined
if (i instanceof ResultInstr) {
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ private void decrementScopeDepth(LocalVariable v, IRScope s, Map<Operand, Operan
}

public void eliminateLocalVars(IRScope s) {
assert s.getClosures().isEmpty() : "We assume that if a scope has nested closures, it uses a dynamic scoope.";

Map<Operand, Operand> varRenameMap = new HashMap<Operand, Operand>();
// Record the fact that we eliminated the scope
s.getFlags().add(IRFlags.DYNSCOPE_ELIMINATED);