DynFlags.hs 172 KB
Newer Older
1 2
{-# LANGUAGE CPP #-}

dterei's avatar
dterei committed
3
-------------------------------------------------------------------------------
4
--
dterei's avatar
dterei committed
5 6 7 8 9 10
-- | Dynamic flags
--
-- Most flags are dynamic flags, which means they can change from compilation
-- to compilation using @OPTIONS_GHC@ pragmas, and in a multi-session GHC each
-- session can be using different dynamic flags. Dynamic flags can also be set
-- at the prompt in GHCi.
11 12 13
--
-- (c) The University of Glasgow 2005
--
dterei's avatar
dterei committed
14
-------------------------------------------------------------------------------
15

16
{-# OPTIONS_GHC -fno-cse #-}
17 18
-- -fno-cse is needed for GLOBAL_VAR's to behave properly

19
module DynFlags (
20
        -- * Dynamic flags and associated configuration types
21
        DumpFlag(..),
22
        GeneralFlag(..),
23
        WarningFlag(..),
24
        ExtensionFlag(..),
25
        Language(..),
26
        PlatformConstants(..),
Ian Lynagh's avatar
Ian Lynagh committed
27
        FatalMessager, LogAction, FlushOut(..), FlushErr(..),
28
        ProfAuto(..),
29
        glasgowExtsFlags,
30
        dopt, dopt_set, dopt_unset,
31 32 33
        gopt, gopt_set, gopt_unset,
        wopt, wopt_set, wopt_unset,
        xopt, xopt_set, xopt_unset,
34
        lang_set,
35
        useUnicodeSyntax,
36 37
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
38
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
39
        DynFlags(..),
40
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
41
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
42
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
43
        HscTarget(..), isObjectTarget, defaultObjectTarget,
44
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
45 46
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
47
        PackageFlag(..), PackageArg(..), ModRenaming(..),
48
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
49
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
50
        DynLibLoader(..),
51
        fFlags, fWarningFlags, fLangFlags, xFlags,
52
        dynFlagDependencies,
53
        tablesNextToCode, mkTablesNextToCode,
Edward Z. Yang's avatar
Edward Z. Yang committed
54
        SigOf, getSigOf,
55
        checkOptLevel,
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_sysman, 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
        setPackageKey,
Edsko de Vries's avatar
Edsko de Vries committed
96
        interpretPackageEnv,
Ian Lynagh's avatar
Ian Lynagh committed
97

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

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

110
        supportedLanguagesAndExtensions,
111
        languageExtensions,
112

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

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

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

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

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

135 136
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

181
import System.IO.Unsafe ( unsafePerformIO )
182
import Data.IORef
183
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
184
import Control.Monad
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.Word
Ian Lynagh's avatar
Ian Lynagh committed
196
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
197 198
import System.Directory
import System.Environment (getEnv)
199
import System.IO
200
import System.IO.Error
201 202
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
203

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

207 208
import GHC.Foreign (withCString, peekCString)

209 210 211 212 213 214 215 216 217 218 219 220 221
-- Note [Updating flag description in the User's Guide]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- If you modify anything in this file please make sure that your changes are
-- described in the User's Guide. Usually at least two sections need to be
-- updated:
--
--  * Flag Reference section in docs/users-guide/flags.xml lists all available
--    flags together with a short description
--
--  * Flag description in docs/users_guide/using.xml provides a detailed
--    explanation of flags' usage.

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

234 235 236
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

   deriving (Eq, Show, Enum)

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

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

Ian Lynagh's avatar
Ian Lynagh committed
329
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
330

331
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
332
   | Opt_PrintExplicitKinds
333
   | Opt_PrintUnicodeSyntax
334
   | Opt_PrintExpandedSynonyms
335

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

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

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

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

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

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

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
   -- 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
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

451
   -- temporary flags
452
   | Opt_AutoLinkPackages
453
   | Opt_ImplicitImportQualified
454 455 456 457 458 459

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
460
   | Opt_KeepRawTokenStream
461
   | Opt_KeepLlvmFiles
462

463 464
   | Opt_BuildDynamicToo

465
   -- safe haskell flags
dterei's avatar
dterei committed
466
   | Opt_DistrustAllPackages
467 468
   | Opt_PackageTrust

Peter Wortmann's avatar
Peter Wortmann committed
469 470 471
   -- debugging flags
   | Opt_Debug

472
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
473

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

530
data Language = Haskell98 | Haskell2010
531
   deriving Enum
532

533
-- | The various Safe Haskell modes
534 535
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
536
   | Sf_Unsafe
537 538 539 540
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
541
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
542 543 544 545
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
546

547
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
548
    ppr = text . show
549

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

595 596
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
597
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
598 599 600
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
601
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
602
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
603
   | Opt_DeriveAnyClass           -- Allow deriving any class
604 605 606 607 608 609

   | Opt_TypeSynonymInstances
   | Opt_FlexibleContexts
   | Opt_FlexibleInstances
   | Opt_ConstrainedClassMethods
   | Opt_MultiParamTypeClasses
610
   | Opt_NullaryTypeClasses
611 612 613 614 615 616
   | Opt_FunctionalDependencies
   | Opt_UnicodeSyntax
   | Opt_ExistentialQuantification
   | Opt_MagicHash
   | Opt_EmptyDataDecls
   | Opt_KindSignatures
617
   | Opt_RoleAnnotations
618 619
   | Opt_ParallelListComp
   | Opt_TransformListComp
620
   | Opt_MonadComprehensions
621 622 623 624 625 626 627 628 629
   | Opt_GeneralizedNewtypeDeriving
   | Opt_RecursiveDo
   | Opt_PostfixOperators
   | Opt_TupleSections
   | Opt_PatternGuards
   | Opt_LiberalTypeSynonyms
   | Opt_RankNTypes
   | Opt_ImpredicativeTypes
   | Opt_TypeOperators
630
   | Opt_ExplicitNamespaces
631 632 633 634 635
   | Opt_PackageImports
   | Opt_ExplicitForAll
   | Opt_AlternativeLayoutRule
   | Opt_AlternativeLayoutRuleTransitional
   | Opt_DatatypeContexts
636
   | Opt_NondecreasingIndentation
637
   | Opt_RelaxedLayout
638
   | Opt_TraditionalRecordSyntax
639
   | Opt_LambdaCase
640
   | Opt_MultiWayIf
641
   | Opt_BinaryLiterals
642
   | Opt_NegativeLiterals
643
   | Opt_EmptyCase
cactus's avatar
cactus committed
644
   | Opt_PatternSynonyms
thomasw's avatar
thomasw committed
645
   | Opt_PartialTypeSignatures
646
   | Opt_NamedWildCards
Facundo Domínguez's avatar
Facundo Domínguez committed
647
   | Opt_StaticPointers
648
   deriving (Eq, Enum, Show)
649

Edward Z. Yang's avatar
Edward Z. Yang committed
650
type SigOf = Map ModuleName Module
651 652

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

655
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
656
-- information relating to the compilation of a single file or GHC session
657
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
658 659 660
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
661
  settings              :: Settings,
662 663
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
664
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
665 666 667
  optLevel              :: Int,         -- ^ Optimisation level
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
668
  ruleCheck             :: Maybe String,
669
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
670

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

675 676 677
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

678 679
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
680
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
681 682
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
683 684
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
685
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
686
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
687
                                        --   See CoreMonad.FloatOutSwitches
688

689
  historySize           :: Int,
690

691
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
692 693 694
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
695
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
696 697
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
698

699
  thisPackage           :: PackageKey,   -- ^ name of package currently being compiled
700 701

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

706 707 708
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

709
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
710
  objectDir             :: Maybe String,
711
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
712 713
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
714
  dumpDir               :: Maybe String,
715

Ian Lynagh's avatar
Ian Lynagh committed
716 717 718
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
719

720 721 722 723
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

724 725 726 727 728 729 730 731
  -- 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
732
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
733
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
734 735
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
736

737
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
738 739
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
740

741 742
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
743 744
  dumpPrefixForce       :: Maybe FilePath,

745
  ldInputs              :: [Option],
746

Ian Lynagh's avatar
Ian Lynagh committed
747 748 749 750 751
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

752
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
753
  rtsOptsEnabled        :: RtsOptsEnabled,
754
  rtsOptsSuggestions