Skip to content

Make AST nodes immutable #1067

Closed
Closed
@whitequark

Description

@whitequark

Right now it's actually possible to do things like "set sig.width on a Signal" or "modify c.parts on a Cat". This has never been explicitly advertised as something that is supported and is arguably a misuse of the API. Amaranth internally treats AST nodes as immutable; all fragment transformers create new ones, and it doesn't mutate them elsewhere. Any mutation would happen only in downstream code (there's one instance deep in the FSM code generation, #1066).

Now that I'm working on reference documentation I'd like to either state that Values are immutable and make them so, or else document them as mutable. This could potentially break some downstream code though, so I'm nominating this for discussion.

If we decide that the nodes should be mutable, then setters must be introduced that typecheck the assignments.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions