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
        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
ian@well-typed.com's avatar
ian@well-typed.com committed
426
   | Opt_Static
427
   | Opt_RPath
428
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
429
   | Opt_Hpc
430
   | Opt_FlatCache
431

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

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

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

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

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

473 474
   | Opt_BuildDynamicToo

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

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

481
data WarningFlag =
482
-- See Note [Updating flag description in the User's Guide]
483
     Opt_WarnDuplicateExports
484
   | Opt_WarnDuplicateConstraints
485
   | Opt_WarnRedundantConstraints
486 487 488 489 490
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
491
   | Opt_WarnOverflowedLiterals
492
   | Opt_WarnEmptyEnumerations
493 494 495 496 497 498 499 500 501
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
502 503 504
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
505 506
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
507
   | Opt_WarnContextQuantification
508 509
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
510
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
511 512
   | Opt_WarnMissingMonadFailInstance -- since 8.0
   | Opt_WarnSemigroup -- since 8.0
513 514 515 516 517 518 519 520 521 522 523
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
524 525
   | Opt_WarnUnsafe
   | Opt_WarnSafe
526
   | Opt_WarnTrustworthySafe
527 528
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
529
   | Opt_WarnUnsupportedCallingConventions
530
   | Opt_WarnUnsupportedLlvmVersion
531
   | Opt_WarnInlineRuleShadowing
532
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
533
   | Opt_WarnPartialTypeSignatures
534
   | Opt_WarnMissingExportedSigs
carlostome's avatar
carlostome committed
535
   | Opt_WarnUntickedPromotedConstructors
536
   | Opt_WarnDerivingTypeable
537
   | Opt_WarnDeferredTypeErrors
538 539
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
   | Opt_WarnNonCanonicalMonoidInstances  -- 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 568 569 570
   = Opt_Cpp
   | Opt_OverlappingInstances
   | Opt_UndecidableInstances
   | Opt_IncoherentInstances
   | Opt_MonomorphismRestriction
   | Opt_MonoPatBinds
   | Opt_MonoLocalBinds
571 572
   | Opt_RelaxedPolyRec           -- Deprecated
   | Opt_ExtendedDefaultRules     -- Use GHC's extended rules for defaulting
573 574
   | Opt_ForeignFunctionInterface
   | Opt_UnliftedFFITypes
575
   | Opt_InterruptibleFFI
576
   | Opt_CApiFFI
577
   | Opt_GHCForeignImportPrim
thoughtpolice's avatar
thoughtpolice committed
578
   | Opt_JavaScriptFFI
579 580
   | Opt_ParallelArrays           -- Syntactic support for parallel arrays
   | Opt_Arrows                   -- Arrow-notation syntax
581
   | Opt_TemplateHaskell
582
   | Opt_TemplateHaskellQuotes    -- subset of TH supported by stage1, no splice
583 584 585 586
   | Opt_QuasiQuotes
   | Opt_ImplicitParams
   | Opt_ImplicitPrelude
   | Opt_ScopedTypeVariables
587
   | Opt_AllowAmbiguousTypes
588 589 590 591
   | Opt_UnboxedTuples
   | Opt_BangPatterns
   | Opt_TypeFamilies
   | Opt_OverloadedStrings
592
   | Opt_OverloadedLists
593
   | Opt_NumDecimals
594 595 596 597 598
   | Opt_DisambiguateRecordFields
   | Opt_RecordWildCards
   | Opt_RecordPuns
   | Opt_ViewPatterns
   | Opt_GADTs
Ian Lynagh's avatar
Ian Lynagh committed
599
   | Opt_GADTSyntax
600
   | Opt_NPlusKPatterns
Ian Lynagh's avatar
Ian Lynagh committed
601
   | Opt_DoAndIfThenElse
602
   | Opt_RebindableSyntax
603
   | Opt_ConstraintKinds
dreixel's avatar
dreixel committed
604
   | Opt_PolyKinds                -- Kind polymorphism
dreixel's avatar
dreixel committed
605
   | Opt_DataKinds                -- Datatype promotion
606
   | Opt_InstanceSigs
Simon Marlow's avatar
Simon Marlow committed
607
   | Opt_ApplicativeDo
608

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

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

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

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

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

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

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

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

711
  historySize           :: Int,
712

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

721
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
722 723

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

728 729 730
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

731
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed