DynFlags.hs 155 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(..),
Ian Lynagh's avatar
Ian Lynagh committed
40
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
41
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
42
        HscTarget(..), isObjectTarget, defaultObjectTarget,
43
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
44 45 46
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
        PackageFlag(..),
47
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
48
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
49
        DynLibLoader(..),
50
        fFlags, fWarningFlags, fLangFlags, xFlags,
51
        dynFlagDependencies,
52
        tablesNextToCode, mkTablesNextToCode,
53

54 55
        printOutputForUser, printInfoForUser,

56
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
57
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
58

59
        -- ** Safe Haskell
60
        SafeHaskellMode(..),
61
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
62
        packageTrustOn,
63
        safeDirectImpsReq, safeImplicitImpsReq,
64
        unsafeFlags,
65

66
        -- ** System tool settings and locations
67
        Settings(..),
68
        targetPlatform,
69 70 71
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
        extraGccViaCFlags, systemPackageConfig,
        pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
72
        pgm_sysman, pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
Ian Lynagh's avatar
Ian Lynagh committed
73
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
74
        opt_windres, opt_lo, opt_lc,
75 76


77
        -- ** Manipulating DynFlags
78
        defaultDynFlags,                -- Settings -> DynFlags
79
        defaultWays,
ian@well-typed.com's avatar
ian@well-typed.com committed
80
        interpWays,
Ian Lynagh's avatar
Ian Lynagh committed
81
        initDynFlags,                   -- DynFlags -> IO DynFlags
Ian Lynagh's avatar
Ian Lynagh committed
82
        defaultFatalMessager,
83
        defaultLogAction,
84
        defaultLogActionHPrintDoc,
85
        defaultLogActionHPutStrDoc,
86 87
        defaultFlushOut,
        defaultFlushErr,
Ian Lynagh's avatar
Ian Lynagh committed
88

89
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
90
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
91 92 93 94
        updOptLevel,
        setTmpDir,
        setPackageName,

95
        -- ** Parsing DynFlags
96 97
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
98 99 100
        parseDynamicFlagsFull,

        -- ** Available DynFlags
101
        allFlags,
102 103 104
        flagsAll,
        flagsDynamic,
        flagsPackage,
105

106
        supportedLanguagesAndExtensions,
107
        languageExtensions,
108

109
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
110
        picCCOpts, picPOpts,
111 112 113 114 115 116

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

        -- * 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)
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
164
import Maybes           ( orElse )
165
import MonadUtils
166
import qualified Pretty
167
import SrcLoc
168
import FastString
Simon Marlow's avatar
Simon Marlow committed
169
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
170
#ifdef GHCI
Ian Lynagh's avatar
Ian Lynagh committed
171
import Foreign.C        ( CInt(..) )
172
import System.IO.Unsafe ( unsafeDupablePerformIO )
Ian Lynagh's avatar
Ian Lynagh committed
173
#endif
174
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessage )
175

176
import System.IO.Unsafe ( unsafePerformIO )
177
import Data.IORef
ian@well-typed.com's avatar
ian@well-typed.com committed
178
import Control.Monad
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
179

180
import Data.Bits
181
import Data.Char
182
import Data.Int
183
import Data.List
184 185
import Data.Map (Map)
import qualified Data.Map as Map
186
import Data.Maybe
187 188
import Data.Set (Set)
import qualified Data.Set as Set
189
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
190
import System.FilePath
191
import System.IO
192
import System.IO.Error
193

194 195 196
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

197 198
import GHC.Foreign (withCString, peekCString)

199 200 201
-- -----------------------------------------------------------------------------
-- DynFlags

202
data DumpFlag
203 204 205

   -- debugging flags
   = Opt_D_dump_cmm
206 207 208 209 210 211
   | 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
   | Opt_D_dump_cmm_proc
212
   | Opt_D_dump_cmm_sink
213 214 215 216 217 218
   | 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
219
   | Opt_D_dump_asm
220 221 222 223 224
   | 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
225
   | Opt_D_dump_asm_stats
226
   | Opt_D_dump_asm_expanded
227
   | Opt_D_dump_llvm
228
   | Opt_D_dump_core_stats
229 230 231 232
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
233
   | Opt_D_dump_rule_firings
234
   | Opt_D_dump_rule_rewrites
235
   | Opt_D_dump_simpl_trace
236 237 238
   | Opt_D_dump_occur_anal
   | Opt_D_dump_parsed
   | Opt_D_dump_rn
239
   | Opt_D_dump_core_pipeline -- TODO FIXME: dump after simplifier stats
240 241
   | Opt_D_dump_simpl
   | Opt_D_dump_simpl_iterations
242
   | Opt_D_dump_simpl_phases
243 244 245
   | Opt_D_dump_spec
   | Opt_D_dump_prep
   | Opt_D_dump_stg
246
   | Opt_D_dump_call_arity
247
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
248
   | Opt_D_dump_strsigs
249 250 251 252 253 254 255 256 257
   | 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
258
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
259 260
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
261
   | Opt_D_dump_vt_trace
262 263 264
   | Opt_D_dump_splices
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
265
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
266
   | Opt_D_dump_rtti
267 268 269 270
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
271
   | Opt_D_dump_mod_cycles
272
   | Opt_D_dump_view_pattern_commoning
273 274 275 276 277 278 279 280
   | Opt_D_verbose_core2core

   deriving (Eq, Show, Enum)

-- | Enumerates the simple on-or-off dynamic flags
data GeneralFlag

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
281
   | Opt_D_faststring_stats
282
   | Opt_D_dump_minimal_imports
283 284 285
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
286
   | Opt_DoAsmLinting
287
   | Opt_NoLlvmMangler                 -- hidden flag
288

Ian Lynagh's avatar
Ian Lynagh committed
289
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
290

291
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
292
   | Opt_PrintExplicitKinds
293

294
   -- optimisation opts
295
   | Opt_CallArity
296
   | Opt_Strictness
297
   | Opt_LateDmdAnal
298 299
   | Opt_KillAbsence
   | Opt_KillOneShot
300
   | Opt_FullLaziness
301 302
   | Opt_FloatIn
   | Opt_Specialise
303
   | Opt_StaticArgumentTransformation
304
   | Opt_CSE
305 306
   | Opt_LiberateCase
   | Opt_SpecConstr
307 308 309 310 311
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
   | Opt_UnboxStrictFields
312
   | Opt_UnboxSmallStrictFields
313
   | Opt_DictsCheap
314
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
315
   | Opt_Vectorise
316
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
317 318
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
319
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
320
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
321
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
322
   | Opt_IrrefutableTuples
323
   | Opt_CmmSink
324
   | Opt_CmmElimCommonBlocks
325
   | Opt_OmitYields
326
   | Opt_SimpleListLiterals
327
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
328 329
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
330
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
331

332 333 334 335 336
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings

Ian Lynagh's avatar
Ian Lynagh committed
337 338
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
339
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
340

341 342
   -- misc opts
   | Opt_Pp
343
   | Opt_ForceRecomp
344
   | Opt_ExcessPrecision
345
   | Opt_EagerBlackHoling
346 347 348
   | Opt_NoHsMain
   | Opt_SplitObjs
   | Opt_StgStats
349
   | Opt_HideAllPackages
350
   | Opt_PrintBindResult
351
   | Opt_Haddock
David Waern's avatar
David Waern committed
352
   | Opt_HaddockOptions
353
   | Opt_Hpc_No_Auto
354
   | Opt_BreakOnException
355
   | Opt_BreakOnError
356
   | Opt_PrintEvldWithShow
357
   | Opt_PrintBindContents
358 359
   | Opt_GenManifest
   | Opt_EmbedManifest
360
   | Opt_EmitExternalCore
