DynFlags.hs 160 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(..),
Ian Lynagh's avatar
Ian Lynagh committed
40
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
41
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
42
        HscTarget(..), isObjectTarget, defaultObjectTarget,
43
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
44 45
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
46
        PackageFlag(..), PackageArg(..), ModRenaming,
47
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
48
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
49
        DynLibLoader(..),
50
        fFlags, fWarningFlags, fLangFlags, xFlags,
51
        dynFlagDependencies,
52
        tablesNextToCode, mkTablesNextToCode,
53
        SigOf(..), getSigOf,
54

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

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

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


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

88
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
89
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
90 91
        updOptLevel,
        setTmpDir,
92
        setPackageKey,
Ian Lynagh's avatar
Ian Lynagh committed
93

94
        -- ** Parsing DynFlags
95 96
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
97 98 99
        parseDynamicFlagsFull,

        -- ** Available DynFlags
100
        allFlags,
101 102 103
        flagsAll,
        flagsDynamic,
        flagsPackage,
104

105
        supportedLanguagesAndExtensions,
106
        languageExtensions,
107

108
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
109
        picCCOpts, picPOpts,
110 111 112 113 114 115

        -- * Configuration of the stg-to-stg passes
        StgToDo(..),
        getStgToDo,

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

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

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

130 131
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

175
import System.IO.Unsafe ( unsafePerformIO )
176
import Data.IORef
ian@well-typed.com's avatar
ian@well-typed.com committed
177
import Control.Monad
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
178

179
import Data.Bits
180
import Data.Char
181
import Data.Int
182
import Data.List
183 184
import Data.Map (Map)
import qualified Data.Map as Map
185
import Data.Maybe
186 187
import Data.Set (Set)
import qualified Data.Set as Set
188
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
189
import System.FilePath
190
import System.IO
191
import System.IO.Error
192 193
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
194

195 196 197
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

198 199
import GHC.Foreign (withCString, peekCString)

200 201 202 203 204 205 206 207 208 209 210 211 212
-- 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:
--
--  * Flag Reference section in docs/users-guide/flags.xml lists all available
--    flags together with a short description
--
--  * Flag description in docs/users_guide/using.xml provides a detailed
--    explanation of flags' usage.

213 214 215
-- -----------------------------------------------------------------------------
-- DynFlags

216
data DumpFlag
217
-- See Note [Updating flag description in the User's Guide]
218 219 220

   -- debugging flags
   = Opt_D_dump_cmm
221 222 223 224 225 226
   | 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
   | Opt_D_dump_cmm_proc
227
   | Opt_D_dump_cmm_sink
228 229 230 231 232 233
   | 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
234
   | Opt_D_dump_asm
235 236 237 238 239
   | 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
240
   | Opt_D_dump_asm_stats
241
   | Opt_D_dump_asm_expanded
242
   | Opt_D_dump_llvm
243
   | Opt_D_dump_core_stats
244 245 246 247
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
248
   | Opt_D_dump_rule_firings
249
   | Opt_D_dump_rule_rewrites
250
   | Opt_D_dump_simpl_trace
251 252 253 254 255 256 257 258
   | 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
259
   | Opt_D_dump_call_arity
260
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
261
   | Opt_D_dump_strsigs
262 263 264 265 266 267 268 269 270
   | 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
271
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
272 273
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
274
   | Opt_D_dump_vt_trace
275 276 277
   | Opt_D_dump_splices
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
278
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
279
   | Opt_D_dump_rtti
280 281 282 283
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
284
   | Opt_D_dump_mod_cycles
285
   | Opt_D_dump_mod_map
286
   | Opt_D_dump_view_pattern_commoning
287 288 289 290 291 292
   | Opt_D_verbose_core2core

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
296
   | Opt_D_faststring_stats
297
   | Opt_D_dump_minimal_imports
298 299 300
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
301
   | Opt_DoAsmLinting
302
   | Opt_NoLlvmMangler                 -- hidden flag
303

Ian Lynagh's avatar
Ian Lynagh committed
304
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
305

306
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
307
   | Opt_PrintExplicitKinds
308

309
   -- optimisation opts
310
   | Opt_CallArity
311
   | Opt_Strictness
312
   | Opt_LateDmdAnal
313 314
   | Opt_KillAbsence
   | Opt_KillOneShot
315
   | Opt_FullLaziness
316 317
   | Opt_FloatIn
   | Opt_Specialise
318
   | Opt_SpecialiseAggressively
319
   | Opt_StaticArgumentTransformation
320
   | Opt_CSE
321 322
   | Opt_LiberateCase
   | Opt_SpecConstr
323 324 325 326 327
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
   | Opt_UnboxStrictFields
328
   | Opt_UnboxSmallStrictFields
329
   | Opt_DictsCheap
330
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
331
   | Opt_Vectorise
332
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
333 334
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
335
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
336
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
337
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
338
   | Opt_IrrefutableTuples
339
   | Opt_CmmSink
340
   | Opt_CmmElimCommonBlocks
341
   | Opt_OmitYields
342
   | Opt_SimpleListLiterals
343
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
344 345
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
346
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
347

348 349 350 351
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
352
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
353

Ian Lynagh's avatar
Ian Lynagh committed
354 355
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
356
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
357

358 359
   -- misc opts
   | Opt_Pp
360
   | Opt_ForceRecomp
361
   | Opt_ExcessPrecision
362
   | Opt_EagerBlackHoling
363 364 365
   | Opt_NoHsMain
   | Opt_SplitObjs
   | Opt_StgStats
366
   | Opt_HideAllPackages
367
   | Opt_PrintBindResult
368
   | Opt_Haddock
David Waern's avatar
David Waern committed
369
   | Opt_HaddockOptions
370
   | Opt_Hpc_No_Auto
371
   | Opt_BreakOnException
372
   | Opt_BreakOnError
373
   | Opt_PrintEvldWithShow
374
   | Opt_PrintBindContents
375 376
   | Opt_GenManifest
   | Opt_EmbedManifest
377
   | Opt_EmitExternalCore
Ian Lynagh's avatar
Ian Lynagh committed
378
   | Opt_SharedImplib
379
   | Opt_BuildingCabalPackage
380
   | Opt_IgnoreDotGhci
381
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
382
   | Opt_GhciHistory
383
   | Opt_HelpfulErrors
384
   | Opt_DeferTypeErrors
Ian Lynagh's avatar
Ian Lynagh committed
385
   | Opt_Parallel
Ian Lynagh's avatar
Ian Lynagh committed
386
   | Opt_GranMacros
Ian Lynagh's avatar
Ian Lynagh committed
387
   | Opt_PIC
388
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
389
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
390 391 392
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
ian@well-typed.com's avatar
ian@well-typed.com committed
393
   | Opt_Static
394
   | Opt_RPath
395
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
396
   | Opt_Hpc
397
   | Opt_FlatCache
398

399 400 401 402
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

403
   -- output style opts
404 405
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
406
   | Opt_PprCaseAsLet
407

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
   -- 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
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

425
   -- temporary flags
426
   | Opt_AutoLinkPackages
427
   | Opt_ImplicitImportQualified
428 429 430 431 432 433

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
434
   | Opt_KeepRawTokenStream
435
   | Opt_KeepLlvmFiles
436

437 438
   | Opt_BuildDynamicToo

439
   -- safe haskell flags
dterei's avatar
dterei committed
440
   | Opt_DistrustAllPackages
441 442
   | Opt_PackageTrust

443
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
444

445
data WarningFlag =
446
-- See Note [Updating flag description in the User's Guide]
447
     Opt_WarnDuplicateExports
448
   | Opt_WarnDuplicateConstraints
449 450 451 452 453
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
454
   | Opt_WarnOverflowedLiterals
455
   | Opt_WarnEmptyEnumerations
456 457 458 459 460 461 462 463 464 465 466 467
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
   | Opt_WarnUnusedBinds
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
468
   | Opt_WarnContextQuantification
469 470
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
471
   | Opt_WarnAMP
472 473 474 475 476 477 478 479 480 481 482
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
483 484
   | Opt_WarnUnsafe
   | Opt_WarnSafe
Ian Lynagh's avatar
Ian Lynagh committed
485
   | Opt_WarnPointlessPragmas
486
   | Opt_WarnUnsupportedCallingConventions
487
   | Opt_WarnUnsupportedLlvmVersion
488
   | Opt_WarnInlineRuleShadowing
489
   | Opt_WarnTypedHoles
490
   deriving (Eq, Show, Enum)
491

492
data Language = Haskell98 | Haskell2010
493
   deriving Enum
494

495
-- | The various Safe Haskell modes
496 497
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
498
   | Sf_Unsafe
499 500 501 502
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
503
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
504 505 506 507
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
508

509
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
510
    ppr = text . show
511

512
data ExtensionFlag
513
-- See Note [Updating flag description in the User's Guide]
514 515 516 517 518 519 520
   = Opt_Cpp
   | Opt_OverlappingInstances
   | Opt_UndecidableInstances
   | Opt_IncoherentInstances
   | Opt_MonomorphismRestriction
   | Opt_MonoPatBinds
   | Opt_MonoLocalBinds
521 522
   | Opt_RelaxedPolyRec           -- Deprecated
   | Opt_ExtendedDefaultRules     -- Use GHC's extended rules for defaulting
523 524
   | Opt_ForeignFunctionInterface
   | Opt_UnliftedFFITypes
525
   | Opt_InterruptibleFFI
526
   | Opt_CApiFFI
527
   | Opt_GHCForeignImportPrim
thoughtpolice's avatar
thoughtpolice committed
528
   | Opt_JavaScriptFFI
529 530
   | Opt_ParallelArrays           -- Syntactic support for parallel arrays
   | Opt_Arrows                   -- Arrow-notation syntax
531 532 533 534 535
   | Opt_TemplateHaskell
   | Opt_QuasiQuotes
   | Opt_ImplicitParams
   | Opt_ImplicitPrelude
   | Opt_ScopedTypeVariables
536
   | Opt_AllowAmbiguousTypes
537 538 539 540
   | Opt_UnboxedTuples
   | Opt_BangPatterns
   | Opt_TypeFamilies
   | Opt_OverloadedStrings
541
   | Opt_OverloadedLists
542
   | Opt_NumDecimals
543 544 545 546 547
   | Opt_DisambiguateRecordFields
   | Opt_RecordWildCards
   | Opt_RecordPuns
   | Opt_ViewPatterns
   | Opt_GADTs
Ian Lynagh's avatar
Ian Lynagh committed
548
   | Opt_GADTSyntax
549
   | Opt_NPlusKPatterns
Ian Lynagh's avatar
Ian Lynagh committed
550
   | Opt_DoAndIfThenElse
551
   | Opt_RebindableSyntax
552
   | Opt_ConstraintKinds
dreixel's avatar
dreixel committed
553
   | Opt_PolyKinds                -- Kind polymorphism
dreixel's avatar
dreixel committed
554
   | Opt_DataKinds                -- Datatype promotion
555
   | Opt_InstanceSigs
556

557 558
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
559
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
560 561 562
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
563
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
564
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
565 566 567 568 569 570

   | Opt_TypeSynonymInstances
   | Opt_FlexibleContexts
   | Opt_FlexibleInstances
   | Opt_ConstrainedClassMethods
   | Opt_MultiParamTypeClasses
571
   | Opt_NullaryTypeClasses
572 573 574 575 576 577
   | Opt_FunctionalDependencies
   | Opt_UnicodeSyntax
   | Opt_ExistentialQuantification
   | Opt_MagicHash
   | Opt_EmptyDataDecls
   | Opt_KindSignatures
578
   | Opt_RoleAnnotations
579 580
   | Opt_ParallelListComp
   | Opt_TransformListComp
581
   | Opt_MonadComprehensions
582 583 584 585 586 587 588 589 590
   | Opt_GeneralizedNewtypeDeriving
   | Opt_RecursiveDo
   | Opt_PostfixOperators
   | Opt_TupleSections
   | Opt_PatternGuards
   | Opt_LiberalTypeSynonyms
   | Opt_RankNTypes
   | Opt_ImpredicativeTypes
   | Opt_TypeOperators
591
   | Opt_ExplicitNamespaces
592 593 594 595 596
   | Opt_PackageImports
   | Opt_ExplicitForAll
   | Opt_AlternativeLayoutRule
   | Opt_AlternativeLayoutRuleTransitional
   | Opt_DatatypeContexts
597
   | Opt_NondecreasingIndentation
598
   | Opt_RelaxedLayout
599
   | Opt_TraditionalRecordSyntax
600
   | Opt_LambdaCase
601
   | Opt_MultiWayIf
602
   | Opt_BinaryLiterals
603
   | Opt_NegativeLiterals
604
   | Opt_EmptyCase
cactus's avatar
cactus committed
605
   | Opt_PatternSynonyms
606
   deriving (Eq, Enum, Show)
607

608 609 610 611 612 613 614 615 616 617 618
data SigOf = NotSigOf
           | SigOf Module
           | SigOfMap (Map ModuleName Module)

getSigOf :: DynFlags -> ModuleName -> Maybe Module
getSigOf dflags n =
    case sigOf dflags of
        NotSigOf -> Nothing
        SigOf m -> Just m
        SigOfMap m -> Map.lookup n m

619
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
620
-- information relating to the compilation of a single file or GHC session
621
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
622 623 624
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
625
  settings              :: Settings,
626 627
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
628
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
629 630 631
  optLevel              :: Int,         -- ^ Optimisation level
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
632
  ruleCheck             :: Maybe String,
633
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
634

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

639 640 641
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

642 643
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
644
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
645 646
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
647 648
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
649
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
650
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
651
                                        --   See CoreMonad.FloatOutSwitches
652

653
  historySize           :: Int,
654

655
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
656 657 658
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
659
  ctxtStkDepth          :: Int,         -- ^ Typechecker context stack depth
660
  tyFunStkDepth         :: Int,         -- ^ Typechecker type function stack depth
661

662
  thisPackage           :: PackageKey,   -- ^ name of package currently being compiled
663 664

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

669 670 671
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

672
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
673
  objectDir             :: Maybe String,
674
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
675 676
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
677
  dumpDir               :: Maybe String,
678

Ian Lynagh's avatar
Ian Lynagh committed
679 680 681
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
682

683 684 685 686
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

687 688 689 690 691 692 693 694
  -- 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
695
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
696
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
697 698
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
699

700
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
701 702
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
703

704 705
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
706 707
  dumpPrefixForce       :: Maybe FilePath,

708
  ldInputs              :: [Option],
709

Ian Lynagh's avatar
Ian Lynagh committed
710 711 712 713 714
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

715
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
716
  rtsOptsEnabled        :: RtsOptsEnabled,
717

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

720 721 722 723
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],

724 725 726
  -- GHC API hooks
  hooks                 :: Hooks,

727 728 729 730 731 732
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

733
  --  Package flags
734
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
735
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
736
        -- they appeared.
737

Ian Lynagh's avatar
Ian Lynagh committed
738
  packageFlags          :: [PackageFlag],
739
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
740

741
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
742
  -- NB. do not modify this field, it is calculated by
743
  -- Packages.initPackages and Packages.updatePackages.
744
  pkgDatabase           :: Maybe [PackageConfig],
Ian Lynagh's avatar
Ian Lynagh committed
745
  pkgState              :: PackageState,
746

747 748 749 750
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
751
  dirsToClean           :: IORef (Map FilePath FilePath),
752
  filesToNotIntermediateClean :: IORef [FilePath],
753 754
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
755

756 757 758 759 760
  -- 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
  generatedDumps        :: IORef (Set FilePath),

761
  -- hsc dynamic flags
762 763
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
764
  warningFlags          :: IntSet,
765
  -- Don't change this without updating extensionFlags:
766
  language              :: Maybe Language,
767 768
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
769 770
  safeInfer             :: Bool,
  safeInferred          :: Bool,
771 772 773
  -- We store the location of where some extension and flags were turned on so
  -- we can produce accurate error messages when Safe Haskell fails due to
  -- them.
774 775
  thOnLoc               :: SrcSpan,
  newDerivOnLoc         :: SrcSpan,
776
  overlapInstLoc        :: SrcSpan,
777
  incoherentOnLoc       :: SrcSpan,
778
  pkgTrustOnLoc         :: SrcSpan,
779 780
  warnSafeOnLoc         :: SrcSpan,
  warnUnsafeOnLoc       :: SrcSpan,
781 782 783 784
  -- Don't change this without updating extensionFlags:
  extensions            :: [OnOff ExtensionFlag],
  -- extensionFlags should always be equal to
  --     flattenExtensionFlags language extensions
785
  extensionFlags        :: IntSet,
Ian Lynagh's avatar
Ian Lynagh committed
786

787 788 789 790 791 792 793 794 795
  -- Unfolding control
  -- See Note [Discounts and thresholds] in CoreUnfold
  ufCreationThreshold   :: Int,
  ufUseThreshold        :: Int,
  ufFunAppDiscount      :: Int,
  ufDictDiscount        :: Int,
  ufKeenessFactor       :: Float,
  ufDearOp              :: Int,