Skip to content

Commit

Permalink
Add KnownNat (DomainPeriod dom) to KnownDomain (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnbastiaan authored Jul 14, 2023
1 parent 897a16f commit 8702bad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/2023-07-13T20_31_20+02_00_add_knownnat_period
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADDED: `KnownNat (DomainPeriod dom)` as an implied constraint to `KnownDomain dom`. This reduces the amount of code needed to write - for example - clock speed dependent code.
3 changes: 2 additions & 1 deletion clash-ghc/src-ghc/Clash/GHC/NetlistTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ ghcTypeToHWType iw = go
"Clash.Signal.Internal.KnownDomain"
-> case tyConDataCons (UniqMap.find tc m) of
[dc] -> case substArgTys dc args of
[_,tyView -> TyConApp _ [_,dom]] -> case tyView (coreView m dom) of
[_knownSymbol, _knownNat, tyView -> TyConApp _ [_,dom]] ->
case tyView (coreView m dom) of
TyConApp _ [tag0, period0, edge0, rstKind0, init0, polarity0] -> do
tag1 <- domTag m tag0
period1 <- domPeriod m period0
Expand Down
4 changes: 2 additions & 2 deletions clash-prelude/src/Clash/Signal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ import Data.Ratio (Ratio)
import Data.Type.Equality ((:~:))
import GHC.Generics (Generic)
import GHC.Stack (HasCallStack, withFrozenCallStack)
import GHC.TypeLits (KnownSymbol, Nat, Symbol, type (<=), sameSymbol)
import GHC.TypeLits (KnownSymbol, KnownNat, Nat, Symbol, type (<=), sameSymbol)
import Language.Haskell.TH.Syntax -- (Lift (..), Q, Dec)
import Language.Haskell.TH.Compat
import Numeric.Natural (Natural)
Expand Down Expand Up @@ -415,7 +415,7 @@ type KnownConfiguration dom conf = (KnownDomain dom, KnownConf dom ~ conf)

-- | A 'KnownDomain' constraint indicates that a circuit's behavior depends on
-- some properties of a domain. See 'DomainConfiguration' for more information.
class KnownSymbol dom => KnownDomain (dom :: Domain) where
class (KnownSymbol dom, KnownNat (DomainPeriod dom)) => KnownDomain (dom :: Domain) where
type KnownConf dom :: DomainConfiguration
-- | Returns 'SDomainConfiguration' corresponding to an instance's 'DomainConfiguration'.
--
Expand Down

0 comments on commit 8702bad

Please sign in to comment.