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

Any{Seq,Const} are not comparable to data structures #1555

Open
rroohhh opened this issue Jan 27, 2025 · 2 comments
Open

Any{Seq,Const} are not comparable to data structures #1555

rroohhh opened this issue Jan 27, 2025 · 2 comments

Comments

@rroohhh
Copy link
Contributor

rroohhh commented Jan 27, 2025

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)

@wanda-phi
Copy link
Member

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)

@rroohhh
Copy link
Contributor Author

rroohhh commented Jan 27, 2025

Ah, thats atleast a nicer workaround, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants