hdl.xfrm: avoid cycles in union-find graph in LHSGroupAnalyzer.
authorwhitequark <cz@m-labs.hk>
Sat, 22 Dec 2018 22:19:14 +0000 (22:19 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 22 Dec 2018 22:19:14 +0000 (22:19 +0000)
nmigen/hdl/xfrm.py
nmigen/test/test_hdl_xfrm.py

index f7f7f2602058dae53cf6ff629dde90356a5bb39f..06e5c284314c7ed606954b3e7ae2c1620b31cdcd 100644 (file)
@@ -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):
index b811160b55b79295ea3185ecb0fe39cb0eedc867..d89db073dd18aa37ba996a4e579980d065c36823 100644 (file)
@@ -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()