clash-lang / clash-compiler

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

Only domains with a positive period are valid #2740

Open christiaanb opened 1 week ago

christiaanb commented 1 week ago

An alternative means to achieve https://github.com/clash-lang/clash-compiler/pull/2734#issuecomment-2182893091

import Clash.Prelude
import Data.Proxy

f ::
  forall dom .
  KnownDomain dom =>
  Proxy dom ->
  SNat (PeriodToCycles dom (Milliseconds 1))
f Proxy = case knownDomain @dom of
    SDomainConfiguration {} -> SNat

now typechecks.

Still TODO:

DigitalBrains1 commented 1 week ago

I like this solution, thanks for giving this the needed amount of thought!

We should then document this feature both in a place where people will find it without specifically looking for the time conversion types and at the time conversion types. Something on the order of If your code needs a 1 <= DomainPeriod dom constraint, you can satisfy this with ... so you don't have to add the constraint to your function. I'm sure we can think of a better way to phrase it.