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

  • Packageghc-9.10.3
  • Exports332
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceGHC.hs

Initialisation

5 declarations

Install some default exception handlers and run the inner computation. Unless you want to handle exceptions yourself, you should wrap this around the top level of your program. The default handlers output the error message(s) to stderr and exit cleanly.

valuewithSignalHandlers :: ExceptionMonad m => m a -> m a
#

Temporarily install standard signal handlers for catching ^C, which just throw an exception in the current thread.

GHC Monad

9 declarations
newtypenewtype Ghc a
#

A minimal implementation of a GhcMonad. If you need a custom monad, e.g., to maintain additional state consider wrapping this monad or using GhcT.

Instances12Monad, Functor, MonadFix, MonadFail, Applicative, MonadIO, …
newtypenewtype GhcT (m :: Type -> Type) a
#

A monad transformer to add GHC specific features to another monad.

Note that the wrapped monad must support IO and handling of exceptions.

Instances12Monad, Functor, MonadFix, MonadFail, Applicative, MonadIO, …
classclass (Functor m, ExceptionMonad m, HasDynFlags m, HasLogger m) => GhcMonad (m :: Type -> Type) where
#

A monad that has all the features needed by GHC API calls.

In short, a GHC monad

  • allows embedding of IO actions,

  • can log warnings,

  • allows handling of (extensible) exceptions, and

  • maintains a current session.

If you do not use Ghc or GhcT, make sure to call initGhcMonad before any call to the GHC API functions can occur.

Methods

Instances3GhcMonad
datadata HscEnv
#

HscEnv is like Session, except that some of the fields are immutable. An HscEnv is used to compile a single module from plain Haskell source code (after preprocessing) to either C, assembly or C--. It's also used to store the dynamic linker state to allow for multiple linkers in the same address space. Things like the module graph don't change during a single compilation.

Historical note: "hsc" used to be the name of the compiler binary, when there was a separate driver and compiler. To compile a single module, the driver would invoke hsc on the source code... so nowadays we think of hsc as the layer of the compiler that deals with compiling a single module.

Instances1ContainsDynFlags
valuerunGhc
  1. :: Maybe FilePath

    See argument to initGhcMonad.

  2. -> Ghc a

    The action to perform.

  3. -> IO a
#

Run function for the Ghc monad.

It initialises the GHC session and warnings via initGhcMonad. Each call to this function will create a new session which should not be shared among several threads.

Any errors not handled inside the Ghc action are propagated as IO exceptions.

valueinitGhcMonad :: GhcMonad m => Maybe FilePath -> m ()
#

Initialise a GHC session.

If you implement a custom GhcMonad you must call this function in the monad run function. It will initialise the session variable and clear all warnings.

The first argument should point to the directory where GHC's library files reside. More precisely, this should be the output of ghc --print-libdir of the version of GHC the module using this API is compiled with. For portability, you should use the ghc-paths package, available at http://hackage.haskell.org/package/ghc-paths.

Flags and settings

23 declarations
datadata DynFlags
#

Contains not only a collection of GeneralFlags but also a plethora of information relating to the compilation of a single file or GHC session

Constructors

datadata GeneralFlag
#

Enumerates the simple on-or-off dynamic flags

Constructors

Instances3Enum, Eq, Show
datadata Severity
#

Used to describe warnings and errors o The message has a file/line/column heading, plus "warning:" or "error:", added by mkLocMessage o With SevIgnore the message is suppressed o Output is intended for end users

Constructors

  • SevIgnore

    Ignore this message, for example in case of suppression of warnings users don't want to see. See Note [Suppressing Messages]

  • SevWarning
  • SevError
Instances5Eq, Ord, Show, Outputable, ToJson
newtypenewtype Backend
#

A value of type Backend represents one of GHC's back ends. The set of back ends cannot be extended except by modifying the definition of Backend in this module.

The Backend type is abstract; that is, its value constructors are not exported. It's crucial that they not be exported, because a value of type Backend carries only the back end's name, not its behavior or properties. If Backend were not abstract, then code elsewhere in the compiler could depend directly on the name, not on the semantics, which would make it challenging to create a new back end. Because Backend is abstract, all the obligations of a new back end are enumerated in this module, in the form of functions that take Backend as an argument.

