DynFlags.hs 182 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
        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
        IgnorePackageFlag(..), TrustFlag(..),
49
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
50
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
51
        DynLibLoader(..),
52 53
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
54
        dynFlagDependencies,
55
        tablesNextToCode, mkTablesNextToCode,
Edward Z. Yang's avatar
Edward Z. Yang committed
56
        SigOf, getSigOf,
Ben Gamari's avatar
Ben Gamari committed
57
        makeDynFlagsConsistent,
58

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

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

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


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

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

101
        -- ** Parsing DynFlags
102 103
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
104 105 106
        parseDynamicFlagsFull,

        -- ** Available DynFlags
107
        allFlags,
108 109 110
        flagsAll,
        flagsDynamic,
        flagsPackage,
111
        flagsForCompletion,
112

113
        supportedLanguagesAndExtensions,
114
        languageExtensions,
115

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

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

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

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

134 135
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

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

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

208 209 210
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

211
import GHC.Foreign (withCString, peekCString)
212
import qualified GHC.LanguageExtensions as LangExt
213

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

227 228 229 230 231 232 233 234 235 236 237 238
-- 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.

239 240 241
-- -----------------------------------------------------------------------------
-- DynFlags

242
data DumpFlag
243
-- See Note [Updating flag description in the User's Guide]
244 245 246

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

   deriving (Eq, Show, Enum)

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

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

Ian Lynagh's avatar
Ian Lynagh committed
334
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
335

336
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
337
   | Opt_PrintExplicitKinds
338 339
   | Opt_PrintExplicitCoercions
   | Opt_PrintEqualityRelations
340
   | Opt_PrintUnicodeSyntax
341
   | Opt_PrintExpandedSynonyms
342
   | Opt_PrintPotentialInstances
343
   | Opt_PrintTypechekerElaboration
344

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

387 388 389 390
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
391
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
392

Ian Lynagh's avatar
Ian Lynagh committed
393 394
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
395
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
396

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

437 438 439 440
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

441
   -- output style opts
442 443
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
444
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
445
   | Opt_PprShowTicks
446

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

466
   -- temporary flags
467
   | Opt_AutoLinkPackages
468
   | Opt_ImplicitImportQualified
469 470 471 472 473 474

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
475
   | Opt_KeepRawTokenStream
476
   | Opt_KeepLlvmFiles
477

478 479
   | Opt_BuildDynamicToo

480
   -- safe haskell flags
dterei's avatar
dterei committed
481
   | Opt_DistrustAllPackages
482 483
   | Opt_PackageTrust

484
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
485

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

548
data Language = Haskell98 | Haskell2010
549
   deriving Enum
550

551
-- | The various Safe Haskell modes
552 553
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
554
   | Sf_Unsafe
555 556 557 558
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
559
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
560 561 562 563
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
564

565
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
566
    ppr = text . show
567

Edward Z. Yang's avatar
Edward Z. Yang committed
568
type SigOf = Map ModuleName Module
569 570

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

573
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
574
-- information relating to the compilation of a single file or GHC session
575
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
576 577 578
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
579
  settings              :: Settings,
580 581
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
582
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
583
  optLevel              :: Int,         -- ^ Optimisation level
584
  debugLevel            :: Int,         -- ^ How much debug information to produce
585 586
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
587
  ruleCheck             :: Maybe String,
588
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
589

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

594 595 596
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

597 598
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
599
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
600 601
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
602 603
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
604
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
605
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
606
                                        --   See CoreMonad.FloatOutSwitches
607

608
  historySize           :: Int,
609

610
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
611 612 613
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
614
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
615 616
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
617

618
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
619 620

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

625 626 627
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

628
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
629
  objectDir             :: Maybe String,
630
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
631 632
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
633
  dumpDir               :: Maybe String,
634

Ian Lynagh's avatar
Ian Lynagh committed
635 636 637
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
638

639 640 641 642
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

643 644 645 646 647 648 649 650
  -- 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
651
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
652
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
653 654
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
655

656
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
657 658
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
659

660 661
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
662 663
  dumpPrefixForce       :: Maybe FilePath,

664
  ldInputs              :: [Option],
665

Ian Lynagh's avatar
Ian Lynagh committed
666 667 668 669 670
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

671
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
672
  rtsOptsEnabled        :: RtsOptsEnabled,
673
  rtsOptsSuggestions    :: Bool,
674

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

677 678 679
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
680
  frontendPluginOpts    :: [String],
681

682 683 684
  -- GHC API hooks
  hooks                 :: Hooks,

685 686 687 688 689 690
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

691
  --  Package flags
692
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
693
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
694
        -- they appeared.
695

696 697
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
698
  packageFlags          :: [PackageFlag],
699
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
700 701
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
702 703
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
704 705
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)