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
   | Opt_PrintUnicodeSyntax
336
   | Opt_PrintExpandedSynonyms
337
   | Opt_PrintPotentialInstances
338

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

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

Ian Lynagh's avatar
Ian Lynagh committed
387 388
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
389
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
390

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

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

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

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

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

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

471 472
   | Opt_BuildDynamicToo

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

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

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

540
data Language = Haskell98 | Haskell2010
541
   deriving Enum
542

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

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

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

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

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

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

Edward Z. Yang's avatar
Edward Z. Yang committed
668
type SigOf = Map ModuleName Module
669 670

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

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

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

694 695 696
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

708
  historySize           :: Int,
709

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

718
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
719 720

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

725 726 727
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

728
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
729
  objectDir             :: Maybe String,
730
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed