DynFlags.hs 222 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(..),
27
        FatalMessager, LogAction, LogFinaliser, 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(..),
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
        packageFlagsChanged,
52
        IgnorePackageFlag(..), TrustFlag(..),
53
        PackageDBFlag(..), 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,
Rufflewind's avatar
Rufflewind committed
61
        shouldUseColor,
62
        positionIndependent,
63

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

67 68
        thisPackage, thisComponentId, thisUnitIdInsts,

Ben Gamari's avatar
Ben Gamari committed
69 70 71
        -- ** Log output
        putLogMsg,

72
        -- ** Safe Haskell
73
        SafeHaskellMode(..),
74
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
75
        packageTrustOn,
76
        safeDirectImpsReq, safeImplicitImpsReq,
77
        unsafeFlags, unsafeFlagsForInfer,
78

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


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

104
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
105
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
106 107
        updOptLevel,
        setTmpDir,
108
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
109
        interpretPackageEnv,
Edward Z. Yang's avatar
Edward Z. Yang committed
110
        canonicalizeHomeModule,
Ian Lynagh's avatar
Ian Lynagh committed
111

112
        -- ** Parsing DynFlags
113 114
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
115 116 117
        parseDynamicFlagsFull,

        -- ** Available DynFlags
118
        allNonDeprecatedFlags,
119 120 121
        flagsAll,
        flagsDynamic,
        flagsPackage,
122
        flagsForCompletion,
123

124
        supportedLanguagesAndExtensions,
125
        languageExtensions,
126

127
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
128
        picCCOpts, picPOpts,
129 130

        -- * Compiler configuration suitable for display to the user
131 132 133
        compilerInfo,

        rtsIsProfiled,
134
        dynamicGhc,
135

136
#include "GHCConstantsHaskellExports.hs"
137
        bLOCK_SIZE_W,
138
        wORD_SIZE_IN_BITS,
139 140
        tAG_MASK,
        mAX_PTR_TAG,
141
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
142

143 144
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

145
        -- * SSE and AVX
146
        isSseEnabled,
147 148
        isSse2Enabled,
        isSse4_2Enabled,
149 150
        isAvxEnabled,
        isAvx2Enabled,
151 152 153 154
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
155

Austin Seipp's avatar
Austin Seipp committed
156
        -- * Linker/compiler information
157
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
158
        CompilerInfo(..),
Douglas Wilson's avatar
Douglas Wilson committed
159 160 161

        -- * File cleanup
        FilesToClean(..), emptyFilesToClean
162 163 164 165
  ) where

#include "HsVersions.h"

