ghc-8.0.0.20160411: The GHC API

Safe HaskellNone
LanguageHaskell2010

HscMain

Contents

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

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 compilation to hard-code

hscIncrementalFrontend :: Bool -> Maybe TcGblEnv -> Maybe Messager -> ModSummary -> SourceModified -> Maybe ModIface -> (Int, Int) -> Hsc (Either ModIface (FrontendResult, Maybe Fingerprint)) Source #

This function runs GHC's frontend with recompilation avoidance. Specifically, it checks if recompilation is needed, and if it is, it parses and typechecks the input module. It does not write out the results of typechecking (See compileOne and hscIncrementalCompile).

hscGenHardCode Source #

Arguments

:: HscEnv 
-> CgGuts 
-> ModSummary 
-> FilePath 
-> IO (FilePath, Maybe FilePath)

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

makeSimpleIface :: HscEnv -> Maybe ModIface -> TcGblEnv -> ModDetails -> IO (ModIface, Bool) Source #

Make a ModIface from the results of typechecking. Used when not optimising, and the interface doesn't need to contain any unfoldings or other cross-module optimisation info. ToDo: the old interface is only needed to get the version numbers, we should use fingerprint versions instead.

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

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

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, [UnitId]) Source #

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

Support for interactive evaluation

hscTcRcLookupName :: HscEnv -> Name -> IO (Maybe TyThing) Source #

Lookup things in the compiler's environment

hscFileFrontEnd :: ModSummary -> Hsc TcGblEnv Source #

Given a ModSummary, parses and typechecks it, returning the TcGblEnv resulting from type-checking.