diff options
| author | XmiliaH <45106915+XmiliaH@users.noreply.github.com> | 2023-10-28 23:37:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-28 14:37:22 -0700 |
| commit | c7a3752481c3c33cc7e460a75daf2a07d2c15c25 (patch) | |
| tree | 211f8446e16e171511197301d87cc600df68bcd6 /chapter04/src/main/java/com/seaofnodes | |
| parent | 97287891c47c17bdba7717a9d141ffe1433e5602 (diff) | |
| download | Simple-c7a3752481c3c33cc7e460a75daf2a07d2c15c25.tar.gz Simple-c7a3752481c3c33cc7e460a75daf2a07d2c15c25.zip | |
set_def might kill new_def in kill recursion caused by old_def being killed (#18)
Diffstat (limited to 'chapter04/src/main/java/com/seaofnodes')
| -rw-r--r-- | chapter04/src/main/java/com/seaofnodes/simple/node/Node.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java index 8d698d1b..7cc9291c 100644 --- a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java @@ -193,14 +193,16 @@ public abstract class Node { Node set_def(int idx, Node new_def ) { Node old_def = in(idx); if( old_def == new_def ) return this; // No change + // If new def is not null, add the corresponding def->use edge + // This needs to happen before removing the old node's def->use edge as + // the new_def might get killed if the old node kills it recursively. + if( new_def != null ) + new_def._outputs.add(this); if( old_def != null && // If the old def exists, remove a def->use edge old_def.delUse(this) ) // If we removed the last use, the old def is now dead old_def.kill(); // Kill old def // Set the new_def over the old (killed) edge _inputs.set(idx,new_def); - // If new def is not null, add the corresponding def->use edge - if( new_def != null ) - new_def._outputs.add(this); // Return self for easy flow-coding return this; } |
