Skip to content

Commit

Permalink
Add ghc-9.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinreact committed Feb 13, 2024
1 parent abc42b9 commit 35f852b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- "9.0.2"
- "9.2.8"
- "9.4.8"
- "9.6.4"

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion circuit-notation.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ library
, clash-prelude >= 1.0
, containers
, data-default
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.6)
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.8)
, lens
, mtl
, parsec
Expand Down
54 changes: 45 additions & 9 deletions src/CircuitNotation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ import qualified GHC.Parser.Annotation as GHC
#if __GLASGOW_HASKELL__ >= 900
import GHC.Data.Bag
import GHC.Data.FastString (mkFastString, unpackFS)
#if __GLASGOW_HASKELL__ < 906
import GHC.Plugins (PromotionFlag(NotPromoted))
#endif
import GHC.Types.SrcLoc hiding (noLoc)
import qualified GHC.Data.FastString as GHC
import qualified GHC.Driver.Plugins as GHC
Expand Down Expand Up @@ -142,6 +144,10 @@ import Control.Lens.Operators
-- mtl
import Control.Monad.State

#if __GLASGOW_HASKELL__ >= 906
import Control.Monad
#endif

-- pretty-show
-- import qualified Text.Show.Pretty as SP

Expand Down Expand Up @@ -251,7 +257,13 @@ pattern ParPatP :: LPat p -> Pat p
pattern ParPatP p <- ParPat _ _ p _
#endif

mkErrMsg :: GHC.DynFlags -> SrcSpan -> Outputable.PrintUnqualified -> Outputable.SDoc -> ErrMsg
#if __GLASGOW_HASKELL__ < 906
type PrintUnqualified = Outputable.PrintUnqualified
#else
type PrintUnqualified = Outputable.NamePprCtx
#endif

mkErrMsg :: GHC.DynFlags -> SrcSpan -> PrintUnqualified -> Outputable.SDoc -> ErrMsg
#if __GLASGOW_HASKELL__ < 902
mkErrMsg = Err.mkErrMsg
#elif __GLASGOW_HASKELL__ >= 902 && __GLASGOW_HASKELL__ < 904
Expand All @@ -266,7 +278,7 @@ mkErrMsg _ locn unqual =
. Err.mkPlainError Err.noHints
#endif

mkLongErrMsg :: GHC.DynFlags -> SrcSpan -> Outputable.PrintUnqualified -> Outputable.SDoc -> Outputable.SDoc -> ErrMsg
mkLongErrMsg :: GHC.DynFlags -> SrcSpan -> PrintUnqualified -> Outputable.SDoc -> Outputable.SDoc -> ErrMsg
#if __GLASGOW_HASKELL__ < 902
mkLongErrMsg = Err.mkLongErrMsg
#elif __GLASGOW_HASKELL__ >= 902 && __GLASGOW_HASKELL__ < 904
Expand Down Expand Up @@ -381,10 +393,22 @@ runCircuitM (CircuitM m) = do
#endif
pure a

#if __GLASGOW_HASKELL__ < 904
mkLocMessage :: Err.Severity -> SrcSpan -> Outputable.SDoc -> Outputable.SDoc
#else
mkLocMessage :: Err.MessageClass -> SrcSpan -> Outputable.SDoc -> Outputable.SDoc
#endif

#if __GLASGOW_HASKELL__ < 906
mkLocMessage = Err.mkLocMessageAnn Nothing
#else
mkLocMessage = Err.mkLocMessage
#endif

errM :: SrcSpan -> String -> CircuitM ()
errM loc msg = do
dflags <- GHC.getDynFlags
let errMsg = Err.mkLocMessageAnn Nothing sevFatal loc (Outputable.text msg)
let errMsg = mkLocMessage sevFatal loc (Outputable.text msg)
cErrors %= consBag (mkErrMsg dflags loc Outputable.alwaysQualify errMsg)

-- ghc helpers ---------------------------------------------------------
Expand Down Expand Up @@ -538,7 +562,11 @@ genLocName _ prefix = prefix
-- | Extract a simple lambda into inputs and body.
simpleLambda :: HsExpr GhcPs -> Maybe ([LPat GhcPs], LHsExpr GhcPs)
simpleLambda expr = do
#if __GLASGOW_HASKELL__ < 906
HsLam _ (MG _x alts _origin) <- Just expr
#else
HsLam _ (MG _x alts) <- Just expr
#endif
L _ [L _ (Match _matchX _matchContext matchPats matchGr)] <- Just alts
GRHSs _grX grHss _grLocalBinds <- Just matchGr
[L _ (GRHS _ _ body)] <- Just grHss
Expand Down Expand Up @@ -587,7 +615,11 @@ lamE :: [LPat GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
lamE pats expr = noLoc $ HsLam noExtField mg
where
mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
#if __GLASGOW_HASKELL__ < 906
mg = MG noExtField matches GHC.Generated
#else
mg = MG GHC.Generated matches
#endif

matches :: GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
matches = noLoc $ [singleMatch]
Expand Down Expand Up @@ -739,8 +771,7 @@ bindSlave (L loc expr) = case expr of
ListPat _ pats -> Vec loc (map bindSlave pats)
pat ->
PortErr loc
(Err.mkLocMessageAnn
Nothing
(mkLocMessage
sevFatal
(locA loc)
(Outputable.text $ "Unhandled pattern " <> show (Data.toConstr pat))
Expand Down Expand Up @@ -785,8 +816,7 @@ bindMaster (L loc expr) = case expr of
-- OpApp _xapp (L _ circuitVar) (L _ infixVar) appR -> k

_ -> PortErr loc
(Err.mkLocMessageAnn
Nothing
(mkLocMessage
sevFatal
(locA loc)
(Outputable.text $ "Unhandled expression " <> show (Data.toConstr expr))
Expand Down Expand Up @@ -952,7 +982,10 @@ decFromBinding dflags Binding {..} = do
in patBind bindPat bod

patBind :: LPat GhcPs -> LHsExpr GhcPs -> HsBind GhcPs
patBind lhs expr = PatBind noExt lhs rhs ([], [])
patBind lhs expr = PatBind noExt lhs rhs
#if __GLASGOW_HASKELL__ < 906
([], [])
#endif
where
rhs :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
rhs = GRHSs emptyComments [gr] $
Expand Down Expand Up @@ -1153,7 +1186,7 @@ completeUnderscores = do
transform
:: (?nms :: ExternalNames)
=> Bool
#if __GLASGOW_HASKELL__ >= 900
#if __GLASGOW_HASKELL__ >= 900 && __GLASGOW_HASKELL__ < 906
-> GHC.Located HsModule
-> GHC.Hsc (GHC.Located HsModule)
#else
Expand Down Expand Up @@ -1223,6 +1256,9 @@ warningMsg sdoc = do
let
diagOpts = GHC.initDiagOpts dflags
mc = Err.mkMCDiagnostic diagOpts GHC.WarningWithoutFlag
#if __GLASGOW_HASKELL__ >= 906
Nothing
#endif
liftIO $ GHC.logMsg logger mc noSrcSpan sdoc
#endif

Expand Down

0 comments on commit 35f852b

Please sign in to comment.