ghc-9.4.4: The GHC API
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.Tc.Types

Description

Various types used during typechecking.

Please see GHC.Tc.Utils.Monad as well for operations on these types. You probably want to import it, instead of this module.

All the monads exported here are built on top of the same IOEnv monad. The monad functions like a Reader monad in the way it passes the environment around. This is done to allow the environment to be manipulated in a stack like fashion when entering expressions... etc.

For state that is global and should be returned at the end (e.g not part of the stack mechanism), you should use a TcRef (= IORef) to store them.

Synopsis

Documentation

type TcRnIf a b = IOEnv (Env a b) Source #

type TcM = TcRn Source #

Historical "type-checking monad" (now it's just TcRn).

type RnM = TcRn Source #

Historical "renaming monad" (now it's just TcRn).

type IfM lcl = TcRnIf IfGblEnv lcl Source #

type IfG = IfM () Source #

type TcRef a = IORef a Source #

Type alias for IORef; the convention is we'll use this for mutable bits of data in TcGblEnv which are updated during typechecking and returned at the end.

data Env gbl lcl Source #

Constructors

Env 

Fields

Instances

Instances details
Quasi TcM Source # 
Instance details

Defined in GHC.Tc.Gen.Splice

MonadThings (IOEnv (Env DsGblEnv DsLclEnv)) Source # 
Instance details

Defined in GHC.HsToCore.Monad

MonadThings (IOEnv (Env TcGblEnv TcLclEnv)) Source # 
Instance details

Defined in GHC.Tc.Utils.Env

MonadUnique (IOEnv (Env gbl lcl)) Source # 
Instance details

Defined in GHC.Tc.Utils.Monad

ContainsHooks (Env gbl lcl) Source # 
Instance details

Defined in GHC.Tc.Types

Methods

extractHooks :: Env gbl lcl -> Hooks Source #

ContainsDynFlags (Env gbl lcl) Source # 
Instance details

Defined in GHC.Tc.Types

Methods

extractDynFlags :: Env gbl lcl -> DynFlags Source #

ContainsModule gbl => ContainsModule (Env gbl lcl) Source # 
Instance details

Defined in GHC.Tc.Types

Methods

extractModule :: Env gbl lcl -> Module Source #

ContainsLogger (Env gbl lcl) Source # 
Instance details

Defined in GHC.Tc.Types

Methods

extractLogger :: Env gbl lcl -> Logger Source #

data TcGblEnv Source #

TcGblEnv describes the top-level of the module at the point at which the typechecker is finished work. It is this structure that is handed on to the desugarer For state that needs to be updated during the typechecking phase and returned at end, use a TcRef (= IORef).

Constructors

TcGblEnv 

Fields

Instances

Instances details
ContainsModule TcGblEnv Source # 
Instance details

Defined in GHC.Tc.Types

Quasi TcM Source # 
Instance details

Defined in GHC.Tc.Gen.Splice

MonadThings (IOEnv (Env TcGblEnv TcLclEnv)) Source # 
Instance details

Defined in GHC.Tc.Utils.Env

data TcLclEnv Source #

Instances

Instances details
Quasi TcM Source # 
Instance details

Defined in GHC.Tc.Gen.Splice

MonadThings (IOEnv (Env TcGblEnv TcLclEnv)) Source # 
Instance details

Defined in GHC.Tc.Utils.Env

data IfGblEnv Source #

Constructors

IfGblEnv 

data RewriteEnv Source #

A RewriteEnv carries the necessary context for performing rewrites (i.e. type family reductions and following filled-in metavariables) in the solver.

Constructors

RE 

Fields

  • re_loc :: !CtLoc

    In which context are we rewriting?

    Type-checking plugins might want to use this location information when emitting new Wanted constraints when rewriting type family applications. This ensures that such Wanted constraints will, when unsolved, give rise to error messages with the correct source location.

  • re_flavour :: !CtFlavour
     
  • re_eq_rel :: !EqRel

    At what role are we rewriting?

    See Note [Rewriter EqRels] in GHC.Tc.Solver.Rewrite

  • re_rewriters :: !(TcRef RewriterSet)

    See Note [Wanteds rewrite Wanteds]

data FrontendResult Source #

FrontendResult describes the result of running the frontend of a Haskell module. Currently one always gets a FrontendTypecheck, since running the frontend involves typechecking a program. hs-sig merges are not handled here.

This data type really should be in GHC.Driver.Env, but it needs to have a TcGblEnv which is only defined here.

data ImportAvails Source #

ImportAvails summarises what was imported from where, irrespective of whether the imported things are actually used or not. It is used:

  • when processing the export list,
  • when constructing usage info for the interface file,
  • to identify the list of directly imported modules for initialisation purposes and for optimised overlap checking of family instances,
  • when figuring out what things are really unused

Constructors

ImportAvails 

Fields

  • imp_mods :: ImportedMods

    Domain is all directly-imported modules

    See the documentation on ImportedModsVal in GHC.Unit.Module.Imported for the meaning of the fields.

    We need a full ModuleEnv rather than a ModuleNameEnv here, because we might be importing modules of the same name from different packages. (currently not the case, but might be in the future).

  • imp_direct_dep_mods :: InstalledModuleEnv ModuleNameWithIsBoot

    Home-package modules directly imported by the module being compiled.

  • imp_dep_direct_pkgs :: Set UnitId

    Packages directly needed by the module being compiled

  • imp_trust_own_pkg :: Bool

    Do we require that our own package is trusted? This is to handle efficiently the case where a Safe module imports a Trustworthy module that resides in the same package as it. See Note [Trust Own Package] in GHC.Rename.Names

  • imp_trust_pkgs :: Set UnitId

    This records the packages the current module needs to trust for Safe Haskell compilation to succeed. A package is required to be trusted if we are dependent on a trustworthy module in that package. See Note [Tracking Trust Transitively] in GHC.Rename.Names

  • imp_boot_mods :: InstalledModuleEnv ModuleNameWithIsBoot

    Domain is all modules which have hs-boot files, and whether we should import the boot version of interface file. Only used in one-shot mode to populate eps_is_boot.

  • imp_sig_mods :: [ModuleName]

    Signature modules below this one

  • imp_orphs :: [Module]

    Orphan modules below us in the import tree (and maybe including us for imported modules)

  • imp_finsts :: [Module]

    Family instance modules below us in the import tree (and maybe including us for imported modules)

plusImportAvails :: ImportAvails -> ImportAvails -> ImportAvails Source #

Union two ImportAvails

This function is a key part of Import handling, basically for each import we create a separate ImportAvails structure and then union them all together with this function.

data WhereFrom Source #

Instances

Instances details
Outputable WhereFrom Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: WhereFrom -> SDoc Source #

data TcBinder Source #

Instances

Instances details
HasOccName TcBinder Source # 
Instance details

Defined in GHC.Tc.Types

Outputable TcBinder Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: TcBinder -> SDoc Source #

data TcTyThing Source #

A typecheckable thing available in a local context. Could be AGlobal TyThing, but also lexically scoped variables, etc. See GHC.Tc.Utils.Env for how to retrieve a TyThing given a Name.

Instances

Instances details
Outputable TcTyThing Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: TcTyThing -> SDoc Source #

tcTyThingTyCon_maybe :: TcTyThing -> Maybe TyCon Source #

Matches on either a global TyCon or a TcTyCon.

data IdBindingInfo Source #

IdBindingInfo describes how an Id is bound.

It is used for the following purposes: a) for static forms in checkClosedInStaticForm and b) to figure out when a nested binding can be generalised, in decideGeneralisationPlan.

Instances

Instances details
Outputable IdBindingInfo Source # 
Instance details

Defined in GHC.Tc.Types

data IsGroupClosed Source #

IsGroupClosed describes a group of mutually-recursive bindings

data CompleteMatch Source #

A list of conlikes which represents a complete pattern match. These arise from COMPLETE signatures. See also Note [Implementation of COMPLETE pragmas].

Instances

Instances details
Outputable CompleteMatch Source # 
Instance details

Defined in GHC.Types.CompleteMatch

data ThStage Source #

Instances

Instances details
Outputable ThStage Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: ThStage -> SDoc Source #

data SpliceType Source #

Constructors

Typed 
Untyped 

data ForeignSrcLang #

Instances

Instances details
Generic ForeignSrcLang 
Instance details

Defined in GHC.ForeignSrcLang.Type

Associated Types

type Rep ForeignSrcLang :: Type -> Type Source #

Show ForeignSrcLang 
Instance details

Defined in GHC.ForeignSrcLang.Type

Eq ForeignSrcLang 
Instance details

Defined in GHC.ForeignSrcLang.Type

type Rep ForeignSrcLang 
Instance details

Defined in GHC.ForeignSrcLang.Type

type Rep ForeignSrcLang = D1 ('MetaData "ForeignSrcLang" "GHC.ForeignSrcLang.Type" "ghc-boot-th-9.4.4" 'False) ((C1 ('MetaCons "LangC" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LangCxx" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LangObjc" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "LangObjcxx" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LangAsm" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RawObject" 'PrefixI 'False) (U1 :: Type -> Type))))

type THDocs = Map DocLoc (HsDoc GhcRn) Source #

The current collection of docs that Template Haskell has built up via putDoc.

data DocLoc Source #

This is a mirror of Template Haskell's DocLoc, but the TH names are resolved to GHC names.

Instances

Instances details
Eq DocLoc Source # 
Instance details

Defined in GHC.Tc.Types

Methods

(==) :: DocLoc -> DocLoc -> Bool #

(/=) :: DocLoc -> DocLoc -> Bool #

Ord DocLoc Source # 
Instance details

Defined in GHC.Tc.Types

data TcSigInfo Source #

Instances

Instances details
Outputable TcSigInfo Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: TcSigInfo -> SDoc Source #

data TcIdSigInfo Source #

Instances

Instances details
Outputable TcIdSigInfo Source # 
Instance details

Defined in GHC.Tc.Types

Methods

ppr :: TcIdSigInfo -> SDoc Source #

hasCompleteSig :: TcSigFun -> Name -> Bool Source #

No signature or a partial signature

type TcId = Id Source #

data NameShape Source #

A NameShape is a substitution on Names that can be used to refine the identities of a hole while we are renaming interfaces (see GHC.Iface.Rename). Specifically, a NameShape for ns_module_name A, defines a mapping from {A.T} (for some OccName T) to some arbitrary other Name.

The most intruiging thing about a NameShape, however, is how it's constructed. A NameShape is *implied* by the exported AvailInfos of the implementor of an interface: if an implementor of signature <H> exports M.T, you implicitly define a substitution from {H.T} to M.T. So a NameShape is computed from the list of AvailInfos that are exported by the implementation of a module, or successively merged together by the export lists of signatures which are joining together.

It's not the most obvious way to go about doing this, but it does seem to work!

NB: Can't boot this and put it in NameShape because then we start pulling in too many DynFlags things.

getPlatform :: TcM Platform Source #

Get target platform

data TcPlugin Source #

Constructors

forall s. TcPlugin 

Fields

  • tcPluginInit :: TcPluginM s

    Initialize plugin, when entering type-checker.

  • tcPluginSolve :: s -> TcPluginSolver

    Solve some constraints.

    This function will be invoked at two points in the constraint solving process: once to simplify Given constraints, and once to solve Wanted constraints. In the first case (and only in the first case), no Wanted constraints will be passed to the plugin.

    The plugin can either return a contradiction, or specify that it has solved some constraints (with evidence), and possibly emit additional constraints. These returned constraints must be Givens in the first case, and Wanteds in the second.

    Use \ _ _ _ _ _ -> pure $ TcPluginOK [] [] if your plugin does not provide this functionality.

  • tcPluginRewrite :: s -> UniqFM TyCon TcPluginRewriter

    Rewrite saturated type family applications.

    The plugin is expected to supply a mapping from type family names to rewriting functions. For each type family TyCon, the plugin should provide a function which takes in the given constraints and arguments of a saturated type family application, and return a possible rewriting. See TcPluginRewriter for the expected shape of such a function.

    Use \ _ -> emptyUFM if your plugin does not provide this functionality.

  • tcPluginStop :: s -> TcPluginM ()

    Clean up after the plugin, when exiting the type-checker.

data TcPluginSolveResult Source #

Result of running a solver plugin.

Constructors

TcPluginSolveResult 

Fields

  • tcPluginInsolubleCts :: [Ct]

    Insoluble constraints found by the plugin.

    These constraints will be added to the inert set, and reported as insoluble to the user.

  • tcPluginSolvedCts :: [(EvTerm, Ct)]

    Solved constraints, together with their evidence.

    These are removed from the inert set, and the evidence for them is recorded.

  • tcPluginNewCts :: [Ct]

    New constraints that the plugin wishes to emit.

    These will be added to the work list.

Bundled Patterns

pattern TcPluginContradiction :: [Ct] -> TcPluginSolveResult

The plugin found a contradiction. The returned constraints are removed from the inert set, and recorded as insoluble.

The returned list of constraints should never be empty.

pattern TcPluginOk :: [(EvTerm, Ct)] -> [Ct] -> TcPluginSolveResult

The plugin has not found any contradictions,

The first field is for constraints that were solved. The second field contains new work, that should be processed by the constraint solver.

data TcPluginRewriteResult Source #

Constructors

TcPluginNoRewrite

The plugin does not rewrite the type family application.

TcPluginRewriteTo

The plugin rewrites the type family application providing a rewriting together with evidence: a Reduction, which contains the rewritten type together with a Coercion whose right-hand-side type is the rewritten type.

The plugin can also emit additional Wanted constraints.

type TcPluginSolver Source #

Arguments

 = EvBindsVar 
-> [Ct]

Givens

-> [Ct]

Wanteds

-> TcPluginM TcPluginSolveResult 

The solve function of a type-checking plugin takes in Given and Wanted constraints, and should return a TcPluginSolveResult indicating which Wanted constraints it could solve, or whether any are insoluble.

type TcPluginRewriter Source #

Arguments

 = RewriteEnv

Rewriter environment

-> [Ct]

Givens

-> [TcType]

type family arguments

-> TcPluginM TcPluginRewriteResult 

For rewriting type family applications, a type-checking plugin provides a function of this type for each type family TyCon.

The function is provided with the current set of Given constraints, together with the arguments to the type family. The type family application will always be fully saturated.

data TcPluginM a Source #

TcPluginM is the monad in which type-checking plugins operate.

Instances

Instances details
MonadFail TcPluginM Source # 
Instance details

Defined in GHC.Tc.Types

Methods

fail :: String -> TcPluginM a Source #

Applicative TcPluginM Source # 
Instance details

Defined in GHC.Tc.Types

Methods

pure :: a -> TcPluginM a Source #

(<*>) :: TcPluginM (a -> b) -> TcPluginM a -> TcPluginM b Source #

liftA2 :: (a -> b -> c) -> TcPluginM a -> TcPluginM b -> TcPluginM c Source #

(*>) :: TcPluginM a -> TcPluginM b -> TcPluginM b Source #

(<*) :: TcPluginM a -> TcPluginM b -> TcPluginM a Source #

Functor TcPluginM Source # 
Instance details

Defined in GHC.Tc.Types

Methods

fmap :: (a -> b) -> TcPluginM a -> TcPluginM b Source #

(<$) :: a -> TcPluginM b -> TcPluginM a Source #

Monad TcPluginM Source # 
Instance details

Defined in GHC.Tc.Types

Methods

(>>=) :: TcPluginM a -> (a -> TcPluginM b) -> TcPluginM b Source #

(>>) :: TcPluginM a -> TcPluginM b -> TcPluginM b Source #

return :: a -> TcPluginM a Source #

unsafeTcPluginTcM :: TcM a -> TcPluginM a Source #

This function provides an escape for direct access to the TcM monad. It should not be used lightly, and the provided TcPluginM API should be favoured instead.

data DefaultingPlugin Source #

A plugin for controlling defaulting.

Constructors

forall s. DefaultingPlugin 

Fields

data DefaultingProposal Source #

A collection of candidate default types for a type variable.

Constructors

DefaultingProposal 

Fields

Instances

Instances details
Outputable DefaultingProposal Source # 
Instance details

Defined in GHC.Tc.Types

lintGblEnv :: Logger -> DynFlags -> TcGblEnv -> TcM () Source #

Check the TcGblEnv for consistency. Currently, only checks axioms, but should check other aspects, too.

data TcRnMessage Source #

An error which might arise during typechecking/renaming.