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

Derived BitPack instance introduces Dubious primitive instantiation warning #2386

Open
lmbollen opened this issue Jan 2, 2023 · 3 comments · May be fixed by #2397
Open

Derived BitPack instance introduces Dubious primitive instantiation warning #2386

lmbollen opened this issue Jan 2, 2023 · 3 comments · May be fixed by #2397
Labels

Comments

@lmbollen
Copy link
Member

lmbollen commented Jan 2, 2023

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

@leonschoorl
Copy link
Member

It's caused by the unpack side of bitCoerce:

topEntity :: BitVector 1 -> AorB
topEntity = unpack

Gives the same error.

@leonschoorl
Copy link
Member

leonschoorl commented Jan 2, 2023

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

)

@DigitalBrains1
Copy link
Member

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

rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
@rowanG077 rowanG077 linked a pull request Jan 4, 2023 that will close this issue
4 tasks
rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
rowanG077 added a commit that referenced this issue Jan 4, 2023
FIXED: Clash no longer gives `Dubious primitive instantiation warning`
when using `unpack` [#2386](#2386).
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.

4 participants