Skip to content

Commit 19b386c

Browse files
Use :>! instead of :> for pattern matching Vecs (#21)
This is used to workaround (spurious) warnings GHC generates on newer versions. Example of such a warning: example/Example.hs:170:1: error: [GHC-62161] [-Wincomplete-uni-patterns, Werror=incomplete-uni-patterns] Pattern match(es) are non-exhaustive In a pattern binding: Patterns of type ‘BusTag (DF dom Int) (Bwd (DF dom Int)) :-> BusTag (Vec 1 (DF dom Int)) (Fwd (Vec 1 (DF dom Int)))’ not matched: _ :-> BusTagBundle (Cons _ _) | 170 | fanout = circuit $ \a -> do | ^^^^^^^^^^^^^^^^^^^^^^^^^^^...
1 parent 565d481 commit 19b386c

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ jobs:
6868
- name: Build
6969
run: |
7070
cabal build all --write-ghc-environment-files=always
71-
ghc -iexample Example
72-
ghc -iexample Testing
71+
ghc -Wall -Werror -iexample Example
72+
ghc -Wall -Werror -iexample Testing
7373
7474
- name: Test
7575
run: |

example/Example.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ vec0 = circuit \[] -> ()
166166
vec00 :: Circuit (Vec 0 a) (Vec 0 a)
167167
vec00 = circuit \[] -> []
168168

169+
fanout :: forall dom. Circuit (DF dom Int) (DF dom Int)
170+
fanout = circuit $ \a -> do
171+
[x] <- go -< a
172+
idC -< x
173+
where
174+
go :: Circuit (DF dom Int) (Vec n (DF dom Int))
175+
go = error "Not implemented"
176+
169177
-- test that signals can be duplicated
170178
dupSignalC0 :: Circuit (Signal dom Bool) (Signal dom Bool, Signal dom Bool)
171179
dupSignalC0 = circuit $ \x -> (x, x)

src/Circuit.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
This file contains the 'Circuit' type, that the notation describes.
1111
-}
1212

13+
{-# LANGUAGE CPP #-}
1314
{-# LANGUAGE DataKinds #-}
1415
{-# LANGUAGE DeriveFunctor #-}
1516
{-# LANGUAGE GADTs #-}
@@ -27,6 +28,16 @@ module Circuit where
2728

2829
import Clash.Prelude
2930

31+
#if __GLASGOW_HASKELL__ > 900
32+
-- | Unsafe version of ':>'. Will fail if applied to empty vectors. This is used to
33+
-- workaround spurious incomplete pattern match warnings generated in newer GHC
34+
-- versions.
35+
pattern (:>!) :: a -> Vec n a -> Vec (n + 1) a
36+
pattern (:>!) x xs <- (\ys -> (head ys, tail ys) -> (x,xs))
37+
{-# COMPLETE (:>!) #-}
38+
infixr 5 :>!
39+
#endif
40+
3041
type family Fwd a
3142
type family Bwd a
3243

src/CircuitNotation.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ tupP :: p ~ GhcPs => [LPat p] -> LPat p
443443
tupP [pat] = pat
444444
tupP pats = noLoc $ TuplePat noExt pats GHC.Boxed
445445

446-
vecP :: SrcSpanAnnA -> [LPat GhcPs] -> LPat GhcPs
446+
vecP :: (?nms :: ExternalNames) => SrcSpanAnnA -> [LPat GhcPs] -> LPat GhcPs
447447
vecP srcLoc = \case
448448
[] -> go []
449449
#if __GLASGOW_HASKELL__ < 904
@@ -464,7 +464,7 @@ vecP srcLoc = \case
464464
l1 = l0
465465
#endif
466466
in
467-
L srcLoc $ conPatIn (L l1 (thName '(:>))) (InfixCon p (go pats))
467+
L srcLoc $ conPatIn (L l1 (consPat ?nms)) (InfixCon p (go pats))
468468
go [] = L srcLoc $ WildPat noExtField
469469

470470
varP :: SrcSpanAnnA -> String -> LPat GhcPs
@@ -1316,6 +1316,7 @@ data ExternalNames = ExternalNames
13161316
, fwdBwdCon :: GHC.RdrName
13171317
, fwdAndBwdTypes :: Direction -> GHC.RdrName
13181318
, trivialBwd :: GHC.RdrName
1319+
, consPat :: GHC.RdrName
13191320
}
13201321

13211322
defExternalNames :: ExternalNames
@@ -1330,4 +1331,9 @@ defExternalNames = ExternalNames
13301331
Fwd -> GHC.Unqual (OccName.mkTcOcc "Fwd")
13311332
Bwd -> GHC.Unqual (OccName.mkTcOcc "Bwd")
13321333
, trivialBwd = GHC.Unqual (OccName.mkVarOcc "unitBwd")
1334+
#if __GLASGOW_HASKELL__ > 900
1335+
, consPat = GHC.Unqual (OccName.mkDataOcc ":>!")
1336+
#else
1337+
, consPat = GHC.Unqual (OccName.mkDataOcc ":>")
1338+
#endif
13331339
}

0 commit comments

Comments
 (0)