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

GHC.Driver.Main

Description

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

Synopsis

Making an HscEnv

Compiling complete source files

data HscStatus Source #

Status of a module compilation to machine code

Constructors

HscNotGeneratingCode ModIface ModDetails

Nothing to do.

HscUpToDate ModIface ModDetails

Nothing to do because code already exists.

HscUpdateBoot ModIface ModDetails

Update boot file result.

HscUpdateSig ModIface ModDetails

Generate signature file (backpack)

HscRecomp

Recompile this module.

Fields

hscIncrementalCompile :: Bool -> Maybe TcGblEnv -> Maybe Messager -> HscEnv -> ModSummary -> SourceModified -> Maybe ModIface -> (Int, Int) -> IO (HscStatus, HscEnv) Source #

Used by both OneShot and batch mode. Runs the pipeline HsSyn and Core parts of the pipeline. We return a interface if we already had an old one around and recompilation was not needed. Otherwise it will be created during later passes when we run the compilation pipeline.

hscMaybeWriteIface :: Logger -> DynFlags -> Bool -> ModIface -> Maybe Fingerprint -> ModLocation -> IO () Source #

Write interface files

hscGenHardCode Source #

Arguments

:: HscEnv 
-> CgGuts 
-> ModLocation 
-> FilePath 
-> IO (FilePath, Maybe FilePath, [(ForeignSrcLang, FilePath)], CgInfos)

Just f = _stub.c is f

Compile to hard-code.

Running passes separately

hscParse :: HscEnv -> ModSummary -> IO HsParsedModule Source #

parse a file, returning the abstract syntax

hscTypecheckRename :: HscEnv -> ModSummary -> HsParsedModule -> IO (TcGblEnv, RenamedStuff) Source #

Rename and typecheck a module, additionally returning the renamed syntax

hscDesugar :: HscEnv -> ModSummary -> TcGblEnv -> IO ModGuts Source #

Convert a typechecked module to Core

makeSimpleDetails :: HscEnv -> TcGblEnv -> IO ModDetails Source #

Make a ModDetails from the results of typechecking. Used when typechecking only, as opposed to full compilation.

hscSimplify :: HscEnv -> [String] -> ModGuts -> IO ModGuts Source #

Run Core2Core simplifier. The list of String is a list of (Core) plugin module names added via TH (cf addCorePlugin).

Safe Haskell

hscCheckSafe :: HscEnv -> Module -> SrcSpan -> IO Bool Source #

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

hscGetSafe :: HscEnv -> Module -> SrcSpan -> IO (Bool, Set UnitId) Source #

Return if a module is trusted and the pkgs it depends on to be trusted.

Support for interactive evaluation

hscRnImportDecls :: HscEnv -> [LImportDecl GhcPs] -> IO GlobalRdrEnv Source #

Rename some import declarations

hscTcRnLookupRdrName :: HscEnv -> LocatedN RdrName -> IO [Name] Source #

Lookup things in the compiler's environment

hscStmt :: HscEnv -> String -> IO (Maybe ([Id], ForeignHValue, FixityEnv)) Source #

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 Source #

Arguments

:: HscEnv 
-> String

The statement

-> String

The source

-> Int

Starting line

-> IO (Maybe ([Id], ForeignHValue, FixityEnv)) 

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 Source #

Arguments

:: HscEnv 
-> GhciLStmt GhcPs

The parsed statement

-> IO (Maybe ([Id], ForeignHValue, FixityEnv)) 

hscDecls Source #

Arguments

:: HscEnv 
-> String

The statement

-> IO ([TyThing], InteractiveContext) 

Compile a decls

hscDeclsWithLocation Source #

Arguments

:: HscEnv 
-> String

The statement

-> String

The source

-> Int

Starting line

-> IO ([TyThing], InteractiveContext) 

Compile a decls

hscTcExpr Source #

Arguments

:: HscEnv 
-> TcRnExprMode 
-> String

The expression

-> IO Type 

Typecheck an expression (but don't run it)

data TcRnExprMode Source #

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)

hscKcType Source #

Arguments

:: HscEnv 
-> Bool

Normalise the type

-> String

The type as a string

-> IO (Type, Kind)

Resulting type (possibly normalised) and kind

Find the kind of a type, after generalisation

Low-level exports for hooks

hscSimplify' :: [String] -> ModGuts -> Hsc ModGuts Source #

Run Core2Core simplifier. The list of String is a list of (Core) plugin module names added via TH (cf addCorePlugin).

ioMsgMaybe :: IO (Messages DecoratedSDoc, Maybe a) -> Hsc a Source #

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:

  1. If the second result indicates success (is of the form 'Just x'), there must be no error messages in the first result.
  2. 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).

hscAddSptEntries :: HscEnv -> [SptEntry] -> IO () Source #

Load the given static-pointer table entries into the interpreter. See Note [Grand plan for static forms] in GHC.Iface.Tidy.StaticPtrTable.