Skip to content

Commit

Permalink
Do not emit extra rescue region during cloning of ensure if there is …
Browse files Browse the repository at this point in the history
…nothing

there yet.  This removes one set of extra empty BBs that current CFG creation
is not removing during optimize().
enebo committed Nov 28, 2017
1 parent 13542d0 commit cd61c27
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -221,6 +221,19 @@ public void emitBody(IRBuilder b) {
}

public void cloneIntoHostScope(IRBuilder builder) {
// $! should be restored before the ensure block is run
if (savedGlobalException != null) {
// We need make sure on all outgoing paths in optimized short-hand rescues we restore the backtrace
if (!needsBacktrace) builder.addInstr(builder.manager.needsBacktrace(true));
builder.addInstr(new PutGlobalVarInstr("$!", savedGlobalException));
}

// Sometimes we process a rescue and it hits something like non-local flow like a 'next' and
// there are no actual instrs pushed yet (but ebi has reserved a frame for it -- e.g. the rescue/ensure
// the next is in). Since it is doing nothing we have nothing to clone. By skipping this we prevent
// setting exception regions and simplify CFG construction.
if (instrs.size() == 0) return;

SimpleCloneInfo ii = new SimpleCloneInfo(builder.scope, true);

// Clone required labels.
@@ -231,13 +244,6 @@ public void cloneIntoHostScope(IRBuilder builder) {
if (i instanceof LabelInstr) ii.renameLabel(((LabelInstr)i).getLabel());
}

// $! should be restored before the ensure block is run
if (savedGlobalException != null) {
// We need make sure on all outgoing paths in optimized short-hand rescues we restore the backtrace
if (!needsBacktrace) builder.addInstr(builder.manager.needsBacktrace(true));
builder.addInstr(new PutGlobalVarInstr("$!", savedGlobalException));
}

// Clone instructions now
builder.addInstr(new LabelInstr(ii.getRenamedLabel(start)));
builder.addInstr(new ExceptionRegionStartMarkerInstr(bodyRescuer));

0 comments on commit cd61c27

Please sign in to comment.