DynFlags.hs 219 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(..),
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,
Rufflewind's avatar
Rufflewind committed
60
        shouldUseColor,
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,

Ben Gamari's avatar
Ben Gamari committed
67 68 69
        -- ** Log output
        putLogMsg,

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

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


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

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

110
        -- ** Parsing DynFlags
111 112
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
113 114 115
        parseDynamicFlagsFull,

        -- ** Available DynFlags
116
        allNonDeprecatedFlags,
117 118 119
        flagsAll,
        flagsDynamic,
        flagsPackage,
120
        flagsForCompletion,
121

122
        supportedLanguagesAndExtensions,
123
        languageExtensions,
124

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

        -- * Compiler configuration suitable for display to the user
129 130 131
        compilerInfo,

        rtsIsProfiled,
132
        dynamicGhc,
133

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

141 142
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

Austin Seipp's avatar
Austin Seipp committed
154
        -- * Linker/compiler information
155
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
156
        CompilerInfo(..),
157 158 159 160
  ) where

#include "HsVersions.h"

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

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

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

217 218
import EnumSet (EnumSet)
import qualified EnumSet
219

220
import GHC.Foreign (withCString, peekCString)
221
import qualified GHC.LanguageExtensions as LangExt
222

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

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

238 239 240 241 242 243 244 245 246 247 248 249
-- 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.

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

303 304 305
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
400
   | Opt_D_faststring_stats
401
   | Opt_D_dump_minimal_imports
402 403 404
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
405
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
406
   | Opt_DoAnnotationLinting
407
   | Opt_NoLlvmMangler                 -- hidden flag
408

Ian Lynagh's avatar
Ian Lynagh committed
409
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
410
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
411
   | Opt_HideSourcePaths                -- Hide module source/object paths
412

413
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
414
   | Opt_PrintExplicitKinds
415
   | Opt_PrintExplicitCoercions
416
   | Opt_PrintExplicitRuntimeReps
417
   | Opt_PrintEqualityRelations
418
   | Opt_PrintUnicodeSyntax
419
   | Opt_PrintExpandedSynonyms
420
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
421
   | Opt_PrintTypecheckerElaboration
422

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

469 470 471 472
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
473
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
474

Ian Lynagh's avatar
Ian Lynagh committed
475 476
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
477
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
478

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

524 525 526 527
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

528
   -- output style opts
529 530
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
Rufflewind's avatar
Rufflewind committed
531
   | Opt_DiagnosticsShowCaret -- Show snippets of offending code
532
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
533
   | Opt_PprShowTicks
534
   | Opt_ShowHoleConstraints
535

536 537 538 539 540 541 542 543 544 545 546
   -- 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
547 548
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
549 550 551 552 553
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques
554
   | Opt_SuppressTicks     -- Replaces Opt_PprShowTicks
555

556
   -- temporary flags
557
   | Opt_AutoLinkPackages
558
   | Opt_ImplicitImportQualified
559 560 561 562 563 564

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
565
   | Opt_KeepRawTokenStream
566
   | Opt_KeepLlvmFiles
567 568
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
569

570 571
   | Opt_BuildDynamicToo

572
   -- safe haskell flags
dterei's avatar
dterei committed
573
   | Opt_DistrustAllPackages
574
   | Opt_PackageTrust
Sylvain Henry's avatar
Sylvain Henry committed
575 576 577

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

580 581 582 583
-- | 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
584 585 586 587
  deriving Show

instance Outputable WarnReason where
  ppr = text . show
588

589 590 591 592
instance ToJson WarnReason where
  json NoReason = JSNull
  json (Reason wf) = JSString (show wf)

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

663
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
664 665 666 667
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
668

669
-- | The various Safe Haskell modes
670 671
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
672
   | Sf_Unsafe
673 674 675 676
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
677
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
678 679 680 681
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
682

683
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
684
    ppr = text . show
685

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

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

706 707 708
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

709 710
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
711 712
  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
                                        --   in non-exhaustiveness warnings
713
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
714 715
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
amosrobinson's avatar