From 621dddebfd9314053509dc7294ea91514c1f392d Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 22 Dec 2018 22:19:14 +0000 Subject: [PATCH] hdl.xfrm: avoid cycles in union-find graph in LHSGroupAnalyzer. --- nmigen/hdl/xfrm.py | 2 ++ nmigen/test/test_hdl_xfrm.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/nmigen/hdl/xfrm.py b/nmigen/hdl/xfrm.py index f7f7f26..06e5c28 100644 --- a/nmigen/hdl/xfrm.py +++ b/nmigen/hdl/xfrm.py @@ -298,6 +298,8 @@ class LHSGroupAnalyzer(StatementVisitor): root_group = self.find(root) for leaf in leaves: leaf_group = self.find(leaf) + if root_group == leaf_group: + continue self.unions[leaf_group] = root_group def groups(self): diff --git a/nmigen/test/test_hdl_xfrm.py b/nmigen/test/test_hdl_xfrm.py index b811160..d89db07 100644 --- a/nmigen/test/test_hdl_xfrm.py +++ b/nmigen/test/test_hdl_xfrm.py @@ -186,6 +186,20 @@ class LHSGroupAnalyzerTestCase(FHDLTestCase): SignalSet((a, b)), ]) + def test_no_loops(self): + a = Signal() + b = Signal() + stmts = [ + a.eq(0), + Cat(a, b).eq(0), + Cat(a, b).eq(0), + ] + + groups = LHSGroupAnalyzer()(stmts) + self.assertEqual(list(groups.values()), [ + SignalSet((a, b)), + ]) + def test_switch(self): a = Signal() b = Signal() -- 2.30.2