From bbc8817c41dd0164a7adef345af6e67259a7d67a Mon Sep 17 00:00:00 2001 From: Martijn Bastiaan Date: Wed, 2 Sep 2026 11:21:35 +0200 Subject: [PATCH 1/2] Drop support for GHC 9.4 and older The code has required GHC 9.6 since 0.2.0.0 (see 73f566c), but the `base` lower bound still admitted much older compilers. Align it with GHC 9.6's base-4.18 and note the dropped versions in the changelog. Co-Authored-By: Claude Fable 5.1 --- CHANGELOG.md | 2 ++ circuit-notation.cabal | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e504990..e961daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ and expressions also take the span of the ports they bundle, so whole-bundle errors (e.g. sharing a value-level variable across clock domains) are blamed on the ports rather than on the head of the circuit. +* Drop support for GHC 9.4 and older. The plugin has required GHC 9.6 since + 0.2.0.0; the `base` lower bound now reflects that. ## 0.2.0.0 -- 2026-04-23 diff --git a/circuit-notation.cabal b/circuit-notation.cabal index e828865..6518472 100644 --- a/circuit-notation.cabal +++ b/circuit-notation.cabal @@ -40,7 +40,7 @@ library GHC.Types.Unique.Map.Extra -- other-extensions: build-depends: - base >=4.12 && <5, + base >=4.18 && <5, clash-prelude >=1.0, containers, data-default, From c1a3be09a62710491e13c159cd927271b8211a93 Mon Sep 17 00:00:00 2001 From: Martijn Bastiaan Date: Wed, 2 Sep 2026 11:29:07 +0200 Subject: [PATCH 2/2] Add GHC 9.14 support GHC 9.14 changed a few AST details the plugin builds by hand: * 'HsConDetails' lost its type-argument list. Introduce a 'PrefixConP' pattern synonym that hides the difference and use it for all prefix constructor patterns. * The guarded right-hand sides of 'GRHSs' are now a 'NonEmpty' list. Introduce a 'SingleGRHS' pattern synonym for the single-alternative case the plugin generates and matches on. * Multiplicity annotations were unified: 'HsNoMultAnn' became 'HsUnannotated EpPatBind' for pattern bindings and 'HsUnrestrictedArrow' became 'HsUnannotated (EpArrow noAnn)' for function arrows. * 'thRdrNameGuesses' gained a list/tuple-pun flag, which is irrelevant for the fully qualified names 'thName' handles. Until a Clash release supporting GHC 9.14 is on Hackage, cabal.project pulls clash-prelude from the clash-compiler 'add-ghc914' branch when building with GHC >= 9.14. Add 9.14.1 to tested-with and the CI matrix. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/ci.yml | 1 + CHANGELOG.md | 1 + cabal.project | 7 +++++ circuit-notation.cabal | 3 ++- src/CircuitNotation.hs | 55 ++++++++++++++++++++++++++++++---------- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5690298..e155887 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: - "9.8.4" - "9.10.3" - "9.12.4" + - "9.14.1" steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index e961daa..ce32009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ domains) are blamed on the ports rather than on the head of the circuit. * Drop support for GHC 9.4 and older. The plugin has required GHC 9.6 since 0.2.0.0; the `base` lower bound now reflects that. +* Add support for GHC 9.14. ## 0.2.0.0 -- 2026-04-23 diff --git a/cabal.project b/cabal.project index facc4ac..b5a5cad 100644 --- a/cabal.project +++ b/cabal.project @@ -5,3 +5,10 @@ packages: . -- plugin (the same mechanism CI uses to compile the Example module). write-ghc-environment-files: always +-- TODO: Remove once a Clash release supporting GHC 9.14 is on Hackage. +if impl(ghc >= 9.14) + source-repository-package + type: git + location: https://github.com/clash-lang/clash-compiler.git + tag: 867786f9d3001ca78602d10abab791c58aa9f15a + subdir: clash-prelude diff --git a/circuit-notation.cabal b/circuit-notation.cabal index 6518472..75005b1 100644 --- a/circuit-notation.cabal +++ b/circuit-notation.cabal @@ -25,6 +25,7 @@ tested-with: ghc ==9.8.4 ghc ==9.10.3 ghc ==9.12.4 + ghc ==9.14.1 source-repository head type: git @@ -44,7 +45,7 @@ library clash-prelude >=1.0, containers, data-default, - ghc >=9.6 && <9.13, + ghc >=9.6 && <9.15, lens, mtl, parsec, diff --git a/src/CircuitNotation.hs b/src/CircuitNotation.hs index 51ecaa8..3296d9f 100644 --- a/src/CircuitNotation.hs +++ b/src/CircuitNotation.hs @@ -96,6 +96,9 @@ import "ghc" GHC.Types.Unique.Map #if __GLASGOW_HASKELL__ < 908 import GHC.Types.Unique.Map.Extra #endif +#if __GLASGOW_HASKELL__ >= 914 +import Data.List.NonEmpty (NonEmpty (..)) +#endif -- clash-prelude import Clash.Prelude (Vec((:>), Nil), bundle, unbundle) @@ -191,6 +194,24 @@ pattern ParPatP :: LPat p -> Pat p pattern ParPatP p <- ParPat _ p #endif +-- GHC 9.14 made the guarded right-hand sides of 'GRHSs' a 'NonEmpty' list. +#if __GLASGOW_HASKELL__ >= 914 +pattern SingleGRHS :: a -> NonEmpty a +pattern SingleGRHS a = a :| [] +#else +pattern SingleGRHS :: a -> [a] +pattern SingleGRHS a = [a] +#endif + +-- GHC 9.14 dropped the type-argument list from 'HsConDetails'. +#if __GLASGOW_HASKELL__ >= 914 +pattern PrefixConP :: [arg] -> HsConDetails arg rec +pattern PrefixConP args = PrefixCon args +#else +pattern PrefixConP :: [arg] -> HsConDetails tyarg arg rec +pattern PrefixConP args = PrefixCon [] args +#endif + type PrintUnqualified = Outputable.NamePprCtx mkErrMsg :: GHC.DynFlags -> SrcSpan -> PrintUnqualified -> Outputable.SDoc -> ErrMsg @@ -495,7 +516,12 @@ unL (L _ a) = a -- | Get a ghc name from a TH name that's known to be unique. thName :: TH.Name -> GHC.RdrName thName nm = +#if __GLASGOW_HASKELL__ >= 914 + -- the flag only affects names that are not fully qualified + case Convert.thRdrNameGuesses True nm of +#else case Convert.thRdrNameGuesses nm of +#endif [name] -> name _ -> error "thName called on a non NameG Name" @@ -520,7 +546,7 @@ simpleLambda expr = do L _ [L _ (Match _matchX _matchContext matchPats matchGr)] <- Just alts #endif GRHSs _grX grHss _grLocalBinds <- Just matchGr - [L _ (GRHS _ _ body)] <- Just grHss + SingleGRHS (L _ (GRHS _ _ body)) <- Just grHss Just (matchPats, body) -- | Create a simple let binding. @@ -601,7 +627,7 @@ lamE pats expr = #endif grHss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) - grHss = GRHSs emptyComments [grHs] $ + grHss = GRHSs emptyComments (SingleGRHS grHs) $ (EmptyLocalBinds noExtField) grHs :: LGRHS GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) @@ -699,7 +725,7 @@ bindSlave (L loc expr) = case expr of VarPat _ (L _ rdrName) -> Ref (PortName loc (fromRdrName rdrName)) TuplePat _ lpat _ -> Tuple $ fmap bindSlave lpat ParPatP lpat -> bindSlave lpat - ConPat _ (L _ (GHC.Unqual occ)) (PrefixCon [] [lpat]) + ConPat _ (L _ (GHC.Unqual occ)) (PrefixConP [lpat]) | Just mk <- markerFromName occ -> FwdPat mk lpat -- empty list is done as the constructor ConPat _ (L _ rdr) _ @@ -928,14 +954,16 @@ decFromBinding dflags Binding {..} = do patBind :: LPat GhcPs -> LHsExpr GhcPs -> HsBind GhcPs patBind lhs expr = -#if __GLASGOW_HASKELL__ < 910 - PatBind noExt lhs rhs -#else +#if __GLASGOW_HASKELL__ >= 914 + PatBind noExtField lhs (HsUnannotated EpPatBind) rhs +#elif __GLASGOW_HASKELL__ >= 910 PatBind noExtField lhs (HsNoMultAnn noExtField) rhs +#else + PatBind noExt lhs rhs #endif where rhs :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) - rhs = GRHSs emptyComments [gr] $ + rhs = GRHSs emptyComments (SingleGRHS gr) $ EmptyLocalBinds noExtField gr :: LGRHS GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)) @@ -948,17 +976,14 @@ runCircuitFun :: (?nms :: ExternalNames) => SrcSpanAnnA -> LHsExpr GhcPs runCircuitFun loc = varE loc (runCircuitName ?nms) -prefixCon :: [arg] -> HsConDetails tyarg arg rec -prefixCon a = PrefixCon [] a - taggedBundleP :: (p ~ GhcPs, ?nms :: ExternalNames) => SrcSpanAnnA -> LPat p -> LPat p -taggedBundleP loc a = L loc (conPatIn (noLoc (tagBundlePat ?nms)) (prefixCon [a])) +taggedBundleP loc a = L loc (conPatIn (noLoc (tagBundlePat ?nms)) (PrefixConP [a])) taggedBundleE :: (p ~ GhcPs, ?nms :: ExternalNames) => SrcSpanAnnA -> LHsExpr p -> LHsExpr p taggedBundleE loc a = varE loc (tagBundlePat ?nms) `appE` a tagP :: (p ~ GhcPs, ?nms :: ExternalNames) => LPat p -> LPat p -tagP a = noLoc (conPatIn (noLoc (tagName ?nms)) (prefixCon [a])) +tagP a = noLoc (conPatIn (noLoc (tagName ?nms)) (PrefixConP [a])) tagE :: (p ~ GhcPs, ?nms :: ExternalNames) => LHsExpr p -> LHsExpr p tagE a = varE noSrcSpanA (tagName ?nms) `appE` a @@ -967,7 +992,7 @@ tagE a = varE noSrcSpanA (tagName ?nms) `appE` a -- errors on the value boundary (e.g. marking a non-signal bus with @Signal@) -- point at the marked pattern or expression sigTagP :: (p ~ GhcPs, ?nms :: ExternalNames) => SigMarker -> LPat p -> LPat p -sigTagP mk a@(L l _) = L l (conPatIn (noLoc (markerTagName mk)) (prefixCon [a])) +sigTagP mk a@(L l _) = L l (conPatIn (noLoc (markerTagName mk)) (PrefixConP [a])) sigTagE :: (p ~ GhcPs, ?nms :: ExternalNames) => SigMarker -> LHsExpr p -> LHsExpr p sigTagE mk a@(L l _) = varE l (markerTagName mk) `appE` a @@ -1023,7 +1048,9 @@ unsnoc (x:xs) = Just (x:a, b) hsFunTy :: (p ~ GhcPs) => LHsType p -> LHsType p -> HsType p hsFunTy = -#if __GLASGOW_HASKELL__ >= 910 +#if __GLASGOW_HASKELL__ >= 914 + HsFunTy noExtField (HsUnannotated (EpArrow noAnn)) +#elif __GLASGOW_HASKELL__ >= 910 HsFunTy noExtField (HsUnrestrictedArrow noAnn) #else HsFunTy noExt (HsUnrestrictedArrow $ L NoTokenLoc HsNormalTok)