DynFlags.hs 181 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
        IgnorePackageFlag(..), TrustFlag(..),
49
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
50
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
51
        DynLibLoader(..),
52 53
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
54
        dynFlagDependencies,
55
        tablesNextToCode, mkTablesNextToCode,
Edward Z. Yang's avatar
Edward Z. Yang committed
56
        SigOf, getSigOf,
Ben Gamari's avatar
Ben Gamari committed
57
        makeDynFlagsConsistent,
58

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

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

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


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

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

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

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

113
        supportedLanguagesAndExtensions,
114
        languageExtensions,
115

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

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

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

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

134 135
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

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

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

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

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

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

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

239 240 241
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

   deriving (Eq, Show, Enum)

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

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

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

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

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

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

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

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

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

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

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

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

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

477 478
   | Opt_BuildDynamicToo

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

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

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

547
data Language = Haskell98 | Haskell2010
548
   deriving Enum
549

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

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

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

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

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

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

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

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

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

607
  historySize           :: Int,
608

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

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

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

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

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

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

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

642 643 644 645 646 647 648 649
  -- 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
650
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
651
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
652 653
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
654

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

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

663
  ldInputs              :: [Option],
664

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

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

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

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

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

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

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

695 696
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
697
  packageFlags          :: [PackageFlag],
698
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
699 700
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
701 702
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
703

704
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
705
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
706
  -- Packages.initPackages
707
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
708
  pkgState              :: PackageState,
709

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

719 720 721
  -- 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
722
  generatedDumps        :: IORef (Set FilePath),
723

724
  -- hsc dynamic flags
725 726
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
727
  warningFlags          :: IntSet,