clash-compiler icon indicating copy to clipboard operation
clash-compiler copied to clipboard

Derived BitPack instance introduces Dubious primitive instantiation warning

Open lmbollen opened this issue 1 year ago • 3 comments

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

lmbollen avatar Jan 02 '23 12:01 lmbollen

It's caused by the unpack side of bitCoerce:

topEntity :: BitVector 1 -> AorB
topEntity = unpack

Gives the same error.

leonschoorl avatar Jan 02 '23 13:01 leonschoorl

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

)

leonschoorl avatar Jan 02 '23 13:01 leonschoorl

I think we should just add a prim for unpack @Int (but don't forget about -fclash-intwidth)

DigitalBrains1 avatar Jan 02 '23 15:01 DigitalBrains1