DynFlags.hs 179 KB
Newer Older
1 2
{-# LANGUAGE CPP #-}

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

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

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

57
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
58
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
59

60
        -- ** Safe Haskell
61
        SafeHaskellMode(..),
62
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
63
        packageTrustOn,
64
        safeDirectImpsReq, safeImplicitImpsReq,
65
        unsafeFlags, unsafeFlagsForInfer,
66

67
        -- ** System tool settings and locations
68
        Settings(..),
69
        targetPlatform, programName, projectVersion,
70
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
Edsko de Vries's avatar
Edsko de Vries committed
71
        versionedAppDir,
72 73
        extraGccViaCFlags, systemPackageConfig,
        pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
74
        pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
Ian Lynagh's avatar
Ian Lynagh committed
75
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
76
        opt_windres, opt_lo, opt_lc,
77 78


79
        -- ** Manipulating DynFlags
80
        defaultDynFlags,                -- Settings -> DynFlags
81
        defaultWays,
ian@well-typed.com's avatar
ian@well-typed.com committed
82
        interpWays,
Ian Lynagh's avatar
Ian Lynagh committed
83
        initDynFlags,                   -- DynFlags -> IO DynFlags
Ian Lynagh's avatar
Ian Lynagh committed
84
        defaultFatalMessager,
85
        defaultLogAction,
86
        defaultLogActionHPrintDoc,
87
        defaultLogActionHPutStrDoc,
88 89
        defaultFlushOut,
        defaultFlushErr,
Ian Lynagh's avatar
Ian Lynagh committed
90

91
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
92
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
93 94
        updOptLevel,
        setTmpDir,
95
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
96
        interpretPackageEnv,
Ian Lynagh's avatar
Ian Lynagh committed
97

98
        -- ** Parsing DynFlags
99 100
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
101 102 103
        parseDynamicFlagsFull,

        -- ** Available DynFlags
104
        allFlags,
105 106 107
        flagsAll,
        flagsDynamic,
        flagsPackage,
108
        flagsForCompletion,
109

110
        supportedLanguagesAndExtensions,
111
        languageExtensions,
112

113
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
114
        picCCOpts, picPOpts,
115 116

        -- * Compiler configuration suitable for display to the user
117 118
        compilerInfo,

119
#ifdef GHCI
120
        rtsIsProfiled,
121
#endif
122
        dynamicGhc,
123 124

#include "../includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs"
125
        bLOCK_SIZE_W,
126
        wORD_SIZE_IN_BITS,
127 128
        tAG_MASK,
        mAX_PTR_TAG,
129
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
130

131 132
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

133
        -- * SSE and AVX
134
        isSseEnabled,
135 136
        isSse2Enabled,
        isSse4_2Enabled,
137 138
        isAvxEnabled,
        isAvx2Enabled,
139 140 141 142
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
143

Austin Seipp's avatar
Austin Seipp committed
144
        -- * Linker/compiler information
145
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
146
        CompilerInfo(..),
147 148 149 150
  ) where

#include "HsVersions.h"

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

175
import System.IO.Unsafe ( unsafePerformIO )
176
import Data.IORef
177
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
178
import Control.Monad
Edsko de Vries's avatar
Edsko de Vries committed
179
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
180

181
import Data.Bits
182
import Data.Char
183
import Data.Int
184
import Data.List
185 186
import Data.Map (Map)
import qualified Data.Map as Map
187 188
import Data.Set (Set)
import qualified Data.Set as Set
189
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
190
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
191 192
import System.Directory
import System.Environment (getEnv)
193
import System.IO
194
import System.IO.Error
195 196
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
197

198 199 200
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

201 202
import GHC.Foreign (withCString, peekCString)

203 204 205 206 207 208 209
-- 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:
--
210 211
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
212
--
213
--  * Flag description in docs/users_guide/using.rst provides a detailed
214 215
--    explanation of flags' usage.

216 217 218 219 220 221 222 223 224 225 226 227
-- 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.

228 229 230
-- -----------------------------------------------------------------------------
-- DynFlags

