amaranth
amaranth copied to clipboard
`Any{Seq,Const}` are not comparable to data structures
Something like this:
from amaranth.lib import data
from amaranth import Signal, Module
from amaranth.asserts import AnyConst
class S(data.Struct):
a: Signal()
m = Module()
any_const = AnyConst(S)
signal = Signal(S)
out = Signal()
m.d.comb += out.eq(signal == any_const)
fails with
Traceback (most recent call last):
File "/tmp/a.py", line 16, in <module>
m.d.comb += out.eq(signal == any_const)
File "/data/projects/amaranth/amaranth/lib/data.py", line 888, in __eq__
raise TypeError(
TypeError: View with layout StructLayout({}) can only be compared to another view or constant with the same layout, not (anyconst 0')
It would be nice if such comparisons would be possible. (Its of course possible to work around this by creating a intermediate Signal with the correct shape driven by the Any{Seq,Const} and comparing to that)
you can work around it by writing any_const = S(AnyConst(S))
it may be a good idea to make AnyConst/AnySeq auto-wrap themselves with a shapecastable like Signal does, but that's probably an RFC-grade item, and AnyConst/AnySeq are currently kinda in limbo because we lack a coherent formal verification model in amaranth (we just kinda emit stuff that yosys parses without much thought)
Ah, thats atleast a nicer workaround, thanks :)