clash-compiler
clash-compiler copied to clipboard
Derived BitPack instance introduces Dubious primitive instantiation warning
The implementation for derived BitPack
instances produces the following warning when producing HDL:
GHC: Setting up GHC took: 0.167s
GHC: Compiling and loading modules took: 0.088s
Clash: Parsing and compiling primitives took 0.143s
GHC+Clash: Loading modules cumulatively took 0.534s
Clash: Compiling Example.Project.topEntity
Clash: Normalization took 0.069s
[WARNING] Dubious primitive instantiation for GHC.Num.Integer.integerToInt#: GHC.Num.Integer.integerToInt#: Integers are dynamically sized in simulation, but fixed-length after synthesis. Use carefully. (disable with -fclash-no-prim-warn)
Clash: Netlist generation took 0.001s
Clash: Compiling Example.Project.topEntity took 0.071s
Clash: Total compilation took 0.606s
Reproducer:
module Example.Project where
import Clash.Prelude
data AorB = A | B
deriving (Generic, BitPack)
topEntity :: Bool -> AorB
topEntity = bitCoerce
GHC 9.0.2 Clash 1.6.4
It's caused by the unpack side of bitCoerce
:
topEntity :: BitVector 1 -> AorB
topEntity = unpack
Gives the same error.
In the definition of unpack we effectively have:
sc = unpack @Int (x :: BitVector 64)
That generates the error seen here.
(Because unpack @Int
uses fromIntegral
instance BitPack Int where
[...]
unpack = fromIntegral
)
I think we should just add a prim for unpack @Int
(but don't forget about -fclash-intwidth
)