Skip to content

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

Open
@rroohhh

Description

@rroohhh

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)

Activity

wanda-phi

wanda-phi commented on Jan 27, 2025

@wanda-phi
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

rroohhh commented on Jan 27, 2025

@rroohhh
ContributorAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @whitequark@rroohhh@wanda-phi

        Issue actions

          `Any{Seq,Const}` are not comparable to data structures · Issue #1555 · amaranth-lang/amaranth