Ian Lynagh's avatar
Ian Lynagh committed
361
   | Opt_SharedImplib
362
   | Opt_BuildingCabalPackage
363
   | Opt_IgnoreDotGhci
364
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
365
   | Opt_GhciHistory
366
   | Opt_HelpfulErrors
367
   | Opt_DeferTypeErrors
Ian Lynagh's avatar
Ian Lynagh committed
368
   | Opt_Parallel
Ian Lynagh's avatar
Ian Lynagh committed
369
   | Opt_GranMacros
Ian Lynagh's avatar
Ian Lynagh committed
370
   | Opt_PIC
371
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
372
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
373 374 375
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
ian@well-typed.com's avatar
ian@well-typed.com committed
376
   | Opt_Static
377
   | Opt_RPath
378
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
379
   | Opt_Hpc
380
   | Opt_FlatCache
381

382 383 384 385
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

386
   -- output style opts
387 388
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
389
   | Opt_PprCaseAsLet
390

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
   -- 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

408
   -- temporary flags
409
   | Opt_RunCPS
410
   | Opt_RunCPSZ
411
   | Opt_AutoLinkPackages
412
   | Opt_ImplicitImportQualified
413 414 415 416 417 418

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
419
   | Opt_KeepRawTokenStream
420
   | Opt_KeepLlvmFiles
421

422 423
   | Opt_BuildDynamicToo

424
   -- safe haskell flags
dterei's avatar
dterei committed
425
   | Opt_DistrustAllPackages
426 427
   | Opt_PackageTrust

428
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
429

430 431
data WarningFlag =
     Opt_WarnDuplicateExports
432
   | Opt_WarnDuplicateConstraints
433 434 435 436 437
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
438
   | Opt_WarnOverflowedLiterals
439
   | Opt_WarnEmptyEnumerations
440 441 442 443 444 445 446 447 448 449 450 451 452 453
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
   | Opt_WarnUnusedBinds
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
454
   | Opt_WarnAMP
455 456 457 458 459 460 461 462 463 464 465
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
466 467
   | Opt_WarnUnsafe
   | Opt_WarnSafe
Ian Lynagh's avatar
Ian Lynagh committed
468
   | Opt_WarnPointlessPragmas
469
   | Opt_WarnUnsupportedCallingConventions
470
   | Opt_WarnUnsupportedLlvmVersion
471
   | Opt_WarnInlineRuleShadowing
472
   | Opt_WarnTypedHoles
473
   deriving (Eq, Show, Enum)
474

475
data Language = Haskell98 | Haskell2010
476
   deriving Enum
477

478
-- | The various Safe Haskell modes
479 480
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
481
   | Sf_Unsafe
482 483
   | Sf_Trustworthy
   | Sf_Safe
484
   | Sf_SafeInferred
485 486
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
487
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
488 489 490 491 492
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
    show Sf_SafeInferred = "Safe-Inferred"
Ian Lynagh's avatar
Ian Lynagh committed
493

494
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
495
    ppr = text . show
496

497
data ExtensionFlag
498 499 500 501 502 503 504
   = Opt_Cpp
   | Opt_OverlappingInstances
   | Opt_UndecidableInstances
   | Opt_IncoherentInstances
   | Opt_MonomorphismRestriction
   | Opt_MonoPatBinds
   | Opt_MonoLocalBinds
505 506
   | Opt_RelaxedPolyRec           -- Deprecated
   | Opt_ExtendedDefaultRules     -- Use GHC's extended rules for defaulting
507 508
   | Opt_ForeignFunctionInterface
   | Opt_UnliftedFFITypes
509
   | Opt_InterruptibleFFI
510
   | Opt_CApiFFI
511
   | Opt_GHCForeignImportPrim
thoughtpolice's avatar
thoughtpolice committed
512
   | Opt_JavaScriptFFI
513 514
   | Opt_ParallelArrays           -- Syntactic support for parallel arrays
   | Opt_Arrows                   -- Arrow-notation syntax
