ghc-9.10.3: The GHC API

Safe Haskell | None
Language | GHC2021

GHC.Tc.Utils.Monad

Contents

- Initialisation
- Simple accessors
- Arrow scopes
- Unique supply
- Accessing input/output
- Debugging
- Typechecker global environment
- Error management
- Usage environment
- Shared error message stuff: renamer and typechecker
- Context management for the type checker
- Diagnostic message generation (type checker)
- Type constraints
- Template Haskell context
- Safe Haskell context
- Stuff for the renamer's local env
- Stuff for interface decls
- Stuff for cost centres.
- Zonking
- Types etc.
- Orphan instances

Description

Functions for working with the typechecker environment (setters, getters...).

Synopsis

- initTc :: HscEnv -> HscSource -> Bool -> Module -> RealSrcSpan -> TcM r -> IO (Messages TcRnMessage, Maybe r)
- initTcWithGbl :: HscEnv -> TcGblEnv -> RealSrcSpan -> TcM r -> IO (Messages TcRnMessage, Maybe r)
- initTcInteractive :: HscEnv -> TcM a -> IO (Messages TcRnMessage, Maybe a)
- initTcRnIf :: Char -> HscEnv -> gbl -> lcl -> TcRnIf gbl lcl a -> IO a
- discardResult :: TcM a -> TcM ()
- getTopEnv :: TcRnIf gbl lcl HscEnv
- updTopEnv :: (HscEnv -> HscEnv) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- getGblEnv :: TcRnIf gbl lcl gbl
- updGblEnv :: (gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- setGblEnv :: gbl' -> TcRnIf gbl' lcl a -> TcRnIf gbl lcl a
- getLclEnv :: TcRnIf gbl lcl lcl
- updLclEnv :: (lcl -> lcl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- updLclCtxt :: (TcLclCtxt -> TcLclCtxt) -> TcRnIf gbl TcLclEnv a -> TcRnIf gbl TcLclEnv a
- setLclEnv :: lcl' -> TcRnIf gbl lcl' a -> TcRnIf gbl lcl a
- restoreLclEnv :: TcLclEnv -> TcRnIf gbl TcLclEnv a -> TcRnIf gbl TcLclEnv a
- updTopFlags :: (DynFlags -> DynFlags) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- getEnvs :: TcRnIf gbl lcl (gbl, lcl)
- setEnvs :: (gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a
- updEnvs :: ((gbl, lcl) -> (gbl, lcl)) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- restoreEnvs :: (TcGblEnv, TcLclEnv) -> TcRn a -> TcRn a
- xoptM :: Extension -> TcRnIf gbl lcl Bool
- doptM :: DumpFlag -> TcRnIf gbl lcl Bool
- goptM :: GeneralFlag -> TcRnIf gbl lcl Bool
- woptM :: WarningFlag -> TcRnIf gbl lcl Bool
- setXOptM :: Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- unsetXOptM :: Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- unsetGOptM :: GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- unsetWOptM :: WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- whenDOptM :: DumpFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- whenGOptM :: GeneralFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- whenWOptM :: WarningFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- whenXOptM :: Extension -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- unlessXOptM :: Extension -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- getGhcMode :: TcRnIf gbl lcl GhcMode
- withoutDynamicNow :: TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- getEpsVar :: TcRnIf gbl lcl (TcRef ExternalPackageState)
- getEps :: TcRnIf gbl lcl ExternalPackageState
- updateEps :: (ExternalPackageState -> (ExternalPackageState, a)) -> TcRnIf gbl lcl a
- updateEps_ :: (ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
- getHpt :: TcRnIf gbl lcl HomePackageTable
- getEpsAndHug :: TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
- newArrowScope :: TcM a -> TcM a
- escapeArrowScope :: TcM a -> TcM a
- newUnique :: TcRnIf gbl lcl Unique
- newUniqueSupply :: TcRnIf gbl lcl UniqSupply
- newName :: OccName -> TcM Name
- newNameAt :: OccName -> SrcSpan -> TcM Name
- cloneLocalName :: Name -> TcM Name
- newSysName :: OccName -> TcRnIf gbl lcl Name
- newSysLocalId :: FastString -> Mult -> TcType -> TcRnIf gbl lcl TcId
- newSysLocalIds :: FastString -> [Scaled TcType] -> TcRnIf gbl lcl [TcId]
- newTcRef :: MonadIO m => a -> m (TcRef a)
- readTcRef :: MonadIO m => TcRef a -> m a
- writeTcRef :: MonadIO m => TcRef a -> a -> m ()
- updTcRef :: MonadIO m => TcRef a -> (a -> a) -> m ()
- updTcRefM :: MonadIO m => TcRef a -> (a -> m a) -> m ()
- traceTc :: String -> SDoc -> TcRn ()
- traceRn :: String -> SDoc -> TcRn ()
- traceOptTcRn :: DumpFlag -> SDoc -> TcRn ()
- dumpOptTcRn :: DumpFlag -> String -> DumpFormat -> SDoc -> TcRn ()
- dumpTcRn :: Bool -> DumpFlag -> String -> DumpFormat -> SDoc -> TcRn ()
- getNamePprCtx :: TcRn NamePprCtx
- printForUserTcRn :: SDoc -> TcRn ()
- traceIf :: SDoc -> TcRnIf m n ()
- traceOptIf :: DumpFlag -> SDoc -> TcRnIf m n ()
- debugTc :: TcM () -> TcM ()
- getIsGHCi :: TcRn Bool
- getGHCiMonad :: TcRn Name
- getInteractivePrintName :: TcRn Name
- tcHscSource :: TcRn HscSource
- tcIsHsBootOrSig :: TcRn Bool
- tcIsHsig :: TcRn Bool
- tcSelfBootInfo :: TcRn SelfBootInfo
- getGlobalRdrEnv :: TcRn GlobalRdrEnv
- getRdrEnvs :: TcRn (GlobalRdrEnv, LocalRdrEnv)
- getImports :: TcRn ImportAvails
- getFixityEnv :: TcRn FixityEnv
- extendFixityEnv :: [(Name, FixItem)] -> RnM a -> RnM a
- getDeclaredDefaultTys :: TcRn (Maybe [Type])
- addDependentFiles :: [FilePath] -> TcRn ()
- getSrcSpanM :: TcRn SrcSpan
- setSrcSpan :: SrcSpan -> TcRn a -> TcRn a
- setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
- addLocM :: HasLoc t => (a -> TcM b) -> GenLocated t a -> TcM b
- inGeneratedCode :: TcRn Bool
- setInGeneratedCode :: TcRn a -> TcRn a
- wrapLocM :: HasLoc t => (a -> TcM b) -> GenLocated t a -> TcM (Located b)
- wrapLocFstM :: (a -> TcM (b, c)) -> Located a -> TcM (Located b, c)
- wrapLocFstMA :: (a -> TcM (b, c)) -> GenLocated (EpAnn ann) a -> TcM (GenLocated (EpAnn ann) b, c)
- wrapLocSndM :: (a -> TcM (b, c)) -> Located a -> TcM (b, Located c)
- wrapLocSndMA :: (a -> TcM (b, c)) -> GenLocated (EpAnn ann) a -> TcM (b, GenLocated (EpAnn ann) c)
- wrapLocM_ :: (a -> TcM ()) -> Located a -> TcM ()
- wrapLocMA_ :: (a -> TcM ()) -> LocatedA a -> TcM ()
- wrapLocMA :: (a -> TcM b) -> GenLocated (EpAnn ann) a -> TcRn (GenLocated (EpAnn ann) b)
- getErrsVar :: TcRn (TcRef (Messages TcRnMessage))
- setErrsVar :: TcRef (Messages TcRnMessage) -> TcRn a -> TcRn a
- addErr :: TcRnMessage -> TcRn ()
- failWith :: TcRnMessage -> TcRn a
- failAt :: SrcSpan -> TcRnMessage -> TcRn a
- addErrAt :: SrcSpan -> TcRnMessage -> TcRn ()
- addErrs :: [(SrcSpan, TcRnMessage)] -> TcRn ()
- checkErr :: Bool -> TcRnMessage -> TcRn ()
- checkErrAt :: SrcSpan -> Bool -> TcRnMessage -> TcRn ()
- addMessages :: Messages TcRnMessage -> TcRn ()
- discardWarnings :: TcRn a -> TcRn a
- mkDetailedMessage :: ErrInfo -> TcRnMessage -> TcRnMessageDetailed
- tcCollectingUsage :: TcM a -> TcM (UsageEnv, a)
- tcScalingUsage :: Mult -> TcM a -> TcM a
- tcEmitBindingUsage :: UsageEnv -> TcM ()
- recoverM :: TcRn r -> TcRn r -> TcRn r
- mapAndRecoverM :: (a -> TcRn b) -> [a] -> TcRn [b]
- mapAndReportM :: (a -> TcRn b) -> [a] -> TcRn [b]
- foldAndRecoverM :: (b -> a -> TcRn b) -> b -> [a] -> TcRn b
- attemptM :: TcRn r -> TcRn (Maybe r)
- tryTc :: TcRn a -> TcRn (Maybe a, Messages TcRnMessage)
- askNoErrs :: TcRn a -> TcRn (a, Bool)
- discardErrs :: TcRn a -> TcRn a
- tryTcDiscardingErrs :: TcM r -> TcM r -> TcM r
- checkNoErrs :: TcM r -> TcM r
- whenNoErrs :: TcM () -> TcM ()
- ifErrsM :: TcRn r -> TcRn r -> TcRn r
- failIfErrsM :: TcRn ()
- getErrCtxt :: TcM [ErrCtxt]
- setErrCtxt :: [ErrCtxt] -> TcM a -> TcM a
- addErrCtxt :: SDoc -> TcM a -> TcM a
- addErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a
- addLandmarkErrCtxt :: SDoc -> TcM a -> TcM a
- addLandmarkErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a
- popErrCtxt :: TcM a -> TcM a
- getCtLocM :: CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
- setCtLocM :: CtLoc -> TcM a -> TcM a
- mkCtLocEnv :: TcLclEnv -> CtLocEnv
- addErrTc :: TcRnMessage -> TcM ()
- addErrTcM :: (TidyEnv, TcRnMessage) -> TcM ()
- failWithTc :: TcRnMessage -> TcM a
- failWithTcM :: (TidyEnv, TcRnMessage) -> TcM a
- checkTc :: Bool -> TcRnMessage -> TcM ()
- checkTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM ()
- failIfTc :: Bool -> TcRnMessage -> TcM ()
- failIfTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM ()
- mkErrInfo :: TidyEnv -> [ErrCtxt] -> TcM SDoc
- addTcRnDiagnostic :: TcRnMessage -> TcM ()
- addDetailedDiagnostic :: (ErrInfo -> TcRnMessage) -> TcM ()
- mkTcRnMessage :: SrcSpan -> TcRnMessage -> TcRn (MsgEnvelope TcRnMessage)
- reportDiagnostic :: MsgEnvelope TcRnMessage -> TcRn ()
- reportDiagnostics :: [MsgEnvelope TcRnMessage] -> TcM ()
- warnIf :: Bool -> TcRnMessage -> TcRn ()
- diagnosticTc :: Bool -> TcRnMessage -> TcM ()
- diagnosticTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM ()
- addDiagnosticTc :: TcRnMessage -> TcM ()
- addDiagnosticTcM :: (TidyEnv, TcRnMessage) -> TcM ()
- addDiagnostic :: TcRnMessage -> TcRn ()
- addDiagnosticAt :: SrcSpan -> TcRnMessage -> TcRn ()
- newTcEvBinds :: TcM EvBindsVar
- newNoTcEvBinds :: TcM EvBindsVar
- cloneEvBindsVar :: EvBindsVar -> TcM EvBindsVar
- addTcEvBind :: EvBindsVar -> EvBind -> TcM ()
- addTopEvBinds :: Bag EvBind -> TcM a -> TcM a
- getTcEvTyCoVars :: EvBindsVar -> TcM TyCoVarSet
- getTcEvBindsMap :: EvBindsVar -> TcM EvBindMap
- setTcEvBindsMap :: EvBindsVar -> EvBindMap -> TcM ()
- chooseUniqueOccTc :: (OccSet -> OccName) -> TcM OccName
- getConstraintVar :: TcM (TcRef WantedConstraints)
- setConstraintVar :: TcRef WantedConstraints -> TcM a -> TcM a
- emitConstraints :: WantedConstraints -> TcM ()
- emitStaticConstraints :: WantedConstraints -> TcM ()
- emitSimple :: Ct -> TcM ()
- emitSimples :: Cts -> TcM ()
- emitImplication :: Implication -> TcM ()
- emitImplications :: Bag Implication -> TcM ()
- emitDelayedErrors :: Bag DelayedError -> TcM ()
- emitHole :: Hole -> TcM ()
- emitHoles :: Bag Hole -> TcM ()
- emitNotConcreteError :: NotConcreteError -> TcM ()
- discardConstraints :: TcM a -> TcM a
- captureConstraints :: TcM a -> TcM (a, WantedConstraints)
- tryCaptureConstraints :: TcM a -> TcM (Maybe a, WantedConstraints)
- pushLevelAndCaptureConstraints :: TcM a -> TcM (TcLevel, WantedConstraints, a)
- pushTcLevelM_ :: TcM a -> TcM a
- pushTcLevelM :: TcM a -> TcM (TcLevel, a)
- getTcLevel :: TcM TcLevel
- setTcLevel :: TcLevel -> TcM a -> TcM a
- isTouchableTcM :: TcTyVar -> TcM Bool
- getLclTypeEnv :: TcM TcTypeEnv
- setLclTypeEnv :: TcLclEnv -> TcM a -> TcM a
- traceTcConstraints :: String -> TcM ()
- emitNamedTypeHole :: (Name, TcTyVar) -> TcM ()
- data IsExtraConstraint
  - = YesExtraConstraint
  - | NoExtraConstraint
- emitAnonTypeHole :: IsExtraConstraint -> TcTyVar -> TcM ()
- recordThUse :: TcM ()
- recordThSpliceUse :: TcM ()
- recordThNeededRuntimeDeps :: [Linkable] -> PkgsLoaded -> TcM ()
- keepAlive :: Name -> TcRn ()
- getStage :: TcM ThStage
- getStageAndBindLevel :: Name -> TcRn (Maybe (TopLevelFlag, ThLevel, ThStage))
- setStage :: ThStage -> TcM a -> TcRn a
- addModFinalizersWithLclEnv :: ThModFinalizers -> TcM ()
- recordUnsafeInfer :: Messages TcRnMessage -> TcM ()
- finalSafeMode :: DynFlags -> TcGblEnv -> IO SafeHaskellMode
- fixSafeInstances :: SafeHaskellMode -> [ClsInst] -> [ClsInst]
- getLocalRdrEnv :: RnM LocalRdrEnv
- setLocalRdrEnv :: LocalRdrEnv -> RnM a -> RnM a
- mkIfLclEnv :: Module -> SDoc -> IsBootInterface -> IfLclEnv
- initIfaceTcRn :: IfG a -> TcRn a
- initIfaceCheck :: SDoc -> HscEnv -> IfG a -> IO a
- initIfaceLcl :: Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
- initIfaceLclWithSubst :: Module -> SDoc -> IsBootInterface -> NameShape -> IfL a -> IfM lcl a
- initIfaceLoad :: HscEnv -> IfG a -> IO a
- initIfaceLoadModule :: HscEnv -> Module -> IfG a -> IO a
- getIfModule :: IfL Module
- failIfM :: SDoc -> IfL a
- forkM :: SDoc -> IfL a -> IfL a
- setImplicitEnvM :: TypeEnv -> IfL a -> IfL a
- withException :: MonadIO m => SDocContext -> m (MaybeErr SDoc a) -> m a
- withIfaceErr :: MonadIO m => SDocContext -> m (MaybeErr MissingInterfaceError a) -> m a
- getCCIndexM :: (gbl -> TcRef CostCentreState) -> FastString -> TcRnIf gbl lcl CostCentreIndex
- getCCIndexTcM :: FastString -> TcM CostCentreIndex
- liftZonkM :: ZonkM a -> TcM a
- newZonkAnyType :: Kind -> TcM Type
- module GHC.Tc.Types
- module GHC.Data.IOEnv

# Initialisation

initTc :: HscEnv -> HscSource -> Bool -> Module -> RealSrcSpan -> TcM r -> IO (Messages TcRnMessage, Maybe r) Source #

Setup the initial typechecking environment

initTcWithGbl :: HscEnv -> TcGblEnv -> RealSrcSpan -> TcM r -> IO (Messages TcRnMessage, Maybe r) Source #

Run a `TcM` action in the context of an existing `GblEnv`.

initTcInteractive :: HscEnv -> TcM a -> IO (Messages TcRnMessage, Maybe a) Source #

initTcRnIf Source #

Arguments

:: Char | Tag for unique supply
-> HscEnv |
-> gbl |
-> lcl |
-> TcRnIf gbl lcl a |
-> IO a |

# Simple accessors

discardResult :: TcM a -> TcM () Source #

getTopEnv :: TcRnIf gbl lcl HscEnv Source #

updTopEnv :: (HscEnv -> HscEnv) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

getGblEnv :: TcRnIf gbl lcl gbl Source #

updGblEnv :: (gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

setGblEnv :: gbl' -> TcRnIf gbl' lcl a -> TcRnIf gbl lcl a Source #

getLclEnv :: TcRnIf gbl lcl lcl Source #

updLclEnv :: (lcl -> lcl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

updLclCtxt :: (TcLclCtxt -> TcLclCtxt) -> TcRnIf gbl TcLclEnv a -> TcRnIf gbl TcLclEnv a Source #

setLclEnv :: lcl' -> TcRnIf gbl lcl' a -> TcRnIf gbl lcl a Source #

restoreLclEnv :: TcLclEnv -> TcRnIf gbl TcLclEnv a -> TcRnIf gbl TcLclEnv a Source #

updTopFlags :: (DynFlags -> DynFlags) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

getEnvs :: TcRnIf gbl lcl (gbl, lcl) Source #

setEnvs :: (gbl', lcl') -> TcRnIf gbl' lcl' a -> TcRnIf gbl lcl a Source #

updEnvs :: ((gbl, lcl) -> (gbl, lcl)) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

restoreEnvs :: (TcGblEnv, TcLclEnv) -> TcRn a -> TcRn a Source #

xoptM :: Extension -> TcRnIf gbl lcl Bool Source #

doptM :: DumpFlag -> TcRnIf gbl lcl Bool Source #

goptM :: GeneralFlag -> TcRnIf gbl lcl Bool Source #

woptM :: WarningFlag -> TcRnIf gbl lcl Bool Source #

setXOptM :: Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

unsetXOptM :: Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

unsetGOptM :: GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

unsetWOptM :: WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

whenDOptM :: DumpFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () Source #

Do it flag is true

whenGOptM :: GeneralFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () Source #

whenWOptM :: WarningFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () Source #

whenXOptM :: Extension -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () Source #

unlessXOptM :: Extension -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () Source #

getGhcMode :: TcRnIf gbl lcl GhcMode Source #

withoutDynamicNow :: TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #

getEpsVar :: TcRnIf gbl lcl (TcRef ExternalPackageState) Source #

getEps :: TcRnIf gbl lcl ExternalPackageState Source #

updateEps :: (ExternalPackageState -> (ExternalPackageState, a)) -> TcRnIf gbl lcl a Source #

Update the external package state. Returns the second result of the modifier function.

This is an atomic operation and forces evaluation of the modified EPS in order to avoid space leaks.

updateEps_ :: (ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl () Source #

Update the external package state.

This is an atomic operation and forces evaluation of the modified EPS in order to avoid space leaks.

getHpt :: TcRnIf gbl lcl HomePackageTable Source #

getEpsAndHug :: TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph) Source #

# Arrow scopes

newArrowScope :: TcM a -> TcM a Source #

escapeArrowScope :: TcM a -> TcM a Source #

# Unique supply

newUnique :: TcRnIf gbl lcl Unique Source #

newUniqueSupply :: TcRnIf gbl lcl UniqSupply Source #

newName :: OccName -> TcM Name Source #

newNameAt :: OccName -> SrcSpan -> TcM Name Source #

cloneLocalName :: Name -> TcM Name Source #

newSysName :: OccName -> TcRnIf gbl lcl Name Source #

newSysLocalId :: FastString -> Mult -> TcType -> TcRnIf gbl lcl TcId Source #

newSysLocalIds :: FastString -> [Scaled TcType] -> TcRnIf gbl lcl [TcId] Source #

# Accessing input/output

newTcRef :: MonadIO m => a -> m (TcRef a) Source #

readTcRef :: MonadIO m => TcRef a -> m a Source #

writeTcRef :: MonadIO m => TcRef a -> a -> m () Source #

updTcRef :: MonadIO m => TcRef a -> (a -> a) -> m () Source #

updTcRefM :: MonadIO m => TcRef a -> (a -> m a) -> m () Source #

# Debugging

traceTc :: String -> SDoc -> TcRn () Source #

traceRn :: String -> SDoc -> TcRn () Source #

traceOptTcRn :: DumpFlag -> SDoc -> TcRn () Source #

dumpOptTcRn :: DumpFlag -> String -> DumpFormat -> SDoc -> TcRn () Source #

Dump if the given `DumpFlag` is set.

dumpTcRn :: Bool -> DumpFlag -> String -> DumpFormat -> SDoc -> TcRn () Source #

Unconditionally dump some trace output

Certain tests (T3017, Roles3, T12763 etc.) expect part of the output generated by `-ddump-types` to be in `PprUser` style. However, generally we want all other debugging output to use `PprDump` style. We `PprUser` style if `useUserStyle` is True.

getNamePprCtx :: TcRn NamePprCtx Source #

printForUserTcRn :: SDoc -> TcRn () Source #

Like logInfoTcRn, but for user consumption

traceIf :: SDoc -> TcRnIf m n () Source #

traceOptIf :: DumpFlag -> SDoc -> TcRnIf m n () Source #

debugTc :: TcM () -> TcM () Source #

# Typechecker global environment

getIsGHCi :: TcRn Bool Source #

getGHCiMonad :: TcRn Name Source #

getInteractivePrintName :: TcRn Name Source #

tcHscSource :: TcRn HscSource Source #

tcIsHsBootOrSig :: TcRn Bool Source #

tcIsHsig :: TcRn Bool Source #

tcSelfBootInfo :: TcRn SelfBootInfo Source #

getGlobalRdrEnv :: TcRn GlobalRdrEnv Source #

getRdrEnvs :: TcRn (GlobalRdrEnv, LocalRdrEnv) Source #

getImports :: TcRn ImportAvails Source #

getFixityEnv :: TcRn FixityEnv Source #

extendFixityEnv :: [(Name, FixItem)] -> RnM a -> RnM a Source #

getDeclaredDefaultTys :: TcRn (Maybe [Type]) Source #

addDependentFiles :: [FilePath] -> TcRn () Source #

# Error management

getSrcSpanM :: TcRn SrcSpan Source #

setSrcSpan :: SrcSpan -> TcRn a -> TcRn a Source #

setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a Source #

addLocM :: HasLoc t => (a -> TcM b) -> GenLocated t a -> TcM b Source #

inGeneratedCode :: TcRn Bool Source #

setInGeneratedCode :: TcRn a -> TcRn a Source #

Mark the inner computation as being done inside generated code.

See Note [Error contexts in generated code]

wrapLocM :: HasLoc t => (a -> TcM b) -> GenLocated t a -> TcM (Located b) Source #

wrapLocFstM :: (a -> TcM (b, c)) -> Located a -> TcM (Located b, c) Source #

wrapLocFstMA :: (a -> TcM (b, c)) -> GenLocated (EpAnn ann) a -> TcM (GenLocated (EpAnn ann) b, c) Source #

wrapLocSndM :: (a -> TcM (b, c)) -> Located a -> TcM (b, Located c) Source #

wrapLocSndMA :: (a -> TcM (b, c)) -> GenLocated (EpAnn ann) a -> TcM (b, GenLocated (EpAnn ann) c) Source #

wrapLocM_ :: (a -> TcM ()) -> Located a -> TcM () Source #

wrapLocMA_ :: (a -> TcM ()) -> LocatedA a -> TcM () Source #

wrapLocMA :: (a -> TcM b) -> GenLocated (EpAnn ann) a -> TcRn (GenLocated (EpAnn ann) b) Source #

getErrsVar :: TcRn (TcRef (Messages TcRnMessage)) Source #

setErrsVar :: TcRef (Messages TcRnMessage) -> TcRn a -> TcRn a Source #

addErr :: TcRnMessage -> TcRn () Source #

failWith :: TcRnMessage -> TcRn a Source #

failAt :: SrcSpan -> TcRnMessage -> TcRn a Source #

addErrAt :: SrcSpan -> TcRnMessage -> TcRn () Source #

addErrs :: [(SrcSpan, TcRnMessage)] -> TcRn () Source #

checkErr :: Bool -> TcRnMessage -> TcRn () Source #

checkErrAt :: SrcSpan -> Bool -> TcRnMessage -> TcRn () Source #

addMessages :: Messages TcRnMessage -> TcRn () Source #

discardWarnings :: TcRn a -> TcRn a Source #

mkDetailedMessage :: ErrInfo -> TcRnMessage -> TcRnMessageDetailed Source #

# Usage environment

tcCollectingUsage :: TcM a -> TcM (UsageEnv, a) Source #

`tcCollectingUsage thing_inside` runs `thing_inside` and returns the usage information which was collected as part of the execution of `thing_inside`. Careful: `tcCollectingUsage thing_inside` itself does not report any usage information, it's up to the caller to incorporate the returned usage information into the larger context appropriately.

tcScalingUsage :: Mult -> TcM a -> TcM a Source #

`tcScalingUsage mult thing_inside` runs `thing_inside` and scales all the usage information by `mult`.

tcEmitBindingUsage :: UsageEnv -> TcM () Source #

# Shared error message stuff: renamer and typechecker

recoverM :: TcRn r -> TcRn r -> TcRn r Source #

mapAndRecoverM :: (a -> TcRn b) -> [a] -> TcRn [b] Source #

Drop elements of the input that fail, so the result list can be shorter than the argument list

mapAndReportM :: (a -> TcRn b) -> [a] -> TcRn [b] Source #

Apply the function to all elements on the input list If all succeed, return the list of results Otherwise fail, propagating all errors

foldAndRecoverM :: (b -> a -> TcRn b) -> b -> [a] -> TcRn b Source #

The accumulator is not updated if the action fails

attemptM :: TcRn r -> TcRn (Maybe r) Source #

tryTc :: TcRn a -> TcRn (Maybe a, Messages TcRnMessage) Source #

askNoErrs :: TcRn a -> TcRn (a, Bool) Source #

discardErrs :: TcRn a -> TcRn a Source #

tryTcDiscardingErrs :: TcM r -> TcM r -> TcM r Source #

checkNoErrs :: TcM r -> TcM r Source #

whenNoErrs :: TcM () -> TcM () Source #

ifErrsM :: TcRn r -> TcRn r -> TcRn r Source #

failIfErrsM :: TcRn () Source #

# Context management for the type checker

getErrCtxt :: TcM [ErrCtxt] Source #

setErrCtxt :: [ErrCtxt] -> TcM a -> TcM a Source #

addErrCtxt :: SDoc -> TcM a -> TcM a Source #

Add a fixed message to the error context. This message should not do any tidying.

addErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a Source #

Add a message to the error context. This message may do tidying.

addLandmarkErrCtxt :: SDoc -> TcM a -> TcM a Source #

Add a fixed landmark message to the error context. A landmark message is always sure to be reported, even if there is a lot of context. It also doesn't count toward the maximum number of contexts reported.

addLandmarkErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, SDoc)) -> TcM a -> TcM a Source #

Variant of `addLandmarkErrCtxt` that allows for monadic operations and tidying.

popErrCtxt :: TcM a -> TcM a Source #

getCtLocM :: CtOrigin -> Maybe TypeOrKind -> TcM CtLoc Source #

setCtLocM :: CtLoc -> TcM a -> TcM a Source #

mkCtLocEnv :: TcLclEnv -> CtLocEnv Source #

# Diagnostic message generation (type checker)

addErrTc :: TcRnMessage -> TcM () Source #

addErrTcM :: (TidyEnv, TcRnMessage) -> TcM () Source #

failWithTc :: TcRnMessage -> TcM a Source #

failWithTcM :: (TidyEnv, TcRnMessage) -> TcM a Source #

checkTc :: Bool -> TcRnMessage -> TcM () Source #

checkTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM () Source #

failIfTc :: Bool -> TcRnMessage -> TcM () Source #

failIfTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM () Source #

mkErrInfo :: TidyEnv -> [ErrCtxt] -> TcM SDoc Source #

addTcRnDiagnostic :: TcRnMessage -> TcM () Source #

addDetailedDiagnostic :: (ErrInfo -> TcRnMessage) -> TcM () Source #

A variation of `addDiagnostic` that takes a function to produce a `TcRnDsMessage` given some additional context about the diagnostic.

mkTcRnMessage :: SrcSpan -> TcRnMessage -> TcRn (MsgEnvelope TcRnMessage) Source #

reportDiagnostic :: MsgEnvelope TcRnMessage -> TcRn () Source #

reportDiagnostics :: [MsgEnvelope TcRnMessage] -> TcM () Source #

warnIf :: Bool -> TcRnMessage -> TcRn () Source #

Display a warning if a condition is met.

diagnosticTc :: Bool -> TcRnMessage -> TcM () Source #

Display a warning if a condition is met.

diagnosticTcM :: Bool -> (TidyEnv, TcRnMessage) -> TcM () Source #

Display a diagnostic if a condition is met.

addDiagnosticTc :: TcRnMessage -> TcM () Source #

Display a diagnostic in the current context.

addDiagnosticTcM :: (TidyEnv, TcRnMessage) -> TcM () Source #

Display a diagnostic in a given context.

addDiagnostic :: TcRnMessage -> TcRn () Source #

Display a diagnostic for the current source location, taken from the `TcRn` monad.

addDiagnosticAt :: SrcSpan -> TcRnMessage -> TcRn () Source #

Display a diagnostic for a given source location.

# Type constraints

newTcEvBinds :: TcM EvBindsVar Source #

newNoTcEvBinds :: TcM EvBindsVar Source #

Creates an EvBindsVar incapable of holding any bindings. It still tracks covar usages (see comments on ebv_tcvs in GHC.Tc.Types.Evidence), thus must be made monadically

cloneEvBindsVar :: EvBindsVar -> TcM EvBindsVar Source #

addTcEvBind :: EvBindsVar -> EvBind -> TcM () Source #

addTopEvBinds :: Bag EvBind -> TcM a -> TcM a Source #

getTcEvTyCoVars :: EvBindsVar -> TcM TyCoVarSet Source #

getTcEvBindsMap :: EvBindsVar -> TcM EvBindMap Source #

setTcEvBindsMap :: EvBindsVar -> EvBindMap -> TcM () Source #

chooseUniqueOccTc :: (OccSet -> OccName) -> TcM OccName Source #

getConstraintVar :: TcM (TcRef WantedConstraints) Source #

setConstraintVar :: TcRef WantedConstraints -> TcM a -> TcM a Source #

emitConstraints :: WantedConstraints -> TcM () Source #

emitStaticConstraints :: WantedConstraints -> TcM () Source #

emitSimple :: Ct -> TcM () Source #

emitSimples :: Cts -> TcM () Source #

emitImplication :: Implication -> TcM () Source #

emitImplications :: Bag Implication -> TcM () Source #

emitDelayedErrors :: Bag DelayedError -> TcM () Source #

emitHole :: Hole -> TcM () Source #

emitHoles :: Bag Hole -> TcM () Source #

emitNotConcreteError :: NotConcreteError -> TcM () Source #

discardConstraints :: TcM a -> TcM a Source #

Throw out any constraints emitted by the thing_inside

captureConstraints :: TcM a -> TcM (a, WantedConstraints) Source #

tryCaptureConstraints :: TcM a -> TcM (Maybe a, WantedConstraints) Source #

pushLevelAndCaptureConstraints :: TcM a -> TcM (TcLevel, WantedConstraints, a) Source #

The name says it all. The returned TcLevel is the *inner* TcLevel.

pushTcLevelM_ :: TcM a -> TcM a Source #

pushTcLevelM :: TcM a -> TcM (TcLevel, a) Source #

getTcLevel :: TcM TcLevel Source #

setTcLevel :: TcLevel -> TcM a -> TcM a Source #

isTouchableTcM :: TcTyVar -> TcM Bool Source #

getLclTypeEnv :: TcM TcTypeEnv Source #

setLclTypeEnv :: TcLclEnv -> TcM a -> TcM a Source #

traceTcConstraints :: String -> TcM () Source #

emitNamedTypeHole :: (Name, TcTyVar) -> TcM () Source #

data IsExtraConstraint Source #

Constructors

YesExtraConstraint |
NoExtraConstraint |

#### Instances

Instances details

Outputable IsExtraConstraint Source # |
Instance details Defined in GHC.Tc.Utils.Monad Methods ppr :: IsExtraConstraint -> SDoc Source #

emitAnonTypeHole :: IsExtraConstraint -> TcTyVar -> TcM () Source #

# Template Haskell context

recordThUse :: TcM () Source #

recordThSpliceUse :: TcM () Source #

recordThNeededRuntimeDeps :: [Linkable] -> PkgsLoaded -> TcM () Source #

keepAlive :: Name -> TcRn () Source #

getStage :: TcM ThStage Source #

getStageAndBindLevel :: Name -> TcRn (Maybe (TopLevelFlag, ThLevel, ThStage)) Source #

setStage :: ThStage -> TcM a -> TcRn a Source #

addModFinalizersWithLclEnv :: ThModFinalizers -> TcM () Source #

Adds the given modFinalizers to the global environment and set them to use the current local environment.

# Safe Haskell context

recordUnsafeInfer :: Messages TcRnMessage -> TcM () Source #

Mark that safe inference has failed See Note [Safe Haskell Overlapping Instances Implementation] although this is used for more than just that failure case.

finalSafeMode :: DynFlags -> TcGblEnv -> IO SafeHaskellMode Source #

Figure out the final correct safe haskell mode

fixSafeInstances :: SafeHaskellMode -> [ClsInst] -> [ClsInst] Source #

Switch instances to safe instances if we're in Safe mode.

# Stuff for the renamer's local env

getLocalRdrEnv :: RnM LocalRdrEnv Source #

setLocalRdrEnv :: LocalRdrEnv -> RnM a -> RnM a Source #

# Stuff for interface decls

mkIfLclEnv :: Module -> SDoc -> IsBootInterface -> IfLclEnv Source #

initIfaceTcRn :: IfG a -> TcRn a Source #

Run an `IfG` (top-level interface monad) computation inside an existing `TcRn` (typecheck-renaming monad) computation by initializing an `IfGblEnv` based on `TcGblEnv`.

initIfaceCheck :: SDoc -> HscEnv -> IfG a -> IO a Source #

initIfaceLcl :: Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a Source #

initIfaceLclWithSubst :: Module -> SDoc -> IsBootInterface -> NameShape -> IfL a -> IfM lcl a Source #

Initialize interface typechecking, but with a `NameShape` to apply when typechecking top-level `OccName`s (see `lookupIfaceTop`)

initIfaceLoad :: HscEnv -> IfG a -> IO a Source #

`initIfaceLoad` can be used when there's no chance that the action will call `typecheckIface` when inside a module loop and hence `tcIfaceGlobal`.

initIfaceLoadModule :: HscEnv -> Module -> IfG a -> IO a Source #

This is used when we are doing to call `typecheckModule` on an `ModIface`, if it's part of a loop with some other modules then we need to use their IORef TypeEnv vars when typechecking but crucially not our own.

getIfModule :: IfL Module Source #

failIfM :: SDoc -> IfL a Source #

forkM :: SDoc -> IfL a -> IfL a Source #

Run thing_inside in an interleaved thread. It shares everything with the parent thread, so this is DANGEROUS.

It throws an error if the computation fails

It's used for lazily type-checking interface signatures, which is pretty benign.

See Note [Masking exceptions in forkM]

setImplicitEnvM :: TypeEnv -> IfL a -> IfL a Source #

withException :: MonadIO m => SDocContext -> m (MaybeErr SDoc a) -> m a Source #

A convenient wrapper for taking a `MaybeErr SDoc a` and throwing an exception if it is an error.

withIfaceErr :: MonadIO m => SDocContext -> m (MaybeErr MissingInterfaceError a) -> m a Source #

# Stuff for cost centres.

getCCIndexM :: (gbl -> TcRef CostCentreState) -> FastString -> TcRnIf gbl lcl CostCentreIndex Source #

Get the next cost centre index associated with a given name.

getCCIndexTcM :: FastString -> TcM CostCentreIndex Source #

See `getCCIndexM`.

# Zonking

liftZonkM :: ZonkM a -> TcM a Source #

Lift a computation from the dedicated zonking monad `ZonkM` to the full-fledged `TcM` monad.

newZonkAnyType :: Kind -> TcM Type Source #

# Types etc.

module GHC.Tc.Types

module GHC.Data.IOEnv

# Orphan instances

MonadUnique (IOEnv (Env gbl lcl)) Source # |
Instance details Methods getUniqueSupplyM :: IOEnv (Env gbl lcl) UniqSupply Source # getUniqueM :: IOEnv (Env gbl lcl) Unique Source # getUniquesM :: IOEnv (Env gbl lcl) [Unique] Source #