The issue of abstraction is discussed at great length in #20927 and !7442.

Instances1Show
  • Show BackendDefined in ghc-9.10.3 · GHC.Driver.Backend

    The Show instance is for messages only. If code depends on what's in the string, you deserve what happens to you.

valuegopt :: GeneralFlag -> DynFlags -> Bool
#

Test whether a GeneralFlag is set

Note that dynamicNow (i.e., dynamic objects built with `-dynamic-too`) always implicitly enables Opt_PIC, Opt_ExternalDynamicRefs, and disables Opt_SplitSections.

valuencgBackend :: Backend
#

The native code generator. Compiles Cmm code into textual assembler, then relies on an external assembler toolchain to produce machine code.

Only supports a few platforms (X86, PowerPC, SPARC).

See GHC.CmmToAsm.

valuellvmBackend :: Backend
#

The LLVM backend.

Compiles Cmm code into LLVM textual IR, then relies on LLVM toolchain to produce machine code.

It relies on LLVM support for the calling convention used by the NCG backend to produce code objects ABI compatible with it (see "cc 10" or "ghccc" calling convention in https://llvm.org/docs/LangRef.html#calling-conventions).

Supports a few platforms (X86, AArch64, s390x, ARM).

See GHC.CmmToLlvm

valueviaCBackend :: Backend
#

Via-C ("unregisterised") backend.

Compiles Cmm code into C code, then relies on a C compiler to produce machine code.

It produces code objects that are not ABI compatible with those produced by NCG and LLVM backends.

Produced code is expected to be less efficient than the one produced by NCG and LLVM backends because STG registers are not pinned into real registers. On the other hand, it supports more target platforms (those having a valid C toolchain).

See GHC.CmmToC

The ByteCode interpreter.

Produce ByteCode objects (BCO, see GHC.ByteCode) that can be interpreted. It is used by GHCi.

Currently some extensions are not supported (foreign primops).

See GHC.StgToByteCode

valuenoBackend :: Backend
#

A dummy back end that generates no code.

Use this back end to disable code generation. It is particularly useful when GHC is used as a library for other purpose than generating code (e.g. to generate documentation with Haddock) or when the user requested it (via `-fno-code`) for some reason.

datadata GhcMode
#

The GhcMode tells us whether we're doing multi-module compilation (controlled via the GHC API) or one-shot (single-module) compilation. This makes a difference primarily to the GHC.Unit.Finder: in one-shot mode we look for interface files for imported modules, but in multi-module mode we look for source files in order to check whether they need to be recompiled.

Constructors

Instances2Eq, Outputable
valuesetProgramDynFlags :: GhcMonad m => DynFlags -> m Bool
#

Sets the program DynFlags. Note: this invalidates the internal cached module graph, causing more work to be done the next time load is called.

Returns a boolean indicating if preload units have changed and need to be reloaded.

Find the package environment (if one exists)

We interpret the package environment as a set of package flags; to be specific, if we find a package environment file like

clear-package-db
global-package-db
package-db blah/package.conf.d
package-id id1
package-id id2

we interpret this as

[ -hide-all-packages
, -clear-package-db
, -global-package-db
, -package-db blah/package.conf.d
, -package-id id1
, -package-id id2
]

There's also an older syntax alias for package-id, which is just an unadorned package id

id1
id2

Logging

9 declarations

Targets

8 declarations
datadata Target
#

A compilation target.

A target may be supplied with the actual text of the module. If so, use this instead of the file contents (this is for use in an IDE where the file hasn't been saved by the user yet).

These fields are strict because Targets are long lived.

Constructors

  • Target
    • targetId :: !TargetId

      module or filename

    • targetAllowObjCode :: !Bool

      object code allowed?

    • targetUnitId :: !UnitId

      id of the unit this target is part of

    • targetContents :: !Maybe (InputFileBuffer, UTCTime)

      Optional in-memory buffer containing the source code GHC should use for this target instead of reading it from disk.

      Since GHC version 8.10 modules which require preprocessors such as Literate Haskell or CPP to run are also supported.

      If a corresponding source file does not exist on disk this will result in a SourceError exception if targetId = TargetModule _ is used. However together with targetId = TargetFile _ GHC will not complain about the file missing.

Instances1Outputable
datadata TargetId
#

Constructors

  • TargetModule !ModuleName

    A module name: search for the file

  • TargetFile !FilePath !(Maybe Phase)

    A filename: preprocess & parse it to find the module name. If specified, the Phase indicates how to compile this file (which phase to start from). Nothing indicates the starting phase should be determined from the suffix of the filename.

Instances2Eq, Outputable
datadata Phase
#

Untyped Phase description

Instances3Eq, Show, Outputable
  • Eq PhaseDefined in ghc-9.10.3 · GHC.Driver.Phases
  • Show PhaseDefined in ghc-9.10.3 · GHC.Driver.Phases
  • Outputable PhaseDefined in ghc-9.10.3 · GHC.Driver.Phases
valuesetTargets :: GhcMonad m => [Target] -> m ()
#

Sets the targets for this session. Each target may be a module name or a filename. The targets correspond to the set of root modules for the program/library. Unloading the current program is achieved by setting the current set of targets to be empty, followed by load.

Attempts to guess what Target a string refers to. This function implements the --make/GHCi command-line syntax for filenames:

  • if the string looks like a Haskell source filename, then interpret it as such

  • if adding a .hs or .lhs suffix yields the name of an existing file, then use that

  • otherwise interpret the string as a module name

Loading/compiling the program

29 declarations
valuedepanal
  1. :: GhcMonad m
  2. => [ModuleName]

    excluded modules

  3. -> Bool

    allow duplicate roots

  4. -> m ModuleGraph
#

Perform a dependency analysis starting from the current targets and update the session with the new module graph.

Dependency analysis entails parsing the import directives and may therefore require running certain preprocessors.

Note that each ModSummary in the module graph caches its DynFlags. These DynFlags are determined by the current session DynFlags and the OPTIONS and LANGUAGE pragmas of the parsed module. Thus if you want changes to the DynFlags to take effect you need to call this function again. In case of errors, just throw them.

valueload :: GhcMonad f => LoadHowMuch -> f SuccessFlag
#

Try to load the program. See LoadHowMuch for the different modes.

This function implements the core of GHC's --make mode. It preprocesses, compiles and loads the specified modules, avoiding re-compilation wherever possible. Depending on the backend (see DynFlags.backend field) compiling and loading may result in files being created on disk.

Calls the defaultWarnErrLogger after each compiling each module, whether successful or not.

If errors are encountered during dependency analysis, the module depanalE returns together with the errors an empty ModuleGraph. After processing this empty ModuleGraph, the errors of depanalE are thrown. All other errors are reported using the defaultWarnErrLogger.

valueworkingDirectoryChanged :: GhcMonad m => m ()
#

Inform GHC that the working directory has changed. GHC will flush its cache of module locations, since it may no longer be valid.

Note: Before changing the working directory make sure all threads running in the same session have stopped. If you change the working directory, you should also unload the current program (set targets to empty, followed by load).

datadata PkgQual
#

Package-qualifier after renaming

Renaming detects if "this" or the unit-id of the home-unit was used as a package qualifier.

Constructors

Instances4Eq, Data, Ord, Outputable

Compiling to Core

This is the way to get access to the Core bindings corresponding to a module. compileToCore parses, typechecks, and desugars the module, then returns the resulting Core module (consisting of the module name, type declarations, and function declarations) if successful.

Inspecting the module structure of the program

14 declarations
datadata ModuleGraph
#

A 'ModuleGraph' contains all the nodes from the home package (only). See 'ModuleGraphNode' for information about the nodes.

Modules need to be compiled. hs-boots need to be typechecked before the associated "real" module so modules with {-# SOURCE #-} imports can be built. Instantiations also need to be typechecked to ensure that the module fits the signature. Substantiation typechecking is roughly comparable to the check that the module and its hs-boot agree.

The graph is not necessarily stored in topologically-sorted order. Use GHC.topSortModuleGraph and flattenSCC to achieve this.

datadata ModSummary
#

Data for a module node in a ModuleGraph. Module nodes of the module graph are one of:

  • A regular Haskell source module

  • A hi-boot source module

Constructors

Instances1Outputable
datadata ModLocation
#

Module Location

Where a module lives on the file system: the actual locations of the .hs, .hi, .dyn_hi, .o, .dyn_o and .hie files, if we have them.

For a module in another unit, the ml_hs_file and ml_obj_file components of ModLocation are undefined.

The locations specified by a ModLocation may or may not correspond to actual files yet: for example, even if the object file doesn't exist, the ModLocation still contains the path to where the object file will reside if/when it is created.

The paths of anything which can affect recompilation should be placed inside ModLocation.

When a ModLocation is created none of the filepaths will have -boot suffixes. This is because in --make mode the ModLocation is put in the finder cache which is indexed by ModuleName, when a ModLocation is retrieved from the FinderCache the boot suffixes are appended. The other case is in -c mode, there the ModLocation immediately gets given the boot suffixes in mkOneShotModLocation.

Constructors

  • ModLocation
    • ml_hs_file :: Maybe FilePath

      The source file, if we have one. Package modules probably don't have source files.

    • ml_hi_file :: FilePath

      Where the .hi file is, whether or not it exists yet. Always of form foo.hi, even if there is an hi-boot file (we add the -boot suffix later)

    • ml_dyn_hi_file :: FilePath

      Where the .dyn_hi file is, whether or not it exists yet.

    • ml_obj_file :: FilePath

      Where the .o file is, whether or not it exists yet. (might not exist either because the module hasn't been compiled yet, or because it is part of a unit with a .a file)

    • ml_dyn_obj_file :: FilePath

      Where the .dy file is, whether or not it exists yet.

    • ml_hie_file :: FilePath

      Where the .hie file is, whether or not it exists yet.

Instances2Show, Outputable
valuetopSortModuleGraph
  1. :: Bool

    Drop hi-boot nodes? (see below)

  2. -> ModuleGraph
  3. -> Maybe HomeUnitModule

    Root module name. If Nothing, use the full graph.

  4. -> [SCC ModuleGraphNode]
#

Topological sort of the module graph

Calculate SCCs of the module graph, possibly dropping the hi-boot nodes The resulting list of strongly-connected-components is in topologically sorted order, starting with the module(s) at the bottom of the dependency graph (ie compile them first) and ending with the ones at the top.

Drop hi-boot nodes (first boolean arg)?

  • False: treat the hi-boot summaries as nodes of the graph, so the graph must be acyclic

  • True: eliminate the hi-boot nodes, and instead pretend the a source-import of Foo is an import of Foo The resulting graph has no hi-boot nodes, but can be cyclic

Inspecting modules

18 declarations
datadata ModIface_ (phase :: ModIfacePhase)
#

A ModIface plus a ModDetails summarises everything we know about a compiled module. The ModIface is the stuff *before* linking, and can be written out to an interface file. The 'ModDetails is after linking and can be completely recovered from just the ModIface.

When we read an interface file, we also construct a ModIface from it, except that we explicitly make the mi_decls and a few other fields empty; as when reading we consolidate the declarations etc. into a number of indexed maps and environments in the ExternalPackageState.

See Note [Strictness in ModIface] to learn about why some fields are strict and others are not.

Constructors

  • ModIface
    • mi_module :: !Module

      Name of the module we are for

    • mi_sig_of :: !Maybe Module

      Are we a sig of another mod?

    • mi_hsc_src :: !HscSource

      Boot? Signature?

    • mi_deps :: Dependencies

      The dependencies of the module. This is consulted for directly-imported modules, but not for anything else (hence lazy)

    • mi_usages :: [Usage]

      Usages; kept sorted so that it's easy to decide whether to write a new iface file (changing usages doesn't affect the hash of this module) NOT STRICT! we read this field lazily from the interface file It is *only* consulted by the recompilation checker

    • mi_exports :: ![IfaceExport]

      Exports Kept sorted by (mod,occ), to make version comparisons easier Records the modules that are the declaration points for things exported by this module, and the OccNames of those things

    • mi_used_th :: !Bool

      Module required TH splices when it was compiled. This disables recompilation avoidance (see #481).

    • mi_fixities :: [(OccName, Fixity)]

      Fixities NOT STRICT! we read this field lazily from the interface file

    • mi_warns :: IfaceWarnings

      Warnings NOT STRICT! we read this field lazily from the interface file

    • mi_anns :: [IfaceAnnotation]

      Annotations NOT STRICT! we read this field lazily from the interface file

    • mi_decls :: [IfaceDeclExts phase]

      Type, class and variable declarations The hash of an Id changes if its fixity or deprecations change (as well as its type of course) Ditto data constructors, class operations, except that the hash of the parent class/tycon changes

    • mi_extra_decls :: Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]

      Extra variable definitions which are **NOT** exposed but when combined with mi_decls allows us to restart code generation. See Note [Interface Files with Core Definitions] and Note [Interface File with Core: Sharing RHSs]

    • mi_globals :: !Maybe IfGlobalRdrEnv

      Binds all the things defined at the top level in the original source code for this module. which is NOT the same as mi_exports, nor mi_decls (which may contains declarations for things not actually defined by the user). Used for GHCi and for inspecting the contents of modules via the GHC API only.

      (We need the source file to figure out the top-level environment, if we didn't compile this module from source then this field contains Nothing).

      Strictly speaking this field should live in the HomeModInfo, but that leads to more plumbing.

    • mi_insts :: [IfaceClsInst]

      Sorted class instance

    • mi_fam_insts :: [IfaceFamInst]

      Sorted family instances

    • mi_rules :: [IfaceRule]

      Sorted rules

    • mi_hpc :: !AnyHpcUsage

      True if this program uses Hpc at any point in the program.

    • mi_trust :: !IfaceTrustInfo

      Safe Haskell Trust information for this module.

    • mi_trust_pkg :: !Bool

      Do we require the package this module resides in be trusted to trust this module? This is used for the situation where a module is Safe (so doesn't require the package be trusted itself) but imports some trustworthy modules from its own package (which does require its own package be trusted). See Note [Trust Own Package] in GHC.Rename.Names

    • mi_complete_matches :: ![IfaceCompleteMatch]
    • mi_docs :: !Maybe Docs

      Docstrings and related data for use by haddock, the ghci :doc command, and other tools.

      Just _ = the module was built with -haddock.

    • mi_final_exts :: !IfaceBackendExts phase

      Either () or ModIfaceBackend for a fully instantiated interface.

    • mi_ext_fields :: !ExtensibleFields

      Additional optional fields, where the Map key represents the field name, resulting in a (size, serialized data) pair. Because the data is intended to be serialized through the internal Binary class (increasing compatibility with types using Name and FastString, such as HIE), this format is chosen over ByteStrings.

    • mi_src_hash :: !Fingerprint

      Hash of the .hs source, used for recompilation checking.

Instances2Binary, NFData

Printing

2 declarations
datadata NamePprCtx
#

When printing code that contains original names, we need to map the original names back to something the user understands. This is the purpose of the triple of functions that gets passed around when rendering SDoc.

Interactive evaluation

0 declarations

Executing statements

Adding new declarations

Get/set the current context

valuesetContext :: GhcMonad m => [InteractiveImport] -> m ()
#

Set the interactive evaluation context.

(setContext imports) sets the ic_imports field (which in turn determines what is in scope at the prompt) to imports, and updates the icReaderEnv environment to reflect it.

We retain in scope all the things defined at the prompt, and kept in ic_tythings. (Indeed, they shadow stuff from ic_imports.)

valuegetContext :: GhcMonad m => m [InteractiveImport]
#

Get the interactive evaluation context, consisting of a pair of the set of modules from which we take the full top-level scope, and the set of modules from which we take just the exports respectively.

valuesetGHCiMonad :: GhcMonad m => String -> m ()
#

Set the monad GHCi lifts user statements into.

Checks that a type (in string form) is an instance of the GHC.GHCi.GHCiSandboxIO type class. Sets it to be the GHCi monad if it is, throws an error otherwise.

Inspecting the current context

valueisModuleTrusted :: GhcMonad m => Module -> m Bool
#

Check that a module is safe to import (according to Safe Haskell).

We return True to indicate the import is safe and False otherwise although in the False case an error may be thrown first.

valuegetInfo
  1. :: GhcMonad m
  2. => Bool
  3. -> Name
  4. -> m (Maybe (TyThing, Fixity, [ClsInst], [FamInst], SDoc))
#

Looks up an identifier in the current interactive context (for :info) Filter the instances by the ones whose tycons (or classes resp) are in scope (qualified or otherwise). Otherwise we list a whole lot too many! The exact choice of which ones to show, and which to hide, is a judgement call. (see #1581)

valuegetNameToInstancesIndex
  1. :: GhcMonad m
  2. => [Module]

    visible modules. An orphan instance will be returned if it is visible from at least one module in the list.

  3. -> Maybe [Module]

    modules to load. If this is not specified, we load modules for everything that is in scope unqualified.

  4. -> m (Messages TcRnMessage, Maybe (NameEnv ([ClsInst], [FamInst])))
#

Retrieve all type and family instances in the environment, indexed by Name. Each name's lists will contain every instance in which that name is mentioned in the instance head.

Inspecting types and kinds

datadata TcRnExprMode
#

How should we infer a type? See Note [TcRnExprMode]

Constructors

  • TM_Inst

    Instantiate inferred quantifiers only (:type)

  • TM_Default

    Instantiate all quantifiers, and do eager defaulting (:type +d)

Looking up a Name

Compiling expressions

newtypenewtype HValue
#
Instances1Show
  • Show HValueDefined in ghci-9.10.3 · GHCi.RemoteTypes

Docs

Other

The debugger

datadata ModBreaks
#

All the information about the breakpoints for a module

Constructors

Abstract syntax elements

0 declarations

Units

Modules

Names

datadata Name
#

A unique, unambiguous name for something, containing information about where that thing originated.

Instances14Eq, Data, Ord, NFData, NamedThing, Outputable, …
classclass NamedThing a where
#

A class allowing convenient access to the Name of various datatypes

Methods

Instances20NamedThing, …
datadata RdrName
#

Reader Name

Do not use the data constructors of RdrName directly: prefer the family of functions that creates them, such as mkRdrUnqual

  • Note: A Located RdrName will only have API Annotations if it is a compound one, e.g.

`bar`
( ~ )

Constructors

  • Unqual OccName

    Unqualified name

    Used for ordinary, unqualified occurrences, e.g. x, y or Foo. Create such a RdrName with mkRdrUnqual

  • Qual ModuleName OccName

    Qualified name

    A qualified name written by the user in source code. The module isn't necessarily the module where the thing is defined; just the one from which it is imported. Examples are Bar.x, Bar.y or Bar.Foo. Create such a RdrName with mkRdrQual

Instances8Eq, Data, Ord, Outputable, OutputableBndr, HasOccName, …

Identifiers

typetype Id = Var
#

Identifier

valueisImplicitId :: Id -> Bool
#

isImplicitId tells whether an Ids info is implied by other declarations, so we don't need to put its signature in an interface file, even if it's mentioned in some other interface unfolding.

valueidDataCon :: Id -> DataCon
#

Get from either the worker or the wrapper Id to the DataCon. Currently used only in the desugarer.

INVARIANT: idDataCon (dataConWrapId d) = d: remember, dataConWrapId can return either the wrapper or the worker

Type constructors

datadata TyCon
#

TyCons represent type constructors. Type constructors are introduced by things such as:

1) Data declarations: data Foo = ... creates the Foo type constructor of kind Type

2) Type synonyms: type Foo = ... creates the Foo type constructor

3) Newtypes: newtype Foo a = MkFoo ... creates the Foo type constructor of kind Type -> Type

4) Class declarations: class Foo where creates the Foo type constructor of kind Constraint

This data type also encodes a number of primitive, built in type constructors such as those for function and tuple types.

If you edit this type, you may need to update the GHC formalism See Note [GHC Formalism] in GHC.Core.Lint

Instances5Eq, Data, NamedThing, Outputable, Uniquable

Type variables

typetype TyVar = Var
#

Type or kind Variable

Data constructors

The user-declared type of the data constructor in the nice-to-read form:

T :: forall a b. a -> b -> T [a]

rather than:

T :: forall a c. forall b. (c~[a]) => a -> b -> T c

The type variables are quantified in the order that the user wrote them. See Note [DataCon user type variable binders].

NB: If the constructor is part of a data instance, the result type mentions the family tycon, not the internal one.

Strictness/unpack annotations, from user; or, for imported DataCons, from the interface file The list is in one-to-one correspondence with the arity of the DataCon

Classes

datadata Class
#
Instances5Eq, Data, NamedThing, Outputable, Uniquable

Instances

datadata ClsInst
#

A type-class instance. Note that there is some tricky laziness at work here. See Note [ClsInst laziness and the rough-match fields] for more details.

Instances3Data, NamedThing, Outputable

Types and Kinds

datadata Type
#
Instances3Data, Outputable, Eq
valuesplitForAllTyCoVars :: Type -> ([TyCoVar], Type)
#

Take a ForAllTy apart, returning the list of tycovars and the result type. This always succeeds, even if it returns only an empty list. Note that the result type returned may have free variables that were bound by a forall.

typetype Kind = Type
#

The key type representing kinds in the compiler.

typetype PredType = Type
#

A type of the form p of constraint kind represents a value whose type is the Haskell predicate p, where a predicate is what occurs before the => in a Haskell type.

We use PredType as documentation to mark those types that we guarantee to have this kind.

It can be expanded into its representation, but:

  • The type checker must treat it as opaque

  • The rest of the compiler treats it as transparent

Consider these examples:

f :: (Eq a) => a -> Int
g :: (?x :: Int -> Int) => a -> Int
h :: (r\l) => {r} => {l::Int | r}

Here the Eq a and ?x :: Int -> Int and rl are all called "predicates"

Entities

Syntax

module GHC.Hs

Fixities

datadata LexicalFixity
#

Captures the fixity of declarations as they are parsed. This is not necessarily the same as the fixity declaration, as the normal fixity may be overridden using parens or backticks.

Instances3Eq, Data, Outputable

Source locations

datadata SrcSpan
#

Source Span

A SrcSpan identifies either a specific portion of a text file or a human-readable description of a location.

Instances22Eq, Data, Show, NFData, HasAnnotation, HasLoc, …
datadata RealSrcSpan
#

A RealSrcSpan delimits a portion of a text file. It could be represented by a pair of (line,column) coordinates, but in fact we optimise slightly by using more compact representations for single-line and zero-length spans, both of which are quite common.

The end position is defined to be the column after the end of the span. That is, a span of (1,1)-(1,2) is one character long, and a span of (1,1)-(1,1) is zero characters long.

Real Source Span

Instances7Eq, Data, Ord, Show, ToJson, Outputable, …

Located

datadata GenLocated l e
#

We attach SrcSpans to lots of things, so let's have a datatype for it.

Constructors

  • L l e
Instances167Semigroup, HasAnnotation, NoAnn, Functor, Foldable, Traversable, …

Constructing Located

Deconstructing Located

Combining and comparing Located values

valueisSubspanOf
  1. :: SrcSpan

    The span that may be enclosed by the other

  2. -> SrcSpan

    The span it may be enclosed by

  3. -> Bool
#

Determines whether a span is enclosed by another one

Exceptions

3 declarations
datadata GhcException
#

GHC's own exception type error messages all take the form:

     <location>: <error>
 

If the location is on the command line, or in GHC itself, then <location>="ghc". All of the error types below correspond to a <location> of "ghc", except for ProgramError (where the string is assumed to contain a location already, so we don't print one).

Constructors

Instances2Show, Exception

Token stream manipulations

5 declarations
datadata Token
#
Instances2Show, Outputable

Pure interface to the parser

1 declaration

API Annotations

2 declarations
datadata AnnKeywordId
#

Exact print annotations exist so that tools can perform source to source conversions of Haskell code. They are used to keep track of the various syntactic keywords that are not otherwise captured in the AST.

The wiki page describing this feature is https://gitlab.haskell.org/ghc/ghc/wikis/api-annotations https://gitlab.haskell.org/ghc/ghc/-/wikis/implementing-trees-that-grow/in-tree-api-annotations

Note: in general the names of these are taken from the corresponding token, unless otherwise noted See Note [exact print annotations] above for details of the usage

Constructors

Instances6Eq, Data, Ord, Show, NoAnn, Outputable
datadata EpaComment
#

Constructors

Instances10Eq, Data, Show, Semigroup, HasAnnotation, HasLoc, …

Miscellaneous

1 declaration