HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Moduleghc-10.0.0.20260917GHC2024

GHC.Tc.Types

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.

  • 65 types
  • 45 values
typetype TcM = TcRn
#

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

typetype RnM = TcRn
#

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

typetype TcRef a = IORef a
#

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

datadata Env gbl lcl
#

Constructors

Instances8Quasi, MonadUnique, MonadThings, ContainsDynFlags, ContainsHooks, ContainsLogger, …
datadata TcGblEnv
#

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

Instances3Quasi, ContainsModule, MonadThings
datadata RewriteEnv
#

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

Constructors

  • RE
    • 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 CoHoleSet

      See Note [Wanteds rewrite Wanteds: rewriter-sets]

datadata FrontendResult
#

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.

datadata HsCtxt
#

The "context" of an error message, e.g. "In the expression ...", "In the pattern ...", or "In the equations for closed type family ...".

Instances1Data
  • Data HsCtxtDefined in ghc-10.0.0.20260917 · GHC.Hs.Instances · orphan
datadata ImportAvails
#

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

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.

datadata ImportUserSpec
#

The import specification as written by the user, including the list of explicitly imported names. Used in ModIface to allow GHCi to reconstruct the top level environment on demand.

This is distinct from ImportSpec because we don't want to store the list of explicitly imported names along with each GRE

We don't want to store the entire GlobalRdrEnv for modules that are imported without explicit export lists, as these may grow to be very large. However, GlobalRdrEnvs which are the result of explicit import lists are typically quite small.

Why do we not store something like (Maybe (ImportListInterpretation, [IE GhcPs]) in such a case? Because we don't want to store source syntax including annotations in interface files.

datadata PromotionErr
#
Instances3Generic, Outputable, Rep
datadata IdBindingInfo
#

IdBindingInfo describes how an Id is bound.

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

Instances1Outputable
newtypenewtype ThLevelIndex
#

The integer which represents the level

Instances4Eq, Data, Ord, Outputable
datadata ForeignSrcLang
#

Foreign formats supported by GHC via TH

Constructors

Instances6Eq, Show, Generic, Binary, Lift, Rep
datadata NameShape
#

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 intriguing 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.

datadata TcMPluginsState
#

Plugins that run in the typechecker.

May be uninitialised or already stopped.

Constructors

datadata TcMPluginsRun
#

"run" actions for already-started TcM plugins (meaning that we have initialised them and not yet stopped them).

Includes typechecker plugins, defaulting plugins, and hole fit plugins.

Constructors

datadata TcPlugin
#

Constructors

  • forall s. TcPlugin
    • tcPluginInit :: TcPluginM s

      Initialize plugin, once per module, when starting the 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.

    • tcPluginPostTc :: s -> TcPluginM ()

      Action to run at the end of typechecking a module, e.g. to intercept the final TcGblEnv/TcLclEnv at the end of typechecking, possibly modifying mutable fields.

      Should not terminate the plugin, as the plugin may continue to be invoked when desugaring the module (as the pattern-match checker may invoke the constraint solver).

    • tcPluginShutdown :: s -> IO ()

      Clean up after the plugin, when GHC is done processing the given module (e.g. after desugaring).

datadata TcPluginSolveResult
#

Result of running a solver plugin.

Constructors

  • TcPluginSolveResult
    • 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.

patternpattern 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.

patternpattern 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.

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.

valueunsafeTcPluginTcM :: TcM a -> TcPluginM a
#

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.

datadata TcRnMessage where
#

An error which might arise during typechecking/renaming.

Instances5Generic, Diagnostic, Rep, DiagnosticOpts, DiagnosticHint