Skip to content

Commit

Permalink
[Types] Disallow wiring different order tuples (#1314)
Browse files Browse the repository at this point in the history
Co-authored-by: Lenny Truong <[email protected]>
  • Loading branch information
rsetaluri and leonardt authored Sep 14, 2023
1 parent 4592ee0 commit 4387b64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion magma/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def wire(self, o, debug_info):
)
return

if self.keys() != o.keys():
if list(self.keys()) != list(o.keys()):
_logger.error(
WiringLog(f"Cannot wire {{}} (type={type(o)}, "
f"keys={list(self.keys())}) to "
Expand Down
17 changes: 17 additions & 0 deletions tests/test_type/test_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import magma as m
from magma import *
from magma.testing.utils import has_error


def test_pair():
Expand Down Expand Up @@ -357,3 +358,19 @@ class Foo(m.Circuit):
assert io.I.y.value() is u.y

assert not caplog.messages, "Should not raise wiring errors"


def test_tuple_key_ordering(caplog):
T0 = m.AnonProduct[{"x": m.Bit, "y": m.Bits[8]}]
T1 = m.AnonProduct[{"y": m.Bits[8], "x": m.Bit}]

class tuple_key_ordering(m.Circuit):
io = m.IO(I=m.In(T0), O=m.Out(T1))
io.O @= io.I

msg = """\
\033[1mtests/test_type/test_tuple.py:368\033[0m: Cannot wire tuple_key_ordering.I (type=Tuple(x=Out(Bit),y=Out(Bits[8])), keys=['y', 'x']) to tuple_key_ordering.O (type=Tuple(y=In(Bits[8]),x=In(Bit)), keys=['x', 'y']) because the tuples do not have the same keys
>> io.O @= io.I\
"""

assert has_error(caplog, "")

0 comments on commit 4387b64

Please sign in to comment.