Skip to content

stateful declarations shouldn't be allowed in conditions (was: what happens when you read from inactive enum variants) #255

@programmerjake

Description

@programmerjake

I noticed that firrtl lets you read from inactive enum variants using code like:

FIRRTL version 3.2.0
circuit test:
    module test:
        input clk: Clock
        input a: UInt<1>
        input b: UInt<1>
        output o: UInt<1>
        connect o, UInt<1>(0)
        wire w: {|Some: UInt<1>, None|}
        connect w, {|Some: UInt<1>, None|}(None)
        when a:
            connect w, {|Some: UInt<1>, None|}(Some, b)
        match w:
            None:
                skip
            Some(v):
                reg r: UInt<1>, clk
                connect r, v
                connect o, r

note how if a is false, it still writes v to r, which you can then read in the next clock cycle.

this makes me think that putting stateful logic elements in a conditional block is a misfeature because state changes still occur even when the conditional block is not active.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions