From: whitequark Date: Sat, 22 Dec 2018 22:19:14 +0000 (+0000) Subject: hdl.xfrm: avoid cycles in union-find graph in LHSGroupAnalyzer. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=44865fd6214aac812a26b0cbda5c94b53f0e665f;p=nmigen.git hdl.xfrm: avoid cycles in union-find graph in LHSGroupAnalyzer. --- 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()