Skip to content

Commit

Permalink
Original code for simple rescues added a backtrace toggle on outgoing
Browse files Browse the repository at this point in the history
path but if there was a return or jump before it then it would be detected
as dead in the CFG and get removed.  This logic now puts it in the ensure
regiion code which I THINK will always cover all non-thrown paths.
enebo committed Oct 2, 2015
1 parent 5c29cbf commit e39eaf0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -177,6 +177,7 @@ private static class EnsureBlockInfo {
Label end;
Label dummyRescueBlockLabel;
Variable savedGlobalException;
boolean needsBacktrace;

// Label of block that will rescue exceptions raised by ensure code
Label bodyRescuer;
@@ -201,6 +202,7 @@ public EnsureBlockInfo(IRScope s, RescueNode n, IRLoop l, Label bodyRescuer) {
innermostLoop = l;
matchingRescueNode = n;
this.bodyRescuer = bodyRescuer;
needsBacktrace = true;
}

public void addInstr(Instr i) {
@@ -231,6 +233,8 @@ 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));
}

@@ -3047,6 +3051,7 @@ private Operand buildRescueInternal(RescueNode rescueNode, EnsureBlockInfo ensur
Label rBeginLabel = getNewLabel();
Label rEndLabel = ensure.end;
Label rescueLabel = getNewLabel(); // Label marking start of the first rescue code.
ensure.needsBacktrace = needsBacktrace;

addInstr(new LabelInstr(rBeginLabel));

@@ -3121,8 +3126,6 @@ private Operand buildRescueInternal(RescueNode rescueNode, EnsureBlockInfo ensur
// Build the actual rescue block(s)
buildRescueBodyInternal(rescueNode.getRescueNode(), rv, exc, rEndLabel);

if (!needsBacktrace) addInstr(manager.needsBacktrace(true));

activeRescueBlockStack.pop();
return rv;
}

0 comments on commit e39eaf0

Please sign in to comment.