nri-prelude-0.7.0.0: src/NriPrelude/Plugin/GhcVersionDependent.hs
{-# LANGUAGE CPP #-}
-- Imports we need to write this module tend to move around in later
-- versions of GHC. This module uses the CPP extension to import the
-- right values dependent on the version of GHC.
module NriPrelude.Plugin.GhcVersionDependent
( setIDeclImplicit,
withParsedResult,
)
where
import qualified GHC.Driver.Plugins
import qualified GHC.Hs
import qualified GHC.Hs.ImpExp
import Prelude
withParsedResult :: GHC.Driver.Plugins.ParsedResult -> (GHC.Hs.HsParsedModule -> GHC.Hs.HsParsedModule) -> GHC.Driver.Plugins.ParsedResult
withParsedResult parsed f =
parsed
{ GHC.Driver.Plugins.parsedResultModule = f (GHC.Driver.Plugins.parsedResultModule parsed)
}
setIDeclImplicit :: Bool -> GHC.Hs.ImpExp.ImportDecl GHC.Hs.GhcPs -> GHC.Hs.ImpExp.ImportDecl GHC.Hs.GhcPs
setIDeclImplicit isImplicit importDecl =
-- no idea what `XImportDeclPass` _is_, btw. just following types
-- ref: https://hackage.haskell.org/package/ghc-9.6.5/docs/Language-Haskell-Syntax-ImpExp.html#t:ImportDecl
-- https://hackage.haskell.org/package/ghc-9.6.5/docs/Language-Haskell-Syntax-Extension.html#t:XCImportDecl
-- https://hackage.haskell.org/package/ghc-9.6.5/docs/GHC-Hs-ImpExp.html#t:XImportDeclPass
let xImportDeclPass = GHC.Hs.ImpExp.ideclExt importDecl
in importDecl
{ GHC.Hs.ImpExp.ideclExt =
xImportDeclPass {GHC.Hs.ImpExp.ideclImplicit = isImplicit}
}