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

Moritz Angermann's avatar
Moritz Angermann committed
79 80 81
        -- ** LLVM Targets
        LlvmTarget(..), LlvmTargets,

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

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

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

114
        -- ** Parsing DynFlags
115 116
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
117 118 119
        parseDynamicFlagsFull,

        -- ** Available DynFlags
120
        allNonDeprecatedFlags,
121 122 123
        flagsAll,
        flagsDynamic,
        flagsPackage,
124
        flagsForCompletion,
125

126
        supportedLanguagesAndExtensions,
127
        languageExtensions,
128

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

        -- * Compiler configuration suitable for display to the user
133 134 135
        compilerInfo,

        rtsIsProfiled,
136
        dynamicGhc,
137

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

145 146
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

        -- * File cleanup
        FilesToClean(..), emptyFilesToClean
164 165 166 167
  ) where

#include "HsVersions.h"

168 169
import GhcPrelude

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

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

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

227 228
import EnumSet (EnumSet)
import qualified EnumSet
229

230
import GHC.Foreign (withCString, peekCString)
231
import qualified GHC.LanguageExtensions as LangExt
232

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

235 236 237 238
-- Note [Updating flag description in the User's Guide]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- If you modify anything in this file please make sure that your changes are
Ben Gamari's avatar
Ben Gamari committed
239 240
-- described in the User's Guide. Please update the flag description in the
-- users guide (docs/users_guide) whenever you add or change a flag.
241

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

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

307 308 309
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

578 579
   | Opt_BuildDynamicToo

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

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

588 589 590
-- | 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.
591 592 593 594 595 596
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
597 598 599 600
  deriving Show

instance Outputable WarnReason where
  ppr = text . show
601

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

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

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

instance Outputable Language where
    ppr = text . show
683

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

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

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

701
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
702
-- information relating to the compilation of a single file or GHC session
703
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
704 705 706
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
707
  settings              :: Settings,
Moritz Angermann's avatar
Moritz Angermann committed
708
  llvmTargets           :: LlvmTargets,
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