DynFlags.hs 212 KB
Newer Older
1
{-# LANGUAGE CPP #-}
2
{-# LANGUAGE FlexibleInstances #-}
3

dterei's avatar
dterei committed
4
-------------------------------------------------------------------------------
5
--
dterei's avatar
dterei committed
6 7 8 9 10 11
-- | 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.
12 13 14
--
-- (c) The University of Glasgow 2005
--
dterei's avatar
dterei committed
15
-------------------------------------------------------------------------------
16

17
{-# OPTIONS_GHC -fno-cse #-}
18 19
-- -fno-cse is needed for GLOBAL_VAR's to behave properly

20
module DynFlags (
21
        -- * Dynamic flags and associated configuration types
22
        DumpFlag(..),
23
        GeneralFlag(..),
24
        WarningFlag(..), WarnReason(..),
25
        Language(..),
26
        PlatformConstants(..),
Ian Lynagh's avatar
Ian Lynagh committed
27
        FatalMessager, LogAction, FlushOut(..), FlushErr(..),
28
        ProfAuto(..),
29
        glasgowExtsFlags,
30
        warningGroups, warningHierarchies,
31
        dopt, dopt_set, dopt_unset,
triple's avatar
triple committed
32
        gopt, gopt_set, gopt_unset, setGeneralFlag', unSetGeneralFlag',
33
        wopt, wopt_set, wopt_unset,
34
        wopt_fatal,
35
        xopt, xopt_set, xopt_unset,
36
        lang_set,
37
        useUnicodeSyntax,
38 39
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
40
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
41
        DynFlags(..),
42
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
43
        HasDynFlags(..), ContainsDynFlags(..),
44
        OverridingBool(..), overrideWith,
Ian Lynagh's avatar
Ian Lynagh committed
45
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
46
        HscTarget(..), isObjectTarget, defaultObjectTarget,
47
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
48 49
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
50
        PackageFlag(..), PackageArg(..), ModRenaming(..),
51
        IgnorePackageFlag(..), TrustFlag(..),
52
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
53
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
54
        DynLibLoader(..),
55 56
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
57
        dynFlagDependencies,
58
        tablesNextToCode, mkTablesNextToCode,
Ben Gamari's avatar
Ben Gamari committed
59
        makeDynFlagsConsistent,
60

61
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
62
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
63

64 65
        thisPackage, thisComponentId, thisUnitIdInsts,

66
        -- ** Safe Haskell
67
        SafeHaskellMode(..),
68
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
69
        packageTrustOn,
70
        safeDirectImpsReq, safeImplicitImpsReq,
71
        unsafeFlags, unsafeFlagsForInfer,
72

73
        -- ** System tool settings and locations
74
        Settings(..),
75
        targetPlatform, programName, projectVersion,
76
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
Edsko de Vries's avatar
Edsko de Vries committed
77
        versionedAppDir,
78 79
        extraGccViaCFlags, systemPackageConfig,
        pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
80 81
        pgm_windres, pgm_libtool, pgm_lo, pgm_lc, pgm_i,
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l, opt_i,
82
        opt_windres, opt_lo, opt_lc,
83 84


85
        -- ** Manipulating DynFlags
86
        defaultDynFlags,                -- Settings -> DynFlags
87
        defaultWays,
ian@well-typed.com's avatar
ian@well-typed.com committed
88
        interpWays,
89
        interpreterProfiled, interpreterDynamic,
Ian Lynagh's avatar
Ian Lynagh committed
90
        initDynFlags,                   -- DynFlags -> IO DynFlags
Ian Lynagh's avatar
Ian Lynagh committed
91
        defaultFatalMessager,
92
        defaultLogAction,
93
        defaultLogActionHPrintDoc,
94
        defaultLogActionHPutStrDoc,
95 96
        defaultFlushOut,
        defaultFlushErr,
Ian Lynagh's avatar
Ian Lynagh committed
97

98
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
99
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
100 101
        updOptLevel,
        setTmpDir,
102
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
103
        interpretPackageEnv,
Edward Z. Yang's avatar
Edward Z. Yang committed
104
        canonicalizeHomeModule,
Ian Lynagh's avatar
Ian Lynagh committed
105

106
        -- ** Parsing DynFlags
107 108
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
109 110 111
        parseDynamicFlagsFull,

        -- ** Available DynFlags
112
        allNonDeprecatedFlags,
113 114 115
        flagsAll,
        flagsDynamic,
        flagsPackage,
116
        flagsForCompletion,
117

118
        supportedLanguagesAndExtensions,
119
        languageExtensions,
120

121
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
122
        picCCOpts, picPOpts,
123 124

        -- * Compiler configuration suitable for display to the user
125 126 127
        compilerInfo,

        rtsIsProfiled,
128
        dynamicGhc,
129

130
#include "GHCConstantsHaskellExports.hs"
131
        bLOCK_SIZE_W,
132
        wORD_SIZE_IN_BITS,
133 134
        tAG_MASK,
        mAX_PTR_TAG,
135
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
136

137 138
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

139
        -- * SSE and AVX
140
        isSseEnabled,
141 142
        isSse2Enabled,
        isSse4_2Enabled,
143 144
        isAvxEnabled,
        isAvx2Enabled,
145 146 147 148
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
149

150
        -- * Linker/compiler information
151
        LinkerInfo(..),
152
        CompilerInfo(..),
153 154 155 156
  ) where

#include "HsVersions.h"

157
import Platform
158
import PlatformConstants
159
import Module
Simon Marlow's avatar
Simon Marlow committed
160
import PackageConfig
161
import {-# SOURCE #-} Hooks
162
import {-# SOURCE #-} PrelNames ( mAIN )
163
import {-# SOURCE #-} Packages (PackageState, emptyPackageState)
Ian Lynagh's avatar
Ian Lynagh committed
164
import DriverPhases     ( Phase(..), phaseInputExt )
165 166
import Config
import CmdLineParser
167
import Constants
168
import Panic
169
import Util
Edsko de Vries's avatar
Edsko de Vries committed
170
import Maybes
171
import MonadUtils
172
import qualified Pretty
173
import SrcLoc
174
import BasicTypes       ( IntWithInf, treatZeroAsInf )
175
import FastString
Simon Marlow's avatar
Simon Marlow committed
176
import Outputable
177
import Foreign.C        ( CInt(..) )
178
import System.IO.Unsafe ( unsafeDupablePerformIO )
179
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn )
180
import SysTools.Terminal ( stderrSupportsAnsiColors )
181

182
import System.IO.Unsafe ( unsafePerformIO )
183
import Data.IORef
184
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
185
import Control.Monad
186 187 188 189
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
190
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
191

192
import Data.Ord
193
import Data.Bits
194
import Data.Char
195
import Data.Int
196
import Data.List
197 198
import Data.Map (Map)
import qualified Data.Map as Map
199 200
import Data.Set (Set)
import qualified Data.Set as Set
201
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
202
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
203 204
import System.Directory
import System.Environment (getEnv)
205
import System.IO
206
import System.IO.Error
207 208
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
209

210 211 212
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

213
import GHC.Foreign (withCString, peekCString)
214
import qualified GHC.LanguageExtensions as LangExt
215

216 217 218 219 220 221 222
#if __GLASGOW_HASKELL__ >= 709
import Foreign
#else
import Foreign.Safe
#endif


223 224 225 226 227 228 229
-- Note [Updating flag description in the User's Guide]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- If you modify anything in this file please make sure that your changes are
-- described in the User's Guide. Usually at least two sections need to be
-- updated:
--
230 231
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
232
--
233
--  * Flag description in docs/users_guide/using.rst provides a detailed
234 235
--    explanation of flags' usage.

236 237 238 239 240 241 242 243 244 245 246 247
-- Note [Supporting CLI completion]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- The command line interface completion (in for example bash) is an easy way
-- for the developer to learn what flags are available from GHC.
-- GHC helps by separating which flags are available when compiling with GHC,
-- and which flags are available when using GHCi.
-- A flag is assumed to either work in both these modes, or only in one of them.
-- When adding or changing a flag, please consider for which mode the flag will
-- have effect, and annotate it accordingly. For Flags use defFlag, defGhcFlag,
-- defGhciFlag, and for FlagSpec use flagSpec or flagGhciSpec.

248 249 250 251 252 253 254
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
255 256
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
--
--  * Adding a flag to DynFlags.xFlags
--
--    This is fairly self-explanatory. The name should be concise, memorable,
--    and consistent with any previous implementations of the similar idea in
--    other Haskell compilers.
--
--  * Adding the flag to the documentation
--
--    This is the same as any other flag. See
--    Note [Updating flag description in the User's Guide]
--
--  * Adding the flag to Cabal
--
--    The Cabal library has its own list of all language extensions supported
--    by all major compilers. This is the list that user code being uploaded
--    to Hackage is checked against to ensure language extension validity.
--    Consequently, it is very important that this list remains up-to-date.
--
--    To this end, there is a testsuite test (testsuite/tests/driver/T4437.hs)
--    whose job it is to ensure these GHC's extensions are consistent with
--    Cabal.
--
--    The recommended workflow is,
--
--     1. Temporarily add your new language extension to the
--        expectedGhcOnlyExtensions list in T4437 to ensure the test doesn't
--        break while Cabal is updated.
--
--     2. After your GHC change is accepted, submit a Cabal pull request adding
--        your new extension to Cabal's list (found in
--        Cabal/Language/Haskell/Extension.hs).
--
--     3. After your Cabal change is accepted, let the GHC developers know so
--        they can update the Cabal submodule and remove the extensions from
--        expectedGhcOnlyExtensions.
--
--  * Adding the flag to the GHC Wiki
--
--    There is a change log tracking language extension additions and removals
--    on the GHC wiki:  https://ghc.haskell.org/trac/ghc/wiki/LanguagePragmaHistory
--
--  See Trac #4437 and #8176.

301 302 303
-- -----------------------------------------------------------------------------
-- DynFlags

304
data DumpFlag
305
-- See Note [Updating flag description in the User's Guide]
306 307 308

   -- debugging flags
   = Opt_D_dump_cmm
309
   | Opt_D_dump_cmm_from_stg
310
   | Opt_D_dump_cmm_raw
311 312 313 314
   | Opt_D_dump_cmm_verbose
   -- All of the cmm subflags (there are a lot!) automatically
   -- enabled if you run -ddump-cmm-verbose
   -- Each flag corresponds to exact stage of Cmm pipeline.
315 316
   | Opt_D_dump_cmm_cfg
   | Opt_D_dump_cmm_cbe
317
   | Opt_D_dump_cmm_switch
318 319
   | Opt_D_dump_cmm_proc
   | Opt_D_dump_cmm_sp
320 321
   | Opt_D_dump_cmm_sink
   | Opt_D_dump_cmm_caf
322 323 324 325 326
   | Opt_D_dump_cmm_procmap
   | Opt_D_dump_cmm_split
   | Opt_D_dump_cmm_info
   | Opt_D_dump_cmm_cps
   -- end cmm subflags
327
   | Opt_D_dump_asm
328 329 330 331 332
   | Opt_D_dump_asm_native
   | Opt_D_dump_asm_liveness
   | Opt_D_dump_asm_regalloc
   | Opt_D_dump_asm_regalloc_stages
   | Opt_D_dump_asm_conflicts
333
   | Opt_D_dump_asm_stats
334
   | Opt_D_dump_asm_expanded
335
   | Opt_D_dump_llvm
336
   | Opt_D_dump_core_stats
337 338 339 340
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
341
   | Opt_D_dump_rule_firings
342
   | Opt_D_dump_rule_rewrites
343
   | Opt_D_dump_simpl_trace
344 345 346
   | Opt_D_dump_occur_anal
   | Opt_D_dump_parsed
   | Opt_D_dump_rn
Edward Z. Yang's avatar
Edward Z. Yang committed
347
   | Opt_D_dump_shape
348 349 350 351 352
   | Opt_D_dump_simpl
   | Opt_D_dump_simpl_iterations
   | Opt_D_dump_spec
   | Opt_D_dump_prep
   | Opt_D_dump_stg
353
   | Opt_D_dump_call_arity
354
   | Opt_D_dump_stranal
manav's avatar
manav committed
355
   | Opt_D_dump_str_signatures
356 357 358 359 360 361 362 363 364
   | Opt_D_dump_tc
   | Opt_D_dump_types
   | Opt_D_dump_rules
   | Opt_D_dump_cse
   | Opt_D_dump_worker_wrapper
   | Opt_D_dump_rn_trace
   | Opt_D_dump_rn_stats
   | Opt_D_dump_opt_cmm
   | Opt_D_dump_simpl_stats
365
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
366
   | Opt_D_dump_tc_trace
367
   | Opt_D_dump_ec_trace -- Pattern match exhaustiveness checker
368
   | Opt_D_dump_if_trace
369
   | Opt_D_dump_vt_trace
370
   | Opt_D_dump_splices
371
   | Opt_D_th_dec_file
372 373
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
374
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
375
   | Opt_D_dump_rtti
376 377 378 379
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
380
   | Opt_D_dump_mod_cycles
381
   | Opt_D_dump_mod_map
382
   | Opt_D_dump_view_pattern_commoning
383
   | Opt_D_verbose_core2core
384
   | Opt_D_dump_debug
385 386 387 388 389

   deriving (Eq, Show, Enum)

-- | Enumerates the simple on-or-off dynamic flags
data GeneralFlag
390
-- See Note [Updating flag description in the User's Guide]
391 392

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
393
   | Opt_D_faststring_stats
394
   | Opt_D_dump_minimal_imports
395 396 397
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
398
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
399
   | Opt_DoAnnotationLinting
400
   | Opt_NoLlvmMangler                 -- hidden flag
401

Ian Lynagh's avatar
Ian Lynagh committed
402
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
403
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
404
   | Opt_HideSourcePaths                -- Hide module source/object paths
405

406
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
407
   | Opt_PrintExplicitKinds
408
   | Opt_PrintExplicitCoercions
409
   | Opt_PrintExplicitRuntimeReps
410
   | Opt_PrintEqualityRelations
411
   | Opt_PrintUnicodeSyntax
412
   | Opt_PrintExpandedSynonyms
413
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
414
   | Opt_PrintTypecheckerElaboration
415

416
   -- optimisation opts
417
   | Opt_CallArity
418
   | Opt_Strictness
419
   | Opt_LateDmdAnal
420 421
   | Opt_KillAbsence
   | Opt_KillOneShot
422
   | Opt_FullLaziness
423 424
   | Opt_FloatIn
   | Opt_Specialise
425
   | Opt_SpecialiseAggressively
426
   | Opt_CrossModuleSpecialise
427
   | Opt_StaticArgumentTransformation
428
   | Opt_CSE
429 430
   | Opt_LiberateCase
   | Opt_SpecConstr
431 432 433 434
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
Sylvain Henry's avatar
Sylvain Henry committed
435
   | Opt_CaseFolding                    -- Constant folding through case-expressions
436
   | Opt_UnboxStrictFields
437
   | Opt_UnboxSmallStrictFields
438
   | Opt_DictsCheap
439
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
440
   | Opt_Vectorise
441
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
442 443
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
444
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
445
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
446
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
447
   | Opt_LlvmFillUndefWithGarbage       -- Testing for undef bugs (hidden flag)
448
   | Opt_IrrefutableTuples
449
   | Opt_CmmSink
450
   | Opt_CmmElimCommonBlocks
451
   | Opt_OmitYields
452
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
453 454
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
455
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
456
   | Opt_CprAnal
457
   | Opt_WorkerWrapper
458

459 460 461 462
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
463
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
464

465 466
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
467
   | Opt_ProfCountEntries
468

469 470
   -- misc opts
   | Opt_Pp
471
   | Opt_ForceRecomp
472
   | Opt_ExcessPrecision
473
   | Opt_EagerBlackHoling
474 475
   | Opt_NoHsMain
   | Opt_SplitObjs
476
   | Opt_SplitSections
477
   | Opt_StgStats
478
   | Opt_HideAllPackages
479
   | Opt_HideAllPluginPackages
480
   | Opt_PrintBindResult
481
   | Opt_Haddock
David Waern's avatar
David Waern committed
482
   | Opt_HaddockOptions
483
   | Opt_BreakOnException
484
   | Opt_BreakOnError
485
   | Opt_PrintEvldWithShow
486
   | Opt_PrintBindContents
487 488
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
489
   | Opt_SharedImplib
490
   | Opt_BuildingCabalPackage
491
   | Opt_IgnoreDotGhci
492
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
493
   | Opt_GhciHistory
494
   | Opt_LocalGhciHistory
495
   | Opt_HelpfulErrors
496
   | Opt_DeferTypeErrors
497
   | Opt_DeferTypedHoles
498
   | Opt_DeferOutOfScopeVariables
Ian Lynagh's avatar
Ian Lynagh committed
499
   | Opt_PIC
500
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
501
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
502 503 504
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
505
   | Opt_RPath
506
   | Opt_RelativeDynlibPaths
507
   | Opt_Hpc
508
   | Opt_FlatCache
509
   | Opt_ExternalInterpreter
Simon Marlow's avatar
Simon Marlow committed
510
   | Opt_OptimalApplicativeDo
511
   | Opt_VersionMacros
512

513 514 515 516
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

517
   -- output style opts
518 519
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
520
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
521
   | Opt_PprShowTicks
522
   | Opt_ShowHoleConstraints
523

524 525 526 527 528 529 530 531 532 533 534
   -- Suppress all coercions, them replacing with '...'
   | Opt_SuppressCoercions
   | Opt_SuppressVarKinds
   -- Suppress module id prefixes on variables.
   | Opt_SuppressModulePrefixes
   -- Suppress type applications.
   | Opt_SuppressTypeApplications
   -- Suppress info such as arity and unfoldings on identifiers.
   | Opt_SuppressIdInfo
   -- Suppress separate type signatures in core, but leave types on
   -- lambda bound vars
535 536
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
537 538 539 540 541 542
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

543
   -- temporary flags
544
   | Opt_AutoLinkPackages
545
   | Opt_ImplicitImportQualified
546 547 548 549 550 551

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
552
   | Opt_KeepRawTokenStream
553
   | Opt_KeepLlvmFiles
554 555
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
556

557 558
   | Opt_BuildDynamicToo

559
   -- safe haskell flags
dterei's avatar
dterei committed
560
   | Opt_DistrustAllPackages
561
   | Opt_PackageTrust
562
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
563

564 565 566 567 568
-- | Used when outputting warnings: if a reason is given, it is
-- displayed. If a warning isn't controlled by a flag, this is made
-- explicit at the point of use.
data WarnReason = NoReason | Reason !WarningFlag

569
data WarningFlag =
570
-- See Note [Updating flag description in the User's Guide]
571
     Opt_WarnDuplicateExports
572
   | Opt_WarnDuplicateConstraints
573
   | Opt_WarnRedundantConstraints
574 575 576 577 578
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
579
   | Opt_WarnOverflowedLiterals
580
   | Opt_WarnEmptyEnumerations
581 582 583
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
584 585
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
586 587 588 589
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
590 591 592
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
593 594
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
595 596
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
597 598
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
599
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
600
   | Opt_WarnMissingMonadFailInstances -- since 8.0
601
   | Opt_WarnSemigroup -- since 8.0
602 603 604 605 606 607 608 609 610 611 612
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
613 614
   | Opt_WarnUnsafe
   | Opt_WarnSafe
615
   | Opt_WarnTrustworthySafe
616 617
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
618
   | Opt_WarnUnsupportedCallingConventions
619
   | Opt_WarnUnsupportedLlvmVersion
620
   | Opt_WarnInlineRuleShadowing
621
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
622
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
623
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
624
   | Opt_WarnUntickedPromotedConstructors
625
   | Opt_WarnDerivingTypeable
626
   | Opt_WarnDeferredTypeErrors
627
   | Opt_WarnDeferredOutOfScopeVariables
628
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
629
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
630
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
631
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
632
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
633
   | Opt_WarnSimplifiableClassConstraints -- Since 8.2
634
   | Opt_WarnCPPUndef                     -- Since 8.2
635
   deriving (Eq, Show, Enum)
636

637
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
638 639 640 641
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
642

643
-- | The various Safe Haskell modes
644 645
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
646
   | Sf_Unsafe
647 648 649 650
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
651
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
652 653 654 655
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
656

657
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
658
    ppr = text . show
659

660
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
661
-- information relating to the compilation of a single file or GHC session
662
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
663 664 665
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
666
  settings              :: Settings,
667
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
668
  optLevel              :: Int,         -- ^ Optimisation level
669
  debugLevel            :: Int,         -- ^ How much debug information to produce
670 671
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
672
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
673
  ruleCheck             :: Maybe String,
674
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
675

676 677
  parMakeCount          :: Maybe Int,   -- ^ The number of modules to compile in parallel
                                        --   in --make mode, where Nothing ==> compile as
678 679
                                        --   many in parallel as there are CPUs.

680 681 682
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

683 684
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
685 686
  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
                                        --   in non-exhaustiveness warnings
687
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
688 689
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
690 691
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
692
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
693
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
694
                                        --   See CoreMonad.FloatOutSwitches
695

696
  historySize           :: Int,         -- ^ Simplification history size
697

Ian Lynagh's avatar
Ian Lynagh committed
698 699 700
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
701
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
702 703
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
704

705 706 707
  thisInstalledUnitId   :: InstalledUnitId,
  thisComponentId_      :: Maybe ComponentId,
  thisUnitIdInsts_      :: Maybe [(ModuleName, Module)],
708 709

  -- ways
710
  ways                  :: [Way],       -- ^ Way flags from the command line
711 712
  buildTag              :: String,      -- ^ The global \"way\" (e.g. \"p\" for prof)
  rtsBuildTag           :: String,      -- ^ The RTS \"way\"
Ian Lynagh's avatar
Ian Lynagh committed
713

714 715 716
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

717
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
718
  objectDir             :: Maybe String,
719
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
720 721
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
722
  dumpDir               :: Maybe String,
723

Ian Lynagh's avatar
Ian Lynagh committed
724 725 726
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
727

728 729 730 731
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

732 733 734 735 736 737 738 739
  -- Packages.isDllName needs to know whether a call is within a
  -- single DLL or not. Normally it does this by seeing if the call
  -- is to the same package, but for the ghc package, we split the
  -- package between 2 DLLs. The dllSplit tells us which sets of
  -- modules are in which package.
  dllSplitFile          :: Maybe FilePath,
  dllSplit              :: Maybe [Set String],

Ian Lynagh's avatar
Ian Lynagh committed
740
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
741
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
742 743
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
744

745
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
746 747
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
748

749 750
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
751 752
  dumpPrefixForce       :: Maybe FilePath,

753
  ldInputs              :: [Option],
754

Ian Lynagh's avatar
Ian Lynagh committed
755 756 757 758 759
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

760
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
761
  rtsOptsEnabled        :: RtsOptsEnabled,
762
  rtsOptsSuggestions    :: Bool,
763

764
  hpcDir                :: String,      -- ^ Path to store the .mix files
andy@galois.com's avatar
andy@galois.com committed
765

766 767 768
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
769
  frontendPluginOpts    :: [String],
770

771 772 773
  -- GHC API hooks
  hooks                 :: Hooks,

774 775 776 777 778 779
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

780
  --  Package flags
781
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
782
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
783
        -- they appeared.
784

785 786
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
787
  packageFlags          :: [PackageFlag],
788
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
789 790
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
791 792
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
793 794
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
795

796
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
797
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
798
  -- Packages.initPackages
799
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
800
  pkgState              :: PackageState,
801

802 803 804 805
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
806
  dirsToClean           :: IORef (Map FilePath FilePath),
807
  filesToNotIntermediateClean :: IORef [FilePath],
808 809
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
810

811 812 813
  -- Names of files which were generated from -ddump-to-file; used to
  -- track which ones we need to truncate because it's our first run
  -- through
814
  generatedDumps        :: IORef (Set FilePath),
815

816
  -- hsc dynamic flags
817 818
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
819
  warningFlags          :: IntSet,
820
  fatalWarningFlags     :: IntSet,
821
  -- Don't change this without updating extensionFlags:
822
  language              :: Maybe Language,
823 824
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
825 826
  safeInfer             :: Bool,
  safeInferred          :: Bool,
827 828 829
  -- We store the location of where some extension and flags were turned on so
  -- we can produce accurate error messages when Safe Haskell fails due to
  -- them.
830 831
  thOnLoc               :: SrcSpan,
  newDerivOnLoc         :: SrcSpan,
832
  overlapInstLoc        :: SrcSpan,
833
  incoherentOnLoc       :: SrcSpan,
834
  pkgTrustOnLoc         :: SrcSpan,
835 836
  warnSafeOnLoc         :: SrcSpan,
  warnUnsafeOnLoc       :: SrcSpan,
837
  trustworthyOnLoc      :: SrcSpan,
838
  -- Don't change this without updating extensionFlags:
839
  extensions            :: [OnOff LangExt.Extension],
840 841
  -- extensionFlags should always be equal to
  --     flattenExtensionFlags language extensions
842 843
  -- LangExt.Extension is defined in libraries/ghc-boot so that it can be used
  -- by template-haskell
844
  extensionFlags        :: IntSet,
Ian Lynagh's avatar
Ian Lynagh committed
845

846 847 848 849 850 851 852 853 854
  -- Unfolding control
  -- See Note [Discounts and thresholds] in CoreUnfold
  ufCreationThreshold   :: Int,
  ufUseThreshold        :: Int,
  ufFunAppDiscount      :: Int,
  ufDictDiscount        :: Int,
  ufKeenessFactor       :: Float,
  ufDearOp              :: Int,

855 856
  maxWorkerArgs         :: Int,

857 858
  ghciHistSize          :: Int,