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

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

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

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


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

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

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

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

110
        supportedLanguagesAndExtensions,
111
        languageExtensions,
112

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

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

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

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

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

135 136
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

179
import System.IO.Unsafe ( unsafePerformIO )
180
import Data.IORef
181
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
182
import Control.Monad
Edsko de Vries's avatar
Edsko de Vries committed
183
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
184

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

202 203 204
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

205 206
import GHC.Foreign (withCString, peekCString)

207 208 209 210 211 212 213 214 215 216 217 218 219
-- 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.

220 221 222 223 224 225 226 227 228 229 230 231
-- 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.

232 233 234
-- -----------------------------------------------------------------------------
-- DynFlags

235
data DumpFlag
236
-- See Note [Updating flag description in the User's Guide]
237 238 239

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

   deriving (Eq, Show, Enum)

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

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

Ian Lynagh's avatar
Ian Lynagh committed
327
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
328

329
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
330
   | Opt_PrintExplicitKinds
331
   | Opt_PrintUnicodeSyntax
332
   | Opt_PrintExpandedSynonyms
333
   | Opt_PrintPotentialInstances
334

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

377 378 379 380
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
381
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
382

Ian Lynagh's avatar
Ian Lynagh committed
383 384
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
385
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
386

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

426 427 428 429
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

430
   -- output style opts
431 432
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
433
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
434
   | Opt_PprShowTicks
435

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

455
   -- temporary flags
456
   | Opt_AutoLinkPackages
457
   | Opt_ImplicitImportQualified
458 459 460 461 462 463

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
464
   | Opt_KeepRawTokenStream
465
   | Opt_KeepLlvmFiles
466

467 468
   | Opt_BuildDynamicToo

469
   -- safe haskell flags
dterei's avatar
dterei committed
470
   | Opt_DistrustAllPackages
471 472
   | Opt_PackageTrust

Peter Wortmann's avatar
Peter Wortmann committed
473 474 475
   -- debugging flags
   | Opt_Debug

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

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

536
data Language = Haskell98 | Haskell2010
537
   deriving Enum
538

539
-- | The various Safe Haskell modes
540 541
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
542
   | Sf_Unsafe
543 544 545 546
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
547
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
548 549 550 551
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
552

553
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
554
    ppr = text . show
555

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

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

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

Edward Z. Yang's avatar
Edward Z. Yang committed
663
type SigOf = Map ModuleName Module
664 665

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

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

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

688 689 690
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

702
  historySize           :: Int,
703

704
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
705 706 707
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
708
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
709 710
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
711

712
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
713 714

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

719 720 721
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

722
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
723
  objectDir             :: Maybe String,
724
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
725 726
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
727
  dumpDir               :: Maybe String,
728

Ian Lynagh's avatar
Ian Lynagh committed
729 730 731
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
732

733 734 735 736
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

737 738 739 740 741 742 743 744
  -- 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
745
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
746
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
747 748
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,