DynFlags.hs 179 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
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
49
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
50
        DynLibLoader(..),
51 52
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
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
import GHC.Foreign (withCString, peekCString)
210
import qualified GHC.LanguageExtensions as LangExt
211

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

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

237 238 239
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

   deriving (Eq, Show, Enum)

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

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

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

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

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

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

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

394 395
   -- misc opts
   | Opt_Pp
396
   | Opt_ForceRecomp
397
   | Opt_ExcessPrecision
398
   | Opt_EagerBlackHoling
399 400
   | Opt_NoHsMain
   | Opt_SplitObjs
401
   | Opt_SplitSections
402
   | Opt_StgStats
403
   | Opt_HideAllPackages
404
   | Opt_PrintBindResult
405
   | Opt_Haddock
David Waern's avatar
David Waern committed
406
   | Opt_HaddockOptions
407
   | Opt_BreakOnException
408
   | Opt_BreakOnError
409
   | Opt_PrintEvldWithShow
410
   | Opt_PrintBindContents
411 412
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
413
   | Opt_SharedImplib
414
   | Opt_BuildingCabalPackage
415
   | Opt_IgnoreDotGhci
416
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
417
   | Opt_GhciHistory
418
   | Opt_HelpfulErrors
419
   | Opt_DeferTypeErrors
420
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
421
   | Opt_PIC
422
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
423
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
424 425 426
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
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 -- remove in 8.2
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
   | Opt_WarnMissingPatSynSigs            -- since 8.0
541
   deriving (Eq, Show, Enum)
542

543
data Language = Haskell98 | Haskell2010
544
   deriving Enum
545

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

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

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

Edward Z. Yang's avatar
Edward Z. Yang committed
563
type SigOf = Map ModuleName Module
564 565

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

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

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

589 590 591
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

603
  historySize           :: Int,
604

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

613
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
614 615

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

620 621 622
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

623
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
624
  objectDir             :: Maybe String,
625
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
626 627
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
628
  dumpDir               :: Maybe String,
629

Ian Lynagh's avatar
Ian Lynagh committed
630 631 632
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
633

634 635 636 637
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

638 639 640 641 642 643 644 645
  -- 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
646
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
647
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
648 649
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
650

651
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
652 653
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
654

655 656
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
657 658
  dumpPrefixForce       :: Maybe FilePath,

659
  ldInputs              :: [Option],
660

Ian Lynagh's avatar
Ian Lynagh committed
661 662 663 664 665
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

666
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
667
  rtsOptsEnabled        :: RtsOptsEnabled,
668
  rtsOptsSuggestions    :: Bool,
669

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

672 673 674
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
675
  frontendPluginOpts    :: [String],
676

677 678 679
  -- GHC API hooks
  hooks                 :: Hooks,

680 681 682 683 684 685
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

686
  --  Package flags
687
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
688
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
689
        -- they appeared.
690

Ian Lynagh's avatar
Ian Lynagh committed
691
  packageFlags          :: [PackageFlag],
692
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
Edsko de Vries's avatar
Edsko de Vries committed
693 694
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
695

696
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
697
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
698
  -- Packages.initPackages