Navigation Menu

Skip to content

Commit

Permalink
class/metaclass/module bodies were sharing their parent scopes IR bui…
Browse files Browse the repository at this point in the history
…lder.

This seemingly only is noticeable when processing ensure blocks.  EnsureBlockListener instance
was capturing current scopes instr and nested module/class/metaclass ones in a weird depth-first
order.  We have not seen this in tests because it only happens if you define a class in an ensure
block :)
  • Loading branch information
enebo committed Oct 23, 2014
1 parent a439381 commit 7ec332a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -477,8 +477,9 @@ public Node skipOverNewlines(IRScope s, Node n) {
}
}

while (n.getNodeType() == NodeType.NEWLINENODE)
n = ((NewlineNode)n).getNextNode();
while (n.getNodeType() == NodeType.NEWLINENODE) {
n = ((NewlineNode) n).getNextNode();
}

return n;
}
Expand Down Expand Up @@ -3517,27 +3518,28 @@ private Operand[] adjustVariableDepth(Operand[] args, int depthFromSuper) {

private Operand buildModuleOrClassBody(IRScope parent, Variable tmpVar, IRModuleBody body, Node bodyNode, int linenumber) {
Variable processBodyResult = addResultInstr(parent, new ProcessModuleBodyInstr(parent.createTemporaryVariable(), tmpVar, getImplicitBlockArg(parent)));
IRBuilder bodyBuilder = newIRBuilder(manager);

if (RubyInstanceConfig.FULL_TRACE_ENABLED) {
addInstr(body, new TraceInstr(RubyEvent.CLASS, null, body.getFileName(), linenumber));
bodyBuilder.addInstr(body, new TraceInstr(RubyEvent.CLASS, null, body.getFileName(), linenumber));
}

addInstr(body, new ReceiveSelfInstr(body.getSelf())); // %self
bodyBuilder.addInstr(body, new ReceiveSelfInstr(body.getSelf())); // %self

if (body instanceof IRMetaClassBody) {
addInstr(body, new ReceiveClosureInstr((Variable)getImplicitBlockArg(body))); // %closure - SClass
bodyBuilder.addInstr(body, new ReceiveClosureInstr((Variable)getImplicitBlockArg(body))); // %closure - SClass
}

addInstr(body, new CopyInstr(body.getCurrentScopeVariable(), new CurrentScope(0))); // %scope
addInstr(body, new CopyInstr(body.getCurrentModuleVariable(), new ScopeModule(0))); // %module
bodyBuilder.addInstr(body, new CopyInstr(body.getCurrentScopeVariable(), new CurrentScope(0))); // %scope
bodyBuilder.addInstr(body, new CopyInstr(body.getCurrentModuleVariable(), new ScopeModule(0))); // %module
// Create a new nested builder to ensure this gets its own IR builder state
Operand bodyReturnValue = newIRBuilder(manager).build(bodyNode, body);
Operand bodyReturnValue = bodyBuilder.build(bodyNode, body);

if (RubyInstanceConfig.FULL_TRACE_ENABLED) {
addInstr(body, new TraceInstr(RubyEvent.END, null, body.getFileName(), -1));
bodyBuilder.addInstr(body, new TraceInstr(RubyEvent.END, null, body.getFileName(), -1));
}

addInstr(body, new ReturnInstr(bodyReturnValue));
bodyBuilder.addInstr(body, new ReturnInstr(bodyReturnValue));

return processBodyResult;
}
Expand Down

0 comments on commit 7ec332a

Please sign in to comment.