166
import Platform
167
import PlatformConstants
168
import Module
Simon Marlow's avatar
Simon Marlow committed
169
import PackageConfig
170
import {-# SOURCE #-} Hooks
171
import {-# SOURCE #-} PrelNames ( mAIN )
172
import {-# SOURCE #-} Packages (PackageState, emptyPackageState)
Ian Lynagh's avatar
Ian Lynagh committed
173
import DriverPhases     ( Phase(..), phaseInputExt )
174
import Config
175 176
import CmdLineParser hiding (WarnReason(..))
import qualified CmdLineParser as Cmd
177
import Constants
178
import Panic
Rufflewind's avatar
Rufflewind committed
179
import qualified PprColour as Col
180
import Util
Edsko de Vries's avatar
Edsko de Vries committed
181
import Maybes
182
import MonadUtils
183
import qualified Pretty
184
import SrcLoc
185
import BasicTypes       ( IntWithInf, treatZeroAsInf )
186
import FastString
Simon Marlow's avatar
Simon Marlow committed
187
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
188
import Foreign.C        ( CInt(..) )
189
import System.IO.Unsafe ( unsafeDupablePerformIO )
Rufflewind's avatar
Rufflewind committed
190
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn
191 192
                               , getCaretDiagnostic, dumpSDoc )
import Json
193
import SysTools.Terminal ( stderrSupportsAnsiColors )
194

195
import System.IO.Unsafe ( unsafePerformIO )
196
import Data.IORef
197
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
198
import Control.Monad
199 200 201 202
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
203
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
204

205
import Data.Ord
206
import Data.Bits
207
import Data.Char
208
import Data.Int
209
import Data.List
210 211
import Data.Map (Map)
import qualified Data.Map as Map
212 213
import Data.Set (Set)
import qualified Data.Set as Set
214
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
215
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
216
import System.Directory
Rufflewind's avatar
Rufflewind committed
217
import System.Environment (getEnv, lookupEnv)
218
import System.IO
219
import System.IO.Error
220 221
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
222

223 224
import EnumSet (EnumSet)
import qualified EnumSet
225

226
import GHC.Foreign (withCString, peekCString)
227
import qualified GHC.LanguageExtensions as LangExt
228

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

231 232 233 234 235 236 237
-- 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:
--
238 239
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
240
--
241
--  * Flag description in docs/users_guide/using.rst provides a detailed
242 243
--    explanation of flags' usage.

244 245 246 247 248 249 250 251 252 253 254 255
-- 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.

256 257 258 259 260 261 262
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
263 264
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
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 301 302 303 304 305 306 307 308
--
--  * 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.

309 310 311
-- -----------------------------------------------------------------------------
-- DynFlags

312
data DumpFlag
313
-- See Note [Updating flag description in the User's Guide]
314 315 316

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

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
406
   | Opt_D_faststring_stats
407
   | Opt_D_dump_minimal_imports
408 409 410
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
411
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
412
   | Opt_DoAnnotationLinting
413
   | Opt_NoLlvmMangler                 -- hidden flag
414

Ian Lynagh's avatar
Ian Lynagh committed
415
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
416
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
417
   | Opt_HideSourcePaths                -- Hide module source/object paths
418

419
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
420
   | Opt_PrintExplicitKinds
421
   | Opt_PrintExplicitCoercions
422
   | Opt_PrintExplicitRuntimeReps
423
   | Opt_PrintEqualityRelations
424
   | Opt_PrintUnicodeSyntax
425
   | Opt_PrintExpandedSynonyms
426
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
427
   | Opt_PrintTypecheckerElaboration
428

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

476 477 478 479
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
480
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
481

Ian Lynagh's avatar
Ian Lynagh committed
482 483
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
484
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
485

486 487
   -- misc opts
   | Opt_Pp
488
   | Opt_ForceRecomp
489
   | Opt_ExcessPrecision
490
   | Opt_EagerBlackHoling
491 492
   | Opt_NoHsMain
   | Opt_SplitObjs
493
   | Opt_SplitSections
494
   | Opt_StgStats
495
   | Opt_HideAllPackages
496
   | Opt_HideAllPluginPackages
497
   | Opt_PrintBindResult
498
   | Opt_Haddock
David Waern's avatar
David Waern committed
499
   | Opt_HaddockOptions
500
   | Opt_BreakOnException
501
   | Opt_BreakOnError
502
   | Opt_PrintEvldWithShow
503
   | Opt_PrintBindContents
504 505
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
506
   | Opt_SharedImplib
507
   | Opt_BuildingCabalPackage
508
   | Opt_IgnoreDotGhci
509
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
510
   | Opt_GhciHistory
511
   | Opt_LocalGhciHistory
512
   | Opt_HelpfulErrors
513
   | Opt_DeferTypeErrors
514
   | Opt_DeferTypedHoles
515
   | Opt_DeferOutOfScopeVariables
516 517 518
   | Opt_PIC                         -- ^ @-fPIC@
   | Opt_PIE                         -- ^ @-fPIE@
   | Opt_PICExecutable               -- ^ @-pie@
519
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
520
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
521 522 523
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
524
   | Opt_RPath
525
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
526
   | Opt_Hpc
527
   | Opt_FlatCache
528
   | Opt_ExternalInterpreter
Simon Marlow's avatar
Simon Marlow committed
529
   | Opt_OptimalApplicativeDo
530
   | Opt_VersionMacros
Simon Marlow's avatar
Simon Marlow committed
531
   | Opt_WholeArchiveHsLibs
532

533 534 535 536
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

537
   -- output style opts
538 539
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
Rufflewind's avatar
Rufflewind committed
540
   | Opt_DiagnosticsShowCaret -- Show snippets of offending code
541
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
542
   | Opt_PprShowTicks
543
   | Opt_ShowHoleConstraints
544

545 546 547 548 549 550 551 552 553 554 555
   -- 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
556 557
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
558 559 560 561 562
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques
563
   | Opt_SuppressTicks     -- Replaces Opt_PprShowTicks
564

565
   -- temporary flags
566
   | Opt_AutoLinkPackages
567
   | Opt_ImplicitImportQualified
568 569 570 571 572 573

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
574
   | Opt_KeepRawTokenStream
575
   | Opt_KeepLlvmFiles
576 577
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
578

579 580
   | Opt_BuildDynamicToo

581
   -- safe haskell flags
dterei's avatar
dterei committed
582
   | Opt_DistrustAllPackages
583
   | Opt_PackageTrust
Sylvain Henry's avatar
Sylvain Henry committed
584 585 586

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

589 590 591
-- | 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.
592 593 594 595 596 597
data WarnReason
  = NoReason
  -- | Warning was enabled with the flag
  | Reason !WarningFlag
  -- | Warning was made an error because of -Werror or -Werror=WarningFlag
  | ErrReason !(Maybe WarningFlag)
Richard Eisenberg's avatar
Richard Eisenberg committed
598 599 600 601
  deriving Show

instance Outputable WarnReason where
  ppr = text . show
602

603 604 605
instance ToJson WarnReason where
  json NoReason = JSNull
  json (Reason wf) = JSString (show wf)
606 607
  json (ErrReason Nothing) = JSString "Opt_WarnIsError"
  json (ErrReason (Just wf)) = JSString (show wf)
608

609
data WarningFlag =
610
-- See Note [Updating flag description in the User's Guide]
611
     Opt_WarnDuplicateExports
612
   | Opt_WarnDuplicateConstraints
613
   | Opt_WarnRedundantConstraints
614 615 616 617 618
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
619
   | Opt_WarnOverflowedLiterals
620
   | Opt_WarnEmptyEnumerations
621 622 623
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
624 625
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
626 627 628 629
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
630 631 632
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
633 634
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
635 636
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
637 638
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
639
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
640
   | Opt_WarnMissingMonadFailInstances -- since 8.0
641
   | Opt_WarnSemigroup -- since 8.0
642 643 644 645 646 647 648 649 650 651 652
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
653 654
   | Opt_WarnUnsafe
   | Opt_WarnSafe
655
   | Opt_WarnTrustworthySafe
656 657
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
658
   | Opt_WarnUnsupportedCallingConventions
659
   | Opt_WarnUnsupportedLlvmVersion
660
   | Opt_WarnInlineRuleShadowing
661
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
662
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
663
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
664
   | Opt_WarnUntickedPromotedConstructors
665
   | Opt_WarnDerivingTypeable
666
   | Opt_WarnDeferredTypeErrors
667
   | Opt_WarnDeferredOutOfScopeVariables
668
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
669
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
670
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
671
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
672
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
673
   | Opt_WarnSimplifiableClassConstraints -- Since 8.2
674
   | Opt_WarnCPPUndef                     -- Since 8.2
Richard Eisenberg's avatar
Richard Eisenberg committed
675
   | Opt_WarnUnbangedStrictPatterns       -- Since 8.2
Yuras's avatar
Yuras committed
676
   | Opt_WarnMissingHomeModules           -- Since 8.2
677
   deriving (Eq, Show, Enum)
678

679
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
680 681 682 683
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
684

685
-- | The various Safe Haskell modes
686 687
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
688
   | Sf_Unsafe
689 690 691 692
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
693
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
694 695 696 697
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
698

699
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
700
    ppr = text . show
701

702
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
703
-- information relating to the compilation of a single file or GHC session
704
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
705 706 707
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
708
  settings              :: Settings,
709
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
710
  optLevel              :: Int,         -- ^ Optimisation level
711
  debugLevel            :: Int,         -- ^ How much debug information to produce
712 713
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
714
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
715
  ruleCheck             :: Maybe String,
716
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis