Skip to content

Commit

Permalink
Fix rebase bug in aggregate wireables, add tests (#1152)
Browse files Browse the repository at this point in the history
I chose the wrong changes for these functions when rebasing the tuple2
code.  With the aggregate_wireable_method decorator, they only need to
implement the logic for when children are elaborated (the decorator
calls the aggregate method if the has_elaborated_children check fails).
This didn't trigger a CI bug because when unwire fails, it just raises a
warning (e.g. driving an already driven value) that occurs silently in
the passing tests.  Adds a test to cover this case.
  • Loading branch information
leonardt authored Oct 11, 2022
1 parent 7512842 commit 5c6cfc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 0 additions & 3 deletions magma/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,6 @@ def wire(self, o, debug_info):
@debug_unwire
@aggregate_wireable_method
def unwire(self, o=None, debug_info=None, keep_wired_when_contexts=False):
if not self._has_elaborated_children():
return AggregateWireable.unwire(self, o, debug_info,
keep_wired_when_contexts)
for i, child in self._enumerate_children():
o_i = None if o is None else o[i]
child.unwire(o_i, debug_info=debug_info,
Expand Down
13 changes: 10 additions & 3 deletions magma/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,16 @@ def wire(self, o, debug_info):
@debug_unwire
@aggregate_wireable_method
def unwire(self, o=None, debug_info=None, keep_wired_when_contexts=False):
if not self._has_elaborated_children():
return AggregateWireable.unwire(self, o, debug_info,
keep_wired_when_contexts)
for k, t in self.items():
if o is None:
t.unwire(debug_info=debug_info,
keep_wired_when_contexts=keep_wired_when_contexts)
elif o[k].is_input():
o[k].unwire(t, debug_info=debug_info,
keep_wired_when_contexts=keep_wired_when_contexts)
else:
t.unwire(o[k], debug_info=debug_info,
keep_wired_when_contexts=keep_wired_when_contexts)

@aggregate_wireable_method
def driven(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_aggregate_wireable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import magma as m


@pytest.mark.parametrize('T', [m.Bits[8], m.Tuple[m.Bit, m.Bits[8]]])
def test_aggregate_wireable_unwire(T):
class Foo(m.Circuit):
io = m.IO(I=m.In(T), O=m.Out(T))
io.O @= io.I
assert io.O.value() is io.I
io.O.unwire(io.I)
assert io.O.value() is None

io.O @= io.I
io.O[0] # Trigger elaboration
assert io.O.value() is io.I
io.O.unwire(io.I)
assert io.O.value() is None

0 comments on commit 5c6cfc5

Please sign in to comment.