231
data DumpFlag
232
-- See Note [Updating flag description in the User's Guide]
233 234 235

   -- debugging flags
   = Opt_D_dump_cmm
236 237 238 239 240
   | Opt_D_dump_cmm_raw
   -- All of the cmm subflags (there are a lot!)  Automatically
   -- enabled if you run -ddump-cmm
   | Opt_D_dump_cmm_cfg
   | Opt_D_dump_cmm_cbe
241
   | Opt_D_dump_cmm_switch
242
   | Opt_D_dump_cmm_proc
243
   | Opt_D_dump_cmm_sink
244 245 246 247 248 249
   | Opt_D_dump_cmm_sp
   | Opt_D_dump_cmm_procmap
   | Opt_D_dump_cmm_split
   | Opt_D_dump_cmm_info
   | Opt_D_dump_cmm_cps
   -- end cmm subflags
250
   | Opt_D_dump_asm
251 252 253 254 255
   | 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
256
   | Opt_D_dump_asm_stats
257
   | Opt_D_dump_asm_expanded
258
   | Opt_D_dump_llvm
259
   | Opt_D_dump_core_stats
260 261 262 263
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
264
   | Opt_D_dump_rule_firings
265
   | Opt_D_dump_rule_rewrites
266
   | Opt_D_dump_simpl_trace
267 268 269 270 271 272 273 274
   | Opt_D_dump_occur_anal
   | Opt_D_dump_parsed
   | Opt_D_dump_rn
   | Opt_D_dump_simpl
   | Opt_D_dump_simpl_iterations
   | Opt_D_dump_spec
   | Opt_D_dump_prep
   | Opt_D_dump_stg
275
   | Opt_D_dump_call_arity
276
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
277
   | Opt_D_dump_strsigs
278 279 280 281 282 283 284 285 286
   | 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
287
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
288 289
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
290
   | Opt_D_dump_vt_trace
291
   | Opt_D_dump_splices
292
   | Opt_D_th_dec_file
293 294
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
295
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
296
   | Opt_D_dump_rtti
297 298 299 300
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
301
   | Opt_D_dump_mod_cycles
302
   | Opt_D_dump_mod_map
303
   | Opt_D_dump_view_pattern_commoning
304
   | Opt_D_verbose_core2core
305
   | Opt_D_dump_debug
306 307 308 309 310

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
314
   | Opt_D_faststring_stats
315
   | Opt_D_dump_minimal_imports
316 317 318
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
319
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
320
   | Opt_DoAnnotationLinting
321
   | Opt_NoLlvmMangler                 -- hidden flag
322

Ian Lynagh's avatar
Ian Lynagh committed
323
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
324

325
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
326
   | Opt_PrintExplicitKinds
327
   | Opt_PrintUnicodeSyntax
328
   | Opt_PrintExpandedSynonyms
329
   | Opt_PrintPotentialInstances
330

331
   -- optimisation opts
332
   | Opt_CallArity
333
   | Opt_Strictness
334
   | Opt_LateDmdAnal
335 336
   | Opt_KillAbsence
   | Opt_KillOneShot
337
   | Opt_FullLaziness
338 339
   | Opt_FloatIn
   | Opt_Specialise
340
   | Opt_SpecialiseAggressively
341
   | Opt_CrossModuleSpecialise
342
   | Opt_StaticArgumentTransformation
343
   | Opt_CSE
344 345
   | Opt_LiberateCase
   | Opt_SpecConstr
346 347 348 349 350
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
   | Opt_UnboxStrictFields
351
   | Opt_UnboxSmallStrictFields
352
   | Opt_DictsCheap
353
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
354
   | Opt_Vectorise
355
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
356 357
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
358
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
359
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
360
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
361
   | Opt_IrrefutableTuples
362
   | Opt_CmmSink
363
   | Opt_CmmElimCommonBlocks
364
   | Opt_OmitYields
365
   | Opt_SimpleListLiterals
366
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
367 368
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
369
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
370
   | Opt_CprAnal
371
   | Opt_WorkerWrapper
372

373 374 375 376
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
377
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
378

Ian Lynagh's avatar
Ian Lynagh committed
379 380
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
381
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
382

383 384
   -- misc opts
   | Opt_Pp
385
   | Opt_ForceRecomp
386
   | Opt_ExcessPrecision
387
   | Opt_EagerBlackHoling
388 389
   | Opt_NoHsMain
   | Opt_SplitObjs
390
   | Opt_SplitSections
391
   | Opt_StgStats
392
   | Opt_HideAllPackages
393
   | Opt_PrintBindResult
394
   | Opt_Haddock
David Waern's avatar
David Waern committed
395
   | Opt_HaddockOptions
396
   | Opt_BreakOnException
397
   | Opt_BreakOnError
398
   | Opt_PrintEvldWithShow
399
   | Opt_PrintBindContents
400 401
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
402
   | Opt_SharedImplib
403
   | Opt_BuildingCabalPackage
404
   | Opt_IgnoreDotGhci
405
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
406
   | Opt_GhciHistory
407
   | Opt_HelpfulErrors
408
   | Opt_DeferTypeErrors
409
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
410
   | Opt_PIC
411
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
412
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
413 414 415
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
ian@well-typed.com's avatar
ian@well-typed.com committed
416
   | Opt_Static
417
   | Opt_RPath
418
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
419
   | Opt_Hpc
420
   | Opt_FlatCache
421

422 423 424 425
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

426
   -- output style opts
427 428
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
429
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
430
   | Opt_PprShowTicks
431

432 433 434 435 436 437 438 439 440 441 442
   -- 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
443 444
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
445 446 447 448 449 450
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

451
   -- temporary flags
452
   | Opt_AutoLinkPackages
453
   | Opt_ImplicitImportQualified
454 455 456 457 458 459

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
460
   | Opt_KeepRawTokenStream
461
   | Opt_KeepLlvmFiles
462

463 464
   | Opt_BuildDynamicToo

465
   -- safe haskell flags
dterei's avatar
dterei committed
466
   | Opt_DistrustAllPackages
467 468
   | Opt_PackageTrust

469
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
470

471
data WarningFlag =
472
-- See Note [Updating flag description in the User's Guide]
473
     Opt_WarnDuplicateExports
474
   | Opt_WarnDuplicateConstraints
475
   | Opt_WarnRedundantConstraints
476 477 478 479 480
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
481
   | Opt_WarnOverflowedLiterals
482
   | Opt_WarnEmptyEnumerations
483 484 485 486 487 488 489 490 491
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
492 493 494
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
495 496
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
497
   | Opt_WarnContextQuantification
498 499
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
500
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
501 502
   | Opt_WarnMissingMonadFailInstance -- since 8.0
   | Opt_WarnSemigroup -- since 8.0
503 504 505 506 507 508 509 510 511 512 513
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
514 515
   | Opt_WarnUnsafe
   | Opt_WarnSafe
516
   | Opt_WarnTrustworthySafe
517 518
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
519
   | Opt_WarnUnsupportedCallingConventions
520
   | Opt_WarnUnsupportedLlvmVersion
521
   | Opt_WarnInlineRuleShadowing
522
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
523
   | Opt_WarnPartialTypeSignatures
524
   | Opt_WarnMissingExportedSigs
carlostome's avatar
carlostome committed
525
   | Opt_WarnUntickedPromotedConstructors
526
   | Opt_WarnDerivingTypeable
527
   | Opt_WarnDeferredTypeErrors
528 529
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
530
   deriving (Eq, Show, Enum)
531

532
data Language = Haskell98 | Haskell2010
533
   deriving Enum
534

535
-- | The various Safe Haskell modes
536 537
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
538
   | Sf_Unsafe
539 540 541 542
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
543
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
544 545 546 547
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
548

549
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
550
    ppr = text . show
551

552
data ExtensionFlag
553
-- See Note [Updating flag description in the User's Guide]
554 555 556 557 558 559 560
   = Opt_Cpp
   | Opt_OverlappingInstances
   | Opt_UndecidableInstances
   | Opt_IncoherentInstances
   | Opt_MonomorphismRestriction
   | Opt_MonoPatBinds
   | Opt_MonoLocalBinds
561 562
   | Opt_RelaxedPolyRec           -- Deprecated
   | Opt_ExtendedDefaultRules     -- Use GHC's extended rules for defaulting
563 564
   | Opt_ForeignFunctionInterface
   | Opt_UnliftedFFITypes
565
   | Opt_InterruptibleFFI
566
   | Opt_CApiFFI
567
   | Opt_GHCForeignImportPrim
thoughtpolice's avatar
thoughtpolice committed
568
   | Opt_JavaScriptFFI
569 570
   | Opt_ParallelArrays           -- Syntactic support for parallel arrays
   | Opt_Arrows                   -- Arrow-notation syntax
571
   | Opt_TemplateHaskell
572
   | Opt_TemplateHaskellQuotes    -- subset of TH supported by stage1, no splice
573 574 575 576
   | Opt_QuasiQuotes
   | Opt_ImplicitParams
   | Opt_ImplicitPrelude
   | Opt_ScopedTypeVariables
577
   | Opt_AllowAmbiguousTypes
578 579 580 581
   | Opt_UnboxedTuples
   | Opt_BangPatterns
   | Opt_TypeFamilies
   | Opt_OverloadedStrings
582
   | Opt_OverloadedLists
583
   | Opt_NumDecimals
584 585 586 587 588
   | Opt_DisambiguateRecordFields
   | Opt_RecordWildCards
   | Opt_RecordPuns
   | Opt_ViewPatterns
   | Opt_GADTs
Ian Lynagh's avatar
Ian Lynagh committed
589
   | Opt_GADTSyntax
590
   | Opt_NPlusKPatterns
Ian Lynagh's avatar
Ian Lynagh committed
591
   | Opt_DoAndIfThenElse
592
   | Opt_RebindableSyntax
593
   | Opt_ConstraintKinds
dreixel's avatar
dreixel committed
594
   | Opt_PolyKinds                -- Kind polymorphism
dreixel's avatar
dreixel committed
595
   | Opt_DataKinds                -- Datatype promotion
596
   | Opt_InstanceSigs
Simon Marlow's avatar
Simon Marlow committed
597
   | Opt_ApplicativeDo
598

599 600
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
601
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
602 603 604
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
605
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
606
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
607
   | Opt_DeriveAnyClass           -- Allow deriving any class
Ryan Scott's avatar
Ryan Scott committed
608
   | Opt_DeriveLift               -- Allow deriving Lift
609 610 611 612 613 614

   | Opt_TypeSynonymInstances
   | Opt_FlexibleContexts
   | Opt_FlexibleInstances
   | Opt_ConstrainedClassMethods
   | Opt_MultiParamTypeClasses
615
   | Opt_NullaryTypeClasses
616 617 618 619 620 621
   | Opt_FunctionalDependencies
   | Opt_UnicodeSyntax
   | Opt_ExistentialQuantification
   | Opt_MagicHash
   | Opt_EmptyDataDecls
   | Opt_KindSignatures
622
   | Opt_RoleAnnotations
623 624
   | Opt_ParallelListComp
   | Opt_TransformListComp
625
   | Opt_MonadComprehensions
626 627 628 629 630 631 632 633 634
   | Opt_GeneralizedNewtypeDeriving
   | Opt_RecursiveDo
   | Opt_PostfixOperators
   | Opt_TupleSections
   | Opt_PatternGuards
   | Opt_LiberalTypeSynonyms
   | Opt_RankNTypes
   | Opt_ImpredicativeTypes
   | Opt_TypeOperators
635
   | Opt_ExplicitNamespaces
636 637 638 639 640
   | Opt_PackageImports
   | Opt_ExplicitForAll
   | Opt_AlternativeLayoutRule
   | Opt_AlternativeLayoutRuleTransitional
   | Opt_DatatypeContexts
641
   | Opt_NondecreasingIndentation
642
   | Opt_RelaxedLayout
643
   | Opt_TraditionalRecordSyntax
644
   | Opt_LambdaCase
645
   | Opt_MultiWayIf
646
   | Opt_BinaryLiterals
647
   | Opt_NegativeLiterals
Adam Gundry's avatar
Adam Gundry committed
648
   | Opt_DuplicateRecordFields
Adam Gundry's avatar
Adam Gundry committed
649
   | Opt_OverloadedLabels
650
   | Opt_EmptyCase
cactus's avatar
cactus committed
651
   | Opt_PatternSynonyms
thomasw's avatar
thomasw committed
652
   | Opt_PartialTypeSignatures
653
   | Opt_NamedWildCards
Facundo Domínguez's avatar
Facundo Domínguez committed
654
   | Opt_StaticPointers
655
   | Opt_Strict
656
   | Opt_StrictData
quchen's avatar
quchen committed
657
   | Opt_MonadFailDesugaring
658
   deriving (Eq, Enum, Show)
659

Edward Z. Yang's avatar
Edward Z. Yang committed
660
type SigOf = Map ModuleName Module
661 662

getSigOf :: DynFlags -> ModuleName -> Maybe Module
Edward Z. Yang's avatar
Edward Z. Yang committed
663
getSigOf dflags n = Map.lookup n (sigOf dflags)
664

665
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
666
-- information relating to the compilation of a single file or GHC session
667
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
668 669 670
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
671
  settings              :: Settings,
672 673
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
674
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
675
  optLevel              :: Int,         -- ^ Optimisation level
676
  debugLevel            :: Int,         -- ^ How much debug information to produce
677 678
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
679
  ruleCheck             :: Maybe String,
680
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
681

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

686 687 688
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

689 690
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
691
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
692 693
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
694 695
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
696
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
697
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
698
                                        --   See CoreMonad.FloatOutSwitches
699

700
  historySize           :: Int,
701

702
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
703 704 705
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
706
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
707 708
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
709

710
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
711 712

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

717 718 719
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

720
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
721
  objectDir             :: Maybe String,
722
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
723 724
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
725
  dumpDir               :: Maybe String,
726

Ian Lynagh's avatar
Ian Lynagh committed
727 728 729
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
730

731 732 733 734
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,