Skip to content

Commit 47f2460

Browse files
Add GHC 9.10 support
1 parent 2b91964 commit 47f2460

File tree

4 files changed

+89
-19
lines changed

4 files changed

+89
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- "9.4.8"
4242
- "9.6.4"
4343
- "9.8.2"
44+
- "9.10.1"
4445

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

cabal.project

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
packages: .
2+
3+
source-repository-package
4+
type: git
5+
location: https://github.com/clash-lang/clash-compiler.git
6+
tag: c300105837fced0207963b172845186c3ae8d5f8
7+
subdir: clash-prelude
8+
9+
allow-newer:
10+
string-interpolate:template-haskell,

circuit-notation.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library
2929
, clash-prelude >= 1.0
3030
, containers
3131
, data-default
32-
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.10)
32+
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.12)
3333
, lens
3434
, mtl
3535
, parsec

src/CircuitNotation.hs

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ import GHC.Driver.Errors.Ppr () -- instance Diagnostic GhcMessage
103103
import qualified GHC.Driver.Config.Diagnostic as GHC
104104
import qualified GHC.Driver.Errors.Types as GHC
105105
import qualified GHC.Utils.Logger as GHC
106+
#endif
107+
#if __GLASGOW_HASKELL__ < 910 && __GLASGOW_HASKELL__ >= 904
106108
import qualified GHC.Parser.PostProcess as GHC
107109
#endif
108110

@@ -207,11 +209,20 @@ locA = id
207209
#else
208210
type MsgDoc = Outputable.SDoc
209211

212+
#if __GLASGOW_HASKELL__ < 910
210213
locA :: SrcSpanAnn' a -> SrcSpan
214+
#else
215+
locA :: EpAnn ann -> SrcSpan
216+
#endif
211217
locA = GHC.locA
212218

219+
#if __GLASGOW_HASKELL__ < 910
213220
noAnnSortKey :: AnnSortKey
214221
noAnnSortKey = NoAnnSortKey
222+
#else
223+
noAnnSortKey :: AnnSortKey tag
224+
noAnnSortKey = NoAnnSortKey
225+
#endif
215226
#endif
216227

217228
#if __GLASGOW_HASKELL__ < 902
@@ -230,7 +241,10 @@ sevFatal :: Err.MessageClass
230241
sevFatal = Err.MCFatal
231242
#endif
232243

233-
#if __GLASGOW_HASKELL__ > 900
244+
#if __GLASGOW_HASKELL__ > 908
245+
noExt :: NoAnn a => a
246+
noExt = noAnn
247+
#elif __GLASGOW_HASKELL__ > 900
234248
noExt :: EpAnn ann
235249
noExt = EpAnnNotUsed
236250
#elif __GLASGOW_HASKELL__ > 808
@@ -246,7 +260,7 @@ noExtField = NoExt
246260
type NoExtField = NoExt
247261
#endif
248262

249-
#if __GLASGOW_HASKELL__ < 904
263+
#if __GLASGOW_HASKELL__ < 904 || __GLASGOW_HASKELL__ >= 910
250264
pattern HsParP :: LHsExpr p -> HsExpr p
251265
pattern HsParP e <- HsPar _ e
252266

@@ -430,12 +444,15 @@ conPatIn loc con = ConPat noExt loc con
430444
conPatIn loc con = ConPatIn loc con
431445
#endif
432446

433-
#if __GLASGOW_HASKELL__ >= 902
434-
noEpAnn :: GenLocated SrcSpan e -> GenLocated (SrcAnn ann) e
435-
noEpAnn (L l e) = L (SrcSpanAnn EpAnnNotUsed l) e
436-
447+
#if __GLASGOW_HASKELL__ >= 910
448+
noLoc :: NoAnn ann => e -> GenLocated (EpAnn ann) e
449+
noLoc = L noAnn
450+
#elif __GLASGOW_HASKELL__ >= 902
437451
noLoc :: e -> GenLocated (SrcAnn ann) e
438452
noLoc = noEpAnn . GHC.noLoc
453+
where
454+
noEpAnn :: GenLocated SrcSpan e -> GenLocated (SrcAnn ann) e
455+
noEpAnn (L l e) = L (SrcSpanAnn EpAnnNotUsed l) e
439456
#else
440457
noLoc :: e -> Located e
441458
noLoc = GHC.noLoc
@@ -448,7 +465,7 @@ tupP pats = noLoc $ TuplePat noExt pats GHC.Boxed
448465
vecP :: (?nms :: ExternalNames) => SrcSpanAnnA -> [LPat GhcPs] -> LPat GhcPs
449466
vecP srcLoc = \case
450467
[] -> go []
451-
#if __GLASGOW_HASKELL__ < 904
468+
#if __GLASGOW_HASKELL__ < 904 || __GLASGOW_HASKELL__ >= 910
452469
as -> L srcLoc $ ParPat noExt $ go as
453470
where
454471
#else
@@ -497,13 +514,19 @@ appTy :: LHsType GhcPs -> LHsType GhcPs -> LHsType GhcPs
497514
appTy a b = noLoc (HsAppTy noExtField a (parenthesizeHsType GHC.appPrec b))
498515

499516
appE :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
500-
appE fun arg = L noSrcSpanA $ HsApp noExt fun (parenthesizeHsExpr GHC.appPrec arg)
517+
appE fun arg = L noSrcSpanA $ HsApp
518+
#if __GLASGOW_HASKELL__ >= 910
519+
noExtField
520+
#else
521+
noExt
522+
#endif
523+
fun (parenthesizeHsExpr GHC.appPrec arg)
501524

502525
varE :: SrcSpanAnnA -> GHC.RdrName -> LHsExpr GhcPs
503526
varE loc rdr = L loc (HsVar noExtField (noLoc rdr))
504527

505528
parenE :: LHsExpr GhcPs -> LHsExpr GhcPs
506-
#if __GLASGOW_HASKELL__ < 904
529+
#if __GLASGOW_HASKELL__ < 904 || __GLASGOW_HASKELL__ >= 910
507530
parenE e@(L l _) = L l (HsPar noExt e)
508531
#else
509532
parenE e@(L l _) = L l (HsPar noExt pL e pR)
@@ -533,7 +556,9 @@ tupE :: p ~ GhcPs => SrcSpanAnnA -> [LHsExpr p] -> LHsExpr p
533556
tupE _ [ele] = ele
534557
tupE loc elems = L loc $ ExplicitTuple noExt tupArgs GHC.Boxed
535558
where
536-
#if __GLASGOW_HASKELL__ >= 902
559+
#if __GLASGOW_HASKELL__ >= 910
560+
tupArgs = map (Present noExtField) elems
561+
#elif __GLASGOW_HASKELL__ >= 902
537562
tupArgs = map (Present noExt) elems
538563
#else
539564
tupArgs = map (\arg@(L l _) -> L l (Present noExt arg)) elems
@@ -567,8 +592,10 @@ simpleLambda :: HsExpr GhcPs -> Maybe ([LPat GhcPs], LHsExpr GhcPs)
567592
simpleLambda expr = do
568593
#if __GLASGOW_HASKELL__ < 906
569594
HsLam _ (MG _x alts _origin) <- Just expr
570-
#else
595+
#elif __GLASGOW_HASKELL__ < 910
571596
HsLam _ (MG _x alts) <- Just expr
597+
#else
598+
HsLam _ _ (MG _x alts) <- Just expr
572599
#endif
573600
L _ [L _ (Match _matchX _matchContext matchPats matchGr)] <- Just alts
574601
GRHSs _grX grHss _grLocalBinds <- Just matchGr
@@ -588,7 +615,7 @@ letE
588615
-- ^ final `in` expressions
589616
-> LHsExpr p
590617
letE loc sigs binds expr =
591-
#if __GLASGOW_HASKELL__ < 904
618+
#if __GLASGOW_HASKELL__ < 904 || __GLASGOW_HASKELL__ >= 910
592619
L loc (HsLet noExt localBinds expr)
593620
#else
594621
L loc (HsLet noExt tkLet localBinds tkIn expr)
@@ -602,7 +629,7 @@ letE loc sigs binds expr =
602629
localBinds = L loc $ HsValBinds noExt valBinds
603630
#endif
604631

605-
#if __GLASGOW_HASKELL__ >= 904
632+
#if __GLASGOW_HASKELL__ >= 904 && __GLASGOW_HASKELL__ < 910
606633
tkLet = L (GHC.mkTokenLocation $ locA loc) HsTok
607634
tkIn = L (GHC.mkTokenLocation $ locA loc) HsTok
608635
#endif
@@ -615,22 +642,38 @@ letE loc sigs binds expr =
615642

616643
-- | Simple construction of a lambda expression
617644
lamE :: [LPat GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
618-
lamE pats expr = noLoc $ HsLam noExtField mg
645+
lamE pats expr = noLoc $ HsLam
646+
#if __GLASGOW_HASKELL__ >= 910
647+
noAnn
648+
LamSingle
649+
#else
650+
noExtField
651+
#endif
652+
mg
619653
where
620654
mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
621655
#if __GLASGOW_HASKELL__ < 906
622656
mg = MG noExtField matches GHC.Generated
623657
#elif __GLASGOW_HASKELL__ < 908
624658
mg = MG GHC.Generated matches
625-
#else
659+
#elif __GLASGOW_HASKELL__ < 910
626660
mg = MG (GHC.Generated GHC.DoPmc) matches
661+
#else
662+
-- TODO: Add explanation
663+
mg = MG (GHC.Generated GHC.OtherExpansion GHC.DoPmc) matches
627664
#endif
628665

629666
matches :: GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
630667
matches = noLoc $ [singleMatch]
631668

632669
singleMatch :: GenLocated SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
633-
singleMatch = noLoc $ Match noExt LambdaExpr pats grHss
670+
singleMatch = noLoc $ Match noExt
671+
#if __GLASGOW_HASKELL__ < 910
672+
LambdaExpr
673+
#else
674+
(LamAlt LamSingle)
675+
#endif
676+
pats grHss
634677

635678
grHss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
636679
grHss = GRHSs emptyComments [grHs] $
@@ -988,7 +1031,17 @@ decFromBinding dflags Binding {..} = do
9881031
in patBind bindPat bod
9891032

9901033
patBind :: LPat GhcPs -> LHsExpr GhcPs -> HsBind GhcPs
991-
patBind lhs expr = PatBind noExt lhs rhs
1034+
patBind lhs expr = PatBind
1035+
#if __GLASGOW_HASKELL__ >= 910
1036+
noExtField
1037+
#else
1038+
noExt
1039+
#endif
1040+
lhs
1041+
#if __GLASGOW_HASKELL__ >= 910
1042+
(HsNoMultAnn noExtField)
1043+
#endif
1044+
rhs
9921045
#if __GLASGOW_HASKELL__ < 906
9931046
([], [])
9941047
#endif
@@ -1087,9 +1140,16 @@ unsnoc (x:xs) = Just (x:a, b)
10871140

10881141
hsFunTy :: (p ~ GhcPs) => LHsType p -> LHsType p -> HsType p
10891142
hsFunTy =
1090-
HsFunTy noExt
1143+
HsFunTy
1144+
#if __GLASGOW_HASKELL__ >= 910
1145+
noExtField
1146+
#else
1147+
noExt
1148+
#endif
10911149
#if __GLASGOW_HASKELL__ >= 900 && __GLASGOW_HASKELL__ < 904
10921150
(HsUnrestrictedArrow GHC.NormalSyntax)
1151+
#elif __GLASGOW_HASKELL__ >= 910
1152+
(HsUnrestrictedArrow NoEpUniTok)
10931153
#elif __GLASGOW_HASKELL__ >= 904
10941154
(HsUnrestrictedArrow $ L NoTokenLoc HsNormalTok)
10951155
#endif

0 commit comments

Comments
 (0)