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

Fails Generating VHDL When Typeclass Has Many Instances #1721

Closed
exclusive-and opened this issue Mar 25, 2021 · 1 comment · Fixed by #1722
Closed

Fails Generating VHDL When Typeclass Has Many Instances #1721

exclusive-and opened this issue Mar 25, 2021 · 1 comment · Fixed by #1722

Comments

@exclusive-and
Copy link

The compiler will fail to generate an output port on noinlined functions when a typeclass has many specialized instances.
It's suspected that the compiler skips generating an output port if the output of a function is one of many instances. Without the output port, the Netlist generator thinks the function is being applied to too many I/O components and throws an UnderApplied error.

An example is given in the attached file (this will fail to generate, and dump a long Core message).
clash-fix.zip

@christiaanb
Copy link
Member

christiaanb commented Mar 26, 2021

What's causing the error is a bug in Clash' implementation of type family reduction, specifically, it doesn't handle nested type families. So given this even smaller reproducer:

module T1721 where

import Clash.Prelude

type family G a
type instance G () = Bool

type family F a

data T a = T a
data TP a = TP Bool

type instance F (T Bool) = TP Bool

f :: F (T (G ()))
  -> F (T (G ()))
f = id
{-# NOINLINE f #-}

topEntity :: F (T (G ()))
          -> F (T (G ()))
topEntity = f

Clash doesn't think there's any matching instance for F (T (G ())) because G () isn't reduced to Bool before doing the instance lookup for F on T (G ()). In turn, this makes Clash not finding a bit-encoding for F (T (G ())).

mergify bot pushed a commit that referenced this issue Mar 26, 2021
christiaanb added a commit that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants