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
        ExtensionFlag(..),
26
        Language(..),
27
        PlatformConstants(..),
Ian Lynagh's avatar
Ian Lynagh committed
28
        FatalMessager, LogAction, FlushOut(..), FlushErr(..),
29
        ProfAuto(..),
30
        glasgowExtsFlags,
31
        dopt, dopt_set, dopt_unset,
32 33 34
        gopt, gopt_set, gopt_unset,
        wopt, wopt_set, wopt_unset,
        xopt, xopt_set, xopt_unset,
35
        lang_set,
36
        useUnicodeSyntax,
37 38
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
39
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
40
        DynFlags(..),
41
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
42
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
43
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
44
        HscTarget(..), isObjectTarget, defaultObjectTarget,
45
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
46 47
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
48
        PackageFlag(..), PackageArg(..), ModRenaming(..),
49
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
50
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
51
        DynLibLoader(..),
52
        fFlags, fWarningFlags, fLangFlags, xFlags,
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
        pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
Ian Lynagh's avatar
Ian Lynagh committed
76
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
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,
Ian Lynagh's avatar
Ian Lynagh committed
84
        initDynFlags,                   -- DynFlags -> IO DynFlags
Ian Lynagh's avatar
Ian Lynagh committed
85
        defaultFatalMessager,
86
        defaultLogAction,
87
        defaultLogActionHPrintDoc,
88
        defaultLogActionHPutStrDoc,
89 90
        defaultFlushOut,
        defaultFlushErr,
Ian Lynagh's avatar
Ian Lynagh committed
91

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

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

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

111
        supportedLanguagesAndExtensions,
112
        languageExtensions,
113

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

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

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

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

132 133
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

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

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

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

209 210
import GHC.Foreign (withCString, peekCString)

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

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

236 237 238
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

   deriving (Eq, Show, Enum)

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

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

Ian Lynagh's avatar
Ian Lynagh committed
331
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
332

333
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
334
   | Opt_PrintExplicitKinds
335 336
   | Opt_PrintExplicitCoercions
   | Opt_PrintEqualityRelations
337
   | Opt_PrintUnicodeSyntax
338
   | Opt_PrintExpandedSynonyms
339
   | Opt_PrintPotentialInstances
340

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

383 384 385 386
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
387
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
388

Ian Lynagh's avatar
Ian Lynagh committed
389 390
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
391
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
392

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

431 432 433 434
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

435
   -- output style opts
436 437
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
438
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
439
   | Opt_PprShowTicks
440

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

460
   -- temporary flags
461
   | Opt_AutoLinkPackages
462
   | Opt_ImplicitImportQualified
463 464 465 466 467 468

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
469
   | Opt_KeepRawTokenStream
470
   | Opt_KeepLlvmFiles
471

472 473
   | Opt_BuildDynamicToo

474
   -- safe haskell flags
dterei's avatar
dterei committed
475
   | Opt_DistrustAllPackages
476 477
   | Opt_PackageTrust

478
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
479

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

542
data Language = Haskell98 | Haskell2010
543
   deriving Enum
544

545
-- | The various Safe Haskell modes
546 547
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
548
   | Sf_Unsafe
549 550 551 552
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
553
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
554 555 556 557
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
558

559
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
560
    ppr = text . show
561

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

610 611
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
612
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
613 614 615
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
616
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
617
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
618
   | Opt_DeriveAnyClass           -- Allow deriving any class
Ryan Scott's avatar
Ryan Scott committed
619
   | Opt_DeriveLift               -- Allow deriving Lift
620 621 622 623 624 625

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

Edward Z. Yang's avatar
Edward Z. Yang committed
672
type SigOf = Map ModuleName Module
673 674

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

677
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
678
-- information relating to the compilation of a single file or GHC session
679
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
680 681 682
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
683
  settings              :: Settings,
684 685
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
686
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
687
  optLevel              :: Int,         -- ^ Optimisation level
688
  debugLevel            :: Int,         -- ^ How much debug information to produce
689 690
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
691
  ruleCheck             :: Maybe String,
692
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
693

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

698 699 700
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

701 702
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
703
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
704 705
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
706 707
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
708
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
709
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
710
                                        --   See CoreMonad.FloatOutSwitches
711

712
  historySize           :: Int,
713

714
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
715 716 717
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
718
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
719 720
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
721

722
  thisPackage           :: UnitId,   -- ^ key of package currently bein