DynFlags.hs 178 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
        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

        -- * Compiler configuration suitable for display to the user
117 118
        compilerInfo,

119
#ifdef GHCI
120
        rtsIsProfiled,
121
#endif
122
        dynamicGhc,
123 124

#include "../includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs"
125
        bLOCK_SIZE_W,
126
        wORD_SIZE_IN_BITS,
127 128
        tAG_MASK,
        mAX_PTR_TAG,
129
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
130

131 132
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

133
        -- * SSE and AVX
134
        isSseEnabled,
135 136
        isSse2Enabled,
        isSse4_2Enabled,
137 138
        isAvxEnabled,
        isAvx2Enabled,
139 140 141 142
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
143

Austin Seipp's avatar
Austin Seipp committed
144
        -- * Linker/compiler information
145
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
146
        CompilerInfo(..),
147 148 149 150
  ) where

#include "HsVersions.h"

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

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

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

205 206 207
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

208
import GHC.Foreign (withCString, peekCString)
209
import qualified GHC.LanguageExtensions as LangExt
210

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

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

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

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

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

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

472 473
   | Opt_BuildDynamicToo

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

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

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

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

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

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

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

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

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

602
  historySize           :: Int,
603

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

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

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

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

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

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

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

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

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

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

658
  ldInputs              :: [Option],
659

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

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

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

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

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

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

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

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

695
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
696
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
697
  -- Packages.initPackages
698
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
699
  pkgState              :: PackageState,
700

701 702 703 704
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
705
  dirsToClean           :: IORef (Map FilePath FilePath),
706
  filesToNotIntermediateClean :: IORef [FilePath],
707 708
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
709

710 711 712
  -- Names of files which were generated from -ddump-to-file; used to
  -- track which ones we need to truncate because it's our first run
  -- through
713
  generatedDumps        :: IORef (Set FilePath),
714

715
  -- hsc dynamic flags
716 717
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
718
  warningFlags          :: IntSet,
719
  -- Don't change this without updating extensionFlags:
720
  language              :: Maybe Language,
721 722
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
723 724
  safeInfer             :: Bool,
  safeInferred          :: Bool,
725 726 727
  -- We store the location of where some extension and flags were turned on so
  -- we can produce accurate error messages when Safe Haskell fails due to
  -- them.