515 516 517 518 519
   | Opt_TemplateHaskell
   | Opt_QuasiQuotes
   | Opt_ImplicitParams
   | Opt_ImplicitPrelude
   | Opt_ScopedTypeVariables
520
   | Opt_AllowAmbiguousTypes
521 522 523 524
   | Opt_UnboxedTuples
   | Opt_BangPatterns
   | Opt_TypeFamilies
   | Opt_OverloadedStrings
525
   | Opt_OverloadedLists
526
   | Opt_NumDecimals
527 528 529 530 531
   | Opt_DisambiguateRecordFields
   | Opt_RecordWildCards
   | Opt_RecordPuns
   | Opt_ViewPatterns
   | Opt_GADTs
Ian Lynagh's avatar
Ian Lynagh committed
532
   | Opt_GADTSyntax
533
   | Opt_NPlusKPatterns
Ian Lynagh's avatar
Ian Lynagh committed
534
   | Opt_DoAndIfThenElse
535
   | Opt_RebindableSyntax
536
   | Opt_ConstraintKinds
dreixel's avatar
dreixel committed
537
   | Opt_PolyKinds                -- Kind polymorphism
dreixel's avatar
dreixel committed
538
   | Opt_DataKinds                -- Datatype promotion
539
   | Opt_InstanceSigs
540

541 542
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
543
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
544 545 546
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
547
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
548
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
549 550 551 552 553 554

   | Opt_TypeSynonymInstances
   | Opt_FlexibleContexts
   | Opt_FlexibleInstances
   | Opt_ConstrainedClassMethods
   | Opt_MultiParamTypeClasses
555
   | Opt_NullaryTypeClasses
556 557 558 559 560 561
   | Opt_FunctionalDependencies
   | Opt_UnicodeSyntax
   | Opt_ExistentialQuantification
   | Opt_MagicHash
   | Opt_EmptyDataDecls
   | Opt_KindSignatures
562
   | Opt_RoleAnnotations
563 564
   | Opt_ParallelListComp
   | Opt_TransformListComp
565
   | Opt_MonadComprehensions
566 567 568 569 570 571 572 573 574
   | Opt_GeneralizedNewtypeDeriving
   | Opt_RecursiveDo
   | Opt_PostfixOperators
   | Opt_TupleSections
   | Opt_PatternGuards
   | Opt_LiberalTypeSynonyms
   | Opt_RankNTypes
   | Opt_ImpredicativeTypes
   | Opt_TypeOperators
575
   | Opt_ExplicitNamespaces
576 577 578 579 580
   | Opt_PackageImports
   | Opt_ExplicitForAll
   | Opt_AlternativeLayoutRule
   | Opt_AlternativeLayoutRuleTransitional
   | Opt_DatatypeContexts
581
   | Opt_NondecreasingIndentation
582
   | Opt_RelaxedLayout
583
   | Opt_TraditionalRecordSyntax
584
   | Opt_LambdaCase
585
   | Opt_MultiWayIf
586
   | Opt_NegativeLiterals
587
   | Opt_EmptyCase
cactus's avatar
cactus committed
588
   | Opt_PatternSynonyms
589
   deriving (Eq, Enum, Show)
590

591
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
592
-- information relating to the compilation of a single file or GHC session
593
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
594 595 596
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
597
  settings              :: Settings,
598
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
599 600 601
  optLevel              :: Int,         -- ^ Optimisation level
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
602
  shouldDumpSimplPhase  :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
603
  ruleCheck             :: Maybe String,
604
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
605

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

610 611 612
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

613 614
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
615
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
616 617
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
618 619
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
620
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
621
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
622
                                        --   See CoreMonad.FloatOutSwitches
623

624
  historySize           :: Int,
625

626
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
627 628 629
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
630
  ctxtStkDepth          :: Int,         -- ^ Typechecker context stack depth
631
  tyFunStkDepth         :: Int,         -- ^ Typechecker type function stack depth
