DynFlags.hs 217 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,
Sylvain Henry's avatar
Sylvain Henry committed
31
        hasPprDebug, hasNoDebugOutput, hasNoStateHack, hasNoOptCoercion,
32
        dopt, dopt_set, dopt_unset,
triple's avatar
triple committed
33
        gopt, gopt_set, gopt_unset, setGeneralFlag', unSetGeneralFlag',
34
        wopt, wopt_set, wopt_unset,
35
        wopt_fatal,
36
        xopt, xopt_set, xopt_unset,
37
        lang_set,
38
        useUnicodeSyntax,
39 40
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
41
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
42
        DynFlags(..),
43
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
44
        HasDynFlags(..), ContainsDynFlags(..),
45
        OverridingBool(..), overrideWith,
Ian Lynagh's avatar
Ian Lynagh committed
46
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
47
        HscTarget(..), isObjectTarget, defaultObjectTarget,
48
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
49 50
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
51
        PackageFlag(..), PackageArg(..), ModRenaming(..),
52
        IgnorePackageFlag(..), TrustFlag(..),
53
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
54
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
55
        DynLibLoader(..),
56 57
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
58
        dynFlagDependencies,
59
        tablesNextToCode, mkTablesNextToCode,
Ben Gamari's avatar
Ben Gamari committed
60
        makeDynFlagsConsistent,
61

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

65 66
        thisPackage, thisComponentId, thisUnitIdInsts,

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

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


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

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

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

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

119
        supportedLanguagesAndExtensions,
120
        languageExtensions,
121

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

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

        rtsIsProfiled,
129
        dynamicGhc,
130

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

138 139
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

Austin Seipp's avatar
Austin Seipp committed
151
        -- * Linker/compiler information
152
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
153
        CompilerInfo(..),
154 155 156 157
  ) where

#include "HsVersions.h"

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

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

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

213 214 215
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

216
import GHC.Foreign (withCString, peekCString)
217
import qualified GHC.LanguageExtensions as LangExt
218

219
import Foreign (Ptr) -- needed for 2nd stage
Moritz Angermann's avatar
Moritz Angermann committed
220

221 222 223 224 225 226 227
-- 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:
--
228 229
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
230
--
231
--  * Flag description in docs/users_guide/using.rst provides a detailed
232 233
--    explanation of flags' usage.

234 235 236 237 238 239 240 241 242 243 244 245
-- 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.

246 247 248 249 250 251 252
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
253 254
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
255 256 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
--
--  * 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.

299 300 301
-- -----------------------------------------------------------------------------
-- DynFlags

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

   -- debugging flags
   = Opt_D_dump_cmm
307
   | Opt_D_dump_cmm_from_stg
308
   | Opt_D_dump_cmm_raw
309 310 311 312
   | 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.
313 314
   | Opt_D_dump_cmm_cfg
   | Opt_D_dump_cmm_cbe
315
   | Opt_D_dump_cmm_switch
316 317
   | Opt_D_dump_cmm_proc
   | Opt_D_dump_cmm_sp
318 319
   | Opt_D_dump_cmm_sink
   | Opt_D_dump_cmm_caf
320 321 322 323 324
   | Opt_D_dump_cmm_procmap
   | Opt_D_dump_cmm_split
   | Opt_D_dump_cmm_info
   | Opt_D_dump_cmm_cps
   -- end cmm subflags
325
   | Opt_D_dump_asm
326 327 328 329 330
   | 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
331
   | Opt_D_dump_asm_stats
332
   | Opt_D_dump_asm_expanded
333
   | Opt_D_dump_llvm
334
   | Opt_D_dump_core_stats
335 336 337 338
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
339
   | Opt_D_dump_rule_firings
340
   | Opt_D_dump_rule_rewrites
341
   | Opt_D_dump_simpl_trace
342 343
   | Opt_D_dump_occur_anal
   | Opt_D_dump_parsed
344
   | Opt_D_dump_parsed_ast
345
   | Opt_D_dump_rn
Edward Z. Yang's avatar
Edward Z. Yang committed
346
   | Opt_D_dump_shape
