{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.Tc.Module (
tcRnStmt, tcRnExpr, TcRnExprMode(..), tcRnType,
tcRnImportDecls,
tcRnLookupRdrName,
getModuleInterface,
tcRnDeclsi,
isGHCiMonad,
runTcInteractive,
tcRnLookupName,
tcRnGetInfo,
tcRnModule, tcRnModuleTcRnM,
tcTopSrcDecls,
rnTopSrcDecls,
checkBootDecl, checkHiBootIface',
findExtraSigImports,
implicitRequirements,
checkUnit,
mergeSignatures,
tcRnMergeSignatures,
instantiateSignature,
tcRnInstantiateSignature,
loadUnqualIfaces,
badReexportedBootThing,
checkBootDeclM,
missingBootThing,
getRenamedStuff, RenamedStuff
) where
import GHC.Prelude
import GHC.Driver.Env
import GHC.Driver.Plugins
import GHC.Driver.Session
import GHC.Tc.Errors.Hole.FitTypes ( HoleFitPluginR (..) )
import {-# SOURCE #-} GHC.Tc.Gen.Splice ( finishTH, runRemoteModFinalizers )
import GHC.Tc.Gen.HsType
import GHC.Tc.Validity( checkValidType )
import GHC.Tc.Gen.Match
import GHC.Tc.Utils.Unify( checkConstraints, tcSubTypeSigma )
import GHC.Tc.Utils.Zonk
import GHC.Tc.Gen.Expr
import GHC.Tc.Gen.App( tcInferSigma )
import GHC.Tc.Utils.Monad
import GHC.Tc.Gen.Export
import GHC.Tc.Types.Evidence
import GHC.Tc.Types.Constraint
import GHC.Tc.Types.Origin
import GHC.Tc.Instance.Family
import GHC.Tc.Gen.Annotation
import GHC.Tc.Gen.Bind
import GHC.Tc.Gen.Default
import GHC.Tc.Utils.Env
import GHC.Tc.Gen.Rule
import GHC.Tc.Gen.Foreign
import GHC.Tc.TyCl.Instance
import GHC.Tc.Utils.TcMType
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.Instantiate (tcGetInsts)
import GHC.Tc.Solver
import GHC.Tc.TyCl
import GHC.Tc.Instance.Typeable ( mkTypeableBinds )
import GHC.Tc.Utils.Backpack
import GHC.Rename.Splice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
import GHC.Rename.HsType
import GHC.Rename.Expr
import GHC.Rename.Utils ( HsDocContext(..) )
import GHC.Rename.Fixity ( lookupFixityRn )
import GHC.Rename.Names
import GHC.Rename.Env
import GHC.Rename.Module
import GHC.Iface.Syntax ( ShowSub(..), showToHeader )
import GHC.Iface.Type ( ShowForAllFlag(..) )
import GHC.Iface.Env ( externaliseName )
import GHC.Iface.Make ( coAxiomToIfaceDecl )
import GHC.Iface.Load
import GHC.Builtin.Types ( unitTy, mkListTy )
import GHC.Builtin.Names
import GHC.Builtin.Utils
import GHC.Hs
import GHC.Hs.Dump
import GHC.Core.PatSyn ( pprPatSynType )
import GHC.Core.Predicate ( classMethodTy )
import GHC.Core.FVs ( orphNamesOfFamInst )
import GHC.Core.InstEnv
import GHC.Core.TyCon
import GHC.Core.ConLike
import GHC.Core.DataCon
import GHC.Core.Type
import GHC.Core.Class
import GHC.Core.Coercion.Axiom
import GHC.Core.Unify( RoughMatchTc(..) )
import GHC.Core.FamInstEnv
( FamInst, pprFamInst, famInstsRepTyCons
, famInstEnvElts, extendFamInstEnvList, normaliseType )
import GHC.Parser.Header ( mkPrelImports )
import GHC.IfaceToCore
import GHC.Runtime.Context
import GHC.Utils.Error
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import GHC.Utils.Misc
import GHC.Utils.Logger
import GHC.Types.Error
import GHC.Types.Name.Reader
import GHC.Types.Fixity.Env
import GHC.Types.Id as Id
import GHC.Types.Id.Info( IdDetails(..) )
import GHC.Types.Var.Env
import GHC.Types.TypeEnv
import GHC.Types.Unique.FM
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Set
import GHC.Types.Avail
import GHC.Types.Basic hiding( SuccessFlag(..) )
import GHC.Types.Annotations
import GHC.Types.SrcLoc
import GHC.Types.SourceText
import GHC.Types.SourceFile
import GHC.Types.TyThing.Ppr ( pprTyThingInContext )
import qualified GHC.LanguageExtensions as LangExt
import GHC.Unit.External
import GHC.Unit.Types
import GHC.Unit.State
import GHC.Unit.Home
import GHC.Unit.Module
import GHC.Unit.Module.Warnings
import GHC.Unit.Module.ModSummary
import GHC.Unit.Module.ModIface
import GHC.Unit.Module.ModDetails
import GHC.Unit.Module.Deps
import GHC.Data.FastString
import GHC.Data.Maybe
import GHC.Data.List.SetOps
import GHC.Data.Bag
import qualified GHC.Data.BooleanFormula as BF
import Data.List ( sortBy, sort )
import Data.Ord
import Data.Data ( Data )
import qualified Data.Set as S
import Control.DeepSeq
import Control.Monad
#include "HsVersions.h"
tcRnModule :: HscEnv
-> ModSummary
-> Bool
-> HsParsedModule
-> IO (Messages DecoratedSDoc, Maybe TcGblEnv)
tcRnModule :: HscEnv
-> ModSummary
-> Bool
-> HsParsedModule
-> IO (Messages DecoratedSDoc, Maybe TcGblEnv)
tcRnModule HscEnv
hsc_env ModSummary
mod_sum Bool
save_rn_syntax
parsedModule :: HsParsedModule
parsedModule@HsParsedModule {hpm_module :: HsParsedModule -> Located HsModule
hpm_module= L SrcSpan
loc HsModule
this_module}
| RealSrcSpan RealSrcSpan
real_loc Maybe BufSpan
_ <- SrcSpan
loc
= forall (m :: * -> *) a.
MonadIO m =>
Logger -> DynFlags -> SDoc -> (a -> ()) -> m a -> m a
withTiming Logger
logger DynFlags
dflags
(String -> SDoc
text String
"Renamer/typechecker"SDoc -> SDoc -> SDoc
<+>SDoc -> SDoc
brackets (forall a. Outputable a => a -> SDoc
ppr Module
this_mod))
(forall a b. a -> b -> a
const ()) forall a b. (a -> b) -> a -> b
$
forall r.
HscEnv
-> HscSource
-> Bool
-> Module
-> RealSrcSpan
-> TcM r
-> IO (Messages DecoratedSDoc, Maybe r)
initTc HscEnv
hsc_env HscSource
hsc_src Bool
save_rn_syntax Module
this_mod RealSrcSpan
real_loc forall a b. (a -> b) -> a -> b
$
forall a. HscEnv -> TcM a -> TcM a
withTcPlugins HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$ forall a. HscEnv -> TcM a -> TcM a
withHoleFitPlugins HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
HscEnv
-> ModSummary
-> HsParsedModule
-> (Module, SrcSpan)
-> TcM TcGblEnv
tcRnModuleTcRnM HscEnv
hsc_env ModSummary
mod_sum HsParsedModule
parsedModule (Module, SrcSpan)
pair
| Bool
otherwise
= forall (m :: * -> *) a. Monad m => a -> m a
return (MsgEnvelope DecoratedSDoc
err_msg forall e. MsgEnvelope e -> Messages e -> Messages e
`addMessage` forall e. Messages e
emptyMessages, forall a. Maybe a
Nothing)
where
hsc_src :: HscSource
hsc_src = ModSummary -> HscSource
ms_hsc_src ModSummary
mod_sum
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
logger :: Logger
logger = HscEnv -> Logger
hsc_logger HscEnv
hsc_env
home_unit :: HomeUnit
home_unit = HscEnv -> HomeUnit
hsc_home_unit HscEnv
hsc_env
err_msg :: MsgEnvelope DecoratedSDoc
err_msg = SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc
mkPlainMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
String -> SDoc
text String
"Module does not have a RealSrcSpan:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Module
this_mod
pair :: (Module, SrcSpan)
pair :: (Module, SrcSpan)
pair@(Module
this_mod,SrcSpan
_)
| Just (L SrcSpanAnnA
mod_loc ModuleName
mod) <- HsModule -> Maybe (GenLocated SrcSpanAnnA ModuleName)
hsmodName HsModule
this_module
= (HomeUnit -> ModuleName -> Module
mkHomeModule HomeUnit
home_unit ModuleName
mod, forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
mod_loc)
| Bool
otherwise
= (HomeUnit -> ModuleName -> Module
mkHomeModule HomeUnit
home_unit ModuleName
mAIN_NAME, SrcLoc -> SrcSpan
srcLocSpan (SrcSpan -> SrcLoc
srcSpanStart SrcSpan
loc))
tcRnModuleTcRnM :: HscEnv
-> ModSummary
-> HsParsedModule
-> (Module, SrcSpan)
-> TcRn TcGblEnv
tcRnModuleTcRnM :: HscEnv
-> ModSummary
-> HsParsedModule
-> (Module, SrcSpan)
-> TcM TcGblEnv
tcRnModuleTcRnM HscEnv
hsc_env ModSummary
mod_sum
(HsParsedModule {
hpm_module :: HsParsedModule -> Located HsModule
hpm_module =
(L SrcSpan
loc (HsModule EpAnn AnnsModule
_ LayoutInfo
_ Maybe (GenLocated SrcSpanAnnA ModuleName)
maybe_mod Maybe (LocatedL [LIE GhcPs])
export_ies
[LImportDecl GhcPs]
import_decls [LHsDecl GhcPs]
local_decls Maybe (LocatedP WarningTxt)
mod_deprec
Maybe LHsDocString
maybe_doc_hdr)),
hpm_src_files :: HsParsedModule -> [String]
hpm_src_files = [String]
src_files
})
(Module
this_mod, SrcSpan
prel_imp_loc)
= forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc forall a b. (a -> b) -> a -> b
$
do { let { explicit_mod_hdr :: Bool
explicit_mod_hdr = forall a. Maybe a -> Bool
isJust Maybe (GenLocated SrcSpanAnnA ModuleName)
maybe_mod
; hsc_src :: HscSource
hsc_src = ModSummary -> HscSource
ms_hsc_src ModSummary
mod_sum }
;
TcGblEnv
tcg_env <- forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; SelfBootInfo
boot_info <- HscSource -> Module -> TcRn SelfBootInfo
tcHiBootIface HscSource
hsc_src Module
this_mod
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv (TcGblEnv
tcg_env { tcg_self_boot :: SelfBootInfo
tcg_self_boot = SelfBootInfo
boot_info })
forall a b. (a -> b) -> a -> b
$ do
{
Bool
implicit_prelude <- forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.ImplicitPrelude
; let { prel_imports :: [LImportDecl GhcPs]
prel_imports = ModuleName
-> SrcSpan -> Bool -> [LImportDecl GhcPs] -> [LImportDecl GhcPs]
mkPrelImports (forall unit. GenModule unit -> ModuleName
moduleName Module
this_mod) SrcSpan
prel_imp_loc
Bool
implicit_prelude [LImportDecl GhcPs]
import_decls }
; forall gbl lcl.
WarningFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
whenWOptM WarningFlag
Opt_WarnImplicitPrelude forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall (f :: * -> *) a. Foldable f => f a -> Bool
notNull [LImportDecl GhcPs]
prel_imports) forall a b. (a -> b) -> a -> b
$
WarnReason -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addWarn (WarningFlag -> WarnReason
Reason WarningFlag
Opt_WarnImplicitPrelude) (SDoc
implicitPreludeWarn)
;
let { simplifyImport :: GenLocated l (ImportDecl pass)
-> (Maybe FastString, Located ModuleName)
simplifyImport (L l
_ ImportDecl pass
idecl) =
( forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap StringLiteral -> FastString
sl_fs (forall pass. ImportDecl pass -> Maybe StringLiteral
ideclPkgQual ImportDecl pass
idecl) , forall a e. LocatedAn a e -> Located e
reLoc forall a b. (a -> b) -> a -> b
$ forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName ImportDecl pass
idecl)
}
; [(Maybe FastString, Located ModuleName)]
raw_sig_imports <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
forall a b. (a -> b) -> a -> b
$ HscEnv
-> HscSource
-> ModuleName
-> IO [(Maybe FastString, Located ModuleName)]
findExtraSigImports HscEnv
hsc_env HscSource
hsc_src
(forall unit. GenModule unit -> ModuleName
moduleName Module
this_mod)
; [(Maybe FastString, Located ModuleName)]
raw_req_imports <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
forall a b. (a -> b) -> a -> b
$ HscEnv
-> [(Maybe FastString, Located ModuleName)]
-> IO [(Maybe FastString, Located ModuleName)]
implicitRequirements HscEnv
hsc_env
(forall a b. (a -> b) -> [a] -> [b]
map forall {pass} {a} {l}.
(XRec pass ModuleName ~ GenLocated (SrcAnn a) ModuleName) =>
GenLocated l (ImportDecl pass)
-> (Maybe FastString, Located ModuleName)
simplifyImport ([LImportDecl GhcPs]
prel_imports
forall a. [a] -> [a] -> [a]
++ [LImportDecl GhcPs]
import_decls))
; let { mkImport :: (Maybe a, GenLocated l ModuleName)
-> LocatedAn an (ImportDecl GhcPs)
mkImport (Maybe a
Nothing, L l
_ ModuleName
mod_name) = forall a an. a -> LocatedAn an a
noLocA
forall a b. (a -> b) -> a -> b
$ (ModuleName -> ImportDecl GhcPs
simpleImportDecl ModuleName
mod_name)
{ ideclHiding :: Maybe (Bool, XRec GhcPs [LIE GhcPs])
ideclHiding = forall a. a -> Maybe a
Just (Bool
False, forall a an. a -> LocatedAn an a
noLocA [])}
; mkImport (Maybe a, GenLocated l ModuleName)
_ = forall a. String -> a
panic String
"mkImport" }
; let { all_imports :: [GenLocated SrcSpanAnnA (ImportDecl GhcPs)]
all_imports = [LImportDecl GhcPs]
prel_imports forall a. [a] -> [a] -> [a]
++ [LImportDecl GhcPs]
import_decls
forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall {a} {l} {an}.
(Maybe a, GenLocated l ModuleName)
-> LocatedAn an (ImportDecl GhcPs)
mkImport ([(Maybe FastString, Located ModuleName)]
raw_sig_imports forall a. [a] -> [a] -> [a]
++ [(Maybe FastString, Located ModuleName)]
raw_req_imports) }
;
TcGblEnv
tcg_env <- {-# SCC "tcRnImports" #-}
HscEnv -> [LImportDecl GhcPs] -> TcM TcGblEnv
tcRnImports HscEnv
hsc_env [GenLocated SrcSpanAnnA (ImportDecl GhcPs)]
all_imports
;
TcGblEnv
tcg_env <- forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env
{ tcg_doc_hdr :: Maybe LHsDocString
tcg_doc_hdr = Maybe LHsDocString
maybe_doc_hdr })
;
let { tcg_env1 :: TcGblEnv
tcg_env1 = case Maybe (LocatedP WarningTxt)
mod_deprec of
Just (L SrcSpanAnnP
_ WarningTxt
txt) ->
TcGblEnv
tcg_env {tcg_warns :: Warnings
tcg_warns = WarningTxt -> Warnings
WarnAll WarningTxt
txt}
Maybe (LocatedP WarningTxt)
Nothing -> TcGblEnv
tcg_env
}
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env1
forall a b. (a -> b) -> a -> b
$ do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn1a" SDoc
empty
; TcGblEnv
tcg_env <- if HscSource -> Bool
isHsBootOrSig HscSource
hsc_src
then do {
; TcGblEnv
tcg_env <- HscSource -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnHsBootDecls HscSource
hsc_src [LHsDecl GhcPs]
local_decls
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn4a: before exports" SDoc
empty
; TcGblEnv
tcg_env <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$
Bool -> Maybe (LocatedL [LIE GhcPs]) -> TcM TcGblEnv
rnExports Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn4b: after exports" SDoc
empty
; forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env
}
else {-# SCC "tcRnSrcDecls" #-}
Bool
-> Maybe (LocatedL [LIE GhcPs]) -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnSrcDecls Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies [LHsDecl GhcPs]
local_decls
; forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_DoCoreLinting) forall a b. (a -> b) -> a -> b
$
Logger -> DynFlags -> TcGblEnv -> TcRnIf TcGblEnv TcLclEnv ()
lintGblEnv (HscEnv -> Logger
hsc_logger HscEnv
hsc_env) (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) TcGblEnv
tcg_env
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env
forall a b. (a -> b) -> a -> b
$ do {
TcGblEnv
tcg_env <- TcGblEnv -> SelfBootInfo -> TcM TcGblEnv
checkHiBootIface TcGblEnv
tcg_env SelfBootInfo
boot_info
;
TcGblEnv -> HscSource -> TcRnIf TcGblEnv TcLclEnv ()
reportUnusedNames TcGblEnv
tcg_env HscSource
hsc_src
;
[String] -> TcRnIf TcGblEnv TcLclEnv ()
addDependentFiles [String]
src_files
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env
forall a b. (a -> b) -> a -> b
$ do { TcGblEnv
tcg_env <- ModSummary -> TcGblEnv -> TcM TcGblEnv
runTypecheckerPlugin ModSummary
mod_sum TcGblEnv
tcg_env
;
TcGblEnv -> TcRnIf TcGblEnv TcLclEnv ()
tcDump TcGblEnv
tcg_env
; forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env
}
}
}
}
}
implicitPreludeWarn :: SDoc
implicitPreludeWarn :: SDoc
implicitPreludeWarn
= String -> SDoc
text String
"Module `Prelude' implicitly imported"
tcRnImports :: HscEnv -> [LImportDecl GhcPs] -> TcM TcGblEnv
tcRnImports :: HscEnv -> [LImportDecl GhcPs] -> TcM TcGblEnv
tcRnImports HscEnv
hsc_env [LImportDecl GhcPs]
import_decls
= do { ([GenLocated SrcSpanAnnA (ImportDecl (GhcPass 'Renamed))]
rn_imports, GlobalRdrEnv
rdr_env, ImportAvails
imports, Bool
hpc_info) <- [LImportDecl GhcPs]
-> RnM
([LImportDecl (GhcPass 'Renamed)], GlobalRdrEnv, ImportAvails,
Bool)
rnImports [LImportDecl GhcPs]
import_decls ;
; Module
this_mod <- forall (m :: * -> *). HasModule m => m Module
getModule
; let { dep_mods :: ModuleNameEnv ModuleNameWithIsBoot
; dep_mods :: ModuleNameEnv ModuleNameWithIsBoot
dep_mods = ImportAvails -> ModuleNameEnv ModuleNameWithIsBoot
imp_dep_mods ImportAvails
imports
; want_instances :: ModuleName -> Bool
; want_instances :: ModuleName -> Bool
want_instances ModuleName
mod = ModuleName
mod forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
`elemUFM` ModuleNameEnv ModuleNameWithIsBoot
dep_mods
Bool -> Bool -> Bool
&& ModuleName
mod forall a. Eq a => a -> a -> Bool
/= forall unit. GenModule unit -> ModuleName
moduleName Module
this_mod
; ([ClsInst]
home_insts, [FamInst]
home_fam_insts) = HscEnv -> (ModuleName -> Bool) -> ([ClsInst], [FamInst])
hptInstances HscEnv
hsc_env
ModuleName -> Bool
want_instances
} ;
; forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ (\ExternalPackageState
eps -> ExternalPackageState
eps { eps_is_boot :: ModuleNameEnv ModuleNameWithIsBoot
eps_is_boot = ModuleNameEnv ModuleNameWithIsBoot
dep_mods }) ;
; forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv ( \ TcGblEnv
gbl ->
TcGblEnv
gbl {
tcg_rdr_env :: GlobalRdrEnv
tcg_rdr_env = TcGblEnv -> GlobalRdrEnv
tcg_rdr_env TcGblEnv
gbl GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv
`plusGlobalRdrEnv` GlobalRdrEnv
rdr_env,
tcg_imports :: ImportAvails
tcg_imports = TcGblEnv -> ImportAvails
tcg_imports TcGblEnv
gbl ImportAvails -> ImportAvails -> ImportAvails
`plusImportAvails` ImportAvails
imports,
tcg_rn_imports :: [LImportDecl (GhcPass 'Renamed)]
tcg_rn_imports = [GenLocated SrcSpanAnnA (ImportDecl (GhcPass 'Renamed))]
rn_imports,
tcg_inst_env :: InstEnv
tcg_inst_env = InstEnv -> [ClsInst] -> InstEnv
extendInstEnvList (TcGblEnv -> InstEnv
tcg_inst_env TcGblEnv
gbl) [ClsInst]
home_insts,
tcg_fam_inst_env :: FamInstEnv
tcg_fam_inst_env = FamInstEnv -> [FamInst] -> FamInstEnv
extendFamInstEnvList (TcGblEnv -> FamInstEnv
tcg_fam_inst_env TcGblEnv
gbl)
[FamInst]
home_fam_insts,
tcg_hpc :: Bool
tcg_hpc = Bool
hpc_info
}) forall a b. (a -> b) -> a -> b
$ do {
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn1" (forall a. Outputable a => a -> SDoc
ppr (ImportAvails -> ModuleNameEnv ModuleNameWithIsBoot
imp_dep_mods ImportAvails
imports))
; TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; SDoc -> [Module] -> TcRnIf TcGblEnv TcLclEnv ()
loadModuleInterfaces (String -> SDoc
text String
"Loading orphan modules")
(forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
/= Module
this_mod) (ImportAvails -> [Module]
imp_orphs ImportAvails
imports))
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn1: checking family instance consistency {" SDoc
empty
; let { dir_imp_mods :: [Module]
dir_imp_mods = forall a. ModuleEnv a -> [Module]
moduleEnvKeys
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImportAvails -> ImportedMods
imp_mods
forall a b. (a -> b) -> a -> b
$ ImportAvails
imports }
; [Module] -> TcRnIf TcGblEnv TcLclEnv ()
checkFamInstConsistency [Module]
dir_imp_mods
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn1: } checking family instance consistency" SDoc
empty
; forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv } }
tcRnSrcDecls :: Bool
-> Maybe (LocatedL [LIE GhcPs])
-> [LHsDecl GhcPs]
-> TcM TcGblEnv
tcRnSrcDecls :: Bool
-> Maybe (LocatedL [LIE GhcPs]) -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnSrcDecls Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies [LHsDecl GhcPs]
decls
= do {
; (TcGblEnv
tcg_env, TcLclEnv
tcl_env, WantedConstraints
lie) <- [LHsDecl GhcPs] -> TcM (TcGblEnv, TcLclEnv, WantedConstraints)
tc_rn_src_decls [LHsDecl GhcPs]
decls
; Bag EvBind
new_ev_binds <- {-# SCC "simplifyTop" #-}
forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
tcg_env, TcLclEnv
tcl_env) forall a b. (a -> b) -> a -> b
$
do { WantedConstraints
lie_main <- TcGblEnv -> TcRn WantedConstraints
checkMainType TcGblEnv
tcg_env
; WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyTop (WantedConstraints
lie WantedConstraints -> WantedConstraints -> WantedConstraints
`andWC` WantedConstraints
lie_main) }
; TcGblEnv
tcg_env <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$
TcM TcGblEnv
mkTypeableBinds
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc9" SDoc
empty
; (TypeEnv
id_env, Bag EvBind
ev_binds', Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
binds', [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fords', [LTcSpecPrag]
imp_specs', [GenLocated SrcSpanAnnA (RuleDecl GhcTc)]
rules')
<- Bag EvBind
-> TcGblEnv
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
zonkTcGblEnv Bag EvBind
new_ev_binds TcGblEnv
tcg_env
; let
init_tcg_env :: TcGblEnv
init_tcg_env = TcGblEnv
tcg_env { tcg_binds :: LHsBinds GhcTc
tcg_binds = forall a. Bag a
emptyBag
, tcg_ev_binds :: Bag EvBind
tcg_ev_binds = forall a. Bag a
emptyBag
, tcg_imp_specs :: [LTcSpecPrag]
tcg_imp_specs = []
, tcg_rules :: [LRuleDecl GhcTc]
tcg_rules = []
, tcg_fords :: [LForeignDecl GhcTc]
tcg_fords = []
, tcg_type_env :: TypeEnv
tcg_type_env = TcGblEnv -> TypeEnv
tcg_type_env TcGblEnv
tcg_env
TypeEnv -> TypeEnv -> TypeEnv
`plusTypeEnv` TypeEnv
id_env }
; (TcGblEnv
tcg_env, TcLclEnv
tcl_env) <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
init_tcg_env
TcM (TcGblEnv, TcLclEnv)
run_th_modfinalizers
; TcRnIf TcGblEnv TcLclEnv ()
finishTH
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc11" SDoc
empty
; TcGblEnv
tcg_env <- forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
tcg_env, TcLclEnv
tcl_env) forall a b. (a -> b) -> a -> b
$
Bool -> Maybe (LocatedL [LIE GhcPs]) -> TcM TcGblEnv
rnExports Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies
; (TcGblEnv
tcg_env, Bag EvBind
main_ev_binds)
<- forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
tcg_env, TcLclEnv
tcl_env) forall a b. (a -> b) -> a -> b
$
do { (TcGblEnv
tcg_env, WantedConstraints
lie) <- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
Bool -> Maybe (LocatedL [LIE GhcPs]) -> TcM TcGblEnv
checkMain Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies
; Bag EvBind
ev_binds <- WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyTop WantedConstraints
lie
; forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env, Bag EvBind
ev_binds) }
; (TypeEnv
id_env_mf, Bag EvBind
ev_binds_mf, Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
binds_mf, [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fords_mf, [LTcSpecPrag]
imp_specs_mf, [GenLocated SrcSpanAnnA (RuleDecl GhcTc)]
rules_mf)
<- Bag EvBind
-> TcGblEnv
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
zonkTcGblEnv Bag EvBind
main_ev_binds TcGblEnv
tcg_env
; let { !final_type_env :: TypeEnv
final_type_env = TcGblEnv -> TypeEnv
tcg_type_env TcGblEnv
tcg_env
TypeEnv -> TypeEnv -> TypeEnv
`plusTypeEnv` TypeEnv
id_env_mf
; tcg_env' :: TcGblEnv
tcg_env' = TcGblEnv
tcg_env
{ tcg_binds :: LHsBinds GhcTc
tcg_binds = Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
binds' forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
binds_mf
, tcg_ev_binds :: Bag EvBind
tcg_ev_binds = Bag EvBind
ev_binds' forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag EvBind
ev_binds_mf
, tcg_imp_specs :: [LTcSpecPrag]
tcg_imp_specs = [LTcSpecPrag]
imp_specs' forall a. [a] -> [a] -> [a]
++ [LTcSpecPrag]
imp_specs_mf
, tcg_rules :: [LRuleDecl GhcTc]
tcg_rules = [GenLocated SrcSpanAnnA (RuleDecl GhcTc)]
rules' forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (RuleDecl GhcTc)]
rules_mf
, tcg_fords :: [LForeignDecl GhcTc]
tcg_fords = [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fords' forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fords_mf } } ;
; TcGblEnv -> TypeEnv -> TcM TcGblEnv
setGlobalTypeEnv TcGblEnv
tcg_env' TypeEnv
final_type_env
}
zonkTcGblEnv :: Bag EvBind -> TcGblEnv
-> TcM (TypeEnv, Bag EvBind, LHsBinds GhcTc,
[LForeignDecl GhcTc], [LTcSpecPrag], [LRuleDecl GhcTc])
zonkTcGblEnv :: Bag EvBind
-> TcGblEnv
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
zonkTcGblEnv Bag EvBind
ev_binds tcg_env :: TcGblEnv
tcg_env@(TcGblEnv { tcg_binds :: TcGblEnv -> LHsBinds GhcTc
tcg_binds = LHsBinds GhcTc
binds
, tcg_ev_binds :: TcGblEnv -> Bag EvBind
tcg_ev_binds = Bag EvBind
cur_ev_binds
, tcg_imp_specs :: TcGblEnv -> [LTcSpecPrag]
tcg_imp_specs = [LTcSpecPrag]
imp_specs
, tcg_rules :: TcGblEnv -> [LRuleDecl GhcTc]
tcg_rules = [LRuleDecl GhcTc]
rules
, tcg_fords :: TcGblEnv -> [LForeignDecl GhcTc]
tcg_fords = [LForeignDecl GhcTc]
fords })
= {-# SCC "zonkTopDecls" #-}
forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$
do { TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; let all_ev_binds :: Bag EvBind
all_ev_binds = Bag EvBind
cur_ev_binds forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag EvBind
ev_binds
; Bag EvBind
-> LHsBinds GhcTc
-> [LRuleDecl GhcTc]
-> [LTcSpecPrag]
-> [LForeignDecl GhcTc]
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
zonkTopDecls Bag EvBind
all_ev_binds LHsBinds GhcTc
binds [LRuleDecl GhcTc]
rules [LTcSpecPrag]
imp_specs [LForeignDecl GhcTc]
fords }
run_th_modfinalizers :: TcM (TcGblEnv, TcLclEnv)
run_th_modfinalizers :: TcM (TcGblEnv, TcLclEnv)
run_th_modfinalizers = do
TcRef [(TcLclEnv, ThModFinalizers)]
th_modfinalizers_var <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TcGblEnv -> TcRef [(TcLclEnv, ThModFinalizers)]
tcg_th_modfinalizers forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
[(TcLclEnv, ThModFinalizers)]
th_modfinalizers <- forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef TcRef [(TcLclEnv, ThModFinalizers)]
th_modfinalizers_var
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(TcLclEnv, ThModFinalizers)]
th_modfinalizers
then forall gbl lcl. TcRnIf gbl lcl (gbl, lcl)
getEnvs
else do
forall a gbl lcl. TcRef a -> a -> TcRnIf gbl lcl ()
writeTcRef TcRef [(TcLclEnv, ThModFinalizers)]
th_modfinalizers_var []
let run_finalizer :: (TcLclEnv, ThModFinalizers) -> TcRnIf TcGblEnv lcl ()
run_finalizer (TcLclEnv
lcl_env, ThModFinalizers
f) =
forall lcl' gbl a lcl.
lcl' -> TcRnIf gbl lcl' a -> TcRnIf gbl lcl a
setLclEnv TcLclEnv
lcl_env (ThModFinalizers -> TcRnIf TcGblEnv TcLclEnv ()
runRemoteModFinalizers ThModFinalizers
f)
(()
_, WantedConstraints
lie_th) <- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ forall {lcl}. (TcLclEnv, ThModFinalizers) -> TcRnIf TcGblEnv lcl ()
run_finalizer [(TcLclEnv, ThModFinalizers)]
th_modfinalizers
(TcGblEnv
tcg_env, TcLclEnv
tcl_env, WantedConstraints
lie_top_decls) <- [LHsDecl GhcPs] -> TcM (TcGblEnv, TcLclEnv, WantedConstraints)
tc_rn_src_decls []
forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
tcg_env, TcLclEnv
tcl_env) forall a b. (a -> b) -> a -> b
$ do
Bag EvBind
new_ev_binds <- {-# SCC "simplifyTop2" #-}
WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyTop (WantedConstraints
lie_th WantedConstraints -> WantedConstraints -> WantedConstraints
`andWC` WantedConstraints
lie_top_decls)
forall a. Bag EvBind -> TcM a -> TcM a
addTopEvBinds Bag EvBind
new_ev_binds TcM (TcGblEnv, TcLclEnv)
run_th_modfinalizers
tc_rn_src_decls :: [LHsDecl GhcPs]
-> TcM (TcGblEnv, TcLclEnv, WantedConstraints)
tc_rn_src_decls :: [LHsDecl GhcPs] -> TcM (TcGblEnv, TcLclEnv, WantedConstraints)
tc_rn_src_decls [LHsDecl GhcPs]
ds
= {-# SCC "tc_rn_src_decls" #-}
do { (HsGroup GhcPs
first_group, Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
group_tail) <- [LHsDecl GhcPs]
-> RnM (HsGroup GhcPs, Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs]))
findSplice [LHsDecl GhcPs]
ds
; (TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
rn_decls) <- HsGroup GhcPs -> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnTopSrcDecls HsGroup GhcPs
first_group
; TcRef [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_topdecls_var <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TcGblEnv -> TcRef [LHsDecl GhcPs]
tcg_th_topdecls forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_ds <- forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef TcRef [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_topdecls_var
; forall a gbl lcl. TcRef a -> a -> TcRnIf gbl lcl ()
writeTcRef TcRef [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_topdecls_var []
; (TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
rn_decls) <-
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_ds
then forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
rn_decls)
else do { (HsGroup GhcPs
th_group, Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
th_group_tail) <- [LHsDecl GhcPs]
-> RnM (HsGroup GhcPs, Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs]))
findSplice [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
th_ds
; case Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
th_group_tail of
{ Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
; Just (SpliceDecl XSpliceDecl GhcPs
_ (L SrcSpanAnnA
loc HsSplice GhcPs
_) SpliceExplicitFlag
_, [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
_) ->
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc
forall a b. (a -> b) -> a -> b
$ SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErr (String -> SDoc
text
(String
"Declaration splices are not "
forall a. [a] -> [a] -> [a]
++ String
"permitted inside top-level "
forall a. [a] -> [a] -> [a]
++ String
"declarations added with addTopDecls"))
}
; (TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
th_rn_decls) <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env
forall a b. (a -> b) -> a -> b
$ HsGroup GhcPs -> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnTopSrcDecls HsGroup GhcPs
th_group
; let msg :: String
msg = String
"top-level declarations added with addTopDecls"
; SpliceInfo -> TcRnIf TcGblEnv TcLclEnv ()
traceSplice
forall a b. (a -> b) -> a -> b
$ SpliceInfo { spliceDescription :: String
spliceDescription = String
msg
, spliceIsDecl :: Bool
spliceIsDecl = Bool
True
, spliceSource :: Maybe (LHsExpr (GhcPass 'Renamed))
spliceSource = forall a. Maybe a
Nothing
, spliceGenerated :: SDoc
spliceGenerated = forall a. Outputable a => a -> SDoc
ppr HsGroup (GhcPass 'Renamed)
th_rn_decls }
; forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env, forall (p :: Pass).
HsGroup (GhcPass p) -> HsGroup (GhcPass p) -> HsGroup (GhcPass p)
appendGroups HsGroup (GhcPass 'Renamed)
rn_decls HsGroup (GhcPass 'Renamed)
th_rn_decls)
}
; ((TcGblEnv
tcg_env, TcLclEnv
tcl_env), WantedConstraints
lie1) <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$
forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
HsGroup (GhcPass 'Renamed) -> TcM (TcGblEnv, TcLclEnv)
tcTopSrcDecls HsGroup (GhcPass 'Renamed)
rn_decls
; forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
tcg_env, TcLclEnv
tcl_env) forall a b. (a -> b) -> a -> b
$
case Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
group_tail of
{ Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env, TcLclEnv
tcl_env, WantedConstraints
lie1)
; Just (SpliceDecl XSpliceDecl GhcPs
_ (L SrcSpanAnnA
_ HsSplice GhcPs
splice) SpliceExplicitFlag
_, [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
rest_ds) ->
do {
; Bag EvBind
ev_binds1 <- WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyTop WantedConstraints
lie1
; ([GenLocated SrcSpanAnnA (HsDecl GhcPs)]
spliced_decls, FreeVars
splice_fvs) <- HsSplice GhcPs -> RnM ([LHsDecl GhcPs], FreeVars)
rnTopSpliceDecls HsSplice GhcPs
splice
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv (TcGblEnv
tcg_env TcGblEnv -> DefUses -> TcGblEnv
`addTcgDUs` FreeVars -> DefUses
usesOnly FreeVars
splice_fvs) forall a b. (a -> b) -> a -> b
$
forall a. Bag EvBind -> TcM a -> TcM a
addTopEvBinds Bag EvBind
ev_binds1 forall a b. (a -> b) -> a -> b
$
[LHsDecl GhcPs] -> TcM (TcGblEnv, TcLclEnv, WantedConstraints)
tc_rn_src_decls ([GenLocated SrcSpanAnnA (HsDecl GhcPs)]
spliced_decls forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
rest_ds)
}
}
}
tcRnHsBootDecls :: HscSource -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnHsBootDecls :: HscSource -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnHsBootDecls HscSource
hsc_src [LHsDecl GhcPs]
decls
= do { (HsGroup GhcPs
first_group, Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
group_tail) <- [LHsDecl GhcPs]
-> RnM (HsGroup GhcPs, Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs]))
findSplice [LHsDecl GhcPs]
decls
; (TcGblEnv
tcg_env, HsGroup { hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass 'Renamed)]
tycl_decls
, hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl (GhcPass 'Renamed)]
deriv_decls
, hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords = [LForeignDecl (GhcPass 'Renamed)]
for_decls
, hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds = [LDefaultDecl (GhcPass 'Renamed)]
def_decls
, hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds = [LRuleDecls (GhcPass 'Renamed)]
rule_decls
, hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds = [LAnnDecl (GhcPass 'Renamed)]
_
, hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds = XValBindsLR (NValBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds [LSig (GhcPass 'Renamed)]
val_sigs) })
<- HsGroup GhcPs -> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnTopSrcDecls HsGroup GhcPs
first_group
; (TcGblEnv
gbl_env, WantedConstraints
lie) <- forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$ forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$ do {
; case Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
group_tail of
Just (SpliceDecl XSpliceDecl GhcPs
_ XRec GhcPs (HsSplice GhcPs)
d SpliceExplicitFlag
_, [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
_) -> forall decl.
HscSource -> String -> LocatedA decl -> TcRnIf TcGblEnv TcLclEnv ()
badBootDecl HscSource
hsc_src String
"splice" XRec GhcPs (HsSplice GhcPs)
d
Maybe (SpliceDecl GhcPs, [GenLocated SrcSpanAnnA (HsDecl GhcPs)])
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall decl.
HscSource -> String -> LocatedA decl -> TcRnIf TcGblEnv TcLclEnv ()
badBootDecl HscSource
hsc_src String
"foreign") [LForeignDecl (GhcPass 'Renamed)]
for_decls
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall decl.
HscSource -> String -> LocatedA decl -> TcRnIf TcGblEnv TcLclEnv ()
badBootDecl HscSource
hsc_src String
"default") [LDefaultDecl (GhcPass 'Renamed)]
def_decls
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall decl.
HscSource -> String -> LocatedA decl -> TcRnIf TcGblEnv TcLclEnv ()
badBootDecl HscSource
hsc_src String
"rule") [LRuleDecls (GhcPass 'Renamed)]
rule_decls
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc2 (boot)" SDoc
empty
; (TcGblEnv
tcg_env, [InstInfo (GhcPass 'Renamed)]
inst_infos, HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
_deriv_binds)
<- [TyClGroup (GhcPass 'Renamed)]
-> [LDerivDecl (GhcPass 'Renamed)]
-> [(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> TcM
(TcGblEnv, [InstInfo (GhcPass 'Renamed)],
HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed))
tcTyClsInstDecls [TyClGroup (GhcPass 'Renamed)]
tycl_decls [LDerivDecl (GhcPass 'Renamed)]
deriv_decls [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$ do {
; TcGblEnv
tcg_env <- TcM TcGblEnv
mkTypeableBinds
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$ do {
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc5" SDoc
empty
; [Var]
val_ids <- [(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [LSig (GhcPass 'Renamed)] -> TcM [Var]
tcHsBootSigs [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds [LSig (GhcPass 'Renamed)]
val_sigs
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc7a" SDoc
empty
; TcGblEnv
gbl_env <- forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; let { type_env0 :: TypeEnv
type_env0 = TcGblEnv -> TypeEnv
tcg_type_env TcGblEnv
gbl_env
; type_env1 :: TypeEnv
type_env1 = TypeEnv -> [Var] -> TypeEnv
extendTypeEnvWithIds TypeEnv
type_env0 [Var]
val_ids
; type_env2 :: TypeEnv
type_env2 = TypeEnv -> [Var] -> TypeEnv
extendTypeEnvWithIds TypeEnv
type_env1 [Var]
dfun_ids
; dfun_ids :: [Var]
dfun_ids = forall a b. (a -> b) -> [a] -> [b]
map forall a. InstInfo a -> Var
iDFunId [InstInfo (GhcPass 'Renamed)]
inst_infos
}
; TcGblEnv -> TypeEnv -> TcM TcGblEnv
setGlobalTypeEnv TcGblEnv
gbl_env TypeEnv
type_env2
}}}
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"boot" (forall a. Outputable a => a -> SDoc
ppr WantedConstraints
lie); forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
gbl_env }
badBootDecl :: HscSource -> String -> LocatedA decl -> TcM ()
badBootDecl :: forall decl.
HscSource -> String -> LocatedA decl -> TcRnIf TcGblEnv TcLclEnv ()
badBootDecl HscSource
hsc_src String
what (L SrcSpanAnnA
loc decl
_)
= SrcSpan -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrAt (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (Char -> SDoc
char Char
'A' SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
what
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"declaration is not (currently) allowed in a"
SDoc -> SDoc -> SDoc
<+> (case HscSource
hsc_src of
HscSource
HsBootFile -> String -> SDoc
text String
"hs-boot"
HscSource
HsigFile -> String -> SDoc
text String
"hsig"
HscSource
_ -> forall a. String -> a
panic String
"badBootDecl: should be an hsig or hs-boot file")
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"file")
checkHiBootIface :: TcGblEnv -> SelfBootInfo -> TcM TcGblEnv
checkHiBootIface :: TcGblEnv -> SelfBootInfo -> TcM TcGblEnv
checkHiBootIface TcGblEnv
tcg_env SelfBootInfo
boot_info
| SelfBootInfo
NoSelfBoot <- SelfBootInfo
boot_info
= forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env
| HscSource
HsBootFile <- TcGblEnv -> HscSource
tcg_src TcGblEnv
tcg_env
= forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env
| SelfBoot { sb_mds :: SelfBootInfo -> ModDetails
sb_mds = ModDetails
boot_details } <- SelfBootInfo
boot_info
, TcGblEnv { tcg_binds :: TcGblEnv -> LHsBinds GhcTc
tcg_binds = LHsBinds GhcTc
binds
, tcg_insts :: TcGblEnv -> [ClsInst]
tcg_insts = [ClsInst]
local_insts
, tcg_type_env :: TcGblEnv -> TypeEnv
tcg_type_env = TypeEnv
local_type_env
, tcg_exports :: TcGblEnv -> [AvailInfo]
tcg_exports = [AvailInfo]
local_exports } <- TcGblEnv
tcg_env
= do {
; [(Var, Var)]
dfun_prs <- [ClsInst]
-> TypeEnv -> [AvailInfo] -> ModDetails -> TcM [(Var, Var)]
checkHiBootIface' [ClsInst]
local_insts TypeEnv
local_type_env
[AvailInfo]
local_exports ModDetails
boot_details
; let boot_dfuns :: [Var]
boot_dfuns = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Var, Var)]
dfun_prs
type_env' :: TypeEnv
type_env' = TypeEnv -> [Var] -> TypeEnv
extendTypeEnvWithIds TypeEnv
local_type_env [Var]
boot_dfuns
dfun_binds :: Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
dfun_binds = forall a. [a] -> Bag a
listToBag [ forall (p :: Pass).
IdP (GhcPass p) -> LHsExpr (GhcPass p) -> LHsBind (GhcPass p)
mkVarBind Var
boot_dfun (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Var
dfun)
| (Var
boot_dfun, Var
dfun) <- [(Var, Var)]
dfun_prs ]
tcg_env_w_binds :: TcGblEnv
tcg_env_w_binds
= TcGblEnv
tcg_env { tcg_binds :: LHsBinds GhcTc
tcg_binds = LHsBinds GhcTc
binds forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
dfun_binds }
; TypeEnv
type_env' seq :: forall a b. a -> b -> b
`seq`
TcGblEnv -> TypeEnv -> TcM TcGblEnv
setGlobalTypeEnv TcGblEnv
tcg_env_w_binds TypeEnv
type_env' }
#if __GLASGOW_HASKELL__ <= 810
| otherwise = panic "checkHiBootIface: unreachable code"
#endif
checkHiBootIface' :: [ClsInst] -> TypeEnv -> [AvailInfo]
-> ModDetails -> TcM [(Id, Id)]
checkHiBootIface' :: [ClsInst]
-> TypeEnv -> [AvailInfo] -> ModDetails -> TcM [(Var, Var)]
checkHiBootIface'
[ClsInst]
local_insts TypeEnv
local_type_env [AvailInfo]
local_exports
(ModDetails { md_types :: ModDetails -> TypeEnv
md_types = TypeEnv
boot_type_env
, md_fam_insts :: ModDetails -> [FamInst]
md_fam_insts = [FamInst]
boot_fam_insts
, md_exports :: ModDetails -> [AvailInfo]
md_exports = [AvailInfo]
boot_exports })
= do { String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"checkHiBootIface" forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ forall a. Outputable a => a -> SDoc
ppr TypeEnv
boot_type_env, forall a. Outputable a => a -> SDoc
ppr [AvailInfo]
boot_exports]
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ AvailInfo -> TcRnIf TcGblEnv TcLclEnv ()
check_export [AvailInfo]
boot_exports
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FamInst]
boot_fam_insts) forall a b. (a -> b) -> a -> b
$
forall a. String -> a
panic (String
"GHC.Tc.Module.checkHiBootIface: Cannot handle family " forall a. [a] -> [a] -> [a]
++
String
"instances in boot files yet...")
; [Maybe (Var, Var)]
mb_dfun_prs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Var -> TcM (Maybe (Var, Var))
check_cls_inst [Var]
boot_dfuns
; TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. [Maybe a] -> [a]
catMaybes [Maybe (Var, Var)]
mb_dfun_prs) }
where
boot_dfun_names :: [Name]
boot_dfun_names = forall a b. (a -> b) -> [a] -> [b]
map Var -> Name
idName [Var]
boot_dfuns
boot_dfuns :: [Var]
boot_dfuns = forall a. (a -> Bool) -> [a] -> [a]
filter Var -> Bool
isDFunId forall a b. (a -> b) -> a -> b
$ TypeEnv -> [Var]
typeEnvIds TypeEnv
boot_type_env
check_export :: AvailInfo -> TcRnIf TcGblEnv TcLclEnv ()
check_export AvailInfo
boot_avail
| Name
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
boot_dfun_names = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Name -> Bool
isWiredInName Name
name = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
missing_names)
= SrcSpan -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrAt (Name -> SrcSpan
nameSrcSpan (forall a. [a] -> a
head [Name]
missing_names))
(Bool -> Name -> String -> SDoc
missingBootThing Bool
True (forall a. [a] -> a
head [Name]
missing_names) String
"exported by")
| forall a. Maybe a -> Bool
isNothing Maybe TyThing
mb_boot_thing = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Just TyThing
real_thing <- TypeEnv -> Name -> Maybe TyThing
lookupTypeEnv TypeEnv
local_type_env Name
name,
Just TyThing
boot_thing <- Maybe TyThing
mb_boot_thing
= Bool -> TyThing -> TyThing -> TcRnIf TcGblEnv TcLclEnv ()
checkBootDeclM Bool
True TyThing
boot_thing TyThing
real_thing
| Bool
otherwise
= SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrTc (Bool -> Name -> String -> SDoc
missingBootThing Bool
True Name
name String
"defined in")
where
name :: Name
name = AvailInfo -> Name
availName AvailInfo
boot_avail
mb_boot_thing :: Maybe TyThing
mb_boot_thing = TypeEnv -> Name -> Maybe TyThing
lookupTypeEnv TypeEnv
boot_type_env Name
name
missing_names :: [Name]
missing_names = case forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv AvailInfo
local_export_env Name
name of
Maybe AvailInfo
Nothing -> [Name
name]
Just AvailInfo
avail -> AvailInfo -> [Name]
availNames AvailInfo
boot_avail forall a. Ord a => [a] -> [a] -> [a]
`minusList` AvailInfo -> [Name]
availNames AvailInfo
avail
local_export_env :: NameEnv AvailInfo
local_export_env :: NameEnv AvailInfo
local_export_env = [AvailInfo] -> NameEnv AvailInfo
availsToNameEnv [AvailInfo]
local_exports
check_cls_inst :: DFunId -> TcM (Maybe (Id, Id))
check_cls_inst :: Var -> TcM (Maybe (Var, Var))
check_cls_inst Var
boot_dfun
| (Var
real_dfun : [Var]
_) <- Var -> [Var]
find_real_dfun Var
boot_dfun
, let local_boot_dfun :: Var
local_boot_dfun = Name -> Type -> Var
Id.mkExportedVanillaId
(Var -> Name
idName Var
boot_dfun) (Var -> Type
idType Var
real_dfun)
= forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just (Var
local_boot_dfun, Var
real_dfun))
| Bool
otherwise
= forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (Name -> SrcSpan
nameSrcSpan (forall a. NamedThing a => a -> Name
getName Var
boot_dfun)) forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"check_cls_inst" forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ String -> SDoc
text String
"local_insts" SDoc -> SDoc -> SDoc
<+>
[SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Type
idType forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClsInst -> Var
instanceDFunId) [ClsInst]
local_insts)
, String -> SDoc
text String
"boot_dfun_ty" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (Var -> Type
idType Var
boot_dfun) ]
; SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrTc (Var -> SDoc
instMisMatch Var
boot_dfun)
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing }
find_real_dfun :: DFunId -> [DFunId]
find_real_dfun :: Var -> [Var]
find_real_dfun Var
boot_dfun
= [Var
dfun | ClsInst
inst <- [ClsInst]
local_insts
, let dfun :: Var
dfun = ClsInst -> Var
instanceDFunId ClsInst
inst
, Var -> Type
idType Var
dfun Type -> Type -> Bool
`eqType` Type
boot_dfun_ty ]
where
boot_dfun_ty :: Type
boot_dfun_ty = Var -> Type
idType Var
boot_dfun
checkBootDeclM :: Bool
-> TyThing -> TyThing -> TcM ()
checkBootDeclM :: Bool -> TyThing -> TyThing -> TcRnIf TcGblEnv TcLclEnv ()
checkBootDeclM Bool
is_boot TyThing
boot_thing TyThing
real_thing
= forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenIsJust (Bool -> TyThing -> TyThing -> Maybe SDoc
checkBootDecl Bool
is_boot TyThing
boot_thing TyThing
real_thing) forall a b. (a -> b) -> a -> b
$ \ SDoc
err ->
SrcSpan -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrAt SrcSpan
span
(Bool -> SDoc -> TyThing -> TyThing -> SDoc
bootMisMatch Bool
is_boot SDoc
err TyThing
real_thing TyThing
boot_thing)
where
span :: SrcSpan
span
| let span :: SrcSpan
span = Name -> SrcSpan
nameSrcSpan (forall a. NamedThing a => a -> Name
getName TyThing
boot_thing)
, SrcSpan -> Bool
isGoodSrcSpan SrcSpan
span
= SrcSpan
span
| Bool
otherwise
= Name -> SrcSpan
nameSrcSpan (forall a. NamedThing a => a -> Name
getName TyThing
real_thing)
checkBootDecl :: Bool -> TyThing -> TyThing -> Maybe SDoc
checkBootDecl :: Bool -> TyThing -> TyThing -> Maybe SDoc
checkBootDecl Bool
_ (AnId Var
id1) (AnId Var
id2)
= ASSERT(id1 == id2)
Bool -> SDoc -> Maybe SDoc
check (Var -> Type
idType Var
id1 Type -> Type -> Bool
`eqType` Var -> Type
idType Var
id2)
(String -> SDoc
text String
"The two types are different")
checkBootDecl Bool
is_boot (ATyCon TyCon
tc1) (ATyCon TyCon
tc2)
= Bool -> TyCon -> TyCon -> Maybe SDoc
checkBootTyCon Bool
is_boot TyCon
tc1 TyCon
tc2
checkBootDecl Bool
_ (AConLike (RealDataCon DataCon
dc1)) (AConLike (RealDataCon DataCon
_))
= forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"checkBootDecl" (forall a. Outputable a => a -> SDoc
ppr DataCon
dc1)
checkBootDecl Bool
_ TyThing
_ TyThing
_ = forall a. a -> Maybe a
Just SDoc
empty
andThenCheck :: Maybe SDoc -> Maybe SDoc -> Maybe SDoc
Maybe SDoc
Nothing andThenCheck :: Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck` Maybe SDoc
msg = Maybe SDoc
msg
Maybe SDoc
msg `andThenCheck` Maybe SDoc
Nothing = Maybe SDoc
msg
Just SDoc
d1 `andThenCheck` Just SDoc
d2 = forall a. a -> Maybe a
Just (SDoc
d1 SDoc -> SDoc -> SDoc
$$ SDoc
d2)
infixr 0 `andThenCheck`
checkUnless :: Bool -> Maybe SDoc -> Maybe SDoc
checkUnless :: Bool -> Maybe SDoc -> Maybe SDoc
checkUnless Bool
True Maybe SDoc
_ = forall a. Maybe a
Nothing
checkUnless Bool
False Maybe SDoc
k = Maybe SDoc
k
checkListBy :: (a -> a -> Maybe SDoc) -> [a] -> [a] -> SDoc
-> Maybe SDoc
checkListBy :: forall a.
(a -> a -> Maybe SDoc) -> [a] -> [a] -> SDoc -> Maybe SDoc
checkListBy a -> a -> Maybe SDoc
check_fun [a]
as [a]
bs SDoc
whats = [SDoc] -> [a] -> [a] -> Maybe SDoc
go [] [a]
as [a]
bs
where
herald :: SDoc
herald = String -> SDoc
text String
"The" SDoc -> SDoc -> SDoc
<+> SDoc
whats SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"do not match"
go :: [SDoc] -> [a] -> [a] -> Maybe SDoc
go [] [] [] = forall a. Maybe a
Nothing
go [SDoc]
docs [] [] = forall a. a -> Maybe a
Just (SDoc -> Arity -> SDoc -> SDoc
hang (SDoc
herald SDoc -> SDoc -> SDoc
<> SDoc
colon) Arity
2 ([SDoc] -> SDoc
vcat forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse [SDoc]
docs))
go [SDoc]
docs (a
x:[a]
xs) (a
y:[a]
ys) = case a -> a -> Maybe SDoc
check_fun a
x a
y of
Just SDoc
doc -> [SDoc] -> [a] -> [a] -> Maybe SDoc
go (SDoc
docforall a. a -> [a] -> [a]
:[SDoc]
docs) [a]
xs [a]
ys
Maybe SDoc
Nothing -> [SDoc] -> [a] -> [a] -> Maybe SDoc
go [SDoc]
docs [a]
xs [a]
ys
go [SDoc]
_ [a]
_ [a]
_ = forall a. a -> Maybe a
Just (SDoc -> Arity -> SDoc -> SDoc
hang (SDoc
herald SDoc -> SDoc -> SDoc
<> SDoc
colon)
Arity
2 (String -> SDoc
text String
"There are different numbers of" SDoc -> SDoc -> SDoc
<+> SDoc
whats))
check :: Bool -> SDoc -> Maybe SDoc
check :: Bool -> SDoc -> Maybe SDoc
check Bool
True SDoc
_ = forall a. Maybe a
Nothing
check Bool
False SDoc
doc = forall a. a -> Maybe a
Just SDoc
doc
checkSuccess :: Maybe SDoc
checkSuccess :: Maybe SDoc
checkSuccess = forall a. Maybe a
Nothing
checkBootTyCon :: Bool -> TyCon -> TyCon -> Maybe SDoc
checkBootTyCon :: Bool -> TyCon -> TyCon -> Maybe SDoc
checkBootTyCon Bool
is_boot TyCon
tc1 TyCon
tc2
| Bool -> Bool
not (Type -> Type -> Bool
eqType (TyCon -> Type
tyConKind TyCon
tc1) (TyCon -> Type
tyConKind TyCon
tc2))
= forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> SDoc
text String
"The types have different kinds"
| Just Class
c1 <- TyCon -> Maybe Class
tyConClass_maybe TyCon
tc1
, Just Class
c2 <- TyCon -> Maybe Class
tyConClass_maybe TyCon
tc2
, let ([Var]
clas_tvs1, [FunDep Var]
clas_fds1, [Type]
sc_theta1, [Var]
_, [ClassATItem]
ats1, [ClassOpItem]
op_stuff1)
= Class
-> ([Var], [FunDep Var], [Type], [Var], [ClassATItem],
[ClassOpItem])
classExtraBigSig Class
c1
([Var]
clas_tvs2, [FunDep Var]
clas_fds2, [Type]
sc_theta2, [Var]
_, [ClassATItem]
ats2, [ClassOpItem]
op_stuff2)
= Class
-> ([Var], [FunDep Var], [Type], [Var], [ClassATItem],
[ClassOpItem])
classExtraBigSig Class
c2
, Just RnEnv2
env <- RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
eqVarBndrs RnEnv2
emptyRnEnv2 [Var]
clas_tvs1 [Var]
clas_tvs2
= let
eqSig :: ClassOpItem -> ClassOpItem -> Maybe SDoc
eqSig (Var
id1, Maybe (Name, DefMethSpec Type)
def_meth1) (Var
id2, Maybe (Name, DefMethSpec Type)
def_meth2)
= Bool -> SDoc -> Maybe SDoc
check (Name
name1 forall a. Eq a => a -> a -> Bool
== Name
name2)
(String -> SDoc
text String
"The names" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"and" SDoc -> SDoc -> SDoc
<+> SDoc
pname2 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"are different") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
op_ty1 Type
op_ty2)
(String -> SDoc
text String
"The types of" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"are different") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
if Bool
is_boot
then Bool -> SDoc -> Maybe SDoc
check (forall a. (a -> a -> Bool) -> Maybe a -> Maybe a -> Bool
eqMaybeBy (Name, DefMethSpec Type) -> (Name, DefMethSpec Type) -> Bool
eqDM Maybe (Name, DefMethSpec Type)
def_meth1 Maybe (Name, DefMethSpec Type)
def_meth2)
(String -> SDoc
text String
"The default methods associated with" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"are different")
else Bool -> SDoc -> Maybe SDoc
check (Type
-> Maybe (Name, DefMethSpec Type)
-> Maybe (Name, DefMethSpec Type)
-> Bool
subDM Type
op_ty1 Maybe (Name, DefMethSpec Type)
def_meth1 Maybe (Name, DefMethSpec Type)
def_meth2)
(String -> SDoc
text String
"The default methods associated with" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"are not compatible")
where
name1 :: Name
name1 = Var -> Name
idName Var
id1
name2 :: Name
name2 = Var -> Name
idName Var
id2
pname1 :: SDoc
pname1 = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name1)
pname2 :: SDoc
pname2 = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name2)
op_ty1 :: Type
op_ty1 = Var -> Type
classMethodTy Var
id1
op_ty2 :: Type
op_ty2 = Var -> Type
classMethodTy Var
id2
eqAT :: ClassATItem -> ClassATItem -> Maybe SDoc
eqAT (ATI TyCon
tc1 Maybe (Type, ATValidityInfo)
def_ats1) (ATI TyCon
tc2 Maybe (Type, ATValidityInfo)
def_ats2)
= Bool -> TyCon -> TyCon -> Maybe SDoc
checkBootTyCon Bool
is_boot TyCon
tc1 TyCon
tc2 Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (Maybe (Type, ATValidityInfo)
-> Maybe (Type, ATValidityInfo) -> Bool
eqATDef Maybe (Type, ATValidityInfo)
def_ats1 Maybe (Type, ATValidityInfo)
def_ats2)
(String -> SDoc
text String
"The associated type defaults differ")
eqDM :: (Name, DefMethSpec Type) -> (Name, DefMethSpec Type) -> Bool
eqDM (Name
_, DefMethSpec Type
VanillaDM) (Name
_, DefMethSpec Type
VanillaDM) = Bool
True
eqDM (Name
_, GenericDM Type
t1) (Name
_, GenericDM Type
t2) = RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
t1 Type
t2
eqDM (Name, DefMethSpec Type)
_ (Name, DefMethSpec Type)
_ = Bool
False
subDM :: Type
-> Maybe (Name, DefMethSpec Type)
-> Maybe (Name, DefMethSpec Type)
-> Bool
subDM Type
_ Maybe (Name, DefMethSpec Type)
Nothing Maybe (Name, DefMethSpec Type)
_ = Bool
True
subDM Type
_ Maybe (Name, DefMethSpec Type)
_ Maybe (Name, DefMethSpec Type)
Nothing = Bool
False
subDM Type
t1 (Just (Name
_, GenericDM Type
t2)) (Just (Name
_, DefMethSpec Type
VanillaDM))
= RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
t1 Type
t2
subDM Type
t1 (Just (Name
_, DefMethSpec Type
VanillaDM)) (Just (Name
_, GenericDM Type
t2))
= RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
t1 Type
t2
subDM Type
_ (Just (Name
_, DefMethSpec Type
VanillaDM)) (Just (Name
_, DefMethSpec Type
VanillaDM)) = Bool
True
subDM Type
_ (Just (Name
_, GenericDM Type
t1)) (Just (Name
_, GenericDM Type
t2))
= RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
t1 Type
t2
eqATDef :: Maybe (Type, ATValidityInfo)
-> Maybe (Type, ATValidityInfo) -> Bool
eqATDef Maybe (Type, ATValidityInfo)
Nothing Maybe (Type, ATValidityInfo)
Nothing = Bool
True
eqATDef (Just (Type
ty1, ATValidityInfo
_loc1)) (Just (Type
ty2, ATValidityInfo
_loc2)) = RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
ty1 Type
ty2
eqATDef Maybe (Type, ATValidityInfo)
_ Maybe (Type, ATValidityInfo)
_ = Bool
False
eqFD :: FunDep Var -> FunDep Var -> Bool
eqFD ([Var]
as1,[Var]
bs1) ([Var]
as2,[Var]
bs2) =
forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env) ([Var] -> [Type]
mkTyVarTys [Var]
as1) ([Var] -> [Type]
mkTyVarTys [Var]
as2) Bool -> Bool -> Bool
&&
forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env) ([Var] -> [Type]
mkTyVarTys [Var]
bs1) ([Var] -> [Type]
mkTyVarTys [Var]
bs2)
in
[Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
roles1 [Role]
roles2 Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy FunDep Var -> FunDep Var -> Bool
eqFD [FunDep Var]
clas_fds1 [FunDep Var]
clas_fds2)
(String -> SDoc
text String
"The functional dependencies do not match") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> Maybe SDoc -> Maybe SDoc
checkUnless (TyCon -> Bool
isAbstractTyCon TyCon
tc1) forall a b. (a -> b) -> a -> b
$
Bool -> SDoc -> Maybe SDoc
check (forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env) [Type]
sc_theta1 [Type]
sc_theta2)
(String -> SDoc
text String
"The class constraints do not match") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
forall a.
(a -> a -> Maybe SDoc) -> [a] -> [a] -> SDoc -> Maybe SDoc
checkListBy ClassOpItem -> ClassOpItem -> Maybe SDoc
eqSig [ClassOpItem]
op_stuff1 [ClassOpItem]
op_stuff2 (String -> SDoc
text String
"methods") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
forall a.
(a -> a -> Maybe SDoc) -> [a] -> [a] -> SDoc -> Maybe SDoc
checkListBy ClassATItem -> ClassATItem -> Maybe SDoc
eqAT [ClassATItem]
ats1 [ClassATItem]
ats2 (String -> SDoc
text String
"associated types") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (Class -> ClassMinimalDef
classMinimalDef Class
c1 forall a.
Uniquable a =>
BooleanFormula a -> BooleanFormula a -> Bool
`BF.implies` Class -> ClassMinimalDef
classMinimalDef Class
c2)
(String -> SDoc
text String
"The MINIMAL pragmas are not compatible")
| Just Type
syn_rhs1 <- TyCon -> DFunInstType
synTyConRhs_maybe TyCon
tc1
, Just Type
syn_rhs2 <- TyCon -> DFunInstType
synTyConRhs_maybe TyCon
tc2
, Just RnEnv2
env <- RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
eqVarBndrs RnEnv2
emptyRnEnv2 (TyCon -> [Var]
tyConTyVars TyCon
tc1) (TyCon -> [Var]
tyConTyVars TyCon
tc2)
= ASSERT(tc1 == tc2)
[Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
roles1 [Role]
roles2 Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
syn_rhs1 Type
syn_rhs2) SDoc
empty
| Bool -> Bool
not Bool
is_boot
, TyCon -> Bool
isAbstractTyCon TyCon
tc1
, Just ([Var]
tvs, Type
ty) <- TyCon -> Maybe ([Var], Type)
synTyConDefn_maybe TyCon
tc2
, Just (TyCon
tc2', [Type]
args) <- HasCallStack => Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
ty
= [Var] -> Type -> TyCon -> [Type] -> Maybe SDoc
checkSynAbsData [Var]
tvs Type
ty TyCon
tc2' [Type]
args
| Bool -> Bool
not Bool
is_boot
, TyCon -> Bool
isAbstractTyCon TyCon
tc1
, Just ([Var]
_,Type
ty2) <- TyCon -> Maybe ([Var], Type)
synTyConDefn_maybe TyCon
tc2
, forall a. Maybe a -> Bool
isJust (Type -> Maybe TyLit
isLitTy Type
ty2)
= forall a. Maybe a
Nothing
| Just FamTyConFlav
fam_flav1 <- TyCon -> Maybe FamTyConFlav
famTyConFlav_maybe TyCon
tc1
, Just FamTyConFlav
fam_flav2 <- TyCon -> Maybe FamTyConFlav
famTyConFlav_maybe TyCon
tc2
= ASSERT(tc1 == tc2)
let eqFamFlav :: FamTyConFlav -> FamTyConFlav -> Bool
eqFamFlav FamTyConFlav
OpenSynFamilyTyCon FamTyConFlav
OpenSynFamilyTyCon = Bool
True
eqFamFlav (DataFamilyTyCon {}) (DataFamilyTyCon {}) = Bool
True
eqFamFlav FamTyConFlav
AbstractClosedSynFamilyTyCon FamTyConFlav
AbstractClosedSynFamilyTyCon = Bool
True
eqFamFlav FamTyConFlav
AbstractClosedSynFamilyTyCon (ClosedSynFamilyTyCon {}) = Bool
True
eqFamFlav (ClosedSynFamilyTyCon {}) FamTyConFlav
AbstractClosedSynFamilyTyCon = Bool
True
eqFamFlav (ClosedSynFamilyTyCon Maybe (CoAxiom Branched)
ax1) (ClosedSynFamilyTyCon Maybe (CoAxiom Branched)
ax2)
= forall {br :: BranchFlag} {br :: BranchFlag}.
Maybe (CoAxiom br) -> Maybe (CoAxiom br) -> Bool
eqClosedFamilyAx Maybe (CoAxiom Branched)
ax1 Maybe (CoAxiom Branched)
ax2
eqFamFlav (BuiltInSynFamTyCon {}) (BuiltInSynFamTyCon {}) = TyCon
tc1 forall a. Eq a => a -> a -> Bool
== TyCon
tc2
eqFamFlav FamTyConFlav
_ FamTyConFlav
_ = Bool
False
injInfo1 :: Injectivity
injInfo1 = TyCon -> Injectivity
tyConInjectivityInfo TyCon
tc1
injInfo2 :: Injectivity
injInfo2 = TyCon -> Injectivity
tyConInjectivityInfo TyCon
tc2
in
[Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
roles1 [Role]
roles2 Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (FamTyConFlav -> FamTyConFlav -> Bool
eqFamFlav FamTyConFlav
fam_flav1 FamTyConFlav
fam_flav2)
(SDoc -> SDoc
whenPprDebug forall a b. (a -> b) -> a -> b
$
String -> SDoc
text String
"Family flavours" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr FamTyConFlav
fam_flav1 SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"and" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr FamTyConFlav
fam_flav2 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"do not match") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (Injectivity
injInfo1 forall a. Eq a => a -> a -> Bool
== Injectivity
injInfo2) (String -> SDoc
text String
"Injectivities do not match")
| TyCon -> Bool
isAlgTyCon TyCon
tc1 Bool -> Bool -> Bool
&& TyCon -> Bool
isAlgTyCon TyCon
tc2
, Just RnEnv2
env <- RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
eqVarBndrs RnEnv2
emptyRnEnv2 (TyCon -> [Var]
tyConTyVars TyCon
tc1) (TyCon -> [Var]
tyConTyVars TyCon
tc2)
= ASSERT(tc1 == tc2)
[Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
roles1 [Role]
roles2 Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env)
(TyCon -> [Type]
tyConStupidTheta TyCon
tc1) (TyCon -> [Type]
tyConStupidTheta TyCon
tc2))
(String -> SDoc
text String
"The datatype contexts do not match") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
forall {p}. p -> AlgTyConRhs -> AlgTyConRhs -> Maybe SDoc
eqAlgRhs TyCon
tc1 (TyCon -> AlgTyConRhs
algTyConRhs TyCon
tc1) (TyCon -> AlgTyConRhs
algTyConRhs TyCon
tc2)
| Bool
otherwise = forall a. a -> Maybe a
Just SDoc
empty
where
roles1 :: [Role]
roles1 = TyCon -> [Role]
tyConRoles TyCon
tc1
roles2 :: [Role]
roles2 = TyCon -> [Role]
tyConRoles TyCon
tc2
roles_msg :: SDoc
roles_msg = String -> SDoc
text String
"The roles do not match." SDoc -> SDoc -> SDoc
$$
(String -> SDoc
text String
"Roles on abstract types default to" SDoc -> SDoc -> SDoc
<+>
SDoc -> SDoc
quotes (String -> SDoc
text String
"representational") SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"in boot files.")
roles_subtype_msg :: SDoc
roles_subtype_msg = String -> SDoc
text String
"The roles are not compatible:" SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"Main module:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [Role]
roles2 SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"Hsig file:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [Role]
roles1
checkRoles :: [Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
r1 [Role]
r2
| Bool
is_boot Bool -> Bool -> Bool
|| TyCon -> Role -> Bool
isInjectiveTyCon TyCon
tc1 Role
Representational
= Bool -> SDoc -> Maybe SDoc
check ([Role]
r1 forall a. Eq a => a -> a -> Bool
== [Role]
r2) SDoc
roles_msg
| Bool
otherwise = Bool -> SDoc -> Maybe SDoc
check ([Role]
r2 forall {a}. Ord a => [a] -> [a] -> Bool
`rolesSubtypeOf` [Role]
r1) SDoc
roles_subtype_msg
rolesSubtypeOf :: [a] -> [a] -> Bool
rolesSubtypeOf [] [] = Bool
True
rolesSubtypeOf (a
x:[a]
xs) (a
y:[a]
ys) = a
x forall a. Ord a => a -> a -> Bool
>= a
y Bool -> Bool -> Bool
&& [a] -> [a] -> Bool
rolesSubtypeOf [a]
xs [a]
ys
rolesSubtypeOf [a]
_ [a]
_ = Bool
False
checkSynAbsData :: [TyVar] -> Type -> TyCon -> [Type] -> Maybe SDoc
checkSynAbsData :: [Var] -> Type -> TyCon -> [Type] -> Maybe SDoc
checkSynAbsData [Var]
tvs Type
ty TyCon
tc2' [Type]
args =
Bool -> SDoc -> Maybe SDoc
check (forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Type -> [(TyCon, [Type])]
tcTyFamInsts Type
ty))
(String -> SDoc
text String
"Illegal type family application in implementation of abstract data.")
Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Var]
tvs)
(String -> SDoc
text String
"Illegal parameterized type synonym in implementation of abstract data." SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"(Try eta reducing your type synonym so that it is nullary.)")
Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> Maybe SDoc -> Maybe SDoc
checkUnless (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Var]
tvs)) forall a b. (a -> b) -> a -> b
$
ASSERT( null roles2 )
[Role] -> [Role] -> Maybe SDoc
checkRoles [Role]
roles1 (forall a. Arity -> [a] -> [a]
drop (forall (t :: * -> *) a. Foldable t => t a -> Arity
length [Type]
args) (TyCon -> [Role]
tyConRoles TyCon
tc2'))
eqAlgRhs :: p -> AlgTyConRhs -> AlgTyConRhs -> Maybe SDoc
eqAlgRhs p
_ AlgTyConRhs
AbstractTyCon AlgTyConRhs
_rhs2
= Maybe SDoc
checkSuccess
eqAlgRhs p
_ tc1 :: AlgTyConRhs
tc1@DataTyCon{} tc2 :: AlgTyConRhs
tc2@DataTyCon{} =
forall a.
(a -> a -> Maybe SDoc) -> [a] -> [a] -> SDoc -> Maybe SDoc
checkListBy DataCon -> DataCon -> Maybe SDoc
eqCon (AlgTyConRhs -> [DataCon]
data_cons AlgTyConRhs
tc1) (AlgTyConRhs -> [DataCon]
data_cons AlgTyConRhs
tc2) (String -> SDoc
text String
"constructors")
eqAlgRhs p
_ tc1 :: AlgTyConRhs
tc1@NewTyCon{} tc2 :: AlgTyConRhs
tc2@NewTyCon{} =
DataCon -> DataCon -> Maybe SDoc
eqCon (AlgTyConRhs -> DataCon
data_con AlgTyConRhs
tc1) (AlgTyConRhs -> DataCon
data_con AlgTyConRhs
tc2)
eqAlgRhs p
_ AlgTyConRhs
_ AlgTyConRhs
_ = forall a. a -> Maybe a
Just (String -> SDoc
text String
"Cannot match a" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"data") SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"definition with a" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (String -> SDoc
text String
"newtype") SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"definition")
eqCon :: DataCon -> DataCon -> Maybe SDoc
eqCon DataCon
c1 DataCon
c2
= Bool -> SDoc -> Maybe SDoc
check (Name
name1 forall a. Eq a => a -> a -> Bool
== Name
name2)
(String -> SDoc
text String
"The names" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"and" SDoc -> SDoc -> SDoc
<+> SDoc
pname2 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"differ") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (DataCon -> Bool
dataConIsInfix DataCon
c1 forall a. Eq a => a -> a -> Bool
== DataCon -> Bool
dataConIsInfix DataCon
c2)
(String -> SDoc
text String
"The fixities of" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"differ") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy HsImplBang -> HsImplBang -> Bool
eqHsBang (DataCon -> [HsImplBang]
dataConImplBangs DataCon
c1) (DataCon -> [HsImplBang]
dataConImplBangs DataCon
c2))
(String -> SDoc
text String
"The strictness annotations for" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"differ") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> Name
flSelector (DataCon -> [FieldLabel]
dataConFieldLabels DataCon
c1) forall a. Eq a => a -> a -> Bool
== forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> Name
flSelector (DataCon -> [FieldLabel]
dataConFieldLabels DataCon
c2))
(String -> SDoc
text String
"The record label lists for" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"differ") Maybe SDoc -> Maybe SDoc -> Maybe SDoc
`andThenCheck`
Bool -> SDoc -> Maybe SDoc
check (Type -> Type -> Bool
eqType (DataCon -> Type
dataConWrapperType DataCon
c1) (DataCon -> Type
dataConWrapperType DataCon
c2))
(String -> SDoc
text String
"The types for" SDoc -> SDoc -> SDoc
<+> SDoc
pname1 SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"differ")
where
name1 :: Name
name1 = DataCon -> Name
dataConName DataCon
c1
name2 :: Name
name2 = DataCon -> Name
dataConName DataCon
c2
pname1 :: SDoc
pname1 = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name1)
pname2 :: SDoc
pname2 = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name2)
eqClosedFamilyAx :: Maybe (CoAxiom br) -> Maybe (CoAxiom br) -> Bool
eqClosedFamilyAx Maybe (CoAxiom br)
Nothing Maybe (CoAxiom br)
Nothing = Bool
True
eqClosedFamilyAx Maybe (CoAxiom br)
Nothing (Just CoAxiom br
_) = Bool
False
eqClosedFamilyAx (Just CoAxiom br
_) Maybe (CoAxiom br)
Nothing = Bool
False
eqClosedFamilyAx (Just (CoAxiom { co_ax_branches :: forall (br :: BranchFlag). CoAxiom br -> Branches br
co_ax_branches = Branches br
branches1 }))
(Just (CoAxiom { co_ax_branches :: forall (br :: BranchFlag). CoAxiom br -> Branches br
co_ax_branches = Branches br
branches2 }))
= forall (br :: BranchFlag). Branches br -> Arity
numBranches Branches br
branches1 forall a. Eq a => a -> a -> Bool
== forall (br :: BranchFlag). Branches br -> Arity
numBranches Branches br
branches2
Bool -> Bool -> Bool
&& (forall (t :: * -> *). Foldable t => t Bool -> Bool
and forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith CoAxBranch -> CoAxBranch -> Bool
eqClosedFamilyBranch [CoAxBranch]
branch_list1 [CoAxBranch]
branch_list2)
where
branch_list1 :: [CoAxBranch]
branch_list1 = forall (br :: BranchFlag). Branches br -> [CoAxBranch]
fromBranches Branches br
branches1
branch_list2 :: [CoAxBranch]
branch_list2 = forall (br :: BranchFlag). Branches br -> [CoAxBranch]
fromBranches Branches br
branches2
eqClosedFamilyBranch :: CoAxBranch -> CoAxBranch -> Bool
eqClosedFamilyBranch (CoAxBranch { cab_tvs :: CoAxBranch -> [Var]
cab_tvs = [Var]
tvs1, cab_cvs :: CoAxBranch -> [Var]
cab_cvs = [Var]
cvs1
, cab_lhs :: CoAxBranch -> [Type]
cab_lhs = [Type]
lhs1, cab_rhs :: CoAxBranch -> Type
cab_rhs = Type
rhs1 })
(CoAxBranch { cab_tvs :: CoAxBranch -> [Var]
cab_tvs = [Var]
tvs2, cab_cvs :: CoAxBranch -> [Var]
cab_cvs = [Var]
cvs2
, cab_lhs :: CoAxBranch -> [Type]
cab_lhs = [Type]
lhs2, cab_rhs :: CoAxBranch -> Type
cab_rhs = Type
rhs2 })
| Just RnEnv2
env1 <- RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
eqVarBndrs RnEnv2
emptyRnEnv2 [Var]
tvs1 [Var]
tvs2
, Just RnEnv2
env <- RnEnv2 -> [Var] -> [Var] -> Maybe RnEnv2
eqVarBndrs RnEnv2
env1 [Var]
cvs1 [Var]
cvs2
= forall a. (a -> a -> Bool) -> [a] -> [a] -> Bool
eqListBy (RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env) [Type]
lhs1 [Type]
lhs2 Bool -> Bool -> Bool
&&
RnEnv2 -> Type -> Type -> Bool
eqTypeX RnEnv2
env Type
rhs1 Type
rhs2
| Bool
otherwise = Bool
False
emptyRnEnv2 :: RnEnv2
emptyRnEnv2 :: RnEnv2
emptyRnEnv2 = InScopeSet -> RnEnv2
mkRnEnv2 InScopeSet
emptyInScopeSet
missingBootThing :: Bool -> Name -> String -> SDoc
missingBootThing :: Bool -> Name -> String -> SDoc
missingBootThing Bool
is_boot Name
name String
what
= SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is exported by the"
SDoc -> SDoc -> SDoc
<+> (if Bool
is_boot then String -> SDoc
text String
"hs-boot" else String -> SDoc
text String
"hsig")
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"file, but not"
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
what SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"the module"
badReexportedBootThing :: Bool -> Name -> Name -> SDoc
badReexportedBootThing :: Bool -> Name -> Name -> SDoc
badReexportedBootThing Bool
is_boot Name
name Name
name'
= PrintUnqualified -> Depth -> SDoc -> SDoc
withUserStyle PrintUnqualified
alwaysQualify Depth
AllTheWay forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ String -> SDoc
text String
"The" SDoc -> SDoc -> SDoc
<+> (if Bool
is_boot then String -> SDoc
text String
"hs-boot" else String -> SDoc
text String
"hsig")
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"file (re)exports" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name)
, String -> SDoc
text String
"but the implementing module exports a different identifier" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name')
]
bootMisMatch :: Bool -> SDoc -> TyThing -> TyThing -> SDoc
bootMisMatch :: Bool -> SDoc -> TyThing -> TyThing -> SDoc
bootMisMatch Bool
is_boot SDoc
extra_info TyThing
real_thing TyThing
boot_thing
= Bool -> SDoc -> TyThing -> SDoc -> SDoc -> SDoc
pprBootMisMatch Bool
is_boot SDoc
extra_info TyThing
real_thing SDoc
real_doc SDoc
boot_doc
where
to_doc :: TyThing -> SDoc
to_doc
= ShowSub -> TyThing -> SDoc
pprTyThingInContext forall a b. (a -> b) -> a -> b
$ ShowSub
showToHeader { ss_forall :: ShowForAllFlag
ss_forall =
if Bool
is_boot
then ShowForAllFlag
ShowForAllMust
else ShowForAllFlag
ShowForAllWhen }
real_doc :: SDoc
real_doc = TyThing -> SDoc
to_doc TyThing
real_thing
boot_doc :: SDoc
boot_doc = TyThing -> SDoc
to_doc TyThing
boot_thing
pprBootMisMatch :: Bool -> SDoc -> TyThing -> SDoc -> SDoc -> SDoc
pprBootMisMatch :: Bool -> SDoc -> TyThing -> SDoc -> SDoc -> SDoc
pprBootMisMatch Bool
is_boot SDoc
extra_info TyThing
real_thing SDoc
real_doc SDoc
boot_doc
= [SDoc] -> SDoc
vcat
[ forall a. Outputable a => a -> SDoc
ppr TyThing
real_thing SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"has conflicting definitions in the module",
String -> SDoc
text String
"and its" SDoc -> SDoc -> SDoc
<+>
(if Bool
is_boot
then String -> SDoc
text String
"hs-boot file"
else String -> SDoc
text String
"hsig file"),
String -> SDoc
text String
"Main module:" SDoc -> SDoc -> SDoc
<+> SDoc
real_doc,
(if Bool
is_boot
then String -> SDoc
text String
"Boot file: "
else String -> SDoc
text String
"Hsig file: ")
SDoc -> SDoc -> SDoc
<+> SDoc
boot_doc,
SDoc
extra_info
]
instMisMatch :: DFunId -> SDoc
instMisMatch :: Var -> SDoc
instMisMatch Var
dfun
= SDoc -> Arity -> SDoc -> SDoc
hang (String -> SDoc
text String
"instance" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (Var -> Type
idType Var
dfun))
Arity
2 (String -> SDoc
text String
"is defined in the hs-boot file, but not in the module itself")
rnTopSrcDecls :: HsGroup GhcPs -> TcM (TcGblEnv, HsGroup GhcRn)
rnTopSrcDecls :: HsGroup GhcPs -> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnTopSrcDecls HsGroup GhcPs
group
= do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn12" SDoc
empty ;
(TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
rn_decls) <- forall r. TcM r -> TcM r
checkNoErrs forall a b. (a -> b) -> a -> b
$ HsGroup GhcPs -> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnSrcDecls HsGroup GhcPs
group ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn13" SDoc
empty ;
(TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
rn_decls) <- TcGblEnv
-> HsGroup (GhcPass 'Renamed)
-> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
runRenamerPlugin TcGblEnv
tcg_env HsGroup (GhcPass 'Renamed)
rn_decls ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"rn13-plugin" SDoc
empty ;
let { tcg_env' :: TcGblEnv
tcg_env'
| Just HsGroup (GhcPass 'Renamed)
grp <- TcGblEnv -> Maybe (HsGroup (GhcPass 'Renamed))
tcg_rn_decls TcGblEnv
tcg_env
= TcGblEnv
tcg_env{ tcg_rn_decls :: Maybe (HsGroup (GhcPass 'Renamed))
tcg_rn_decls = forall a. a -> Maybe a
Just (forall (p :: Pass).
HsGroup (GhcPass p) -> HsGroup (GhcPass p) -> HsGroup (GhcPass p)
appendGroups HsGroup (GhcPass 'Renamed)
grp HsGroup (GhcPass 'Renamed)
rn_decls) }
| Bool
otherwise
= TcGblEnv
tcg_env };
forall a.
(Outputable a, Data a) =>
a -> TcRnIf TcGblEnv TcLclEnv ()
rnDump HsGroup (GhcPass 'Renamed)
rn_decls ;
forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env', HsGroup (GhcPass 'Renamed)
rn_decls)
}
tcTopSrcDecls :: HsGroup GhcRn -> TcM (TcGblEnv, TcLclEnv)
tcTopSrcDecls :: HsGroup (GhcPass 'Renamed) -> TcM (TcGblEnv, TcLclEnv)
tcTopSrcDecls (HsGroup { hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass 'Renamed)]
tycl_decls,
hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl (GhcPass 'Renamed)]
deriv_decls,
hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords = [LForeignDecl (GhcPass 'Renamed)]
foreign_decls,
hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds = [LDefaultDecl (GhcPass 'Renamed)]
default_decls,
hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds = [LAnnDecl (GhcPass 'Renamed)]
annotation_decls,
hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds = [LRuleDecls (GhcPass 'Renamed)]
rule_decls,
hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds = hs_val_binds :: HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
hs_val_binds@(XValBindsLR
(NValBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds [LSig (GhcPass 'Renamed)]
val_sigs)) })
= do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc2 (src)" SDoc
empty ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc3" SDoc
empty ;
(TcGblEnv
tcg_env, [InstInfo (GhcPass 'Renamed)]
inst_infos, XValBindsLR (NValBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
deriv_binds [LSig (GhcPass 'Renamed)]
deriv_sigs))
<- [TyClGroup (GhcPass 'Renamed)]
-> [LDerivDecl (GhcPass 'Renamed)]
-> [(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> TcM
(TcGblEnv, [InstInfo (GhcPass 'Renamed)],
HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed))
tcTyClsInstDecls [TyClGroup (GhcPass 'Renamed)]
tycl_decls [LDerivDecl (GhcPass 'Renamed)]
deriv_decls [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds ;
forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$ do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc3b" SDoc
empty ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc3c" SDoc
empty ;
TcRnIf TcGblEnv TcLclEnv ()
tcSemigroupWarnings ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc4" SDoc
empty ;
([Var]
fi_ids, [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fi_decls, Bag GlobalRdrElt
fi_gres) <- [LForeignDecl (GhcPass 'Renamed)]
-> TcM ([Var], [LForeignDecl GhcTc], Bag GlobalRdrElt)
tcForeignImports [LForeignDecl (GhcPass 'Renamed)]
foreign_decls ;
forall a. [Var] -> TcM a -> TcM a
tcExtendGlobalValEnv [Var]
fi_ids forall a b. (a -> b) -> a -> b
$ do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc4a" SDoc
empty ;
Maybe [Type]
default_tys <- [LDefaultDecl (GhcPass 'Renamed)] -> TcM (Maybe [Type])
tcDefaults [LDefaultDecl (GhcPass 'Renamed)]
default_decls ;
forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv (\TcGblEnv
gbl -> TcGblEnv
gbl { tcg_default :: Maybe [Type]
tcg_default = Maybe [Type]
default_tys }) forall a b. (a -> b) -> a -> b
$ do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc5" SDoc
empty ;
(TcGblEnv, TcLclEnv)
tc_envs <- [(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [LSig (GhcPass 'Renamed)] -> TcM (TcGblEnv, TcLclEnv)
tcTopBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
val_binds [LSig (GhcPass 'Renamed)]
val_sigs;
forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv, TcLclEnv)
tc_envs forall a b. (a -> b) -> a -> b
$ do {
tc_envs :: (TcGblEnv, TcLclEnv)
tc_envs@(TcGblEnv
tcg_env, TcLclEnv
tcl_env)
<- forall r. TcM r -> TcM r
discardWarnings ([(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> [LSig (GhcPass 'Renamed)] -> TcM (TcGblEnv, TcLclEnv)
tcTopBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
deriv_binds [LSig (GhcPass 'Renamed)]
deriv_sigs) ;
forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv, TcLclEnv)
tc_envs forall a b. (a -> b) -> a -> b
$ do {
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc6" SDoc
empty ;
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
inst_binds <- [LTyClDecl (GhcPass 'Renamed)]
-> [InstInfo (GhcPass 'Renamed)] -> TcM (LHsBinds GhcTc)
tcInstDecls2 (forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls [TyClGroup (GhcPass 'Renamed)]
tycl_decls) [InstInfo (GhcPass 'Renamed)]
inst_infos ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc7" SDoc
empty ;
(Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
foe_binds, [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
foe_decls, Bag GlobalRdrElt
foe_gres) <- [LForeignDecl (GhcPass 'Renamed)]
-> TcM (LHsBinds GhcTc, [LForeignDecl GhcTc], Bag GlobalRdrElt)
tcForeignExports [LForeignDecl (GhcPass 'Renamed)]
foreign_decls ;
[Annotation]
annotations <- [LAnnDecl (GhcPass 'Renamed)] -> TcM [Annotation]
tcAnnotations [LAnnDecl (GhcPass 'Renamed)]
annotation_decls ;
[GenLocated SrcSpanAnnA (RuleDecls GhcTc)]
rules <- [LRuleDecls (GhcPass 'Renamed)] -> TcM [LRuleDecls GhcTc]
tcRules [LRuleDecls (GhcPass 'Renamed)]
rule_decls ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"Tc7a" SDoc
empty ;
let { all_binds :: Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
all_binds = Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
inst_binds forall a. Bag a -> Bag a -> Bag a
`unionBags`
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
foe_binds
; fo_gres :: Bag GlobalRdrElt
fo_gres = Bag GlobalRdrElt
fi_gres forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag GlobalRdrElt
foe_gres
; fo_fvs :: FreeVars
fo_fvs = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\GlobalRdrElt
gre FreeVars
fvs -> FreeVars
fvs FreeVars -> Name -> FreeVars
`addOneFV` GlobalRdrElt -> Name
greMangledName GlobalRdrElt
gre)
FreeVars
emptyFVs Bag GlobalRdrElt
fo_gres
; sig_names :: FreeVars
sig_names = [Name] -> FreeVars
mkNameSet (forall (idL :: Pass) (idR :: Pass).
CollectPass (GhcPass idL) =>
CollectFlag (GhcPass idL)
-> HsValBindsLR (GhcPass idL) (GhcPass idR) -> [IdP (GhcPass idL)]
collectHsValBinders forall p. CollectFlag p
CollNoDictBinders HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
hs_val_binds)
FreeVars -> FreeVars -> FreeVars
`minusNameSet` [LSig (GhcPass 'Renamed)] -> FreeVars
getTypeSigNames [LSig (GhcPass 'Renamed)]
val_sigs
; tcg_env' :: TcGblEnv
tcg_env' = TcGblEnv
tcg_env { tcg_binds :: LHsBinds GhcTc
tcg_binds = TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
tcg_env forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
all_binds
, tcg_sigs :: FreeVars
tcg_sigs = TcGblEnv -> FreeVars
tcg_sigs TcGblEnv
tcg_env FreeVars -> FreeVars -> FreeVars
`unionNameSet` FreeVars
sig_names
, tcg_rules :: [LRuleDecl GhcTc]
tcg_rules = TcGblEnv -> [LRuleDecl GhcTc]
tcg_rules TcGblEnv
tcg_env
forall a. [a] -> [a] -> [a]
++ forall (p :: Pass).
[LRuleDecls (GhcPass p)] -> [LRuleDecl (GhcPass p)]
flattenRuleDecls [GenLocated SrcSpanAnnA (RuleDecls GhcTc)]
rules
, tcg_anns :: [Annotation]
tcg_anns = TcGblEnv -> [Annotation]
tcg_anns TcGblEnv
tcg_env forall a. [a] -> [a] -> [a]
++ [Annotation]
annotations
, tcg_ann_env :: AnnEnv
tcg_ann_env = AnnEnv -> [Annotation] -> AnnEnv
extendAnnEnvList (TcGblEnv -> AnnEnv
tcg_ann_env TcGblEnv
tcg_env) [Annotation]
annotations
, tcg_fords :: [LForeignDecl GhcTc]
tcg_fords = TcGblEnv -> [LForeignDecl GhcTc]
tcg_fords TcGblEnv
tcg_env forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
foe_decls forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (ForeignDecl GhcTc)]
fi_decls
, tcg_dus :: DefUses
tcg_dus = TcGblEnv -> DefUses
tcg_dus TcGblEnv
tcg_env DefUses -> DefUses -> DefUses
`plusDU` FreeVars -> DefUses
usesOnly FreeVars
fo_fvs } } ;
[GlobalRdrElt] -> TcRnIf TcGblEnv TcLclEnv ()
addUsedGREs (forall a. Bag a -> [a]
bagToList Bag GlobalRdrElt
fo_gres) ;
forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env', TcLclEnv
tcl_env)
}}}}}}
tcTopSrcDecls HsGroup (GhcPass 'Renamed)
_ = forall a. String -> a
panic String
"tcTopSrcDecls: ValBindsIn"
tcSemigroupWarnings :: TcM ()
tcSemigroupWarnings :: TcRnIf TcGblEnv TcLclEnv ()
tcSemigroupWarnings = do
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcSemigroupWarnings" SDoc
empty
let warnFlag :: WarningFlag
warnFlag = WarningFlag
Opt_WarnSemigroup
WarningFlag -> Name -> TcRnIf TcGblEnv TcLclEnv ()
tcPreludeClashWarn WarningFlag
warnFlag Name
sappendName
WarningFlag -> Name -> Name -> TcRnIf TcGblEnv TcLclEnv ()
tcMissingParentClassWarn WarningFlag
warnFlag Name
monoidClassName Name
semigroupClassName
tcPreludeClashWarn :: WarningFlag
-> Name
-> TcM ()
tcPreludeClashWarn :: WarningFlag -> Name -> TcRnIf TcGblEnv TcLclEnv ()
tcPreludeClashWarn WarningFlag
warnFlag Name
name = do
{ Bool
warn <- forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
warnFlag
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
warn forall a b. (a -> b) -> a -> b
$ do
{ String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcPreludeClashWarn/wouldBeImported" SDoc
empty
; [ImportDecl (GhcPass 'Renamed)]
rnImports <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> [a] -> [b]
map forall l e. GenLocated l e -> e
unLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcGblEnv -> [LImportDecl (GhcPass 'Renamed)]
tcg_rn_imports) forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Name -> [ImportDecl (GhcPass 'Renamed)] -> Bool
importedViaPrelude Name
name [ImportDecl (GhcPass 'Renamed)]
rnImports) forall a b. (a -> b) -> a -> b
$ do
{ [GlobalRdrElt]
rdrElts <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. OccEnv a -> [a]
occEnvElts forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcGblEnv -> GlobalRdrEnv
tcg_rdr_env) forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; let clashes :: GlobalRdrElt -> Bool
clashes :: GlobalRdrElt -> Bool
clashes GlobalRdrElt
x = Bool
isLocalDef Bool -> Bool -> Bool
&& Bool
nameClashes Bool -> Bool -> Bool
&& Bool
isNotInProperModule
where
isLocalDef :: Bool
isLocalDef = GlobalRdrElt -> Bool
gre_lcl GlobalRdrElt
x forall a. Eq a => a -> a -> Bool
== Bool
True
nameClashes :: Bool
nameClashes = Name -> OccName
nameOccName (GlobalRdrElt -> Name
greMangledName GlobalRdrElt
x) forall a. Eq a => a -> a -> Bool
== Name -> OccName
nameOccName Name
name
isNotInProperModule :: Bool
isNotInProperModule = GlobalRdrElt -> Name
greMangledName GlobalRdrElt
x forall a. Eq a => a -> a -> Bool
/= Name
name
clashingElts :: [GlobalRdrElt]
clashingElts :: [GlobalRdrElt]
clashingElts = forall a. (a -> Bool) -> [a] -> [a]
filter GlobalRdrElt -> Bool
clashes [GlobalRdrElt]
rdrElts
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcPreludeClashWarn/prelude_functions"
(SDoc -> Arity -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr Name
name) Arity
4 ([SDoc] -> SDoc
sep [forall a. Outputable a => a -> SDoc
ppr [GlobalRdrElt]
clashingElts]))
; let warn_msg :: GlobalRdrElt -> TcRnIf TcGblEnv TcLclEnv ()
warn_msg GlobalRdrElt
x = WarnReason -> SrcSpan -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addWarnAt (WarningFlag -> WarnReason
Reason WarningFlag
warnFlag) (Name -> SrcSpan
nameSrcSpan (GlobalRdrElt -> Name
greMangledName GlobalRdrElt
x)) ([SDoc] -> SDoc
hsep
[ String -> SDoc
text String
"Local definition of"
, (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalRdrElt -> Name
greMangledName) GlobalRdrElt
x
, String -> SDoc
text String
"clashes with a future Prelude name." ]
SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"This will become an error in a future release." )
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ GlobalRdrElt -> TcRnIf TcGblEnv TcLclEnv ()
warn_msg [GlobalRdrElt]
clashingElts
}}}
where
importedViaPrelude :: Name
-> [ImportDecl GhcRn]
-> Bool
importedViaPrelude :: Name -> [ImportDecl (GhcPass 'Renamed)] -> Bool
importedViaPrelude Name
name = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ImportDecl (GhcPass 'Renamed) -> Bool
importViaPrelude
where
isPrelude :: ImportDecl GhcRn -> Bool
isPrelude :: ImportDecl (GhcPass 'Renamed) -> Bool
isPrelude ImportDecl (GhcPass 'Renamed)
imp = forall l e. GenLocated l e -> e
unLoc (forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName ImportDecl (GhcPass 'Renamed)
imp) forall a. Eq a => a -> a -> Bool
== ModuleName
pRELUDE_NAME
isImplicit :: ImportDecl GhcRn -> Bool
isImplicit :: ImportDecl (GhcPass 'Renamed) -> Bool
isImplicit = forall pass. ImportDecl pass -> Bool
ideclImplicit
isUnqualified :: ImportDecl GhcRn -> Bool
isUnqualified :: ImportDecl (GhcPass 'Renamed) -> Bool
isUnqualified = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImportDeclQualifiedStyle -> Bool
isImportDeclQualified forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pass. ImportDecl pass -> ImportDeclQualifiedStyle
ideclQualified
importListOf :: ImportDecl GhcRn -> Maybe (Bool, [Name])
importListOf :: ImportDecl (GhcPass 'Renamed) -> Maybe (Bool, [Name])
importListOf = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a} {l} {l} {p :: Pass}.
(a, GenLocated l [GenLocated l (IE (GhcPass p))])
-> (a, [IdGhcP p])
toImportList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pass. ImportDecl pass -> Maybe (Bool, XRec pass [LIE pass])
ideclHiding
where
toImportList :: (a, GenLocated l [GenLocated l (IE (GhcPass p))])
-> (a, [IdGhcP p])
toImportList (a
h, GenLocated l [GenLocated l (IE (GhcPass p))]
loc) = (a
h, forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass). IE (GhcPass p) -> IdP (GhcPass p)
ieName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) (forall l e. GenLocated l e -> e
unLoc GenLocated l [GenLocated l (IE (GhcPass p))]
loc))
isExplicit :: ImportDecl GhcRn -> Bool
isExplicit :: ImportDecl (GhcPass 'Renamed) -> Bool
isExplicit ImportDecl (GhcPass 'Renamed)
x = case ImportDecl (GhcPass 'Renamed) -> Maybe (Bool, [Name])
importListOf ImportDecl (GhcPass 'Renamed)
x of
Maybe (Bool, [Name])
Nothing -> Bool
False
Just (Bool
False, [Name]
explicit)
-> Name -> OccName
nameOccName Name
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall a b. (a -> b) -> [a] -> [b]
map Name -> OccName
nameOccName [Name]
explicit
Just (Bool
True, [Name]
hidden)
-> Name -> OccName
nameOccName Name
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` forall a b. (a -> b) -> [a] -> [b]
map Name -> OccName
nameOccName [Name]
hidden
importViaPrelude :: ImportDecl GhcRn -> Bool
importViaPrelude :: ImportDecl (GhcPass 'Renamed) -> Bool
importViaPrelude ImportDecl (GhcPass 'Renamed)
x = ImportDecl (GhcPass 'Renamed) -> Bool
isPrelude ImportDecl (GhcPass 'Renamed)
x
Bool -> Bool -> Bool
&& ImportDecl (GhcPass 'Renamed) -> Bool
isUnqualified ImportDecl (GhcPass 'Renamed)
x
Bool -> Bool -> Bool
&& (ImportDecl (GhcPass 'Renamed) -> Bool
isImplicit ImportDecl (GhcPass 'Renamed)
x Bool -> Bool -> Bool
|| ImportDecl (GhcPass 'Renamed) -> Bool
isExplicit ImportDecl (GhcPass 'Renamed)
x)
tcMissingParentClassWarn :: WarningFlag
-> Name
-> Name
-> TcM ()
tcMissingParentClassWarn :: WarningFlag -> Name -> Name -> TcRnIf TcGblEnv TcLclEnv ()
tcMissingParentClassWarn WarningFlag
warnFlag Name
isName Name
shouldName
= do { Bool
warn <- forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
warnFlag
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
warn forall a b. (a -> b) -> a -> b
$ do
{ String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcMissingParentClassWarn" SDoc
empty
; Maybe Class
isClass' <- Name -> TcM (Maybe Class)
tcLookupClass_maybe Name
isName
; Maybe Class
shouldClass' <- Name -> TcM (Maybe Class)
tcLookupClass_maybe Name
shouldName
; case (Maybe Class
isClass', Maybe Class
shouldClass') of
(Just Class
isClass, Just Class
shouldClass) -> do
{ [ClsInst]
localInstances <- TcM [ClsInst]
tcGetInsts
; let isInstance :: ClsInst -> Bool
isInstance ClsInst
m = ClsInst -> Class
is_cls ClsInst
m forall a. Eq a => a -> a -> Bool
== Class
isClass
isInsts :: [ClsInst]
isInsts = forall a. (a -> Bool) -> [a] -> [a]
filter ClsInst -> Bool
isInstance [ClsInst]
localInstances
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcMissingParentClassWarn/isInsts" (forall a. Outputable a => a -> SDoc
ppr [ClsInst]
isInsts)
; forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [ClsInst]
isInsts (Class -> Class -> ClsInst -> TcRnIf TcGblEnv TcLclEnv ()
checkShouldInst Class
isClass Class
shouldClass)
}
(Maybe Class
is',Maybe Class
should') ->
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcMissingParentClassWarn/notIsShould"
(SDoc -> Arity -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr Name
isName SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"/" SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr Name
shouldName) Arity
2 (
([SDoc] -> SDoc
hsep [ SDoc -> SDoc
quotes (String -> SDoc
text String
"Is"), String -> SDoc
text String
"lookup for"
, forall a. Outputable a => a -> SDoc
ppr Name
isName
, String -> SDoc
text String
"resulted in", forall a. Outputable a => a -> SDoc
ppr Maybe Class
is' ])
SDoc -> SDoc -> SDoc
$$
([SDoc] -> SDoc
hsep [ SDoc -> SDoc
quotes (String -> SDoc
text String
"Should"), String -> SDoc
text String
"lookup for"
, forall a. Outputable a => a -> SDoc
ppr Name
shouldName
, String -> SDoc
text String
"resulted in", forall a. Outputable a => a -> SDoc
ppr Maybe Class
should' ])))
}}
where
checkShouldInst :: Class
-> Class
-> ClsInst
-> TcM ()
checkShouldInst :: Class -> Class -> ClsInst -> TcRnIf TcGblEnv TcLclEnv ()
checkShouldInst Class
isClass Class
shouldClass ClsInst
isInst
= do { InstEnvs
instEnv <- TcM InstEnvs
tcGetInstEnvs
; let ([InstMatch]
instanceMatches, [ClsInst]
shouldInsts, [InstMatch]
_)
= Bool
-> InstEnvs
-> Class
-> [Type]
-> ([InstMatch], [ClsInst], [InstMatch])
lookupInstEnv Bool
False InstEnvs
instEnv Class
shouldClass (ClsInst -> [Type]
is_tys ClsInst
isInst)
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcMissingParentClassWarn/checkShouldInst"
(SDoc -> Arity -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr ClsInst
isInst) Arity
4
([SDoc] -> SDoc
sep [forall a. Outputable a => a -> SDoc
ppr [InstMatch]
instanceMatches, forall a. Outputable a => a -> SDoc
ppr [ClsInst]
shouldInsts]))
; let instLoc :: SrcSpan
instLoc = SrcLoc -> SrcSpan
srcLocSpan forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> SrcLoc
nameSrcLoc forall a b. (a -> b) -> a -> b
$ forall a. NamedThing a => a -> Name
getName ClsInst
isInst
warnMsg :: [RoughMatchTc] -> TcRnIf TcGblEnv TcLclEnv ()
warnMsg (KnownTc Name
name:[RoughMatchTc]
_) =
WarnReason -> SrcSpan -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addWarnAt (WarningFlag -> WarnReason
Reason WarningFlag
warnFlag) SrcSpan
instLoc forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
hsep [ (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName) Name
name
, String -> SDoc
text String
"is an instance of"
, (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName forall b c a. (b -> c) -> (a -> b) -> a -> c
. Class -> Name
className) Class
isClass
, String -> SDoc
text String
"but not"
, (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName forall b c a. (b -> c) -> (a -> b) -> a -> c
. Class -> Name
className) Class
shouldClass ]
SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"."
SDoc -> SDoc -> SDoc
$$
[SDoc] -> SDoc
hsep [ String -> SDoc
text String
"This will become an error in"
, String -> SDoc
text String
"a future release." ]
warnMsg [RoughMatchTc]
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ClsInst]
shouldInsts Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [InstMatch]
instanceMatches) forall a b. (a -> b) -> a -> b
$
[RoughMatchTc] -> TcRnIf TcGblEnv TcLclEnv ()
warnMsg (ClsInst -> [RoughMatchTc]
is_tcs ClsInst
isInst)
}
tcLookupClass_maybe :: Name -> TcM (Maybe Class)
tcLookupClass_maybe :: Name -> TcM (Maybe Class)
tcLookupClass_maybe Name
name = Name -> TcM (MaybeErr SDoc TyThing)
tcLookupImported_maybe Name
name forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Succeeded (ATyCon TyCon
tc) | cls :: Maybe Class
cls@(Just Class
_) <- TyCon -> Maybe Class
tyConClass_maybe TyCon
tc -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Class
cls
MaybeErr SDoc TyThing
_else -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing
tcTyClsInstDecls :: [TyClGroup GhcRn]
-> [LDerivDecl GhcRn]
-> [(RecFlag, LHsBinds GhcRn)]
-> TcM (TcGblEnv,
[InstInfo GhcRn],
HsValBinds GhcRn)
tcTyClsInstDecls :: [TyClGroup (GhcPass 'Renamed)]
-> [LDerivDecl (GhcPass 'Renamed)]
-> [(RecFlag, LHsBinds (GhcPass 'Renamed))]
-> TcM
(TcGblEnv, [InstInfo (GhcPass 'Renamed)],
HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed))
tcTyClsInstDecls [TyClGroup (GhcPass 'Renamed)]
tycl_decls [LDerivDecl (GhcPass 'Renamed)]
deriv_decls [(RecFlag, LHsBinds (GhcPass 'Renamed))]
binds
= forall a. [LInstDecl (GhcPass 'Renamed)] -> TcM a -> TcM a
tcAddDataFamConPlaceholders ([TyClGroup (GhcPass 'Renamed)]
tycl_decls forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall pass. TyClGroup pass -> [LInstDecl pass]
group_instds) forall a b. (a -> b) -> a -> b
$
forall a.
[PatSynBind (GhcPass 'Renamed) (GhcPass 'Renamed)]
-> TcM a -> TcM a
tcAddPatSynPlaceholders (forall id.
UnXRec id =>
[(RecFlag, LHsBinds id)] -> [PatSynBind id id]
getPatSynBinds [(RecFlag, LHsBinds (GhcPass 'Renamed))]
binds) forall a b. (a -> b) -> a -> b
$
do { (TcGblEnv
tcg_env, [InstInfo (GhcPass 'Renamed)]
inst_info, [DerivInfo]
deriv_info)
<- [TyClGroup (GhcPass 'Renamed)]
-> TcM (TcGblEnv, [InstInfo (GhcPass 'Renamed)], [DerivInfo])
tcTyAndClassDecls [TyClGroup (GhcPass 'Renamed)]
tycl_decls ;
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env forall a b. (a -> b) -> a -> b
$ do {
; TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; (TcGblEnv
tcg_env', [InstInfo (GhcPass 'Renamed)]
inst_info', HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
val_binds)
<- [DerivInfo]
-> [LDerivDecl (GhcPass 'Renamed)]
-> TcM
(TcGblEnv, [InstInfo (GhcPass 'Renamed)],
HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed))
tcInstDeclsDeriv [DerivInfo]
deriv_info [LDerivDecl (GhcPass 'Renamed)]
deriv_decls
; forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
tcg_env' forall a b. (a -> b) -> a -> b
$ do {
TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; forall (f :: * -> *) a. Applicative f => a -> f a
pure (TcGblEnv
tcg_env', [InstInfo (GhcPass 'Renamed)]
inst_info' forall a. [a] -> [a] -> [a]
++ [InstInfo (GhcPass 'Renamed)]
inst_info, HsValBindsLR (GhcPass 'Renamed) (GhcPass 'Renamed)
val_binds)
}}}
checkMainType :: TcGblEnv -> TcRn WantedConstraints
checkMainType :: TcGblEnv -> TcRn WantedConstraints
checkMainType TcGblEnv
tcg_env
= do { HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; if TcGblEnv -> Module
tcg_mod TcGblEnv
tcg_env forall a. Eq a => a -> a -> Bool
/= HscEnv -> Module
mainModIs HscEnv
hsc_env
then forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
emptyWC else
do { GlobalRdrEnv
rdr_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
main_occ :: OccName
main_occ = DynFlags -> OccName
getMainOcc DynFlags
dflags
main_gres :: [GlobalRdrElt]
main_gres = GlobalRdrEnv -> OccName -> [GlobalRdrElt]
lookupGlobalRdrEnv GlobalRdrEnv
rdr_env OccName
main_occ
; case forall a. (a -> Bool) -> [a] -> [a]
filter GlobalRdrElt -> Bool
isLocalGRE [GlobalRdrElt]
main_gres of {
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
emptyWC ;
(GlobalRdrElt
_:GlobalRdrElt
_:[GlobalRdrElt]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
emptyWC ;
[GlobalRdrElt
main_gre] ->
do { let main_name :: Name
main_name = GlobalRdrElt -> Name
greMangledName GlobalRdrElt
main_gre
ctxt :: UserTypeCtxt
ctxt = Name -> Bool -> UserTypeCtxt
FunSigCtxt Name
main_name Bool
False
; Var
main_id <- Name -> TcM Var
tcLookupId Name
main_name
; (Type
io_ty,Type
_) <- TcM (Type, Type)
getIOType
; let main_ty :: Type
main_ty = Var -> Type
idType Var
main_id
eq_orig :: CtOrigin
eq_orig = TypeEqOrigin { uo_actual :: Type
uo_actual = Type
main_ty
, uo_expected :: Type
uo_expected = Type
io_ty
, uo_thing :: Maybe SDoc
uo_thing = forall a. Maybe a
Nothing
, uo_visible :: Bool
uo_visible = Bool
True }
; ((TcEvBinds, HsWrapper)
_, WantedConstraints
lie) <- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
forall a. Name -> Type -> TcM a -> TcM (TcEvBinds, a)
setMainCtxt Name
main_name Type
io_ty forall a b. (a -> b) -> a -> b
$
CtOrigin -> UserTypeCtxt -> Type -> Type -> TcM HsWrapper
tcSubTypeSigma CtOrigin
eq_orig UserTypeCtxt
ctxt Type
main_ty Type
io_ty
; forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
lie } } } }
checkMain :: Bool
-> Maybe (LocatedL [LIE GhcPs])
-> TcM TcGblEnv
checkMain :: Bool -> Maybe (LocatedL [LIE GhcPs]) -> TcM TcGblEnv
checkMain Bool
explicit_mod_hdr Maybe (LocatedL [LIE GhcPs])
export_ies
= do { HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; TcGblEnv
tcg_env <- forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
main_mod :: Module
main_mod = HscEnv -> Module
mainModIs HscEnv
hsc_env
main_occ :: OccName
main_occ = DynFlags -> OccName
getMainOcc DynFlags
dflags
exported_mains :: [Name]
exported_mains :: [Name]
exported_mains = [ Name
name | AvailInfo
avail <- TcGblEnv -> [AvailInfo]
tcg_exports TcGblEnv
tcg_env
, Name
name <- AvailInfo -> [Name]
availNames AvailInfo
avail
, Name -> OccName
nameOccName Name
name forall a. Eq a => a -> a -> Bool
== OccName
main_occ ]
; if | TcGblEnv -> Module
tcg_mod TcGblEnv
tcg_env forall a. Eq a => a -> a -> Bool
/= Module
main_mod
->
forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env
| [Name
main_name] <- [Name]
exported_mains
->
TcGblEnv -> Name -> TcM TcGblEnv
generateMainBinding TcGblEnv
tcg_env Name
main_name
| Bool
otherwise
-> ASSERT( null exported_mains )
do { DynFlags -> Module -> OccName -> TcRnIf TcGblEnv TcLclEnv ()
complain_no_main DynFlags
dflags Module
main_mod OccName
main_occ
; forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
tcg_env } }
where
complain_no_main :: DynFlags -> Module -> OccName -> TcRnIf TcGblEnv TcLclEnv ()
complain_no_main DynFlags
dflags Module
main_mod OccName
main_occ
= forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
interactive Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
explicit_mod_hdr) forall a b. (a -> b) -> a -> b
$
SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrTc (Module -> OccName -> SDoc
noMainMsg Module
main_mod OccName
main_occ)
where
interactive :: Bool
interactive = DynFlags -> GhcLink
ghcLink DynFlags
dflags forall a. Eq a => a -> a -> Bool
== GhcLink
LinkInMemory
noMainMsg :: Module -> OccName -> SDoc
noMainMsg Module
main_mod OccName
main_occ
= String -> SDoc
text String
"The" SDoc -> SDoc -> SDoc
<+> OccName -> SDoc
ppMainFn OccName
main_occ
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is not" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
defOrExp SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"module"
SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
main_mod)
defOrExp :: String
defOrExp | Bool
explicit_export_list = String
"exported by"
| Bool
otherwise = String
"defined in"
explicit_export_list :: Bool
explicit_export_list = Bool
explicit_mod_hdr Bool -> Bool -> Bool
&& forall a. Maybe a -> Bool
isJust Maybe (LocatedL [LIE GhcPs])
export_ies
getMainOcc :: DynFlags -> OccName
getMainOcc :: DynFlags -> OccName
getMainOcc DynFlags
dflags = case DynFlags -> Maybe String
mainFunIs DynFlags
dflags of
Just String
fn -> FastString -> OccName
mkVarOccFS (String -> FastString
mkFastString String
fn)
Maybe String
Nothing -> OccName
mainOcc
ppMainFn :: OccName -> SDoc
ppMainFn :: OccName -> SDoc
ppMainFn OccName
main_occ
| OccName
main_occ forall a. Eq a => a -> a -> Bool
== OccName
mainOcc
= String -> SDoc
text String
"IO action" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
main_occ)
| Bool
otherwise
= String -> SDoc
text String
"main IO action" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
main_occ)
mainOcc :: OccName
mainOcc :: OccName
mainOcc = FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"main")
generateMainBinding :: TcGblEnv -> Name -> TcM TcGblEnv
generateMainBinding :: TcGblEnv -> Name -> TcM TcGblEnv
generateMainBinding TcGblEnv
tcg_env Name
main_name = do
{ String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"checkMain found" (forall a. Outputable a => a -> SDoc
ppr Name
main_name)
; (Type
io_ty, Type
res_ty) <- TcM (Type, Type)
getIOType
; let loc :: SrcSpan
loc = forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
main_name
main_expr_rn :: GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
main_expr_rn = forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) Name
main_name))
; (TcEvBinds
ev_binds, GenLocated SrcSpanAnnA (HsExpr GhcTc)
main_expr) <- forall a. Name -> Type -> TcM a -> TcM (TcEvBinds, a)
setMainCtxt Name
main_name Type
io_ty forall a b. (a -> b) -> a -> b
$
LHsExpr (GhcPass 'Renamed) -> Type -> TcM (LHsExpr GhcTc)
tcCheckMonoExpr GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
main_expr_rn Type
io_ty
; Var
run_main_id <- Name -> TcM Var
tcLookupId Name
runMainIOName
; let { root_main_name :: Name
root_main_name = Unique -> Module -> OccName -> SrcSpan -> Name
mkExternalName Unique
rootMainKey Module
rOOT_MAIN
(FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"main"))
(forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
main_name)
; root_main_id :: Var
root_main_id = Name -> Type -> Var
Id.mkExportedVanillaId Name
root_main_name Type
io_ty
; co :: HsWrapper
co = [Type] -> HsWrapper
mkWpTyApps [Type
res_ty]
; rhs :: LHsExpr GhcTc
rhs = forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (HsWrapper -> LHsExpr GhcTc -> LHsExpr GhcTc
mkLHsWrap HsWrapper
co (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Var
run_main_id)) forall a b. (a -> b) -> a -> b
$
TcEvBinds -> LHsExpr GhcTc -> LHsExpr GhcTc
mkHsDictLet TcEvBinds
ev_binds GenLocated SrcSpanAnnA (HsExpr GhcTc)
main_expr
; main_bind :: LHsBind GhcTc
main_bind = forall (p :: Pass).
IdP (GhcPass p) -> LHsExpr (GhcPass p) -> LHsBind (GhcPass p)
mkVarBind Var
root_main_id LHsExpr GhcTc
rhs }
; forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env { tcg_main :: Maybe Name
tcg_main = forall a. a -> Maybe a
Just Name
main_name
, tcg_binds :: LHsBinds GhcTc
tcg_binds = TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
tcg_env
forall a. Bag a -> a -> Bag a
`snocBag` LHsBind GhcTc
main_bind
, tcg_dus :: DefUses
tcg_dus = TcGblEnv -> DefUses
tcg_dus TcGblEnv
tcg_env
DefUses -> DefUses -> DefUses
`plusDU` FreeVars -> DefUses
usesOnly (Name -> FreeVars
unitFV Name
main_name) })
}
getIOType :: TcM (TcType, TcType)
getIOType :: TcM (Type, Type)
getIOType = do { TyCon
ioTyCon <- Name -> TcM TyCon
tcLookupTyCon Name
ioTyConName
; Type
res_ty <- Type -> TcM Type
newFlexiTyVarTy Type
liftedTypeKind
; forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> [Type] -> Type
mkTyConApp TyCon
ioTyCon [Type
res_ty], Type
res_ty) }
setMainCtxt :: Name -> TcType -> TcM a -> TcM (TcEvBinds, a)
setMainCtxt :: forall a. Name -> Type -> TcM a -> TcM (TcEvBinds, a)
setMainCtxt Name
main_name Type
io_ty TcM a
thing_inside
= forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
main_name) forall a b. (a -> b) -> a -> b
$
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
main_ctxt forall a b. (a -> b) -> a -> b
$
forall result.
SkolemInfo
-> [Var] -> [Var] -> TcM result -> TcM (TcEvBinds, result)
checkConstraints SkolemInfo
skol_info [] [] forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
where
skol_info :: SkolemInfo
skol_info = UserTypeCtxt -> Type -> [(Name, Var)] -> SkolemInfo
SigSkol (Name -> Bool -> UserTypeCtxt
FunSigCtxt Name
main_name Bool
False) Type
io_ty []
main_ctxt :: SDoc
main_ctxt = String -> SDoc
text String
"When checking the type of the"
SDoc -> SDoc -> SDoc
<+> OccName -> SDoc
ppMainFn (Name -> OccName
nameOccName Name
main_name)
runTcInteractive :: HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive :: forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env TcRn a
thing_inside
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
initTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$ forall a. HscEnv -> TcM a -> TcM a
withTcPlugins HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$ forall a. HscEnv -> TcM a -> TcM a
withHoleFitPlugins HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"setInteractiveContext" forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"ic_tythings:" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr (InteractiveContext -> [TyThing]
ic_tythings InteractiveContext
icxt))
, String -> SDoc
text String
"ic_insts:" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map (forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
LetBind forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClsInst -> Var
instanceDFunId) [ClsInst]
ic_insts)
, String -> SDoc
text String
"ic_rn_gbl_env (LocalDef)" SDoc -> SDoc -> SDoc
<+>
[SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [ [GlobalRdrElt]
local_gres | [GlobalRdrElt]
gres <- forall a. OccEnv a -> [a]
occEnvElts (InteractiveContext -> GlobalRdrEnv
ic_rn_gbl_env InteractiveContext
icxt)
, let local_gres :: [GlobalRdrElt]
local_gres = forall a. (a -> Bool) -> [a] -> [a]
filter GlobalRdrElt -> Bool
isLocalGRE [GlobalRdrElt]
gres
, Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GlobalRdrElt]
local_gres) ]) ]
; let getOrphans :: ModuleName
-> Maybe FastString -> IOEnv (Env TcGblEnv TcLclEnv) [Module]
getOrphans ModuleName
m Maybe FastString
mb_pkg = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ModIface_ 'ModIfaceFinal
iface -> forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface_ 'ModIfaceFinal
iface
forall a. a -> [a] -> [a]
: Dependencies -> [Module]
dep_orphs (forall (phase :: ModIfacePhase). ModIface_ phase -> Dependencies
mi_deps ModIface_ 'ModIfaceFinal
iface))
(SDoc
-> ModuleName
-> IsBootInterface
-> Maybe FastString
-> RnM (ModIface_ 'ModIfaceFinal)
loadSrcInterface (String -> SDoc
text String
"runTcInteractive") ModuleName
m
IsBootInterface
NotBoot Maybe FastString
mb_pkg)
; ![Module]
orphs <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. NFData a => a -> a
force forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (InteractiveContext -> [InteractiveImport]
ic_imports InteractiveContext
icxt) forall a b. (a -> b) -> a -> b
$ \InteractiveImport
i ->
case InteractiveImport
i of
IIModule ModuleName
n -> ModuleName
-> Maybe FastString -> IOEnv (Env TcGblEnv TcLclEnv) [Module]
getOrphans ModuleName
n forall a. Maybe a
Nothing
IIDecl ImportDecl GhcPs
i ->
let mb_pkg :: Maybe FastString
mb_pkg = StringLiteral -> FastString
sl_fs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall pass. ImportDecl pass -> Maybe StringLiteral
ideclPkgQual ImportDecl GhcPs
i in
ModuleName
-> Maybe FastString -> IOEnv (Env TcGblEnv TcLclEnv) [Module]
getOrphans (forall l e. GenLocated l e -> e
unLoc (forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName ImportDecl GhcPs
i)) Maybe FastString
mb_pkg
; let imports :: ImportAvails
imports = ImportAvails
emptyImportAvails {
imp_orphs :: [Module]
imp_orphs = [Module]
orphs
}
; (TcGblEnv
gbl_env, TcLclEnv
lcl_env) <- forall gbl lcl. TcRnIf gbl lcl (gbl, lcl)
getEnvs
; let gbl_env' :: TcGblEnv
gbl_env' = TcGblEnv
gbl_env {
tcg_rdr_env :: GlobalRdrEnv
tcg_rdr_env = InteractiveContext -> GlobalRdrEnv
ic_rn_gbl_env InteractiveContext
icxt
, tcg_type_env :: TypeEnv
tcg_type_env = TypeEnv
type_env
, tcg_inst_env :: InstEnv
tcg_inst_env = InstEnv -> [ClsInst] -> InstEnv
extendInstEnvList
(InstEnv -> [ClsInst] -> InstEnv
extendInstEnvList (TcGblEnv -> InstEnv
tcg_inst_env TcGblEnv
gbl_env) [ClsInst]
ic_insts)
[ClsInst]
home_insts
, tcg_fam_inst_env :: FamInstEnv
tcg_fam_inst_env = FamInstEnv -> [FamInst] -> FamInstEnv
extendFamInstEnvList
(FamInstEnv -> [FamInst] -> FamInstEnv
extendFamInstEnvList (TcGblEnv -> FamInstEnv
tcg_fam_inst_env TcGblEnv
gbl_env)
[FamInst]
ic_finsts)
[FamInst]
home_fam_insts
, tcg_field_env :: RecFieldEnv
tcg_field_env = forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, [FieldLabel])]
con_fields
, tcg_fix_env :: FixityEnv
tcg_fix_env = InteractiveContext -> FixityEnv
ic_fix_env InteractiveContext
icxt
, tcg_default :: Maybe [Type]
tcg_default = InteractiveContext -> Maybe [Type]
ic_default InteractiveContext
icxt
, tcg_imports :: ImportAvails
tcg_imports = ImportAvails
imports
}
lcl_env' :: TcLclEnv
lcl_env' = TcLclEnv -> [(Name, TcTyThing)] -> TcLclEnv
tcExtendLocalTypeEnv TcLclEnv
lcl_env [(Name, TcTyThing)]
lcl_ids
; forall gbl' lcl' a gbl lcl.
(gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
setEnvs (TcGblEnv
gbl_env', TcLclEnv
lcl_env') TcRn a
thing_inside }
where
([ClsInst]
home_insts, [FamInst]
home_fam_insts) = HscEnv -> (ModuleName -> Bool) -> ([ClsInst], [FamInst])
hptInstances HscEnv
hsc_env (\ModuleName
_ -> Bool
True)
icxt :: InteractiveContext
icxt = HscEnv -> InteractiveContext
hsc_IC HscEnv
hsc_env
([ClsInst]
ic_insts, [FamInst]
ic_finsts) = InteractiveContext -> ([ClsInst], [FamInst])
ic_instances InteractiveContext
icxt
([(Name, TcTyThing)]
lcl_ids, [TyThing]
top_ty_things) = forall a b c. (a -> Either b c) -> [a] -> ([b], [c])
partitionWith TyThing -> Either (Name, TcTyThing) TyThing
is_closed (InteractiveContext -> [TyThing]
ic_tythings InteractiveContext
icxt)
is_closed :: TyThing -> Either (Name, TcTyThing) TyThing
is_closed :: TyThing -> Either (Name, TcTyThing) TyThing
is_closed TyThing
thing
| AnId Var
id <- TyThing
thing
, Bool -> Bool
not (Var -> Bool
isTypeClosedLetBndr Var
id)
= forall a b. a -> Either a b
Left (Var -> Name
idName Var
id, ATcId { tct_id :: Var
tct_id = Var
id
, tct_info :: IdBindingInfo
tct_info = IdBindingInfo
NotLetBound })
| Bool
otherwise
= forall a b. b -> Either a b
Right TyThing
thing
type_env1 :: TypeEnv
type_env1 = [TyThing] -> TypeEnv
mkTypeEnvWithImplicits [TyThing]
top_ty_things
type_env :: TypeEnv
type_env = TypeEnv -> [Var] -> TypeEnv
extendTypeEnvWithIds TypeEnv
type_env1 (forall a b. (a -> b) -> [a] -> [b]
map ClsInst -> Var
instanceDFunId [ClsInst]
ic_insts)
con_fields :: [(Name, [FieldLabel])]
con_fields = [ (DataCon -> Name
dataConName DataCon
c, DataCon -> [FieldLabel]
dataConFieldLabels DataCon
c)
| ATyCon TyCon
t <- [TyThing]
top_ty_things
, DataCon
c <- TyCon -> [DataCon]
tyConDataCons TyCon
t ]
tcRnStmt :: HscEnv -> GhciLStmt GhcPs
-> IO (Messages DecoratedSDoc, Maybe ([Id], LHsExpr GhcTc, FixityEnv))
tcRnStmt :: HscEnv
-> GhciLStmt GhcPs
-> IO
(Messages DecoratedSDoc, Maybe ([Var], LHsExpr GhcTc, FixityEnv))
tcRnStmt HscEnv
hsc_env GhciLStmt GhcPs
rdr_stmt
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$ do {
(([Var]
bound_ids, GenLocated SrcSpanAnnA (HsExpr GhcTc)
tc_expr), FixityEnv
fix_env) <- GhciLStmt GhcPs -> TcM (PlanResult, FixityEnv)
tcUserStmt GhciLStmt GhcPs
rdr_stmt ;
GenLocated SrcSpanAnnA (HsExpr GhcTc)
zonked_expr <- LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkTopLExpr GenLocated SrcSpanAnnA (HsExpr GhcTc)
tc_expr ;
[Var]
zonked_ids <- [Var] -> TcM [Var]
zonkTopBndrs [Var]
bound_ids ;
TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM ;
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Var -> TcRnIf TcGblEnv TcLclEnv ()
bad_unboxed (forall a. (a -> Bool) -> [a] -> [a]
filter (HasDebugCallStack => Type -> Bool
isUnliftedType forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Type
idType) [Var]
zonked_ids) ;
String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcs 1" SDoc
empty ;
Module
this_mod <- forall (m :: * -> *). HasModule m => m Module
getModule ;
[Var]
global_ids <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Module -> Var -> TcM Var
externaliseAndTidyId Module
this_mod) [Var]
zonked_ids ;
DumpFlag -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceOptTcRn DumpFlag
Opt_D_dump_tc
([SDoc] -> SDoc
vcat [String -> SDoc
text String
"Bound Ids" SDoc -> SDoc -> SDoc
<+> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall a. Outputable a => a -> SDoc
ppr [Var]
global_ids,
String -> SDoc
text String
"Typechecked expr" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsExpr GhcTc)
zonked_expr]) ;
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
global_ids, GenLocated SrcSpanAnnA (HsExpr GhcTc)
zonked_expr, FixityEnv
fix_env)
}
where
bad_unboxed :: Var -> TcRnIf TcGblEnv TcLclEnv ()
bad_unboxed Var
id = SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErr ([SDoc] -> SDoc
sep [String -> SDoc
text String
"GHCi can't bind a variable of unlifted type:",
Arity -> SDoc -> SDoc
nest Arity
2 (forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc Var
id SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (Var -> Type
idType Var
id))])
type PlanResult = ([Id], LHsExpr GhcTc)
type Plan = TcM PlanResult
runPlans :: [Plan] -> TcM PlanResult
runPlans :: [Plan] -> Plan
runPlans [] = forall a. String -> a
panic String
"runPlans"
runPlans [Plan
p] = Plan
p
runPlans (Plan
p:[Plan]
ps) = forall r. TcM r -> TcM r -> TcM r
tryTcDiscardingErrs ([Plan] -> Plan
runPlans [Plan]
ps) Plan
p
tcUserStmt :: GhciLStmt GhcPs -> TcM (PlanResult, FixityEnv)
tcUserStmt :: GhciLStmt GhcPs -> TcM (PlanResult, FixityEnv)
tcUserStmt (L SrcSpanAnnA
loc (BodyStmt XBodyStmt GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
expr SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_))
= do { (GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr, FreeVars
fvs) <- forall r. TcM r -> TcM r
checkNoErrs (LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), FreeVars)
rnLExpr GenLocated SrcSpanAnnA (HsExpr GhcPs)
expr)
; GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
ghciStep <- TcM (LHsExpr (GhcPass 'Renamed))
getGhciStepIO
; Unique
uniq <- forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; let loc' :: SrcSpanAnnN
loc' = forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc
; Name
interPrintName <- TcRn Name
getInteractivePrintName
; let fresh_it :: Name
fresh_it = Unique -> SrcSpan -> Name
itName Unique
uniq (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
matches :: [GenLocated
SrcSpanAnnA
(Match
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
matches = [forall (p :: Pass).
IsPass p =>
HsMatchContext (NoGhcTc (GhcPass p))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> HsLocalBinds (GhcPass p)
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch (forall p. LIdP p -> HsMatchContext p
mkPrefixFunRhs (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc' Name
fresh_it)) [] GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds]
the_bind :: GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
the_bind = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ (Origin
-> GenLocated SrcSpanAnnN Name
-> [LMatch (GhcPass 'Renamed) (LHsExpr (GhcPass 'Renamed))]
-> HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed)
mkTopFunBind Origin
FromSource
(forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc' Name
fresh_it) [GenLocated
SrcSpanAnnA
(Match
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))]
matches)
{ fun_ext :: XFunBind (GhcPass 'Renamed) (GhcPass 'Renamed)
fun_ext = FreeVars
fvs }
let_stmt :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
let_stmt = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XLetStmt idL idR body
-> HsLocalBindsLR idL idR -> StmtLR idL idR body
LetStmt forall a. EpAnn a
noAnn forall a b. (a -> b) -> a -> b
$ forall idL idR.
XHsValBinds idL idR
-> HsValBindsLR idL idR -> HsLocalBindsLR idL idR
HsValBinds forall a. EpAnn a
noAnn
forall a b. (a -> b) -> a -> b
$ forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR
(forall idL.
[(RecFlag, LHsBinds idL)]
-> [LSig (GhcPass 'Renamed)] -> NHsValBindsLR idL
NValBinds [(RecFlag
NonRecursive,forall a. a -> Bag a
unitBag GenLocated
SrcSpanAnnA (HsBindLR (GhcPass 'Renamed) (GhcPass 'Renamed))
the_bind)] [])
bind_stmt :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
bind_stmt = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBindStmt idL idR body -> LPat idL -> body -> StmtLR idL idR body
BindStmt
(XBindStmtRn
{ xbsrn_bindOp :: SyntaxExpr (GhcPass 'Renamed)
xbsrn_bindOp = Name -> SyntaxExprRn
mkRnSyntaxExpr Name
bindIOName
, xbsrn_failOp :: FailOperator (GhcPass 'Renamed)
xbsrn_failOp = forall a. Maybe a
Nothing
})
(forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall p. XVarPat p -> LIdP p -> Pat p
VarPat NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc' Name
fresh_it)))
(forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
ghciStep GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr)
print_it :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
print_it = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt NoExtField
noExtField
(forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
interPrintName)
(forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
fresh_it))
(Name -> SyntaxExprRn
mkRnSyntaxExpr Name
thenIOName)
forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
no_it_a :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_a = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt NoExtField
noExtField (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> [LHsExpr (GhcPass p)] -> LHsExpr (GhcPass p)
nlHsApps Name
bindIOName
[GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr , forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
interPrintName])
(Name -> SyntaxExprRn
mkRnSyntaxExpr Name
thenIOName)
forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
no_it_b :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_b = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt NoExtField
noExtField (GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr)
(Name -> SyntaxExprRn
mkRnSyntaxExpr Name
thenIOName)
forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
no_it_c :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_c = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt NoExtField
noExtField
(forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
interPrintName) GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr)
(Name -> SyntaxExprRn
mkRnSyntaxExpr Name
thenIOName)
forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
it_plans :: [IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
it_plans = [
do { stuff :: ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
stuff@([Var
it_id], GenLocated SrcSpanAnnA (HsExpr GhcTc)
_) <- [GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
bind_stmt, GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
print_it]
; Type
it_ty <- Type -> TcM Type
zonkTcType (Var -> Type
idType Var
it_id)
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Type -> Bool
isUnitTy forall a b. (a -> b) -> a -> b
$ Type
it_ty) forall env a. IOEnv env a
failM
; forall (m :: * -> *) a. Monad m => a -> m a
return ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
stuff },
[GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
bind_stmt],
do { ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
_ <- forall r. TcM r -> TcM r
checkNoErrs ([GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
let_stmt])
; [GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
let_stmt, GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
print_it] } ]
no_it_plans :: [IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
no_it_plans = [
[GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_a] ,
[GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_b] ,
[GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
no_it_c] ]
; Bool
generate_it <- forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_NoIt
; ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
plan <- forall gbl lcl a.
GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetGOptM GeneralFlag
Opt_DeferTypeErrors forall a b. (a -> b) -> a -> b
$
forall gbl lcl a.
GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetGOptM GeneralFlag
Opt_DeferTypedHoles forall a b. (a -> b) -> a -> b
$
forall gbl lcl a.
GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetGOptM GeneralFlag
Opt_DeferOutOfScopeVariables forall a b. (a -> b) -> a -> b
$
[Plan] -> Plan
runPlans forall a b. (a -> b) -> a -> b
$ if Bool
generate_it
then [IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
no_it_plans
else [IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
it_plans
; FixityEnv
fix_env <- TcRn FixityEnv
getFixityEnv
; forall (m :: * -> *) a. Monad m => a -> m a
return (([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
plan, FixityEnv
fix_env) }
tcUserStmt rdr_stmt :: GhciLStmt GhcPs
rdr_stmt@(L SrcSpanAnnA
loc StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
_)
= do { (([GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
rn_stmt], FixityEnv
fix_env), FreeVars
fvs) <- forall r. TcM r -> TcM r
checkNoErrs forall a b. (a -> b) -> a -> b
$
forall (body :: * -> *) thing.
AnnoBody body =>
HsStmtContext (GhcPass 'Renamed)
-> (body GhcPs -> RnM (body (GhcPass 'Renamed), FreeVars))
-> [LStmt GhcPs (LocatedA (body GhcPs))]
-> ([Name] -> RnM (thing, FreeVars))
-> RnM
(([LStmt (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))],
thing),
FreeVars)
rnStmts forall p. HsStmtContext p
GhciStmtCtxt HsExpr GhcPs -> RnM (HsExpr (GhcPass 'Renamed), FreeVars)
rnExpr [GhciLStmt GhcPs
rdr_stmt] forall a b. (a -> b) -> a -> b
$ \[Name]
_ -> do
FixityEnv
fix_env <- TcRn FixityEnv
getFixityEnv
forall (m :: * -> *) a. Monad m => a -> m a
return (FixityEnv
fix_env, FreeVars
emptyFVs)
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceRn String
"tcRnStmt" ([SDoc] -> SDoc
vcat [forall a. Outputable a => a -> SDoc
ppr GhciLStmt GhcPs
rdr_stmt, forall a. Outputable a => a -> SDoc
ppr GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
rn_stmt, forall a. Outputable a => a -> SDoc
ppr FreeVars
fvs])
; forall a.
(Outputable a, Data a) =>
a -> TcRnIf TcGblEnv TcLclEnv ()
rnDump GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
rn_stmt ;
; GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
ghciStep <- TcM (LHsExpr (GhcPass 'Renamed))
getGhciStepIO
; let gi_stmt :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
gi_stmt
| (L SrcSpanAnnA
loc (BindStmt XBindStmt
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
x LPat (GhcPass 'Renamed)
pat GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
expr)) <- GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
rn_stmt
= forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBindStmt idL idR body -> LPat idL -> body -> StmtLR idL idR body
BindStmt XBindStmt
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
x LPat (GhcPass 'Renamed)
pat (forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
ghciStep GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
expr)
| Bool
otherwise = GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
rn_stmt
; Bool
opt_pr_flag <- forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_PrintBindResult
; let print_result_plan :: [IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
print_result_plan
| Bool
opt_pr_flag
, [IdP (GhcPass 'Renamed)
v] <- forall (idL :: Pass) (idR :: Pass) body.
CollectPass (GhcPass idL) =>
CollectFlag (GhcPass idL)
-> LStmtLR (GhcPass idL) (GhcPass idR) body -> [IdP (GhcPass idL)]
collectLStmtBinders forall p. CollectFlag p
CollNoDictBinders GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
gi_stmt
= [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
-> Name
-> IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
mk_print_result_plan GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
gi_stmt IdP (GhcPass 'Renamed)
v]
| Bool
otherwise = []
; ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
plan <- [Plan] -> Plan
runPlans ([IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))]
print_result_plan forall a. [a] -> [a] -> [a]
++ [[GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
gi_stmt]])
; forall (m :: * -> *) a. Monad m => a -> m a
return (([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
plan, FixityEnv
fix_env) }
where
mk_print_result_plan :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
-> Name
-> IOEnv
(Env TcGblEnv TcLclEnv)
([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
mk_print_result_plan GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
stmt Name
v
= do { stuff :: ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
stuff@([Var
v_id], GenLocated SrcSpanAnnA (HsExpr GhcTc)
_) <- [GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
stmt, GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
print_v]
; Type
v_ty <- Type -> TcM Type
zonkTcType (Var -> Type
idType Var
v_id)
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Type -> Bool
isUnitTy Type
v_ty Bool -> Bool -> Bool
|| Bool -> Bool
not (Type -> Bool
isTauTy Type
v_ty)) forall env a. IOEnv env a
failM
; forall (m :: * -> *) a. Monad m => a -> m a
return ([Var], GenLocated SrcSpanAnnA (HsExpr GhcTc))
stuff }
where
print_v :: GenLocated
SrcSpanAnnA
(StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))))
print_v = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt NoExtField
noExtField (forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
printName)
(forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
v))
(Name -> SyntaxExprRn
mkRnSyntaxExpr Name
thenIOName) forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
tcGhciStmts :: [GhciLStmt GhcRn] -> TcM PlanResult
tcGhciStmts :: [GhciLStmt (GhcPass 'Renamed)] -> Plan
tcGhciStmts [GhciLStmt (GhcPass 'Renamed)]
stmts
= do { TyCon
ioTyCon <- Name -> TcM TyCon
tcLookupTyCon Name
ioTyConName
; Var
ret_id <- Name -> TcM Var
tcLookupId Name
returnIOName
; let ret_ty :: Type
ret_ty = Type -> Type
mkListTy Type
unitTy
io_ret_ty :: Type
io_ret_ty = TyCon -> [Type] -> Type
mkTyConApp TyCon
ioTyCon [Type
ret_ty]
tc_io_stmts :: (ExpType -> TcM [Var])
-> TcM
([LStmt GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))], [Var])
tc_io_stmts = forall (body :: * -> *) rho_type thing.
AnnoBody body =>
HsStmtContext (GhcPass 'Renamed)
-> TcStmtChecker body rho_type
-> [LStmt (GhcPass 'Renamed) (LocatedA (body (GhcPass 'Renamed)))]
-> rho_type
-> (rho_type -> TcM thing)
-> TcM ([LStmt GhcTc (LocatedA (body GhcTc))], thing)
tcStmtsAndThen forall p. HsStmtContext p
GhciStmtCtxt TcExprStmtChecker
tcDoStmt [GhciLStmt (GhcPass 'Renamed)]
stmts
(Type -> ExpType
mkCheckExpType Type
io_ret_ty)
names :: [IdP (GhcPass 'Renamed)]
names = forall (idL :: Pass) (idR :: Pass) body.
CollectPass (GhcPass idL) =>
CollectFlag (GhcPass idL)
-> [LStmtLR (GhcPass idL) (GhcPass idR) body]
-> [IdP (GhcPass idL)]
collectLStmtsBinders forall p. CollectFlag p
CollNoDictBinders [GhciLStmt (GhcPass 'Renamed)]
stmts
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"GHC.Tc.Module.tcGhciStmts: tc stmts" SDoc
empty
; (([LocatedAn
AnnListItem
(StmtLR GhcTc GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
tc_stmts, [Var]
ids), WantedConstraints
lie) <- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
(ExpType -> TcM [Var])
-> TcM
([LStmt GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))], [Var])
tc_io_stmts forall a b. (a -> b) -> a -> b
$ \ ExpType
_ ->
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Name -> TcM Var
tcLookupId [IdP (GhcPass 'Renamed)]
names
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"GHC.Tc.Module.tcGhciStmts: simplify ctxt" SDoc
empty
; Bag EvBind
const_binds <- forall r. TcM r -> TcM r
checkNoErrs (WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyInteractive WantedConstraints
lie)
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"GHC.Tc.Module.tcGhciStmts: done" SDoc
empty
; AnId Var
unsafe_coerce_id <- Name -> TcM TyThing
tcLookupGlobal Name
unsafeCoercePrimName
; let ret_expr :: LHsExpr GhcTc
ret_expr = forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (Var -> [Type] -> LHsExpr GhcTc
nlHsTyApp Var
ret_id [Type
ret_ty]) forall a b. (a -> b) -> a -> b
$
forall a an. a -> LocatedAn an a
noLocA forall a b. (a -> b) -> a -> b
$ forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList Type
unitTy forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map Var -> LHsExpr GhcTc
mk_item [Var]
ids
mk_item :: Var -> LHsExpr GhcTc
mk_item Var
id = Var
unsafe_coerce_id Var -> [Type] -> LHsExpr GhcTc
`nlHsTyApp` [ HasDebugCallStack => Type -> Type
getRuntimeRep (Var -> Type
idType Var
id)
, HasDebugCallStack => Type -> Type
getRuntimeRep Type
unitTy
, Var -> Type
idType Var
id, Type
unitTy]
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Var
id
stmts :: [LocatedAn
AnnListItem
(StmtLR GhcTc GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
stmts = [LocatedAn
AnnListItem
(StmtLR GhcTc GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
tc_stmts forall a. [a] -> [a] -> [a]
++ [forall a an. a -> LocatedAn an a
noLocA (forall (idR :: Pass) (bodyR :: * -> *) (idL :: Pass).
IsPass idR =>
LocatedA (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (LocatedA (bodyR (GhcPass idR)))
mkLastStmt LHsExpr GhcTc
ret_expr)]
; forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
ids, TcEvBinds -> LHsExpr GhcTc -> LHsExpr GhcTc
mkHsDictLet (Bag EvBind -> TcEvBinds
EvBinds Bag EvBind
const_binds) forall a b. (a -> b) -> a -> b
$
forall a an. a -> LocatedAn an a
noLocA (forall p.
XDo p
-> HsStmtContext (HsDoRn p) -> XRec p [ExprLStmt p] -> HsExpr p
HsDo Type
io_ret_ty forall p. HsStmtContext p
GhciStmtCtxt (forall a an. a -> LocatedAn an a
noLocA [LocatedAn
AnnListItem
(StmtLR GhcTc GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
stmts)))
}
getGhciStepIO :: TcM (LHsExpr GhcRn)
getGhciStepIO :: TcM (LHsExpr (GhcPass 'Renamed))
getGhciStepIO = do
Name
ghciTy <- TcRn Name
getGHCiMonad
Name
a_tv <- OccName -> TcRn Name
newName (FastString -> OccName
mkTyVarOccFS (String -> FastString
fsLit String
"a"))
let ghciM :: LHsType (GhcPass 'Renamed)
ghciM = forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
nlHsAppTy (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar Name
ghciTy) (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar Name
a_tv)
ioM :: LHsType (GhcPass 'Renamed)
ioM = forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
nlHsAppTy (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar Name
ioTyConName) (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar Name
a_tv)
step_ty :: LHsSigType GhcRn
step_ty :: LHsSigType (GhcPass 'Renamed)
step_ty = forall a an. a -> LocatedAn an a
noLocA forall a b. (a -> b) -> a -> b
$ HsSig
{ sig_bndrs :: HsOuterSigTyVarBndrs (GhcPass 'Renamed)
sig_bndrs = HsOuterImplicit{hso_ximplicit :: XHsOuterImplicit (GhcPass 'Renamed)
hso_ximplicit = [Name
a_tv]}
, sig_ext :: XHsSig (GhcPass 'Renamed)
sig_ext = NoExtField
noExtField
, sig_body :: LHsType (GhcPass 'Renamed)
sig_body = forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
nlHsFunTy LHsType (GhcPass 'Renamed)
ghciM LHsType (GhcPass 'Renamed)
ioM }
stepTy :: LHsSigWcType GhcRn
stepTy :: LHsSigWcType (GhcPass 'Renamed)
stepTy = forall thing. thing -> HsWildCardBndrs (GhcPass 'Renamed) thing
mkEmptyWildCardBndrs LHsSigType (GhcPass 'Renamed)
step_ty
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a an. a -> LocatedAn an a
noLocA forall a b. (a -> b) -> a -> b
$ forall p.
XExprWithTySig p
-> LHsExpr p -> LHsSigWcType (NoGhcTc p) -> HsExpr p
ExprWithTySig NoExtField
noExtField (forall (p :: Pass) a.
IsSrcSpanAnn p a =>
IdP (GhcPass p) -> LHsExpr (GhcPass p)
nlHsVar Name
ghciStepIoMName) LHsSigWcType (GhcPass 'Renamed)
stepTy)
isGHCiMonad :: HscEnv -> String -> IO (Messages DecoratedSDoc, Maybe Name)
isGHCiMonad :: HscEnv -> String -> IO (Messages DecoratedSDoc, Maybe Name)
isGHCiMonad HscEnv
hsc_env String
ty
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$ do
GlobalRdrEnv
rdrEnv <- TcRn GlobalRdrEnv
getGlobalRdrEnv
let occIO :: Maybe [GlobalRdrElt]
occIO = forall a. OccEnv a -> OccName -> Maybe a
lookupOccEnv GlobalRdrEnv
rdrEnv (NameSpace -> String -> OccName
mkOccName NameSpace
tcName String
ty)
case Maybe [GlobalRdrElt]
occIO of
Just [GlobalRdrElt
n] -> do
let name :: Name
name = GlobalRdrElt -> Name
greMangledName GlobalRdrElt
n
Class
ghciClass <- Name -> TcM Class
tcLookupClass Name
ghciIoClassName
TyCon
userTyCon <- Name -> TcM TyCon
tcLookupTyCon Name
name
let userTy :: Type
userTy = TyCon -> [Type] -> Type
mkTyConApp TyCon
userTyCon []
ClsInst
_ <- Class -> [Type] -> TcM ClsInst
tcLookupInstance Class
ghciClass [Type
userTy]
forall (m :: * -> *) a. Monad m => a -> m a
return Name
name
Just [GlobalRdrElt]
_ -> forall a. SDoc -> TcM a
failWithTc forall a b. (a -> b) -> a -> b
$ String -> SDoc
text String
"Ambiguous type!"
Maybe [GlobalRdrElt]
Nothing -> forall a. SDoc -> TcM a
failWithTc forall a b. (a -> b) -> a -> b
$ String -> SDoc
text (String
"Can't find type:" forall a. [a] -> [a] -> [a]
++ String
ty)
data TcRnExprMode = TM_Inst
| TM_Default
tcRnExpr :: HscEnv
-> TcRnExprMode
-> LHsExpr GhcPs
-> IO (Messages DecoratedSDoc, Maybe Type)
tcRnExpr :: HscEnv
-> TcRnExprMode
-> LHsExpr GhcPs
-> IO (Messages DecoratedSDoc, DFunInstType)
tcRnExpr HscEnv
hsc_env TcRnExprMode
mode LHsExpr GhcPs
rdr_expr
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
do {
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr, FreeVars
_fvs) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), FreeVars)
rnLExpr LHsExpr GhcPs
rdr_expr ;
TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM ;
((TcLevel
tclvl, Type
res_ty), WantedConstraints
lie)
<- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
forall a. TcM a -> TcM (TcLevel, a)
pushTcLevelM forall a b. (a -> b) -> a -> b
$
Bool -> LHsExpr (GhcPass 'Renamed) -> TcM Type
tcInferSigma Bool
inst GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
rn_expr ;
Unique
uniq <- forall gbl lcl. TcRnIf gbl lcl Unique
newUnique ;
let { fresh_it :: Name
fresh_it = Unique -> SrcSpan -> Name
itName Unique
uniq (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsExpr GhcPs
rdr_expr) } ;
(([Var]
qtvs, [Var]
dicts, TcEvBinds
_, Bool
_), WantedConstraints
residual)
<- forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints forall a b. (a -> b) -> a -> b
$
TcLevel
-> InferMode
-> [TcIdSigInst]
-> [(Name, Type)]
-> WantedConstraints
-> TcM ([Var], [Var], TcEvBinds, Bool)
simplifyInfer TcLevel
tclvl InferMode
infer_mode
[]
[(Name
fresh_it, Type
res_ty)]
WantedConstraints
lie ;
Bag EvBind
_ <- TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
-> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
perhaps_disable_default_warnings forall a b. (a -> b) -> a -> b
$
WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyInteractive WantedConstraints
residual ;
let { all_expr_ty :: Type
all_expr_ty = [Var] -> Type -> Type
mkInfForAllTys [Var]
qtvs forall a b. (a -> b) -> a -> b
$
[Type] -> Type -> Type
mkPhiTy (forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
idType [Var]
dicts) Type
res_ty } ;
Type
ty <- Type -> TcM Type
zonkTcType Type
all_expr_ty ;
FamInstEnvs
fam_envs <- TcM FamInstEnvs
tcGetFamInstEnvs ;
let { normalised_type :: Type
normalised_type = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ FamInstEnvs -> Role -> Type -> (Coercion, Type)
normaliseType FamInstEnvs
fam_envs Role
Nominal Type
ty
; final_type :: Type
final_type = if Type -> Bool
isSigmaTy Type
res_ty then Type
ty else Type
normalised_type } ;
forall (m :: * -> *) a. Monad m => a -> m a
return Type
final_type }
where
(Bool
inst, InferMode
infer_mode, TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
-> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
perhaps_disable_default_warnings) = case TcRnExprMode
mode of
TcRnExprMode
TM_Inst -> (Bool
False, InferMode
NoRestrictions, forall a. a -> a
id)
TcRnExprMode
TM_Default -> (Bool
True, InferMode
EagerDefaulting, forall gbl lcl a.
WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetWOptM WarningFlag
Opt_WarnTypeDefaults)
tcRnImportDecls :: HscEnv
-> [LImportDecl GhcPs]
-> IO (Messages DecoratedSDoc, Maybe GlobalRdrEnv)
tcRnImportDecls :: HscEnv
-> [LImportDecl GhcPs]
-> IO (Messages DecoratedSDoc, Maybe GlobalRdrEnv)
tcRnImportDecls HscEnv
hsc_env [LImportDecl GhcPs]
import_decls
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
do { TcGblEnv
gbl_env <- forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv TcGblEnv -> TcGblEnv
zap_rdr_env forall a b. (a -> b) -> a -> b
$
HscEnv -> [LImportDecl GhcPs] -> TcM TcGblEnv
tcRnImports HscEnv
hsc_env [LImportDecl GhcPs]
import_decls
; forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv -> GlobalRdrEnv
tcg_rdr_env TcGblEnv
gbl_env) }
where
zap_rdr_env :: TcGblEnv -> TcGblEnv
zap_rdr_env TcGblEnv
gbl_env = TcGblEnv
gbl_env { tcg_rdr_env :: GlobalRdrEnv
tcg_rdr_env = GlobalRdrEnv
emptyGlobalRdrEnv }
tcRnType :: HscEnv
-> ZonkFlexi
-> Bool
-> LHsType GhcPs
-> IO (Messages DecoratedSDoc, Maybe (Type, Kind))
tcRnType :: HscEnv
-> ZonkFlexi
-> Bool
-> LHsType GhcPs
-> IO (Messages DecoratedSDoc, Maybe (Type, Type))
tcRnType HscEnv
hsc_env ZonkFlexi
flexi Bool
normalise LHsType GhcPs
rdr_type
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
forall gbl lcl a. Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setXOptM Extension
LangExt.PolyKinds forall a b. (a -> b) -> a -> b
$
do { (HsWC { hswc_ext :: forall pass thing. HsWildCardBndrs pass thing -> XHsWC pass thing
hswc_ext = XHsWC
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
wcs, hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
rn_type }, FreeVars
_fvs)
<- HsDocContext
-> LHsWcType GhcPs -> RnM (LHsWcType (GhcPass 'Renamed), FreeVars)
rnHsWcType HsDocContext
GHCiCtx (forall thing. thing -> HsWildCardBndrs GhcPs thing
mkHsWildCardBndrs LHsType GhcPs
rdr_type)
; TcRnIf TcGblEnv TcLclEnv ()
failIfErrsM
; String -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
traceTc String
"tcRnType" ([SDoc] -> SDoc
vcat [forall a. Outputable a => a -> SDoc
ppr XHsWC
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
wcs, forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
rn_type])
; ((Type
ty, Type
kind), WantedConstraints
wanted)
<- forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints forall a b. (a -> b) -> a -> b
$
forall r. TcM r -> TcM r
pushTcLevelM_ forall a b. (a -> b) -> a -> b
$
forall a. [Name] -> ([(Name, Var)] -> TcM a) -> TcM a
bindNamedWildCardBinders XHsWC
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
wcs forall a b. (a -> b) -> a -> b
$ \ [(Name, Var)]
wcs' ->
do { forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Name, Var) -> TcRnIf TcGblEnv TcLclEnv ()
emitNamedTypeHole [(Name, Var)]
wcs'
; LHsType (GhcPass 'Renamed) -> TcM (Type, Type)
tcInferLHsTypeUnsaturated GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
rn_type }
; Bag EvBind
empty_binds <- WantedConstraints -> TcRnIf TcGblEnv TcLclEnv (Bag EvBind)
simplifyTop WantedConstraints
wanted
; MASSERT2( isEmptyBag empty_binds, ppr empty_binds )
; [Var]
kvs <- Type -> TcM [Var]
kindGeneralizeAll Type
kind
; ZonkEnv
e <- ZonkFlexi -> TcM ZonkEnv
mkEmptyZonkEnv ZonkFlexi
flexi
; Type
ty <- ZonkEnv -> Type -> TcM Type
zonkTcTypeToTypeX ZonkEnv
e Type
ty
; UserTypeCtxt -> Type -> TcRnIf TcGblEnv TcLclEnv ()
checkValidType (Bool -> UserTypeCtxt
GhciCtxt Bool
True) Type
ty
; FamInstEnvs
fam_envs <- TcM FamInstEnvs
tcGetFamInstEnvs
; let ty' :: Type
ty' | Bool
normalise = Type -> Type
expandTypeSynonyms forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$
FamInstEnvs -> Role -> Type -> (Coercion, Type)
normaliseType FamInstEnvs
fam_envs Role
Nominal Type
ty
| Bool
otherwise = Type
ty
; forall (m :: * -> *) a. Monad m => a -> m a
return (Type
ty', [Var] -> Type -> Type
mkInfForAllTys [Var]
kvs (HasDebugCallStack => Type -> Type
tcTypeKind Type
ty')) }
tcRnDeclsi :: HscEnv
-> [LHsDecl GhcPs]
-> IO (Messages DecoratedSDoc, Maybe TcGblEnv)
tcRnDeclsi :: HscEnv
-> [LHsDecl GhcPs] -> IO (Messages DecoratedSDoc, Maybe TcGblEnv)
tcRnDeclsi HscEnv
hsc_env [LHsDecl GhcPs]
local_decls
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
Bool
-> Maybe (LocatedL [LIE GhcPs]) -> [LHsDecl GhcPs] -> TcM TcGblEnv
tcRnSrcDecls Bool
False forall a. Maybe a
Nothing [LHsDecl GhcPs]
local_decls
externaliseAndTidyId :: Module -> Id -> TcM Id
externaliseAndTidyId :: Module -> Var -> TcM Var
externaliseAndTidyId Module
this_mod Var
id
= do { Name
name' <- forall m n. Module -> Name -> TcRnIf m n Name
externaliseName Module
this_mod (Var -> Name
idName Var
id)
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Var -> Var
globaliseId Var
id
Var -> Name -> Var
`setIdName` Name
name'
Var -> Type -> Var
`setIdType` Type -> Type
tidyTopType (Var -> Type
idType Var
id) }
getModuleInterface :: HscEnv -> Module -> IO (Messages DecoratedSDoc, Maybe ModIface)
getModuleInterface :: HscEnv
-> Module
-> IO (Messages DecoratedSDoc, Maybe (ModIface_ 'ModIfaceFinal))
getModuleInterface HscEnv
hsc_env Module
mod
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
SDoc -> Module -> RnM (ModIface_ 'ModIfaceFinal)
loadModuleInterface (String -> SDoc
text String
"getModuleInterface") Module
mod
tcRnLookupRdrName :: HscEnv -> LocatedN RdrName
-> IO (Messages DecoratedSDoc, Maybe [Name])
tcRnLookupRdrName :: HscEnv
-> GenLocated SrcSpanAnnN RdrName
-> IO (Messages DecoratedSDoc, Maybe [Name])
tcRnLookupRdrName HscEnv
hsc_env (L SrcSpanAnnN
loc RdrName
rdr_name)
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
forall ann a. SrcSpanAnn' ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnN
loc forall a b. (a -> b) -> a -> b
$
do {
let rdr_names :: [RdrName]
rdr_names = RdrName -> [RdrName]
dataTcOccs RdrName
rdr_name
; [[Name]]
names_s <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RdrName -> TcRn [Name]
lookupInfoOccRn [RdrName]
rdr_names
; let names :: [Name]
names = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Name]]
names_s
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
names) (SDoc -> TcRnIf TcGblEnv TcLclEnv ()
addErrTc (String -> SDoc
text String
"Not in scope:" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)))
; forall (m :: * -> *) a. Monad m => a -> m a
return [Name]
names }
tcRnLookupName :: HscEnv -> Name -> IO (Messages DecoratedSDoc, Maybe TyThing)
tcRnLookupName :: HscEnv -> Name -> IO (Messages DecoratedSDoc, Maybe TyThing)
tcRnLookupName HscEnv
hsc_env Name
name
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
Name -> TcM TyThing
tcRnLookupName' Name
name
tcRnLookupName' :: Name -> TcRn TyThing
tcRnLookupName' :: Name -> TcM TyThing
tcRnLookupName' Name
name = do
TcTyThing
tcthing <- Name -> TcM TcTyThing
tcLookup Name
name
case TcTyThing
tcthing of
AGlobal TyThing
thing -> forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
thing
ATcId{tct_id :: TcTyThing -> Var
tct_id=Var
id} -> forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> TyThing
AnId Var
id)
TcTyThing
_ -> forall a. String -> a
panic String
"tcRnLookupName'"
tcRnGetInfo :: HscEnv
-> Name
-> IO ( Messages DecoratedSDoc
, Maybe (TyThing, Fixity, [ClsInst], [FamInst], SDoc))
tcRnGetInfo :: HscEnv
-> Name
-> IO
(Messages DecoratedSDoc,
Maybe (TyThing, Fixity, [ClsInst], [FamInst], SDoc))
tcRnGetInfo HscEnv
hsc_env Name
name
= forall a. HscEnv -> TcRn a -> IO (Messages DecoratedSDoc, Maybe a)
runTcInteractive HscEnv
hsc_env forall a b. (a -> b) -> a -> b
$
do { HscEnv -> InteractiveContext -> TcRnIf TcGblEnv TcLclEnv ()
loadUnqualIfaces HscEnv
hsc_env (HscEnv -> InteractiveContext
hsc_IC HscEnv
hsc_env)
; TyThing
thing <- Name -> TcM TyThing
tcRnLookupName' Name
name
; Fixity
fixity <- Name -> RnM Fixity
lookupFixityRn Name
name
; ([ClsInst]
cls_insts, [FamInst]
fam_insts) <- TyThing -> TcM ([ClsInst], [FamInst])
lookupInsts TyThing
thing
; let info :: SDoc
info = Name -> SDoc
lookupKnownNameInfo Name
name
; forall (m :: * -> *) a. Monad m => a -> m a
return (TyThing
thing, Fixity
fixity, [ClsInst]
cls_insts, [FamInst]
fam_insts, SDoc
info) }
lookupInsts :: TyThing -> TcM ([ClsInst],[FamInst])
lookupInsts :: TyThing -> TcM ([ClsInst], [FamInst])
lookupInsts (ATyCon TyCon
tc)
= do { InstEnvs { ie_global :: InstEnvs -> InstEnv
ie_global = InstEnv
pkg_ie, ie_local :: InstEnvs -> InstEnv
ie_local = InstEnv
home_ie, ie_visible :: InstEnvs -> VisibleOrphanModules
ie_visible = VisibleOrphanModules
vis_mods } <- TcM InstEnvs
tcGetInstEnvs
; (FamInstEnv
pkg_fie, FamInstEnv
home_fie) <- TcM FamInstEnvs
tcGetFamInstEnvs
; let cls_insts :: [ClsInst]
cls_insts =
[ ClsInst
ispec
| ClsInst
ispec <- InstEnv -> [ClsInst]
instEnvElts InstEnv
home_ie forall a. [a] -> [a] -> [a]
++ InstEnv -> [ClsInst]
instEnvElts InstEnv
pkg_ie
, VisibleOrphanModules -> ClsInst -> Bool
instIsVisible VisibleOrphanModules
vis_mods ClsInst
ispec
, Name
tc_name Name -> FreeVars -> Bool
`elemNameSet` ClsInst -> FreeVars
orphNamesOfClsInst ClsInst
ispec ]
; let fam_insts :: [FamInst]
fam_insts =
[ FamInst
fispec
| FamInst
fispec <- FamInstEnv -> [FamInst]
famInstEnvElts FamInstEnv
home_fie forall a. [a] -> [a] -> [a]
++ FamInstEnv -> [FamInst]
famInstEnvElts FamInstEnv
pkg_fie
, Name
tc_name Name -> FreeVars -> Bool
`elemNameSet` FamInst -> FreeVars
orphNamesOfFamInst FamInst
fispec ]
; forall (m :: * -> *) a. Monad m => a -> m a
return ([ClsInst]
cls_insts, [FamInst]
fam_insts) }
where
tc_name :: Name
tc_name = TyCon -> Name
tyConName TyCon
tc
lookupInsts TyThing
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ([],[])
loadUnqualIfaces :: HscEnv -> InteractiveContext -> TcM ()
loadUnqualIfaces :: HscEnv -> InteractiveContext -> TcRnIf TcGblEnv TcLclEnv ()
loadUnqualIfaces HscEnv
hsc_env InteractiveContext
ictxt
= forall a. IfG a -> TcRn a
initIfaceTcRn forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall lcl. SDoc -> Module -> IfM lcl (ModIface_ 'ModIfaceFinal)
loadSysInterface SDoc
doc) (VisibleOrphanModules -> [Module]
moduleSetElts ([Module] -> VisibleOrphanModules
mkModuleSet [Module]
unqual_mods))
where
home_unit :: HomeUnit
home_unit = HscEnv -> HomeUnit
hsc_home_unit HscEnv
hsc_env
unqual_mods :: [Module]
unqual_mods = [ HasDebugCallStack => Name -> Module
nameModule Name
name
| GlobalRdrElt
gre <- GlobalRdrEnv -> [GlobalRdrElt]
globalRdrEnvElts (InteractiveContext -> GlobalRdrEnv
ic_rn_gbl_env InteractiveContext
ictxt)
, let name :: Name
name = GlobalRdrElt -> Name
greMangledName GlobalRdrElt
gre
, HomeUnit -> Name -> Bool
nameIsFromExternalPackage HomeUnit
home_unit Name
name
, OccName -> Bool
isTcOcc (Name -> OccName
nameOccName Name
name)
, GlobalRdrElt -> Bool
unQualOK GlobalRdrElt
gre ]
doc :: SDoc
doc = String -> SDoc
text String
"Need interface for module whose export(s) are in scope unqualified"
rnDump :: (Outputable a, Data a) => a -> TcRn ()
rnDump :: forall a.
(Outputable a, Data a) =>
a -> TcRnIf TcGblEnv TcLclEnv ()
rnDump a
rn = DumpFlag
-> String -> DumpFormat -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
dumpOptTcRn DumpFlag
Opt_D_dump_rn String
"Renamer" DumpFormat
FormatHaskell (forall a. Outputable a => a -> SDoc
ppr a
rn)
tcDump :: TcGblEnv -> TcRn ()
tcDump :: TcGblEnv -> TcRnIf TcGblEnv TcLclEnv ()
tcDump TcGblEnv
env
= do { DynFlags
dflags <- forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags ;
UnitState
unit_state <- HscEnv -> UnitState
hsc_units forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv ;
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (DumpFlag -> DynFlags -> Bool
dopt DumpFlag
Opt_D_dump_types DynFlags
dflags Bool -> Bool -> Bool
|| DumpFlag -> DynFlags -> Bool
dopt DumpFlag
Opt_D_dump_tc DynFlags
dflags)
(Bool
-> DumpFlag
-> String
-> DumpFormat
-> SDoc
-> TcRnIf TcGblEnv TcLclEnv ()
dumpTcRn Bool
True DumpFlag
Opt_D_dump_types
String
"" DumpFormat
FormatText (UnitState -> SDoc -> SDoc
pprWithUnitState UnitState
unit_state SDoc
short_dump)) ;
DumpFlag
-> String -> DumpFormat -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
dumpOptTcRn DumpFlag
Opt_D_dump_tc String
"Typechecker" DumpFormat
FormatHaskell SDoc
full_dump;
DumpFlag
-> String -> DumpFormat -> SDoc -> TcRnIf TcGblEnv TcLclEnv ()
dumpOptTcRn DumpFlag
Opt_D_dump_tc_ast String
"Typechecker AST" DumpFormat
FormatHaskell SDoc
ast_dump
}
where
short_dump :: SDoc
short_dump = TcGblEnv -> SDoc
pprTcGblEnv TcGblEnv
env
full_dump :: SDoc
full_dump = forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
LHsBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprLHsBinds (TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
env)
ast_dump :: SDoc
ast_dump = forall a. Data a => BlankSrcSpan -> BlankEpAnnotations -> a -> SDoc
showAstData BlankSrcSpan
NoBlankSrcSpan BlankEpAnnotations
NoBlankEpAnnotations (TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
env)
pprTcGblEnv :: TcGblEnv -> SDoc
pprTcGblEnv :: TcGblEnv -> SDoc
pprTcGblEnv (TcGblEnv { tcg_type_env :: TcGblEnv -> TypeEnv
tcg_type_env = TypeEnv
type_env,
tcg_insts :: TcGblEnv -> [ClsInst]
tcg_insts = [ClsInst]
insts,
tcg_fam_insts :: TcGblEnv -> [FamInst]
tcg_fam_insts = [FamInst]
fam_insts,
tcg_rules :: TcGblEnv -> [LRuleDecl GhcTc]
tcg_rules = [LRuleDecl GhcTc]
rules,
tcg_imports :: TcGblEnv -> ImportAvails
tcg_imports = ImportAvails
imports })
= (Bool -> SDoc) -> SDoc
getPprDebug forall a b. (a -> b) -> a -> b
$ \Bool
debug ->
[SDoc] -> SDoc
vcat [ Bool -> TypeEnv -> SDoc
ppr_types Bool
debug TypeEnv
type_env
, Bool -> [FamInst] -> TypeEnv -> SDoc
ppr_tycons Bool
debug [FamInst]
fam_insts TypeEnv
type_env
, Bool -> TypeEnv -> SDoc
ppr_datacons Bool
debug TypeEnv
type_env
, TypeEnv -> SDoc
ppr_patsyns TypeEnv
type_env
, [ClsInst] -> SDoc
ppr_insts [ClsInst]
insts
, [FamInst] -> SDoc
ppr_fam_insts [FamInst]
fam_insts
, [LRuleDecl GhcTc] -> SDoc
ppr_rules [LRuleDecl GhcTc]
rules
, String -> SDoc
text String
"Dependent modules:" SDoc -> SDoc -> SDoc
<+>
forall key a. UniqFM key a -> ([a] -> SDoc) -> SDoc
pprUFM (ImportAvails -> ModuleNameEnv ModuleNameWithIsBoot
imp_dep_mods ImportAvails
imports) (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort)
, String -> SDoc
text String
"Dependent packages:" SDoc -> SDoc -> SDoc
<+>
forall a. Outputable a => a -> SDoc
ppr (forall a. Set a -> [a]
S.toList forall a b. (a -> b) -> a -> b
$ ImportAvails -> Set UnitId
imp_dep_pkgs ImportAvails
imports)]
ppr_rules :: [LRuleDecl GhcTc] -> SDoc
ppr_rules :: [LRuleDecl GhcTc] -> SDoc
ppr_rules [LRuleDecl GhcTc]
rules
= Bool -> SDoc -> SDoc
ppUnless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LRuleDecl GhcTc]
rules) forall a b. (a -> b) -> a -> b
$
SDoc -> Arity -> SDoc -> SDoc
hang (String -> SDoc
text String
"RULES")
Arity
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LRuleDecl GhcTc]
rules))
ppr_types :: Bool -> TypeEnv -> SDoc
ppr_types :: Bool -> TypeEnv -> SDoc
ppr_types Bool
debug TypeEnv
type_env
= forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"TYPE SIGNATURES" Var -> SDoc
ppr_sig
(forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing forall a. NamedThing a => a -> OccName
getOccName) [Var]
ids)
where
ids :: [Var]
ids = [Var
id | Var
id <- TypeEnv -> [Var]
typeEnvIds TypeEnv
type_env, Var -> Bool
want_sig Var
id]
want_sig :: Var -> Bool
want_sig Var
id
| Bool
debug = Bool
True
| Bool
otherwise = forall x. NamedThing x => x -> Bool
hasTopUserName Var
id
Bool -> Bool -> Bool
&& case Var -> IdDetails
idDetails Var
id of
IdDetails
VanillaId -> Bool
True
RecSelId {} -> Bool
True
ClassOpId {} -> Bool
True
FCallId {} -> Bool
True
IdDetails
_ -> Bool
False
ppr_sig :: Var -> SDoc
ppr_sig Var
id = SDoc -> Arity -> SDoc -> SDoc
hang (forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc Var
id SDoc -> SDoc -> SDoc
<+> SDoc
dcolon) Arity
2 (forall a. Outputable a => a -> SDoc
ppr (Type -> Type
tidyTopType (Var -> Type
idType Var
id)))
ppr_tycons :: Bool -> [FamInst] -> TypeEnv -> SDoc
ppr_tycons :: Bool -> [FamInst] -> TypeEnv -> SDoc
ppr_tycons Bool
debug [FamInst]
fam_insts TypeEnv
type_env
= [SDoc] -> SDoc
vcat [ forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"TYPE CONSTRUCTORS" TyCon -> SDoc
ppr_tc [TyCon]
tycons
, forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"COERCION AXIOMS" forall {br :: BranchFlag}. CoAxiom br -> SDoc
ppr_ax
(TypeEnv -> [CoAxiom Branched]
typeEnvCoAxioms TypeEnv
type_env) ]
where
fi_tycons :: [TyCon]
fi_tycons = [FamInst] -> [TyCon]
famInstsRepTyCons [FamInst]
fam_insts
tycons :: [TyCon]
tycons = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing forall a. NamedThing a => a -> OccName
getOccName) forall a b. (a -> b) -> a -> b
$
[TyCon
tycon | TyCon
tycon <- TypeEnv -> [TyCon]
typeEnvTyCons TypeEnv
type_env
, TyCon -> Bool
want_tycon TyCon
tycon]
want_tycon :: TyCon -> Bool
want_tycon TyCon
tycon | Bool
debug = Bool
True
| Bool
otherwise = Name -> Bool
isExternalName (TyCon -> Name
tyConName TyCon
tycon) Bool -> Bool -> Bool
&&
Bool -> Bool
not (TyCon
tycon forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [TyCon]
fi_tycons)
ppr_tc :: TyCon -> SDoc
ppr_tc TyCon
tc
= [SDoc] -> SDoc
vcat [ SDoc -> Arity -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr (TyCon -> TyConFlavour
tyConFlavour TyCon
tc) SDoc -> SDoc -> SDoc
<+> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (TyCon -> Name
tyConName TyCon
tc)
SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces (forall a. Outputable a => a -> SDoc
ppr (TyCon -> Arity
tyConArity TyCon
tc)) SDoc -> SDoc -> SDoc
<+> SDoc
dcolon)
Arity
2 (forall a. Outputable a => a -> SDoc
ppr (Type -> Type
tidyTopType (TyCon -> Type
tyConKind TyCon
tc)))
, Arity -> SDoc -> SDoc
nest Arity
2 forall a b. (a -> b) -> a -> b
$
Bool -> SDoc -> SDoc
ppWhen Bool
show_roles forall a b. (a -> b) -> a -> b
$
String -> SDoc
text String
"roles" SDoc -> SDoc -> SDoc
<+> ([SDoc] -> SDoc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Role]
roles)) ]
where
show_roles :: Bool
show_roles = Bool
debug Bool -> Bool -> Bool
|| Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== Role
boring_role) [Role]
roles)
roles :: [Role]
roles = TyCon -> [Role]
tyConRoles TyCon
tc
boring_role :: Role
boring_role | TyCon -> Bool
isClassTyCon TyCon
tc = Role
Nominal
| Bool
otherwise = Role
Representational
ppr_ax :: CoAxiom br -> SDoc
ppr_ax CoAxiom br
ax = forall a. Outputable a => a -> SDoc
ppr (forall (br :: BranchFlag). CoAxiom br -> IfaceDecl
coAxiomToIfaceDecl CoAxiom br
ax)
ppr_datacons :: Bool -> TypeEnv -> SDoc
ppr_datacons :: Bool -> TypeEnv -> SDoc
ppr_datacons Bool
debug TypeEnv
type_env
= forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"DATA CONSTRUCTORS" DataCon -> SDoc
ppr_dc [DataCon]
wanted_dcs
where
ppr_dc :: DataCon -> SDoc
ppr_dc DataCon
dc = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocLinearTypes (\Bool
show_linear_types ->
forall a. Outputable a => a -> SDoc
ppr DataCon
dc SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (Bool -> DataCon -> Type
dataConDisplayType Bool
show_linear_types DataCon
dc))
all_dcs :: [DataCon]
all_dcs = TypeEnv -> [DataCon]
typeEnvDataCons TypeEnv
type_env
wanted_dcs :: [DataCon]
wanted_dcs | Bool
debug = [DataCon]
all_dcs
| Bool
otherwise = forall a. (a -> Bool) -> [a] -> [a]
filterOut DataCon -> Bool
is_cls_dc [DataCon]
all_dcs
is_cls_dc :: DataCon -> Bool
is_cls_dc DataCon
dc = TyCon -> Bool
isClassTyCon (DataCon -> TyCon
dataConTyCon DataCon
dc)
ppr_patsyns :: TypeEnv -> SDoc
ppr_patsyns :: TypeEnv -> SDoc
ppr_patsyns TypeEnv
type_env
= forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"PATTERN SYNONYMS" PatSyn -> SDoc
ppr_ps
(TypeEnv -> [PatSyn]
typeEnvPatSyns TypeEnv
type_env)
where
ppr_ps :: PatSyn -> SDoc
ppr_ps PatSyn
ps = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc PatSyn
ps SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> PatSyn -> SDoc
pprPatSynType PatSyn
ps
ppr_insts :: [ClsInst] -> SDoc
ppr_insts :: [ClsInst] -> SDoc
ppr_insts [ClsInst]
ispecs
= forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"CLASS INSTANCES" ClsInst -> SDoc
pprInstance [ClsInst]
ispecs
ppr_fam_insts :: [FamInst] -> SDoc
ppr_fam_insts :: [FamInst] -> SDoc
ppr_fam_insts [FamInst]
fam_insts
= forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
"FAMILY INSTANCES" FamInst -> SDoc
pprFamInst [FamInst]
fam_insts
ppr_things :: String -> (a -> SDoc) -> [a] -> SDoc
ppr_things :: forall a. String -> (a -> SDoc) -> [a] -> SDoc
ppr_things String
herald a -> SDoc
ppr_one [a]
things
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
things = SDoc
empty
| Bool
otherwise = String -> SDoc
text String
herald SDoc -> SDoc -> SDoc
$$ Arity -> SDoc -> SDoc
nest Arity
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
ppr_one [a]
things))
hasTopUserName :: NamedThing x => x -> Bool
hasTopUserName :: forall x. NamedThing x => x -> Bool
hasTopUserName x
x
= Name -> Bool
isExternalName Name
name Bool -> Bool -> Bool
&& Bool -> Bool
not (OccName -> Bool
isDerivedOccName (Name -> OccName
nameOccName Name
name))
where
name :: Name
name = forall a. NamedThing a => a -> Name
getName x
x
withTcPlugins :: HscEnv -> TcM a -> TcM a
withTcPlugins :: forall a. HscEnv -> TcM a -> TcM a
withTcPlugins HscEnv
hsc_env TcM a
m =
case HscEnv -> [TcPlugin]
getTcPlugins HscEnv
hsc_env of
[] -> TcM a
m
[TcPlugin]
plugins -> do
EvBindsVar
ev_binds_var <- TcM EvBindsVar
newTcEvBinds
([TcPluginSolver]
solvers,[TcPluginM ()]
stops) <- forall a b. [(a, b)] -> ([a], [b])
unzip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (EvBindsVar
-> TcPlugin
-> IOEnv (Env TcGblEnv TcLclEnv) (TcPluginSolver, TcPluginM ())
startPlugin EvBindsVar
ev_binds_var) [TcPlugin]
plugins
Either IOEnvFailure a
eitherRes <- forall env r. IOEnv env r -> IOEnv env (Either IOEnvFailure r)
tryM forall a b. (a -> b) -> a -> b
$
forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv (\TcGblEnv
e -> TcGblEnv
e { tcg_tc_plugins :: [TcPluginSolver]
tcg_tc_plugins = [TcPluginSolver]
solvers }) TcM a
m
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. TcPluginM a -> EvBindsVar -> TcM a
runTcPluginM EvBindsVar
ev_binds_var) [TcPluginM ()]
stops
case Either IOEnvFailure a
eitherRes of
Left IOEnvFailure
_ -> forall env a. IOEnv env a
failM
Right a
res -> forall (m :: * -> *) a. Monad m => a -> m a
return a
res
where
startPlugin :: EvBindsVar
-> TcPlugin
-> IOEnv (Env TcGblEnv TcLclEnv) (TcPluginSolver, TcPluginM ())
startPlugin EvBindsVar
ev_binds_var (TcPlugin TcPluginM s
start s -> TcPluginSolver
solve s -> TcPluginM ()
stop) =
do s
s <- forall a. TcPluginM a -> EvBindsVar -> TcM a
runTcPluginM TcPluginM s
start EvBindsVar
ev_binds_var
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> TcPluginSolver
solve s
s, s -> TcPluginM ()
stop s
s)
getTcPlugins :: HscEnv -> [GHC.Tc.Utils.Monad.TcPlugin]
getTcPlugins :: HscEnv -> [TcPlugin]
getTcPlugins HscEnv
hsc_env = forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a. HscEnv -> (Plugin -> [String] -> a) -> [a]
mapPlugins HscEnv
hsc_env (\Plugin
p [String]
args -> Plugin -> [String] -> Maybe TcPlugin
tcPlugin Plugin
p [String]
args)
withHoleFitPlugins :: HscEnv -> TcM a -> TcM a
withHoleFitPlugins :: forall a. HscEnv -> TcM a -> TcM a
withHoleFitPlugins HscEnv
hsc_env TcM a
m =
case HscEnv -> [HoleFitPluginR]
getHfPlugins HscEnv
hsc_env of
[] -> TcM a
m
[HoleFitPluginR]
plugins -> do ([HoleFitPlugin]
plugins,[TcRnIf TcGblEnv TcLclEnv ()]
stops) <- forall a b. [(a, b)] -> ([a], [b])
unzip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM HoleFitPluginR
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HoleFitPlugin, TcRnIf TcGblEnv TcLclEnv ())
startPlugin [HoleFitPluginR]
plugins
Either IOEnvFailure a
eitherRes <- forall env r. IOEnv env r -> IOEnv env (Either IOEnvFailure r)
tryM forall a b. (a -> b) -> a -> b
$
forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv (\TcGblEnv
e -> TcGblEnv
e { tcg_hf_plugins :: [HoleFitPlugin]
tcg_hf_plugins = [HoleFitPlugin]
plugins }) TcM a
m
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [TcRnIf TcGblEnv TcLclEnv ()]
stops
case Either IOEnvFailure a
eitherRes of
Left IOEnvFailure
_ -> forall env a. IOEnv env a
failM
Right a
res -> forall (m :: * -> *) a. Monad m => a -> m a
return a
res
where
startPlugin :: HoleFitPluginR
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HoleFitPlugin, TcRnIf TcGblEnv TcLclEnv ())
startPlugin (HoleFitPluginR TcM (TcRef s)
init TcRef s -> HoleFitPlugin
plugin TcRef s -> TcRnIf TcGblEnv TcLclEnv ()
stop) =
do TcRef s
ref <- TcM (TcRef s)
init
forall (m :: * -> *) a. Monad m => a -> m a
return (TcRef s -> HoleFitPlugin
plugin TcRef s
ref, TcRef s -> TcRnIf TcGblEnv TcLclEnv ()
stop TcRef s
ref)
getHfPlugins :: HscEnv -> [HoleFitPluginR]
getHfPlugins :: HscEnv -> [HoleFitPluginR]
getHfPlugins HscEnv
hsc_env =
forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a. HscEnv -> (Plugin -> [String] -> a) -> [a]
mapPlugins HscEnv
hsc_env (\Plugin
p [String]
args -> Plugin -> [String] -> Maybe HoleFitPluginR
holeFitPlugin Plugin
p [String]
args)
runRenamerPlugin :: TcGblEnv
-> HsGroup GhcRn
-> TcM (TcGblEnv, HsGroup GhcRn)
runRenamerPlugin :: TcGblEnv
-> HsGroup (GhcPass 'Renamed)
-> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
runRenamerPlugin TcGblEnv
gbl_env HsGroup (GhcPass 'Renamed)
hs_group = do
HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
forall (m :: * -> *) a.
Monad m =>
HscEnv -> PluginOperation m a -> a -> m a
withPlugins HscEnv
hsc_env
(\Plugin
p [String]
opts (TcGblEnv
e, HsGroup (GhcPass 'Renamed)
g) -> ( DynFlags -> TcRnIf TcGblEnv TcLclEnv ()
mark_plugin_unsafe (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Plugin
-> [String]
-> TcGblEnv
-> HsGroup (GhcPass 'Renamed)
-> TcM (TcGblEnv, HsGroup (GhcPass 'Renamed))
renamedResultAction Plugin
p [String]
opts TcGblEnv
e HsGroup (GhcPass 'Renamed)
g))
(TcGblEnv
gbl_env, HsGroup (GhcPass 'Renamed)
hs_group)
type RenamedStuff =
(Maybe (HsGroup GhcRn, [LImportDecl GhcRn], Maybe [(LIE GhcRn, Avails)],
Maybe LHsDocString))
getRenamedStuff :: TcGblEnv -> RenamedStuff
getRenamedStuff :: TcGblEnv -> RenamedStuff
getRenamedStuff TcGblEnv
tc_result
= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\HsGroup (GhcPass 'Renamed)
decls -> ( HsGroup (GhcPass 'Renamed)
decls, TcGblEnv -> [LImportDecl (GhcPass 'Renamed)]
tcg_rn_imports TcGblEnv
tc_result
, TcGblEnv -> Maybe [(LIE (GhcPass 'Renamed), [AvailInfo])]
tcg_rn_exports TcGblEnv
tc_result, TcGblEnv -> Maybe LHsDocString
tcg_doc_hdr TcGblEnv
tc_result ) )
(TcGblEnv -> Maybe (HsGroup (GhcPass 'Renamed))
tcg_rn_decls TcGblEnv
tc_result)
runTypecheckerPlugin :: ModSummary -> TcGblEnv -> TcM TcGblEnv
runTypecheckerPlugin :: ModSummary -> TcGblEnv -> TcM TcGblEnv
runTypecheckerPlugin ModSummary
sum TcGblEnv
gbl_env = do
HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
forall (m :: * -> *) a.
Monad m =>
HscEnv -> PluginOperation m a -> a -> m a
withPlugins HscEnv
hsc_env
(\Plugin
p [String]
opts TcGblEnv
env -> DynFlags -> TcRnIf TcGblEnv TcLclEnv ()
mark_plugin_unsafe (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Plugin -> [String] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
typeCheckResultAction Plugin
p [String]
opts ModSummary
sum TcGblEnv
env)
TcGblEnv
gbl_env
mark_plugin_unsafe :: DynFlags -> TcM ()
mark_plugin_unsafe :: DynFlags -> TcRnIf TcGblEnv TcLclEnv ()
mark_plugin_unsafe DynFlags
dflags = forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_PluginTrustworthy DynFlags
dflags) forall a b. (a -> b) -> a -> b
$
WarningMessages -> TcRnIf TcGblEnv TcLclEnv ()
recordUnsafeInfer WarningMessages
pluginUnsafe
where
unsafeText :: String
unsafeText = String
"Use of plugins makes the module unsafe"
pluginUnsafe :: WarningMessages
pluginUnsafe = forall a. a -> Bag a
unitBag ( SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc
mkPlainWarnMsg SrcSpan
noSrcSpan
(String -> SDoc
Outputable.text String
unsafeText) )