HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

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.

  • 60 types
  • 36 values
  • Packageghc-9.10.3
  • Exports98
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceTypes.hs
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 RewriterSet

      See Note [Wanteds rewrite Wanteds]

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.

typetype ErrCtxt = (Bool, TidyEnv -> ZonkM (TidyEnv, SDoc))
#

Additional context to include in an error message, e.g. "In the type signature ...", "In the ambiguity check for ...", etc.

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

  • ImportAvails
    • 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)

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 PromotionErr
#
Instances3Generic, Outputable, Rep
datadata CompleteMatch
#

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

Instances1Outputable
datadata ForeignSrcLang
#

Foreign formats supported by GHC via TH

Constructors

Instances5Eq, Show, Generic, Binary, 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 TcPlugin
#

Constructors

  • forall s. TcPlugin
    • 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.

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.

Instances4Generic, Diagnostic, Rep, DiagnosticOpts