DynFlags.hs 189 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 185
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
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.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 239 240 241 242
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
243
--    The Extension type in libraries/ghc-boot/GHC/LanguageExtensions.hs is
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
--    the canonical list of language extensions known by GHC.
--
--  * Adding a flag to DynFlags.xFlags
--
--    This is fairly self-explanatory. The name should be concise, memorable,
--    and consistent with any previous implementations of the similar idea in
--    other Haskell compilers.
--
--  * Adding the flag to the documentation
--
--    This is the same as any other flag. See
--    Note [Updating flag description in the User's Guide]
--
--  * Adding the flag to Cabal
--
--    The Cabal library has its own list of all language extensions supported
--    by all major compilers. This is the list that user code being uploaded
--    to Hackage is checked against to ensure language extension validity.
--    Consequently, it is very important that this list remains up-to-date.
--
--    To this end, there is a testsuite test (testsuite/tests/driver/T4437.hs)
--    whose job it is to ensure these GHC's extensions are consistent with
--    Cabal.
--
--    The recommended workflow is,
--
--     1. Temporarily add your new language extension to the
--        expectedGhcOnlyExtensions list in T4437 to ensure the test doesn't
--        break while Cabal is updated.
--
--     2. After your GHC change is accepted, submit a Cabal pull request adding
--        your new extension to Cabal's list (found in
--        Cabal/Language/Haskell/Extension.hs).
--
--     3. After your Cabal change is accepted, let the GHC developers know so
--        they can update the Cabal submodule and remove the extensions from
--        expectedGhcOnlyExtensions.
--
--  * Adding the flag to the GHC Wiki
--
--    There is a change log tracking language extension additions and removals
--    on the GHC wiki:  https://ghc.haskell.org/trac/ghc/wiki/LanguagePragmaHistory
--
--  See Trac #4437 and #8176.

289 290 291
-- -----------------------------------------------------------------------------
-- DynFlags