347 348 349 350 351
   | Opt_D_dump_simpl
   | Opt_D_dump_simpl_iterations
   | Opt_D_dump_spec
   | Opt_D_dump_prep
   | Opt_D_dump_stg
352
   | Opt_D_dump_call_arity
353
   | Opt_D_dump_stranal
manav's avatar
manav committed
354
   | Opt_D_dump_str_signatures
355 356 357 358 359 360 361 362 363
   | 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
364
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
365
   | Opt_D_dump_tc_trace
366
   | Opt_D_dump_ec_trace -- Pattern match exhaustiveness checker
367
   | Opt_D_dump_if_trace
368
   | Opt_D_dump_vt_trace
369
   | Opt_D_dump_splices
370
   | Opt_D_th_dec_file
371 372
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
373
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
374
   | Opt_D_dump_rtti
375 376 377 378
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
379
   | Opt_D_dump_mod_cycles
380
   | Opt_D_dump_mod_map
381
   | Opt_D_dump_view_pattern_commoning
382
   | Opt_D_verbose_core2core
383
   | Opt_D_dump_debug
384
   | Opt_D_dump_json
Sylvain Henry's avatar
Sylvain Henry committed
385 386
   | Opt_D_ppr_debug
   | Opt_D_no_debug_output
387 388 389 390
   deriving (Eq, Show, Enum)

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

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

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

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

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

462 463 464 465
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
466
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
467

Ian Lynagh's avatar
Ian Lynagh committed
468 469
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
470
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
471

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

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

520
   -- output style opts
521 522
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
Rufflewind's avatar
Rufflewind committed
523
   | Opt_DiagnosticsShowCaret -- Show snippets of offending code
524
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
525
   | Opt_PprShowTicks
526
   | Opt_ShowHoleConstraints
527

528 529 530 531 532 533 534 535 536 537 538
   -- 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
539 540
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
541 542 543 544 545 546
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

547
   -- temporary flags
548
   | Opt_AutoLinkPackages
549
   | Opt_ImplicitImportQualified
550 551 552 553 554 555

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
556
   | Opt_KeepRawTokenStream
557
   | Opt_KeepLlvmFiles
558 559
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
560

561 562
   | Opt_BuildDynamicToo

563
   -- safe haskell flags
dterei's avatar
dterei committed
564
   | Opt_DistrustAllPackages
565
   | Opt_PackageTrust
Sylvain Henry's avatar
Sylvain Henry committed
566 567 568

   | Opt_G_NoStateHack
   | Opt_G_NoOptCoercion
569
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
570

571 572 573 574
-- | 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
Richard Eisenberg's avatar
Richard Eisenberg committed
575 576 577 578
  deriving Show

instance Outputable WarnReason where
  ppr = text . show
579

580 581 582 583
instance ToJson WarnReason where
  json NoReason = JSNull
  json (Reason wf) = JSString (show wf)

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

654
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
655 656 657 658
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
659

660
-- | The various Safe Haskell modes
661 662
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
663
   | Sf_Unsafe
664 665 666 667
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
668
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
669 670 671 672
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
673

674
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
675
    ppr = text . show
676

677
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
678
-- information relating to the compilation of a single file or GHC session
679
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
680 681 682
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
683
  settings              :: Settings,
684
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
685
  optLevel              :: Int,         -- ^ Optimisation level
686
  debugLevel            :: Int,         -- ^ How much debug information to produce
687 688
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
689
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
690
  ruleCheck             :: Maybe String,
691
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
692

693 694
  parMakeCount          :: Maybe Int,   -- ^ The number of modules to compile in parallel
                                        --   in --make mode, where Nothing ==> compile as
parcs's avatar
parcs committed
695 696
                                        --   many in parallel as there are CPUs.

697 698 699
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

700 701
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
702 703
  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
                                        --   in non-exhaustiveness warnings
704
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
705 706
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
707 708
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
709
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
710
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
711
                                        --   See CoreMonad.FloatOutSwitches
712

713
  historySize           :: Int,         -- ^ Simplification history size
714

Ian Lynagh's avatar
Ian Lynagh committed
715 716 717
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
718
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth