DynFlags.hs 180 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(..),
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 52
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
53
        dynFlagDependencies,
54
        tablesNextToCode, mkTablesNextToCode,
Edward Z. Yang's avatar
Edward Z. Yang committed
55
        SigOf, getSigOf,
Ben Gamari's avatar
Ben Gamari committed
56
        makeDynFlagsConsistent,
57

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

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

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


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

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

100
        -- ** Parsing DynFlags
101 102
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
103 104 105
        parseDynamicFlagsFull,

        -- ** Available DynFlags
106
        allFlags,
107 108 109
        flagsAll,
        flagsDynamic,
        flagsPackage,
110
        flagsForCompletion,
111

112
        supportedLanguagesAndExtensions,
113
        languageExtensions,
114

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

        -- * Compiler configuration suitable for display to the user
119 120
        compilerInfo,

121
#ifdef GHCI
122
        rtsIsProfiled,
123
#endif
124
        dynamicGhc,
125 126

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

133 134
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

177
import System.IO.Unsafe ( unsafePerformIO )
178
import Data.IORef
179
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
180
import Control.Monad
181 182 183
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
184
#if MIN_VERSION_transformers(0,4,0)
185 186
import Control.Monad.Trans.Except
#endif
Edsko de Vries's avatar
Edsko de Vries committed
187
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
188

189
import Data.Bits
190
import Data.Char
191
import Data.Int
192
import Data.List
193 194
import Data.Map (Map)
import qualified Data.Map as Map
195 196
import Data.Set (Set)
import qualified Data.Set as Set
197
import Data.Monoid (Monoid)
198
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
199
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
200 201
import System.Directory
import System.Environment (getEnv)
202
import System.IO
203
import System.IO.Error
204 205
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
206

207 208 209
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

210
import GHC.Foreign (withCString, peekCString)
211
import qualified GHC.LanguageExtensions as LangExt
212

213 214 215 216 217 218 219
-- 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:
--
220 221
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
222
--
223
--  * Flag description in docs/users_guide/using.rst provides a detailed
224 225
--    explanation of flags' usage.

226 227 228 229 230 231 232 233 234 235 236 237
-- 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.

238 239 240
-- -----------------------------------------------------------------------------
-- DynFlags

241
data DumpFlag
242
-- See Note [Updating flag description in the User's Guide]
243 244 245

   -- debugging flags
   = Opt_D_dump_cmm
246 247 248 249 250
   | 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
251
   | Opt_D_dump_cmm_switch
252
   | Opt_D_dump_cmm_proc
253
   | Opt_D_dump_cmm_sink
254 255 256 257 258 259
   | 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
260
   | Opt_D_dump_asm
261 262 263 264 265
   | 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
266
   | Opt_D_dump_asm_stats
267
   | Opt_D_dump_asm_expanded
268
   | Opt_D_dump_llvm
269
   | Opt_D_dump_core_stats
270 271 272 273
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
274
   | Opt_D_dump_rule_firings
275
   | Opt_D_dump_rule_rewrites
276
   | Opt_D_dump_simpl_trace
277 278 279 280 281 282 283 284
   | 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
285
   | Opt_D_dump_call_arity
286
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
287
   | Opt_D_dump_strsigs
288 289 290 291 292 293 294 295 296
   | 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
297
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
298 299
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
300
   | Opt_D_dump_vt_trace
301
   | Opt_D_dump_splices
302
   | Opt_D_th_dec_file
303 304
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
305
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
306
   | Opt_D_dump_rtti
307 308 309 310
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
311
   | Opt_D_dump_mod_cycles
312
   | Opt_D_dump_mod_map
313
   | Opt_D_dump_view_pattern_commoning
314
   | Opt_D_verbose_core2core
315
   | Opt_D_dump_debug
316 317 318 319 320

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
324
   | Opt_D_faststring_stats
325
   | Opt_D_dump_minimal_imports
326 327 328
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
329
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
330
   | Opt_DoAnnotationLinting
331
   | Opt_NoLlvmMangler                 -- hidden flag
332

Ian Lynagh's avatar
Ian Lynagh committed
333
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
334

335
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
336
   | Opt_PrintExplicitKinds
337 338
   | Opt_PrintExplicitCoercions
   | Opt_PrintEqualityRelations
339
   | Opt_PrintUnicodeSyntax
340
   | Opt_PrintExpandedSynonyms
341
   | Opt_PrintPotentialInstances
342
   | Opt_PrintTypechekerElaboration
343

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

386 387 388 389
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
390
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
391

Ian Lynagh's avatar
Ian Lynagh committed
392 393
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
394
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
395

396 397
   -- misc opts
   | Opt_Pp
398
   | Opt_ForceRecomp
399
   | Opt_ExcessPrecision
400
   | Opt_EagerBlackHoling
401 402
   | Opt_NoHsMain
   | Opt_SplitObjs
403
   | Opt_SplitSections
404
   | Opt_StgStats
405
   | Opt_HideAllPackages
406
   | Opt_PrintBindResult
407
   | Opt_Haddock
David Waern's avatar
David Waern committed
408
   | Opt_HaddockOptions
409
   | Opt_BreakOnException
410
   | Opt_BreakOnError
411
   | Opt_PrintEvldWithShow
412
   | Opt_PrintBindContents
413 414
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
415
   | Opt_SharedImplib
416
   | Opt_BuildingCabalPackage
417
   | Opt_IgnoreDotGhci
418
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
419
   | Opt_GhciHistory
420
   | Opt_HelpfulErrors
421
   | Opt_DeferTypeErrors
422
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
423
   | Opt_PIC
424
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
425
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
426 427 428
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
429
   | Opt_RPath
430
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
431
   | Opt_Hpc
432
   | Opt_FlatCache
433
   | Opt_ExternalInterpreter
434

435 436 437 438
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

439
   -- output style opts
440 441
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
442
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
443
   | Opt_PprShowTicks
444

445 446 447 448 449 450 451 452 453 454 455
   -- 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
456 457
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
458 459 460 461 462 463
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

464
   -- temporary flags
465
   | Opt_AutoLinkPackages
466
   | Opt_ImplicitImportQualified
467 468 469 470 471 472

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
473
   | Opt_KeepRawTokenStream
474
   | Opt_KeepLlvmFiles
475

476 477
   | Opt_BuildDynamicToo

478
   -- safe haskell flags
dterei's avatar
dterei committed
479
   | Opt_DistrustAllPackages
480 481
   | Opt_PackageTrust

482
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
483

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

546
data Language = Haskell98 | Haskell2010
547
   deriving Enum
548

549
-- | The various Safe Haskell modes
550 551
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
552
   | Sf_Unsafe
553 554 555 556
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
557
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
558 559 560 561
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
562

563
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
564
    ppr = text . show
565

Edward Z. Yang's avatar
Edward Z. Yang committed
566
type SigOf = Map ModuleName Module
567 568

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

571
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
572
-- information relating to the compilation of a single file or GHC session
573
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
574 575 576
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
577
  settings              :: Settings,
578 579
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
580
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
581
  optLevel              :: Int,         -- ^ Optimisation level
582
  debugLevel            :: Int,         -- ^ How much debug information to produce
583 584
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
585
  ruleCheck             :: Maybe String,
586
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
587

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

592 593 594
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

595 596
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
597
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
598 599
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
600 601
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
602
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
603
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
604
                                        --   See CoreMonad.FloatOutSwitches
605

606
  historySize           :: Int,
607

608
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
609 610 611
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
612
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
613 614
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
615

616
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
617 618

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

623 624 625
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

626
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
627
  objectDir             :: Maybe String,
628
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
629 630
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
631
  dumpDir               :: Maybe String,
632

Ian Lynagh's avatar
Ian Lynagh committed
633 634 635
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
636

637 638 639 640
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

641 642 643 644 645 646 647 648
  -- Packages.isDllName needs to know whether a call is within a
  -- single DLL or not. Normally it does this by seeing if the call
  -- is to the same package, but for the ghc package, we split the
  -- package between 2 DLLs. The dllSplit tells us which sets of
  -- modules are in which package.
  dllSplitFile          :: Maybe FilePath,
  dllSplit              :: Maybe [Set String],

Ian Lynagh's avatar
Ian Lynagh committed
649
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
650
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
651 652
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
653

654
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
655 656
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
657

658 659
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
660 661
  dumpPrefixForce       :: Maybe FilePath,

662
  ldInputs              :: [Option],
663

Ian Lynagh's avatar
Ian Lynagh committed
664 665 666 667 668
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

669
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
670
  rtsOptsEnabled        :: RtsOptsEnabled,
671
  rtsOptsSuggestions    :: Bool,
672

673
  hpcDir                :: String,      -- ^ Path to store the .mix files
andy@galois.com's avatar
andy@galois.com committed
674

675 676 677
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
678
  frontendPluginOpts    :: [String],
679

680 681 682
  -- GHC API hooks
  hooks                 :: Hooks,

683 684 685 686 687 688
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

689
  --  Package flags
690
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
691
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
692
        -- they appeared.
693

Ian Lynagh's avatar
Ian Lynagh committed
694
  packageFlags          :: [PackageFlag],
695
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
Edsko de Vries's avatar
Edsko de Vries committed
696 697
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
698

699
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
700
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
701
  -- Packages.initPackages
702
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
703
  pkgState              :: PackageState,
704

705 706 707 708
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
709
  dirsToClean           :: IORef (Map FilePath FilePath),
710
  filesToNotIntermediateClean :: IORef [FilePath],
711 712
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
713

714 715 716
  -- Names of files which were generated from -ddump-to-file; used to
  -- track which ones we need to truncate because it's our first run
  -- through
717
  generatedDumps        :: IORef (Set FilePath),
718

719
  -- hsc dynamic flags
720 721
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
722
  warningFlags          :: IntSet,
723
  -- Don't change this without updating extensionFlags:
724
  language              :: Maybe Language,
725 726
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,