Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Types] Fix rebase bug in aggregate wireables #1152

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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