Skip to content

Commit 39eb0ec

Browse files
Add GHC 9.8 support (#22)
1 parent 19b386c commit 39eb0ec

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- "9.2.8"
4141
- "9.4.8"
4242
- "9.6.4"
43+
- "9.8.2"
4344

4445
steps:
4546
- uses: actions/checkout@v3

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.insertFinalNewline": true,
3+
"files.trimFinalNewlines": true,
4+
"files.trimTrailingWhitespace": true,
5+
"editor.tabSize": 2
6+
}

cabal.project

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
packages: .
2-
3-
source-repository-package
4-
type: git
5-
location: https://github.com/clash-lang/clash-compiler.git
6-
tag: 5b055fb3fcdaf6e2b89cb86486d7280fc781fa84
7-
subdir: clash-prelude

circuit-notation.cabal

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ library
1919
other-modules:
2020
GHC.Types.Unique.Map
2121

22-
other-modules:
23-
GHC.Types.Unique.Map.Extra
22+
if impl(ghc < 9.10)
23+
other-modules:
24+
GHC.Types.Unique.Map.Extra
2425

2526
-- other-extensions:
2627
build-depends:
2728
base >=4.12
2829
, clash-prelude >= 1.0
2930
, containers
3031
, data-default
31-
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.8)
32+
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.10)
3233
, lens
3334
, mtl
3435
, parsec

src/CircuitNotation.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ import "ghc" GHC.Types.Unique.Map
133133
import GHC.Types.Unique.Map
134134
#endif
135135

136+
#if __GLASGOW_HASKELL__ < 908
136137
import GHC.Types.Unique.Map.Extra
138+
#endif
137139

138140
-- clash-prelude
139141
import Clash.Prelude (Vec((:>), Nil))
@@ -486,7 +488,7 @@ tupT tys = noLoc $ HsTupleTy noExt hsBoxedTuple tys
486488

487489
vecT :: SrcSpanAnnA -> [LHsType GhcPs] -> LHsType GhcPs
488490
vecT s [] = L s $ HsParTy noExt (conT s (thName ''Vec) `appTy` tyNum s 0 `appTy` (varT s (genLocName s "vec")))
489-
vecT s tys = L s $ HsParTy noExt (conT s (thName ''Vec) `appTy` tyNum s (length tys) `appTy` head tys)
491+
vecT s tys@(ty:_) = L s $ HsParTy noExt (conT s (thName ''Vec) `appTy` tyNum s (length tys) `appTy` ty)
490492

491493
tyNum :: SrcSpanAnnA -> Int -> LHsType GhcPs
492494
tyNum s i = L s (HsTyLit noExtField (HsNumTy GHC.NoSourceText (fromIntegral i)))
@@ -618,8 +620,10 @@ lamE pats expr = noLoc $ HsLam noExtField mg
618620
mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
619621
#if __GLASGOW_HASKELL__ < 906
620622
mg = MG noExtField matches GHC.Generated
621-
#else
623+
#elif __GLASGOW_HASKELL__ < 908
622624
mg = MG GHC.Generated matches
625+
#else
626+
mg = MG (GHC.Generated GHC.DoPmc) matches
623627
#endif
624628

625629
matches :: GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
@@ -874,18 +878,19 @@ checkCircuit = do
874878
topNames = portNames Slave slaves <> portNames Master masters
875879
nameMap = listToUniqMap_C mappend $ topNames <> concatMap bindingNames binds
876880

877-
duplicateMasters <- concat <$> forM (nonDetUniqMapToList nameMap) \(name, occ) ->
881+
duplicateMasters <- concat <$> forM (nonDetUniqMapToList nameMap) \(name, occ) -> do
882+
let isIgnored = case unpackFS name of {('_':_) -> True; _ -> False}
883+
878884
case occ of
885+
([], []) -> pure []
879886
([_], [_]) -> pure []
880-
(ss, ms) -> do
881-
unless (head (unpackFS name) == '_') $ do
882-
when (null ms) $ errM (locA (head ss)) $ "Slave port " <> show name <> " has no associated master"
883-
when (null ss) $ errM (locA (head ms)) $ "Master port " <> show name <> " has no associated slave"
887+
(s:_, []) | not isIgnored -> errM (locA s) ("Slave port " <> show name <> " has no associated master") >> pure []
888+
([], m:_) | not isIgnored -> errM (locA m) ("Master port " <> show name <> " has no associated slave") >> pure []
889+
(ss@(s:_:_), _) ->
884890
-- would be nice to show locations of all occurrences here, not sure how to do that while
885891
-- keeping ghc api
886-
when (length ss > 1) $
887-
errM (locA (head ss)) $ "Slave port " <> show name <> " defined " <> show (length ss) <> " times"
888-
892+
errM (locA s) ("Slave port " <> show name <> " defined " <> show (length ss) <> " times") >> pure []
893+
(_ss, ms) -> do
889894
-- if master is defined multiple times, we broadcast it
890895
if length ms > 1
891896
then pure [name]

0 commit comments

Comments
 (0)