Skip to content

Commit

Permalink
Teach deriveAutoReg to handle LitT's in constraints
Browse files Browse the repository at this point in the history
This allows it to drop constraints like `KnownNat 4`.

Fixes #1632

(cherry picked from commit 399bf5d)
  • Loading branch information
leonschoorl authored and martijnbastiaan committed Jan 18, 2021
1 parent de3a1a3 commit 16d9bae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clash-prelude/src/Clash/Class/AutoReg/Internal.hs
Expand Up @@ -380,9 +380,10 @@ constraintsWantedFor clsNm [ty] = case ty of
needRecurse :: Type -> Bool
needRecurse (unfoldType -> (cls,tys)) =
case tys of
[VarT _] -> False
[ConT _] -> False -- we can just drop constraints like: "AutoReg Bool => ..."
[AppT _ _] -> True
[VarT _] -> False -- gets copied by "filter isOk" above
[ConT _] -> False -- we can just drop constraints like: "AutoReg Bool => ..."
[LitT _] -> False -- or "KnownNat 4 =>"
[_] -> error ( "Error while deriveAutoReg: don't know how to handle: "
++ pprint cls ++ " (" ++ pprint tys ++ ")" )
_ -> False -- see [NOTE: MultiParamTypeClasses]
Expand Down
10 changes: 10 additions & 0 deletions tests/shouldwork/AutoReg/T1632.hs
@@ -0,0 +1,10 @@
module T1632 where
import Clash.Prelude

data MCause
= MCause (BitVector 4)
deriving (Generic, NFDataX)
deriveAutoReg ''MCause

topEntity :: SystemClockResetEnable => Signal System MCause -> Signal System MCause
topEntity = autoReg (MCause 0)
2 changes: 2 additions & 0 deletions testsuite/Main.hs
Expand Up @@ -211,6 +211,8 @@ runClashTest = defaultMain $ clashTestRoot
[ clashTestGroup "AutoReg"
[ NEEDS_PRIMS(outputTest ("tests" </> "shouldwork" </> "AutoReg") allTargets [] [] "AutoReg" "main")
, NEEDS_PRIMS(runTest "T1507" def{hdlSim=False})
, let _opts = def{hdlSim=False, hdlTargets=[VHDL]}
in NEEDS_PRIMS(runTest "T1632" _opts)
]
, clashTestGroup "Basic"
[ NEEDS_PRIMS(runTest "AES" def{hdlSim=False})
Expand Down

0 comments on commit 16d9bae

Please sign in to comment.