HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Moduleghc-10.0.0.20260917GHC2024

GHC.Driver.Session

Dynamic flags

Most flags are dynamic flags, which means they can change from compilation to compilation using OPTIONS_GHC pragmas, and in a multi-session GHC each session can be using different dynamic flags. Dynamic flags can also be set at the prompt in GHCi.

(c) The University of Glasgow 2005

Contents
  1. Dynamic flags and associated configuration types
  2. Safe Haskell
  3. base
  4. System tool settings and locations
  5. Manipulating DynFlags
  6. State
  7. Parsing DynFlags
  8. Available DynFlags
  9. DynFlags C compiler options
  10. DynFlags C linker options
  11. Compiler configuration suitable for display to the user
  12. SSE and AVX
  13. Linker/compiler information
  14. Include specifications
  15. SDoc
Synopsis

Dynamic flags and associated configuration types

datadata DumpFlag

Debugging flags

Constructors

Instances3Enum, Eq, Show
  • Enum DumpFlagDefined in ghc-10.0.0.20260917 · GHC.Driver.Flags
  • Eq DumpFlagDefined in ghc-10.0.0.20260917 · GHC.Driver.Flags
  • Show DumpFlagDefined in ghc-10.0.0.20260917 · GHC.Driver.Flags
datadata GeneralFlag

Enumerates the simple on-or-off dynamic flags

Constructors

Instances3Enum, Eq, Show
datadata WarningFlag
#

Constructors

Instances5Bounded, Enum, Eq, Ord, Show

The reason why a Diagnostic was emitted in the first place. Diagnostic messages are born within GHC with a very precise reason, which can be completely statically-computed (i.e. this is an error or a warning no matter what), or influenced by the specific state of the DynFlags at the moment of the creation of a new Diagnostic. For example, a parsing error is always going to be an error, whereas a 'WarningWithoutFlag Opt_WarnUnusedImports' might turn into an error due to '-Werror' or '-Werror=warn-unused-imports'. Interpreting a DiagnosticReason together with its associated Severity gives us the full picture.

Constructors

Instances3Eq, Show, Outputable
datadata Language
#
Instances7Bounded, Enum, Eq, Show, NFData, Outputable, …
datadata ProfAuto

What kind of {-# SCC #-} to add automatically

Constructors

Instances3Enum, Eq, Show
  • Enum ProfAutoDefined in ghc-10.0.0.20260917 · GHC.Types.ProfAuto
  • Eq ProfAutoDefined in ghc-10.0.0.20260917 · GHC.Types.ProfAuto
  • Show ProfAutoDefined in ghc-10.0.0.20260917 · GHC.Types.ProfAuto
datadata OnOff a
#

Constructors

Instances3Eq, Show, Outputable
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

classclass HasDynFlags (m :: Type -> Type) where
#

Methods

Instances13HasDynFlags, …
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
  • Eq GhcModeDefined in ghc-10.0.0.20260917 · GHC.Driver.DynFlags
  • Outputable GhcModeDefined in ghc-10.0.0.20260917 · GHC.Driver.DynFlags
datadata PackageArg

We accept flags which make packages visible, but how they select the package varies; this data type reflects what selection criterion is used.

Constructors

Instances4Eq, Ord, Show, Outputable
datadata ModRenaming

Represents the renaming that may be associated with an exposed package, e.g. the rns part of -package "foo (rns)".

Here are some example parsings of the package flags (where a string literal is punned to be a ModuleName:

  • -package foo is ModRenaming True []

  • -package foo () is ModRenaming False []

  • -package foo (A) is ModRenaming False [(A, A)]

  • -package foo (A as B) is ModRenaming False [(A, B)]

  • -package foo with (A as B) is ModRenaming True [(A, B)]

Constructors

Instances3Eq, Ord, Outputable
datadata Option

When invoking external tools as part of the compilation pipeline, we pass these a sequence of options on the command-line. Rather than just using a list of Strings, we use a type that allows us to distinguish between filepaths and 'other stuff'. The reason for this is that this type gives us a handle on transforming filenames, and filenames only, to whatever format they're expected to be on a particular platform.

Instances1Eq
  • Eq OptionDefined in ghc-10.0.0.20260917 · GHC.Utils.CliOption

The set of flags which affect optimisation for the purposes of recompilation avoidance. Specifically, these include flags which affect code generation but not the semantics of the program.

See Note [Ignoring some flag changes] in GHC.Iface.Recomp.Flags)

The set of flags which affect code generation and can change a program's runtime behavior (other than performance). These include flags which affect:

  • user visible debugging information (e.g. info table provenance)

  • the ability to catch runtime errors (e.g. -fignore-asserts)

  • the runtime result of the program (e.g. -fomit-yields)

  • which code or interface file declarations are emitted

We also considered placing flags which affect asympototic space behavior (e.g. -ffull-laziness) however this would mean that changing optimisation levels would trigger recompilation even with -fignore-optim-changes, regressing #13604.

Also, arguably Opt_IgnoreAsserts should be here as well; however, we place it instead in optimisationFlags since it is implied by -O[12] and therefore would also break #13604.

See #23369.

Safe Haskell

Are all direct imports required to be safe for this Safe Haskell mode? Direct imports are when the code explicitly imports a module

Are all implicit imports required to be safe for this Safe Haskell mode? Implicit imports are things in the prelude. e.g System.IO when print is used.

base

System tool settings and locations

The directory for this version of ghc in the user's app directory The appdir used to be in ~/.ghc but to respect the XDG specification we want to move it under $XDG_DATA_HOME/ However, old tooling (like cabal) might still write package environments to the old directory, so we prefer that if a subdirectory of ~/.ghc with the correct target and GHC version suffix exists.

i.e. if ~.ghc$UNIQUE_SUBDIR exists we use that otherwise we use $XDG_DATA_HOME/$UNIQUE_SUBDIR

UNIQUE_SUBDIR is typically a combination of the target platform and GHC version

Manipulating DynFlags

valuegetOpts
  1. :: DynFlags

    DynFlags to retrieve the options from

  2. -> (DynFlags -> [a])

    Relevant record accessor: one of the opt_* accessors

  3. -> [a]

    Correctly ordered extracted options

Retrieve the options corresponding to a particular opt_* field in the correct order

Gets the verbosity flag for the current verbosity level. This is fed to other tools, so GHC-specific verbosity flags like -ddump-most are not included

State

Parsing DynFlags

valueparseDynamicFlagsFull
  1. :: MonadIO m
  2. => [Flag (CmdLineP DynFlags)]

    valid flags to match against

  3. -> Bool

    are the arguments from the command line?

  4. -> Logger

    logger

  5. -> DynFlags

    current dynamic flags

  6. -> [Located String]

    arguments to parse

  7. -> m (DynFlags, [Located String], Messages DriverMessage)

Parses the dynamically set flags for GHC. This is the most general form of the dynamic flag parser that the other methods simply wrap. It allows saying which flags are valid flags and indicating if we are parsing arguments from the command line or from a file pragma.

Available DynFlags

All dynamic flags option strings without the deprecated ones. These are the user facing strings for enabling and disabling options.

Make a list of flags for shell completion. Filter all available flags into two groups, for interactive GHC vs all other.

DynFlags C compiler options

DynFlags C linker options

Compiler configuration suitable for display to the user

SSE and AVX

Linker/compiler information

Include specifications

SDoc