{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ImplicitParams #-}
module Compat(module Compat) where
import GHC
#if __GLASGOW_HASKELL__ < 900
import BasicTypes
import TcEvidence
import RnTypes as Compat
import UniqSupply
#else
import GHC.Types.Basic
import GHC.Unit.Types
import GHC.Parser.Annotation
import GHC.Rename.HsType as Compat
import GHC.Types.Unique.Supply
#endif
#if __GLASGOW_HASKELL__ < 810
import HsSyn as Compat
#else
import GHC.Hs as Compat
#endif
#if __GLASGOW_HASKELL__ < 808
import System.IO.Unsafe as Compat (unsafePerformIO)
import TcRnTypes
import IOEnv
import DynFlags
import HscTypes
#endif
import Data.IORef as Compat
noL :: e -> GenLocated SrcSpan e
noL :: e -> GenLocated SrcSpan e
noL = e -> GenLocated SrcSpan e
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc
#if __GLASGOW_HASKELL__ < 810
noE :: NoExt
noE = NoExt
#else
noE :: NoExtField
noE :: NoExtField
noE = NoExtField
noExtField
#endif
realSrcLoc :: SrcLoc -> Maybe RealSrcLoc
#if __GLASGOW_HASKELL__ < 811
realSrcLoc :: SrcLoc -> Maybe RealSrcLoc
realSrcLoc (RealSrcLoc RealSrcLoc
x) = RealSrcLoc -> Maybe RealSrcLoc
forall a. a -> Maybe a
Just RealSrcLoc
x
#else
realSrcLoc (RealSrcLoc x _) = Just x
#endif
realSrcLoc SrcLoc
_ = Maybe RealSrcLoc
forall a. Maybe a
Nothing
#if __GLASGOW_HASKELL__ >= 900
hsLTyVarBndrToType :: LHsTyVarBndr flag (GhcPass p) -> LHsType (GhcPass p)
hsLTyVarBndrToType x = noL $ HsTyVar noE NotPromoted $ noL $ hsLTyVarName x
#endif
#if __GLASGOW_HASKELL__ < 811
type Module = HsModule GhcPs
#else
type Module = HsModule
#endif
mkAppType :: LHsExpr GhcPs -> LHsType GhcPs -> LHsExpr GhcPs
mkTypeAnn :: LHsExpr GhcPs -> LHsType GhcPs -> LHsExpr GhcPs
mkFunTy :: LHsType GhcPs -> LHsType GhcPs -> LHsType GhcPs
newFunBind :: Located RdrName -> MatchGroup GhcPs (LHsExpr GhcPs) -> HsBind GhcPs
#if __GLASGOW_HASKELL__ < 807
mkAppType expr typ = noL $ HsAppType (HsWC noE typ) expr
mkTypeAnn expr typ = noL $ ExprWithTySig (HsWC noE (HsIB noE typ)) expr
#else
mkAppType :: LHsExpr GhcPs -> LHsType GhcPs -> LHsExpr GhcPs
mkAppType LHsExpr GhcPs
expr LHsType GhcPs
typ = HsExpr GhcPs -> LHsExpr GhcPs
forall e. e -> GenLocated SrcSpan e
noL (HsExpr GhcPs -> LHsExpr GhcPs) -> HsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ XAppTypeE GhcPs
-> LHsExpr GhcPs -> LHsWcType (NoGhcTc GhcPs) -> HsExpr GhcPs
forall p.
XAppTypeE p -> LHsExpr p -> LHsWcType (NoGhcTc p) -> HsExpr p
HsAppType NoExtField
XAppTypeE GhcPs
noE LHsExpr GhcPs
expr (XHsWC GhcPs (LHsType GhcPs)
-> LHsType GhcPs -> HsWildCardBndrs GhcPs (LHsType GhcPs)
forall pass thing.
XHsWC pass thing -> thing -> HsWildCardBndrs pass thing
HsWC NoExtField
XHsWC GhcPs (LHsType GhcPs)
noE LHsType GhcPs
typ)
mkTypeAnn :: LHsExpr GhcPs -> LHsType GhcPs -> LHsExpr GhcPs
mkTypeAnn LHsExpr GhcPs
expr LHsType GhcPs
typ = HsExpr GhcPs -> LHsExpr GhcPs
forall e. e -> GenLocated SrcSpan e
noL (HsExpr GhcPs -> LHsExpr GhcPs) -> HsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ XExprWithTySig GhcPs
-> LHsExpr GhcPs -> LHsSigWcType (NoGhcTc GhcPs) -> HsExpr GhcPs
forall p.
XExprWithTySig p
-> LHsExpr p -> LHsSigWcType (NoGhcTc p) -> HsExpr p
ExprWithTySig NoExtField
XExprWithTySig GhcPs
noE LHsExpr GhcPs
expr (XHsWC GhcPs (HsImplicitBndrs GhcPs (LHsType GhcPs))
-> HsImplicitBndrs GhcPs (LHsType GhcPs)
-> HsWildCardBndrs GhcPs (HsImplicitBndrs GhcPs (LHsType GhcPs))
forall pass thing.
XHsWC pass thing -> thing -> HsWildCardBndrs pass thing
HsWC NoExtField
XHsWC GhcPs (HsImplicitBndrs GhcPs (LHsType GhcPs))
noE (XHsIB GhcPs (LHsType GhcPs)
-> LHsType GhcPs -> HsImplicitBndrs GhcPs (LHsType GhcPs)
forall pass thing.
XHsIB pass thing -> thing -> HsImplicitBndrs pass thing
HsIB NoExtField
XHsIB GhcPs (LHsType GhcPs)
noE LHsType GhcPs
typ))
#endif
#if __GLASGOW_HASKELL__ < 811
mkFunTy :: LHsType GhcPs -> LHsType GhcPs -> LHsType GhcPs
mkFunTy LHsType GhcPs
a LHsType GhcPs
b = HsType GhcPs -> LHsType GhcPs
forall e. e -> GenLocated SrcSpan e
noL (HsType GhcPs -> LHsType GhcPs) -> HsType GhcPs -> LHsType GhcPs
forall a b. (a -> b) -> a -> b
$ XFunTy GhcPs -> LHsType GhcPs -> LHsType GhcPs -> HsType GhcPs
forall pass.
XFunTy pass -> LHsType pass -> LHsType pass -> HsType pass
HsFunTy NoExtField
XFunTy GhcPs
noE LHsType GhcPs
a LHsType GhcPs
b
newFunBind :: Located RdrName -> MatchGroup GhcPs (LHsExpr GhcPs) -> HsBind GhcPs
newFunBind Located RdrName
a MatchGroup GhcPs (LHsExpr GhcPs)
b = XFunBind GhcPs GhcPs
-> Located (IdP GhcPs)
-> MatchGroup GhcPs (LHsExpr GhcPs)
-> HsWrapper
-> [Tickish Id]
-> HsBind GhcPs
forall idL idR.
XFunBind idL idR
-> Located (IdP idL)
-> MatchGroup idR (LHsExpr idR)
-> HsWrapper
-> [Tickish Id]
-> HsBindLR idL idR
FunBind NoExtField
XFunBind GhcPs GhcPs
noE Located (IdP GhcPs)
Located RdrName
a MatchGroup GhcPs (LHsExpr GhcPs)
b HsWrapper
WpHole []
#else
mkFunTy a b = noL $ HsFunTy noE (HsUnrestrictedArrow NormalSyntax) a b
newFunBind a b = FunBind noE a b []
#endif
#if __GLASGOW_HASKELL__ < 807
compat_m_pats :: [Pat GhcPs] -> [LPat GhcPs]
compat_m_pats = map noL
#elif __GLASGOW_HASKELL__ < 809
compat_m_pats :: [Pat GhcPs] -> [Pat GhcPs]
compat_m_pats = id
#else
compat_m_pats :: [Pat GhcPs] -> [LPat GhcPs]
compat_m_pats :: [Pat GhcPs] -> [LPat GhcPs]
compat_m_pats = (Pat GhcPs -> GenLocated SrcSpan (Pat GhcPs))
-> [Pat GhcPs] -> [GenLocated SrcSpan (Pat GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map Pat GhcPs -> GenLocated SrcSpan (Pat GhcPs)
forall e. e -> GenLocated SrcSpan e
noL
#endif
qualifiedImplicitImport :: ModuleName -> LImportDecl GhcPs
#if __GLASGOW_HASKELL__ < 809
qualifiedImplicitImport x = noL $ ImportDecl noE NoSourceText (noL x) Nothing False False
True True Nothing Nothing
#elif __GLASGOW_HASKELL__ < 811
qualifiedImplicitImport :: ModuleName -> LImportDecl GhcPs
qualifiedImplicitImport ModuleName
x = ImportDecl GhcPs -> LImportDecl GhcPs
forall e. e -> GenLocated SrcSpan e
noL (ImportDecl GhcPs -> LImportDecl GhcPs)
-> ImportDecl GhcPs -> LImportDecl GhcPs
forall a b. (a -> b) -> a -> b
$ XCImportDecl GhcPs
-> SourceText
-> Located ModuleName
-> Maybe StringLiteral
-> Bool
-> Bool
-> ImportDeclQualifiedStyle
-> Bool
-> Maybe (Located ModuleName)
-> Maybe (Bool, Located [LIE GhcPs])
-> ImportDecl GhcPs
forall pass.
XCImportDecl pass
-> SourceText
-> Located ModuleName
-> Maybe StringLiteral
-> Bool
-> Bool
-> ImportDeclQualifiedStyle
-> Bool
-> Maybe (Located ModuleName)
-> Maybe (Bool, Located [LIE pass])
-> ImportDecl pass
ImportDecl NoExtField
XCImportDecl GhcPs
noE SourceText
NoSourceText (ModuleName -> Located ModuleName
forall e. e -> GenLocated SrcSpan e
noL ModuleName
x) Maybe StringLiteral
forall a. Maybe a
Nothing Bool
False Bool
False
ImportDeclQualifiedStyle
QualifiedPost Bool
True Maybe (Located ModuleName)
forall a. Maybe a
Nothing Maybe (Bool, Located [LIE GhcPs])
forall a. Maybe a
Nothing
#else
qualifiedImplicitImport x = noL $ ImportDecl noE NoSourceText (noL x) Nothing NotBoot False
QualifiedPost True Nothing Nothing
#endif
type PluginEnv = (?hscenv :: HscEnv, ?uniqSupply :: IORef UniqSupply)
dropRnTraceFlags :: HscEnv -> HscEnv
#if __GLASGOW_HASKELL__ < 808
dropRnTraceFlags env@HscEnv{hsc_dflags = dflags} = env{hsc_dflags = dopt_unset dflags Opt_D_dump_rn_trace}
#else
dropRnTraceFlags :: HscEnv -> HscEnv
dropRnTraceFlags = HscEnv -> HscEnv
forall a. a -> a
id
#endif
freeTyVars :: PluginEnv => LHsType GhcPs -> [Located RdrName]
#if __GLASGOW_HASKELL__ < 808
{-# NOINLINE freeTyVars #-}
freeTyVars = freeKiTyVarsAllVars . runRnM . extractHsTyRdrTyVars
where
runRnM :: RnM a -> a
runRnM rnm = unsafePerformIO $ do
let env = Env ?hscenv ?uniqSupply unused unused
runIOEnv env rnm
unused = error "never called"
#elif __GLASGOW_HASKELL__ < 810
freeTyVars = freeKiTyVarsAllVars . extractHsTyRdrTyVars
#else
freeTyVars :: LHsType GhcPs -> [Located RdrName]
freeTyVars = LHsType GhcPs -> [Located RdrName]
extractHsTyRdrTyVars
#endif