# HG changeset patch # User Andreas Woess # Date 1382233851 -7200 # Node ID b7c8b843dc7b44ada5ea80bbe873190c0dcbb464 # Parent 57b8a41c0e18dde45e05c87209a2b3a81ea8ecd0 Truffle: add sanity check. diff -r 57b8a41c0e18 -r b7c8b843dc7b graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Sun Oct 20 03:26:03 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Sun Oct 20 03:50:51 2013 +0200 @@ -171,6 +171,7 @@ * @return the new node */ public final T replace(T newNode, String reason) { + CompilerDirectives.transferToInterpreter(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } @@ -196,18 +197,23 @@ if (rootNode == null) { throw new UnsupportedOperationException("Tree does not have a root node."); } - rootNode.fixupChildren(); + int fixCount = rootNode.fixupChildren(); + assert fixCount != 0 : "sanity check failed: missing @Child[ren] or adoptChild?"; + // if nothing had to be fixed, rewrite failed due to node not being a proper child. } - private void fixupChildren() { + private int fixupChildren() { + int fixCount = 0; for (Node child : getChildren()) { if (child != null) { if (child.parent != this) { child.parent = this; + fixCount++; } - child.fixupChildren(); + fixCount += child.fixupChildren(); } } + return fixCount; } /**