fix(mir): make BackLink parent removal precise#531
fix(mir): make BackLink parent removal precise#531phrwlk wants to merge 1 commit into0xMiden:nextfrom
Conversation
|
Review: Fix is incomplete. Link::PartialEq compares by value, not pointer identity @phrwlk I tested this PR locally and the included test add_remove_parent_removes_only_target fails: thread 'ir::nodes::ops::add::tests::add_remove_parent_removes_only_target' panicked The root cause diagnosis is correct — BackLink::PartialEq always returning true breaks retain. However, the proposed Switching to p.to_link() and then link != parent uses Link::PartialEq, which compares by value (self.link == The fix needs pointer identity, using the already-available get_ptr() method on Link: fn remove_parent(&mut self, parent: LinkSelf::Parent) { This uses Rc::as_ptr under the hood, which correctly distinguishes different allocations regardless of value The test itself is well-structured and proves the regression correctly but it just needs the implementation to match. |
Describe your changes
BackLink implements PartialEq as always true so that backlink fields are ignored in derived equality and hashing. However,
remove_parent in MIR ops compared BackLink values directly:
Because of the always-true PartialEq, this predicate was always false and effectively cleared the entire parents vector instead of removing only the requested parent.
This change updates all remove_parent implementations for ops that use parents: Vec<BackLink> to compare against the upgraded Link via to_link(), keeping BackLink’s structural Eq/Hash semantics intact while making parent removal semantically correct.