-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure caseCon only works on matching data constructors
Fixes #2376
- Loading branch information
1 parent
b0e00cc
commit dd094b3
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module T2376_unsafeCoerce_Dict where | ||
|
||
import Clash.Prelude | ||
import Data.Constraint | ||
import Data.Proxy | ||
import Unsafe.Coerce | ||
|
||
data T depth = T (BitVector depth) deriving (Generic) | ||
|
||
instance (1 <= CLog 2 depth, KnownNat depth) => NFDataX (T depth) | ||
|
||
-- | if (2 <= n) holds, then (1 <= CLog 2 n) also holds. | ||
oneLeCLog2n :: forall n . (2 <= n) => Proxy n -> Dict (1 <= CLog 2 n) | ||
oneLeCLog2n Proxy = unsafeCoerce (Dict :: Dict ()) | ||
|
||
f :: | ||
forall dom depth. | ||
( HiddenClockResetEnable dom | ||
, KnownNat depth | ||
, 2 <= depth ) => | ||
Proxy depth -> | ||
Signal dom Bool -> | ||
Signal dom Bool | ||
f Proxy = | ||
case oneLeCLog2n (Proxy @depth) of | ||
Dict -> mealy go (T 0) | ||
|
||
where | ||
go :: T depth -> Bool -> (T depth, Bool) | ||
go (T n) True = (T (n + 1), False) | ||
go (T n) False = (T (n - 1), True) | ||
{-# NOINLINE f #-} | ||
|
||
topEntity clk rst ena = | ||
withClockResetEnable clk rst ena $ | ||
f @System @2 Proxy | ||
{-# NOINLINE topEntity #-} |