Moduleghc-9.10.3GHC2021
GHC.Driver.Main
Main API for compiling plain Haskell source code.
This module implements compilation of a Haskell source. It is not concerned with preprocessing of source files; this is handled in GHC.Driver.Pipeline
There are various entry points depending on what mode we're in:
"batch" mode (--make), "one-shot" mode (-c, -S etc.), and
"interactive" mode (GHCi). There are also entry points for
individual passes: parsing, typechecking/renaming, desugaring, and
simplification.
All the functions here take an HscEnv as a parameter, but none of them return a new one: HscEnv is treated as an immutable value from here on in (although it has mutable components, for the caches).
We use the Hsc monad to deal with warning messages consistently:
specifically, while executing within an Hsc monad, warnings are
collected. When a Hsc monad returns to an IO monad, the
warnings are printed, or compilation aborts if the -Werror
flag is enabled.
(c) The GRASP/AQUA Project, Glasgow University, 1993-2000
- 5 types
- 61 values
- Packageghc-9.10.3
- Exports66
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceMain.hs
Making an HscEnv
3 declarationsInitialize HscEnv from an optional top_dir path
Compiling complete source files
15 declarationsAction to perform in backend compilation
Constructors
HscUpdate ModIfaceUpdate the boot and signature file results.
HscRecompRecompile this module.
hscs_guts :: CgGutsInformation for the code generator.
hscs_mod_location :: !ModLocationModule info
hscs_partial_iface :: !PartialModIfacePartial interface
hscs_old_iface_hash :: !Maybe FingerprintOld interface hash for this compilation, if an old interface file exists. Pass to
hscMaybeWriteIfacewhen writing the interface to avoid updating the existing interface when the interface isn't changed.
Instances1Outputable
Outputable HscBackendActionDefined in ghc-9.10.3 · GHC.Unit.Module.Status
Status of a module in incremental compilation
Constructors
HscUpToDate ModIface HomeModLinkableNothing to do because code already exists.
HscRecompNeeded (Maybe Fingerprint)Recompilation of module, or update of interface is required. Optionally pass the old interface hash to avoid updating the existing interface when it has not changed.
hscMaybeWriteIface :: Logger-> DynFlags-> BoolIs this a simple interface generated after the core pipeline, or one with information from the backend? See: Note [Writing interface files]
-> ModIface-> Maybe FingerprintThe old interface hash, used to decide if we need to actually write the new interface.
-> ModLocation-> IO ()
Write interface files
hscGenHardCode :: HscEnv-> CgGuts-> ModLocation-> FilePath-> IO (FilePath, Maybe FilePath, [(ForeignSrcLang, FilePath)], Maybe StgCgInfos, Maybe CmmCgInfos)Just f= _stub.c is f
Compile to hard-code.
Running passes separately
8 declarationsDo the recompilation avoidance checks for both one-shot and --make modes This function is the *only* place in the compiler where we decide whether to recompile a module or not!
parse a file, returning the abstract syntax
Rename and typecheck a module, additionally returning the renamed syntax
Do Typechecking without throwing SourceError exception with -Werror
Convert a typechecked module to Core
Make a ModDetails from the results of typechecking. Used when typechecking only, as opposed to full compilation.
Run Core2Core simplifier. The list of String is a list of (Core) plugin
module names added via TH (cf addCorePlugin).
Safe Haskell
2 declarationsCheck that a module is safe to import.
We return True to indicate the import is safe and False otherwise although in the False case an exception may be thrown first.
Return if a module is trusted and the pkgs it depends on to be trusted.
Support for interactive evaluation
24 declarationsRename some import declarations
Lookup things in the compiler's environment
Compile a stmt all the way to an HValue, but don't run it
We return Nothing to indicate an empty statement (or comment only), not a parse error.
hscStmtWithLocation Compile a stmt all the way to an HValue, but don't run it
We return Nothing to indicate an empty statement (or comment only), not a parse error.
hscParsedStmt Compile a decls
hscDeclsWithLocation Compile a decls
Typecheck an expression (but don't run it)
How should we infer a type? See Note [TcRnExprMode]
Constructors
TM_InstInstantiate inferred quantifiers only (:type)
TM_DefaultInstantiate all quantifiers, and do eager defaulting (:type +d)
hscKcType Find the kind of a type, after generalisation
Low-level exports for hooks
14 declarationsRun Core2Core simplifier. The list of String is a list of (Core) plugin
module names added via TH (cf addCorePlugin).
doCodeGen :: HscEnv-> Module-> InfoTableProvMap-> [TyCon]-> CollectedCCs-> [CgStgTopBinding]Bindings come already annotated with fvs
-> HpcInfo-> IO (Stream IO CmmGroupSRTs CmmCgInfos)
Deal with errors and warnings returned by a compilation step
In order to reduce dependencies to other parts of the compiler, functions outside the "main" parts of GHC return warnings and errors as a parameter and signal success via by wrapping the result in a Maybe type. This function logs the returned warnings and propagates errors as exceptions (of type SourceError).
This function assumes the following invariants:
If the second result indicates success (is of the form 'Just x'), there must be no error messages in the first result.
If there are no error messages, but the second result indicates failure there should be warnings in the first result. That is, if the action failed, it must have been due to the warnings (i.e.,
-Werror).
Load the given static-pointer table entries into the interpreter. See Note [Grand plan for static forms] in GHC.Iface.Tidy.StaticPtrTable.