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

Commits on Oct 31, 2016

  1. Copy the full SHA
    061764e View commit details
  2. Copy the full SHA
    5debf23 View commit details
  3. Merge pull request #4252 from headius/nil_init_for_temp_locals

    Also perform uninitialized check on temp locals.
    headius authored Oct 31, 2016
    Copy the full SHA
    b9b86fc View commit details
Showing with 14 additions and 2 deletions.
  1. +8 −2 core/src/main/java/org/jruby/ir/dataflow/analyses/DefinedVariableNode.java
  2. +6 −0 spec/compiler/general_spec.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.operands.LocalVariable;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.TemporaryLocalVariable;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.IRClosure;
@@ -116,17 +117,22 @@ public void identifyInits(Set<Variable> undefinedVars) {
initSolution();
for (Instr i: basicBlock.getInstrs()) {
for (Variable v: i.getUsedVariables()) {
LocalVariable lv;
if (!v.isSelf()) {
if (v instanceof LocalVariable) {
lv = (LocalVariable)v;
LocalVariable lv = (LocalVariable) v;
// Variables that belong to outer scopes
// are considered already defined.
if (lv.getScopeDepth() < parentScopeDepth && !tmp.get(problem.getDFVar(v))) {
// We want lv suitable for initializing in this scope
undefinedVars.add(lv.getScopeDepth() == 0 ? lv : lv.cloneForDepth(0));
}
tmp.set(problem.getDFVar(lv));
} else if (v instanceof TemporaryLocalVariable) {
TemporaryLocalVariable tlv = (TemporaryLocalVariable) v;
if (!tmp.get(problem.getDFVar(v))) {
undefinedVars.add(tlv);
}
tmp.set(problem.getDFVar(tlv));
}
}
}
6 changes: 6 additions & 0 deletions spec/compiler/general_spec.rb
Original file line number Diff line number Diff line change
@@ -326,6 +326,12 @@ def self.bar
expect{run("def foo(a, b=(c=1));[a,b,c];end;foo(1,2,3)")}.to raise_error(ArgumentError)
end

it "compiles accesses of uninitialized variables" do
run("def foo(a); if a; b = 1; end; b.inspect; end; foo(false)") {|result| expect(result).to eq("nil") }
run("def foo(a); a ||= (b = 1); b.inspect; end; foo(1)") {|result| expect(result).to eq("nil")}
run("def foo(a); a &&= (b = 1); b.inspect; end; foo(nil)") {|result| expect(result).to eq("nil")}
end

it "compiles grouped and intra-list rest args" do
run("def foo(a, (b, *, c), d, *e, f, (g, *h, i), j); [a,b,c,d,e,f,g,h,i,j]; end; foo(1,[2,3,4],5,6,7,8,[9,10,11],12)") do |result|
expect(result).to eq([1, 2, 4, 5, [6, 7], 8, 9, [10], 11, 12])