292
data DumpFlag
293
-- See Note [Updating flag description in the User's Guide]
294 295 296

   -- debugging flags
   = Opt_D_dump_cmm
297 298 299 300 301
   | 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
302
   | Opt_D_dump_cmm_switch
303
   | Opt_D_dump_cmm_proc
304
   | Opt_D_dump_cmm_sink
305 306 307 308 309 310
   | 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
311
   | Opt_D_dump_asm
312 313 314 315 316
   | 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
317
   | Opt_D_dump_asm_stats
318
   | Opt_D_dump_asm_expanded
319
   | Opt_D_dump_llvm
320
   | Opt_D_dump_core_stats
321 322 323 324
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
325
   | Opt_D_dump_rule_firings
326
   | Opt_D_dump_rule_rewrites
327
   | Opt_D_dump_simpl_trace
328 329 330 331 332 333 334 335
   | 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
336
   | Opt_D_dump_call_arity
337
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
338
   | Opt_D_dump_strsigs
339 340 341 342 343 344 345 346 347
   | 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
348
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
349 350
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
351
   | Opt_D_dump_vt_trace
352
   | Opt_D_dump_splices
353
   | Opt_D_th_dec_file
354 355
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
356
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
357
   | Opt_D_dump_rtti
358 359 360 361
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
362
   | Opt_D_dump_mod_cycles
363
   | Opt_D_dump_mod_map
364
   | Opt_D_dump_view_pattern_commoning
365
   | Opt_D_verbose_core2core
366
   | Opt_D_dump_debug
367 368 369 370 371

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
375
   | Opt_D_faststring_stats
376
   | Opt_D_dump_minimal_imports
377 378 379
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
380
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
381
   | Opt_DoAnnotationLinting
382
   | Opt_NoLlvmMangler                 -- hidden flag
383

Ian Lynagh's avatar
Ian Lynagh committed
384
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
385

386
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
387
   | Opt_PrintExplicitKinds
388 389
   | Opt_PrintExplicitCoercions
   | Opt_PrintEqualityRelations
390
   | Opt_PrintUnicodeSyntax
391
   | Opt_PrintExpandedSynonyms
392
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
393
   | Opt_PrintTypecheckerElaboration
394

395
   -- optimisation opts
396
   | Opt_CallArity
397
   | Opt_Strictness
398
   | Opt_LateDmdAnal
399 400
   | Opt_KillAbsence
   | Opt_KillOneShot
401
   | Opt_FullLaziness
402 403
   | Opt_FloatIn
   | Opt_Specialise
404
   | Opt_SpecialiseAggressively
405
   | Opt_CrossModuleSpecialise
406
   | Opt_StaticArgumentTransformation
407
   | Opt_CSE
408 409
   | Opt_LiberateCase
   | Opt_SpecConstr
410 411 412 413 414
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
   | Opt_UnboxStrictFields
415
   | Opt_UnboxSmallStrictFields
416
   | Opt_DictsCheap
417
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
418
   | Opt_Vectorise
419
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
420 421
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
422
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
423
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
424
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
425
   | Opt_IrrefutableTuples
426
   | Opt_CmmSink
427
   | Opt_CmmElimCommonBlocks
428
   | Opt_OmitYields
429
   | Opt_SimpleListLiterals
430
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
431 432
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
433
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
434
   | Opt_CprAnal
435
   | Opt_WorkerWrapper
436

437 438 439 440
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
441
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
442

Ian Lynagh's avatar
Ian Lynagh committed
443 444
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
445
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
446

447 448
   -- misc opts
   | Opt_Pp
449
   | Opt_ForceRecomp
450
   | Opt_ExcessPrecision
451
   | Opt_EagerBlackHoling
452 453
   | Opt_NoHsMain
   | Opt_SplitObjs
454
   | Opt_SplitSections
455
   | Opt_StgStats
456
   | Opt_HideAllPackages
457
   | Opt_HideAllPluginPackages
458
   | Opt_PrintBindResult
459
   | Opt_Haddock
David Waern's avatar
David Waern committed
460
   | Opt_HaddockOptions
461
   | Opt_BreakOnException
462
   | Opt_BreakOnError
463
   | Opt_PrintEvldWithShow
464
   | Opt_PrintBindContents
465 466
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
467
   | Opt_SharedImplib
468
   | Opt_BuildingCabalPackage
469
   | Opt_IgnoreDotGhci
470
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
471
   | Opt_GhciHistory
472
   | Opt_HelpfulErrors
473
   | Opt_DeferTypeErrors
474
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
475
   | Opt_PIC
476
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
477
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
478 479 480
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
481
   | Opt_RPath
482
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
483
   | Opt_Hpc
484
   | Opt_FlatCache
485
   | Opt_ExternalInterpreter
486

487 488 489 490
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

491
   -- output style opts
492 493
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
494
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
495
   | Opt_PprShowTicks
496

497 498 499 500 501 502 503 504 505 506 507
   -- 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
508 509
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
510 511 512 513 514 515
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

516
   -- temporary flags
517
   | Opt_AutoLinkPackages
518
   | Opt_ImplicitImportQualified
519 520 521 522 523 524

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
525
   | Opt_KeepRawTokenStream
526
   | Opt_KeepLlvmFiles
527

528 529
   | Opt_BuildDynamicToo

530
   -- safe haskell flags
dterei's avatar
dterei committed
531
   | Opt_DistrustAllPackages
532 533
   | Opt_PackageTrust

534 535
   -- pm checking with guards
   | Opt_FullGuardReasoning
536
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
537

538
data WarningFlag =
539
-- See Note [Updating flag description in the User's Guide]
540
     Opt_WarnDuplicateExports
541
   | Opt_WarnDuplicateConstraints
542
   | Opt_WarnRedundantConstraints
543 544 545 546 547
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
548
   | Opt_WarnOverflowedLiterals
549
   | Opt_WarnEmptyEnumerations
550 551 552 553 554 555 556
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
557
   | Opt_WarnTooManyGuards
558 559
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
560 561 562
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
563 564
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
565
   | Opt_WarnContextQuantification -- remove in 8.2
566 567
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
568
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
569
   | Opt_WarnMissingMonadFailInstances -- since 8.0
570
   | Opt_WarnSemigroup -- since 8.0
571 572 573 574 575 576 577 578 579 580 581
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
582 583
   | Opt_WarnUnsafe
   | Opt_WarnSafe
584
   | Opt_WarnTrustworthySafe
585 586
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
587
   | Opt_WarnUnsupportedCallingConventions
588
   | Opt_WarnUnsupportedLlvmVersion
589
   | Opt_WarnInlineRuleShadowing
590
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
591
   | Opt_WarnPartialTypeSignatures
592
   | Opt_WarnMissingExportedSigs
carlostome's avatar
carlostome committed
593
   | Opt_WarnUntickedPromotedConstructors
594
   | Opt_WarnDerivingTypeable
595
   | Opt_WarnDeferredTypeErrors
596
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
597
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
598
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
599
   | Opt_WarnMissingPatSynSigs            -- since 8.0
600
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
601
   deriving (Eq, Show, Enum)
602

603
data Language = Haskell98 | Haskell2010
604
   deriving Enum
605

606
-- | The various Safe Haskell modes
607 608
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
609
   | Sf_Unsafe
610 611 612 613
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
614
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
615 616 617 618
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
619

620
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
621
    ppr = text . show
622

Edward Z. Yang's avatar
Edward Z. Yang committed
623
type SigOf = Map ModuleName Module
624 625

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

628
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
629
-- information relating to the compilation of a single file or GHC session
630
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
631 632 633
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
634
  settings              :: Settings,
635 636
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
637
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
638
  optLevel              :: Int,         -- ^ Optimisation level
639
  debugLevel            :: Int,         -- ^ How much debug information to produce
640 641
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
642
  ruleCheck             :: Maybe String,
643
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
644

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

649 650 651
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

652 653
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
654
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
655 656
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
657 658
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
659
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
660
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
661
                                        --   See CoreMonad.FloatOutSwitches
662

663
  historySize           :: Int,
664

665
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
666 667 668
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
669
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
670 671
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
672

673
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
674 675

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

680 681 682
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

683
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
684
  objectDir             :: Maybe String,
685
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
686 687
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
688
  dumpDir               :: Maybe String,
689

Ian Lynagh's avatar
Ian Lynagh committed
690 691 692
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
693

694 695 696 697
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

698 699 700 701 702 703 704 705
  -- 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
706
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
707
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
708 709
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
710

711
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
712 713
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
714

715 716
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
717 718
  dumpPrefixForce       :: Maybe FilePath,

719
  ldInputs              :: [Option],
720

Ian Lynagh's avatar
Ian Lynagh committed
721 722 723 724 725
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

726
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
727
  rtsOptsEnabled        :: RtsOptsEnabled,
728
  rtsOptsSuggestions    :: Bool,
729

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

732 733 734
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
735
  frontendPluginOpts    :: [String],
736

737 738 739
  -- GHC API hooks
  hooks                 :: Hooks,

740 741 742 743 744 745
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

746
  --  Package flags
747
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
748
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
749
        -- they appeared.
750

751 752
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
753
  packageFlags          :: [PackageFlag],
754
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
755 756
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
757 758
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
759 760
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
761