clash-lang / clash-compiler

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

Cannot reduce to an integer: closed type family #1534

Open martijnbastiaan opened 4 years ago

martijnbastiaan commented 4 years ago
{-# LANGUAGE UndecidableInstances #-}

module Issue where

import Clash.Prelude

type family Width a where
  Width a = BitSize a

topEntity :: BitVector (Width Bool) -> ()
topEntity _ = ()

gives:

    Clash.Netlist.Util(910): Clash.Core.Util(322): Cannot reduce to an integer:
    Clash.Class.BitPack.BitSize[8214565720323786306]
      GHC.Types.Bool[3674937295934324744]

however:

*Issue> :kind! (BitVector (Width Bool))
(BitVector (Width Bool)) :: Type
= BitVector 1

Apparently this violates one of Clash's invariants. When using:

topEntity :: BitVector (Width Bool)
topEntity = 0

It gives me a proper (but still wrong?) error message:

    Clash.Normalize(223): This bndr has a non-representable return type and can't be normalized:
    Issue.topEntity :: Clash.Sized.Internal.BitVector.BitVector
                         (Issue.Width GHC.Types.Bool)
christiaanb commented 4 years ago

I can't reproduce on master using GHC 8.8.3

martijnbastiaan commented 4 years ago

This seems to only happen when using the clash-starter-project. Definitions in the starter projected are loaded from interface files, so it seems natural for it to be some issue in LoadModules..

martijnbastiaan commented 4 years ago

from chat:

it only fails for the instances defined in Clash.Class.BitPack :

BitVector n
Bit
Bool
Int
Word
etc

But works for any instance defined outside of it, e.g.:

Vec n a
Signed n

I'll use -isrc as a workaround for now and continue with my other tasks.

martijnbastiaan commented 4 years ago

Another workaround; add:

Signal dom (BitVector (BitSize ()))

Now it does find BitSize and compiles