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

Bug: HDL generation failure with GHC 9.0.2, multiple hidden, synthesis attribute #2593

Closed
DigitalBrains1 opened this issue Oct 21, 2023 · 4 comments · Fixed by #2673
Closed
Labels

Comments

@DigitalBrains1
Copy link
Member

DigitalBrains1 commented Oct 21, 2023

In Clash master and 1.6, there is a bug when generating HDL under very specific conditions. Only with GHC 9.0.2 (out of the versions we test in CI), with multiple hidden enabled, an annotation from Clash.Annotations.SynthesisAttributes and the following reproducer:

topEntity ::
  Signal System Bit ->
  Signal System Bit `Annotate` 'StringAttr "break" "me"
topEntity dIn =
  exposeClockResetEnable (register 0) clk rst en dIn
 where
   clk = clockGen
   rst = resetGen
   en = enableGen

VHDL generation will produce the error:

<no location info>: error:
    Clash error call:
    Clash.Netlist.BlackBox.Util(585): IsActiveEnable: Expected Bool or Enable, not: Void Nothing
    CallStack (from HasCallStack):
      error, called at src/Clash/Netlist/BlackBox/Util.hs:585:13 in clash-lib-1.7.0-inplace:Clash.Netlist.BlackBox.Util
      renderElem, called at src/Clash/Netlist/BlackBox/Util.hs:319:15 in clash-lib-1.7.0-inplace:Clash.Netlist.BlackBox.Util

Verilog and SystemVerilog instead say:

<no location info>: error:
    Clash error call:
    Clash.Netlist.BlackBox(290): Forced to evaluate untranslatable type: (resetGenN
      @(IfStuck
          TryDomainResult
          [...]
               (TryDomain (Signal "System" Bit -> Signal "System" Bit) (Signal "System" Bit -> Signal "System" Bit))))))
    CallStack (from HasCallStack):
      error, called at src/Clash/Netlist/BlackBox.hs:290:21 in clash-lib-1.7.0-inplace:Clash.Netlist.BlackBox

Each of the following is enough to make the code produce HDL again:

  • Disable multiple-hidden
  • Remove Annotate
  • Add type application/signature to either clk, rst or en
  • Add type application to exposeClockResetEnable
  • Eta-reduce topEntity (topEntity = exposeClockResetEnable ...)

Type-applying register, though, does not help.

I created a branch issue-2593 which tests the reproducer in CI. The full file with the reproducer is T2593.hs
For 1.6, the branch is issue-2593-1.6.

@DigitalBrains1
Copy link
Member Author

This issue prevents me from writing the code I want to write in the examples in #2592 (I need to add type signatures where they aren't needed).

@leonschoorl
Copy link
Member

When run with -fclash-debug DebugSilent or higher you can see it stumble over the type of the enable signal a little earlier:

Clash.Normalize(212): Expr belonging to bndr: enableGen (:: Enable
  (ErrOnConflict
     (Signal "System" Bit -> Signal "System" Bit)
     (Merge' (Found "System") (TryDomain (Signal "System" Bit -> Signal "System" Bit) (Signal "System" Bit))))) has a non-representable return type. Not normalising:
(Λdom ->
  Enable @dom (clockGen1[GlobalId] @dom))
  @(ErrOnConflict
      (Signal "System" Bit -> Signal "System" Bit)
      (Merge' (Found "System") (TryDomain (Signal "System" Bit -> Signal "System" Bit) (Signal "System" Bit))))

Some alternative workarounds you might like better:

  • exposeClockResetEnable (register 0 dIn) clk rst en
  • withClockResetEnable clk rst en (register 0 dIn)

@DigitalBrains1
Copy link
Member Author

Oh, such a register 0 dIn workaround is much smoother, thanks!

christiaanb added a commit that referenced this issue Feb 16, 2024
1. Annotations are implemented as type synonyms.
2. GHC looks through type synonyms when matching type families
3. So Clash should do the same.

Fixes #2593
christiaanb added a commit that referenced this issue Feb 16, 2024
1. Annotations are implemented as type synonyms.
2. GHC looks through type synonyms when matching type families
3. So Clash should do the same.

Fixes #2593
mergify bot pushed a commit that referenced this issue Feb 23, 2024
1. Annotations are implemented as type synonyms.
2. GHC looks through type synonyms when matching type families
3. So Clash should do the same.

Fixes #2593

(cherry picked from commit da6ee06)
martijnbastiaan pushed a commit that referenced this issue Feb 24, 2024
1. Annotations are implemented as type synonyms.
2. GHC looks through type synonyms when matching type families
3. So Clash should do the same.

Fixes #2593

(cherry picked from commit da6ee06)

Co-authored-by: Christiaan Baaij <[email protected]>
@christiaanb
Copy link
Member

We've released v1.8.2, which includes a fix for this issue.

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

Successfully merging a pull request may close this issue.

3 participants