Skip to content

Commit

Permalink
[Truffle] Give DeadNodes a description and fix a case of them leaking…
Browse files Browse the repository at this point in the history
… into a final AST.
  • Loading branch information
chrisseaton committed Jan 15, 2015
1 parent 07a515f commit ad62bc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Expand Up @@ -1446,7 +1446,7 @@ public RubyNode visitInstAsgnNode(org.jruby.ast.InstAsgnNode node) {
RubyNode rhs;

if (node.getValueNode() == null) {
rhs = new DeadNode(context, sourceSection);
rhs = new DeadNode(context, sourceSection, "null RHS of instance variable assignment");
} else {
rhs = node.getValueNode().accept(this);
}
Expand Down Expand Up @@ -1538,7 +1538,7 @@ public RubyNode visitLocalAsgnNode(org.jruby.ast.LocalAsgnNode node) {
RubyNode rhs;

if (node.getValueNode() == null) {
rhs = new DeadNode(context, sourceSection);
rhs = new DeadNode(context, sourceSection, "null RHS of local variable assignment");
} else {
if (node.getValueNode().getPosition() == InvalidSourcePosition.INSTANCE) {
parentSourceSection = sourceSection;
Expand Down Expand Up @@ -1998,7 +1998,7 @@ public RubyNode visitNextNode(org.jruby.ast.NextNode node) {
@Override
public RubyNode visitNilNode(org.jruby.ast.NilNode node) {
if (node.getPosition() == InvalidSourcePosition.INSTANCE && parentSourceSection == null) {
return new DeadNode(context, null);
return new DeadNode(context, null, "nil node with no invalid source position - assumed to be implicit null");
}

return new NilLiteralNode(context, translate(node.getPosition()));
Expand Down Expand Up @@ -2289,8 +2289,8 @@ public RubyNode visitRescueNode(org.jruby.ast.RescueNode node) {

RubyNode translatedBody;

if (rescueBody.getBodyNode() == null) {
translatedBody = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
if (rescueBody.getBodyNode() == null || rescueBody.getBodyNode().getPosition() == InvalidSourcePosition.INSTANCE) {
translatedBody = new NilLiteralNode(context, sourceSection);
} else {
translatedBody = rescueBody.getBodyNode().accept(this);
}
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/truffle/translator/DeadNode.java
Expand Up @@ -20,12 +20,15 @@
*/
public class DeadNode extends RubyNode {

public DeadNode(RubyContext context, SourceSection sourceSection) {
private final String description;

public DeadNode(RubyContext context, SourceSection sourceSection, String description) {
super(context, sourceSection);
this.description = description;
}

@Override
public Object execute(VirtualFrame frame) {
throw new UnsupportedOperationException("Dead nodes should have been pruned before execution starts");
throw new UnsupportedOperationException("Dead nodes should have been pruned before execution starts: " + description);
}
}

0 comments on commit ad62bc0

Please sign in to comment.