Skip to content

Commit

Permalink
Enable backtrace removal for long-form rescue:
Browse files Browse the repository at this point in the history
begin
  foo
rescue
  nil
end

Where body of rescue must be a simple return value which cannot possibly
capture $!.  I did not originally land this because I was under the impression
ensure could see $!.  Happily it cannot so this optimization was much simpler
to enable than I thought.
enebo committed Sep 30, 2015
1 parent da88f57 commit 42278a5
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2248,11 +2248,8 @@ public Operand buildEnsureInternal(Node ensureBodyNode, Node ensurerNode) {
addInstr(new ExceptionRegionEndMarkerInstr());
activeRescuers.pop();

// Clone the ensure body and jump to the end.
// Don't bother if the protected body ended in a return
// Clone the ensure body and jump to the end. Don't bother if the protected body ended in a return
// OR if we are really processing a rescue node
//
// SSS FIXME: How can ensureBodyNode be anything but a RescueNode (if non-null)
if (ensurerNode != null && rv != U_NIL && !(ensureBodyNode instanceof RescueNode)) {
ebi.cloneIntoHostScope(this);
addInstr(new JumpInstr(ebi.end));
@@ -3034,8 +3031,8 @@ public Operand buildRescue(RescueNode node) {
}

private boolean canBacktraceBeRemoved(RescueNode rescueNode) {
// For now we will only contemplate 'foo rescue nil' cases but simple non-mod rescue forms can be added later.
if (RubyInstanceConfig.FULL_TRACE_ENABLED || !(rescueNode instanceof RescueModNode)) return false;
if (RubyInstanceConfig.FULL_TRACE_ENABLED || !(rescueNode instanceof RescueModNode) &&
rescueNode.getElseNode() != null) return false;

// FIXME: This MIGHT be able to expand to more complicated expressions like Hash or Array if they
// contain only SideEffectFree nodes. Constructing a literal out of these should be safe from

0 comments on commit 42278a5

Please sign in to comment.