clash-lang / clash-compiler

Haskell to VHDL/Verilog/SystemVerilog compiler
https://clash-lang.org/
Other
1.43k stars 151 forks source link

Clash doesn't handle `DataTag (CustomSum ...)` expressions #2724

Open bgamari opened 4 months ago

bgamari commented 4 months ago

This program:

{-# LANGUAGE MagicHash #-}

module Hello where

import Clash.Annotations.BitRepresentation
import Clash.Prelude

data Animal = Turtle | Wombat | Bear
    deriving (Eq)

{-# ANN module (DataReprAnn
                $(liftQ [t|Animal|])
                2
                [ ConstrRepr 'Turtle    0b11 0b00 []
                , ConstrRepr 'Wombat  0b11 0b01 []
                , ConstrRepr 'Bear    0b11 0b10 []
                ]) #-}

hi :: Signal System Animal -> Signal System Bool
hi = fmap (== Bear)
{-# ANN hi (defSyn "hi") #-}

fails to compile with

<no location info>: error:
    Clash error call:
    Clash.Backend.Verilog(1195): DataTag (CustomSum "Hello.Animal" (DataRepr' {drType = ConstTy' "Hello.Animal", drSize = 2, drConstrs = [ConstrRepr' {crName = "Hello.Turtle", crPosition = 0, crMask = 3, crValue = 0, crFieldAnns = []},ConstrRepr' {crName = "Hello.Wombat", crPosition = 1, crMask = 3, crValue = 1, crFieldAnns = []},ConstrRepr' {crName = "Hello.Bear", crPosition = 2, crMask = 3, crValue = 2, crFieldAnns = []}]}) 2 [(ConstrRepr' {crName = "Hello.Turtle", crPosition = 0, crMask = 3, crValue = 0, crFieldAnns = []},"Hello.Turtle"),(ConstrRepr' {crName = "Hello.Wombat", crPosition = 1, crMask = 3, crValue = 1, crFieldAnns = []},"Hello.Wombat"),(ConstrRepr' {crName = "Hello.Bear", crPosition = 2, crMask = 3, crValue = 2, crFieldAnns = []},"Hello.Bear")]) (Right (RawIdentifier "x" Nothing []))
    CallStack (from HasCallStack):
      error, called at src/Clash/Backend/Verilog.hs:1195:13 in clash-lib-1.8.2-FtOTsji7dyd7AMMWGi63fJ:Clash.Backend.Verilog