632

633
  thisPackage           :: PackageId,   -- ^ name of package currently being compiled
634 635

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

640 641 642
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

643
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
644
  objectDir             :: Maybe String,
645
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
646 647
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
648
  dumpDir               :: Maybe String,
649

Ian Lynagh's avatar
Ian Lynagh committed
650 651 652
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
653

654 655 656 657
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

658 659 660 661 662 663 664 665
  -- 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
666
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
667
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
668 669
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
670

671
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
672 673
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
674

675 676
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
677 678
  dumpPrefixForce       :: Maybe FilePath,

679
  ldInputs              :: [Option],
680

Ian Lynagh's avatar
Ian Lynagh committed
681 682 683 684 685
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

686
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
687
  rtsOptsEnabled        :: RtsOptsEnabled,
688

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

691 692 693 694
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],

695 696 697
  -- GHC API hooks
  hooks                 :: Hooks,

698 699 700 701 702 703
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

704
  --  Package flags
705
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
706
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
707
        -- they appeared.
708

Ian Lynagh's avatar
Ian Lynagh committed
709
  packageFlags          :: [PackageFlag],
710
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
711

712
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
713
  -- NB. do not modify this field, it is calculated by
714
  -- Packages.initPackages and Packages.updatePackages.
715
  pkgDatabase           :: Maybe [PackageConfig],
Ian Lynagh's avatar
Ian Lynagh committed
716
  pkgState              :: PackageState,
717

718 719 720 721
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
722
  dirsToClean           :: IORef (Map FilePath FilePath),
723
  filesToNotIntermediateClean :: IORef [FilePath],
724 725
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
726

727 728 729 730 731
  -- 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
  generatedDumps        :: IORef (Set FilePath),

732
  -- hsc dynamic flags
733 734
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
735
  warningFlags          :: IntSet,
736
  -- Don't change this without updating extensionFlags:
737
  language              :: Maybe Language,
738 739
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
740 741 742
  -- 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.
743 744
  thOnLoc               :: SrcSpan,
  newDerivOnLoc         :: SrcSpan,
745
  pkgTrustOnLoc         :: SrcSpan,
746 747
  warnSafeOnLoc         :: SrcSpan,
  warnUnsafeOnLoc       :: SrcSpan,
748 749 750 751
  -- Don't change this without updating extensionFlags:
  extensions            :: [OnOff ExtensionFlag],
  -- extensionFlags should always be equal to
  --     flattenExtensionFlags language extensions
752
  extensionFlags        :: IntSet,
Ian Lynagh's avatar
Ian Lynagh committed
753

754 755 756 757 758 759 760 761 762
  -- Unfolding control
  -- See Note [Discounts and thresholds] in CoreUnfold
  ufCreationThreshold   :: Int,
  ufUseThreshold        :: Int,
  ufFunAppDiscount      :: Int,
  ufDictDiscount        :: Int,
  ufKeenessFactor       :: Float,
  ufDearOp              :: Int,

763 764
  maxWorkerArgs         :: Int,

765 766
  ghciHistSize          :: Int,

767
  -- | MsgDoc output action: use "ErrUtils" instead of this if you can
768
  log_action            :: LogAction,
769 770
  flushOut              :: FlushOut,
  flushErr              :: FlushErr,
David Waern's avatar
David Waern committed
771

772
  haddockOptions        :: Maybe String,
773
  ghciScripts           :: [String],
774

775 776
  -- Output style options
  pprUserLength         :: Int,
Ian Lynagh's avatar
Ian Lynagh committed
777
  pprCols               :: Int,
Ian Lynagh's avatar
Ian Lynagh committed
778
  traceLevel            :: Int, -- Standard level is 1. Less verbose is 0.
779

780 781
  useUnicodeQuotes      :: Bool,

782
  -- | what kind of {-# SCC #-} to add automatically
783 784
  profAuto              :: ProfAuto,

785
  interactivePrint      :: Maybe String,