DynFlags.hs 155 KB
Newer Older
dterei's avatar
dterei committed
1
-------------------------------------------------------------------------------
2
--
dterei's avatar
dterei committed
3 4 5 6 7 8
-- | 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.
9 10 11
--
-- (c) The University of Glasgow 2005
--
dterei's avatar
dterei committed
12
-------------------------------------------------------------------------------
13

14 15 16
{-# OPTIONS -fno-cse #-}
-- -fno-cse is needed for GLOBAL_VAR's to behave properly

17
module DynFlags (
18
        -- * Dynamic flags and associated configuration types
19
        DumpFlag(..),
20
        GeneralFlag(..),
21
        WarningFlag(..),
22
        ExtensionFlag(..),
23
        Language(..),
24
        PlatformConstants(..),
Ian Lynagh's avatar
Ian Lynagh committed
25
        FatalMessager, LogAction, FlushOut(..), FlushErr(..),
26
        ProfAuto(..),
27
        glasgowExtsFlags,
28
        dopt, dopt_set, dopt_unset,
29 30 31
        gopt, gopt_set, gopt_unset,
        wopt, wopt_set, wopt_unset,
        xopt, xopt_set, xopt_unset,
32
        lang_set,
33 34
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
35
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
36
        DynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
37
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
38
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
39
        HscTarget(..), isObjectTarget, defaultObjectTarget,
40
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
41 42 43
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
        PackageFlag(..),
44
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
45
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
46
        DynLibLoader(..),
47
        fFlags, fWarningFlags, fLangFlags, xFlags,
48
        dynFlagDependencies,
49
        tablesNextToCode, mkTablesNextToCode,
50

51 52
        printOutputForUser, printInfoForUser,

53
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
54
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
55

56
        -- ** Safe Haskell
57
        SafeHaskellMode(..),
58
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
59
        packageTrustOn,
60
        safeDirectImpsReq, safeImplicitImpsReq,
61
        unsafeFlags,
62

63
        -- ** System tool settings and locations
64
        Settings(..),
65
        targetPlatform,
66 67 68
        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,
69
        pgm_sysman, pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
Ian Lynagh's avatar
Ian Lynagh committed
70
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
71
        opt_windres, opt_lo, opt_lc,
72 73


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

86
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
87
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
88 89 90 91
        updOptLevel,
        setTmpDir,
        setPackageName,

92
        -- ** Parsing DynFlags
93 94
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
95 96 97
        parseDynamicFlagsFull,

        -- ** Available DynFlags
98
        allFlags,
99 100 101
        flagsAll,
        flagsDynamic,
        flagsPackage,
102

103
        supportedLanguagesAndExtensions,
104
        languageExtensions,
105

106
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
107
        picCCOpts, picPOpts,
108 109 110 111 112 113

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

        -- * Compiler configuration suitable for display to the user
114 115
        compilerInfo,

116
#ifdef GHCI
dterei's avatar
dterei committed
117
-- Only in stage 2 can we be sure that the RTS
118
-- exposes the appropriate runtime boolean
119
        rtsIsProfiled,
120
        dynamicGhc,
121
#endif
122 123

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

130 131
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

        -- * Linker information
        LinkerInfo(..),
145 146 147 148
  ) where

#include "HsVersions.h"

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

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

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

192 193 194
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

195 196
import GHC.Foreign (withCString, peekCString)

197 198 199
-- -----------------------------------------------------------------------------
-- DynFlags

200
data DumpFlag
201 202 203

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

Ian Lynagh's avatar
Ian Lynagh committed
285
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
286

287
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
288
   | Opt_PrintExplicitKinds
289

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

327 328 329 330 331
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings

Ian Lynagh's avatar
Ian Lynagh committed
332 333
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
334
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
335

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

377 378 379 380
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

381
   -- output style opts
382 383
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
384
   | Opt_PprCaseAsLet
385

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
   -- 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

403
   -- temporary flags
404
   | Opt_RunCPS
405
   | Opt_RunCPSZ
406
   | Opt_AutoLinkPackages
407
   | Opt_ImplicitImportQualified
408 409 410 411 412 413

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
414
   | Opt_KeepRawTokenStream
415
   | Opt_KeepLlvmFiles
416

417 418
   | Opt_BuildDynamicToo

419
   -- safe haskell flags
dterei's avatar
dterei committed
420
   | Opt_DistrustAllPackages
421 422
   | Opt_PackageTrust

423
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
424

425 426
data WarningFlag =
     Opt_WarnDuplicateExports
427
   | Opt_WarnDuplicateConstraints
428 429 430 431 432
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
433
   | Opt_WarnOverflowedLiterals
434
   | Opt_WarnEmptyEnumerations
435 436 437 438 439 440 441 442 443 444 445 446 447 448
   | 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
449
   | Opt_WarnAMP
450 451 452 453 454 455 456 457 458 459 460 461
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnLazyUnliftedBindings
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
462 463
   | Opt_WarnUnsafe
   | Opt_WarnSafe
Ian Lynagh's avatar
Ian Lynagh committed
464
   | Opt_WarnPointlessPragmas
465
   | Opt_WarnUnsupportedCallingConventions
466
   | Opt_WarnUnsupportedLlvmVersion
467
   | Opt_WarnInlineRuleShadowing
468
   deriving (Eq, Show, Enum)
469

470
data Language = Haskell98 | Haskell2010
471
   deriving Enum
472

473
-- | The various Safe Haskell modes
474 475
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
476
   | Sf_Unsafe
477 478
   | Sf_Trustworthy
   | Sf_Safe
479
   | Sf_SafeInferred
480 481
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
482
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
483 484 485 486 487
    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
488

489
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
490
    ppr = text . show
491

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

536 537
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
538
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
539 540 541
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
542
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
543
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
544 545 546 547 548 549

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

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

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

605 606 607
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

619
  historySize           :: Int,
620

621
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
622 623 624
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
625
  ctxtStkDepth          :: Int,         -- ^ Typechecker context stack depth
626
  tyFunStkDepth         :: Int,         -- ^ Typechecker type function stack depth
627

628
  thisPackage           :: PackageId,   -- ^ name of package currently being compiled
629 630

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

635 636 637
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

638
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
639
  objectDir             :: Maybe String,
640
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
641 642
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
643
  dumpDir               :: Maybe String,
644

Ian Lynagh's avatar
Ian Lynagh committed
645 646 647
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
648

649 650 651 652
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

653 654 655 656 657 658 659 660
  -- 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
661
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
662
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
663 664
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
665

666
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
667 668
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
669

670 671
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
672 673
  dumpPrefixForce       :: Maybe FilePath,

674
  ldInputs              :: [Option],
675

Ian Lynagh's avatar
Ian Lynagh committed
676 677 678 679 680
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

681
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
682
  rtsOptsEnabled        :: RtsOptsEnabled,
683

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

686 687 688 689
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],

690 691 692
  -- GHC API hooks
  hooks                 :: Hooks,

693 694 695 696 697 698
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

699
  --  Package flags
700
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
701
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
702
        -- they appeared.
703

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

707
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
708
  -- NB. do not modify this field, it is calculated by
709
  -- Packages.initPackages and Packages.updatePackages.
710
  pkgDatabase           :: Maybe [PackageConfig],
Ian Lynagh's avatar
Ian Lynagh committed
711
  pkgState              :: PackageState,
712

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

722 723 724 725 726
  -- 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),

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

749 750 751 752 753 754 755 756 757
  -- Unfolding control
  -- See Note [Discounts and thresholds] in CoreUnfold
  ufCreationThreshold   :: Int,
  ufUseThreshold        :: Int,
  ufFunAppDiscount      :: Int,
  ufDictDiscount        :: Int,
  ufKeenessFactor       :: Float,
  ufDearOp              :: Int,

758 759
  maxWorkerArgs         :: Int,

760 761
  ghciHistSize          :: Int,

762
  -- | MsgDoc output action: use "ErrUtils" instead of this if you can
763
  log_action            :: LogAction,
764 765
  flushOut              :: FlushOut,
  flushErr              :: FlushErr,
David Waern's avatar
David Waern committed
766

767
  haddockOptions        :: Maybe String,
768
  ghciScripts           :: [String],
769

770 771
  -- Output style options
  pprUserLength         :: Int,
Ian Lynagh's avatar
Ian Lynagh committed
772
  pprCols               :: Int,
Ian Lynagh's avatar
Ian Lynagh committed
773
  traceLevel            :: Int, -- Standard level is 1. Less verbose is 0.
774

775 776
  useUnicodeQuotes      :: Bool,

777
  -- | what kind of {-# SCC #-} to add automatically
778 779
  profAuto              :: ProfAuto,

780
  interactivePrint      :: Maybe String,
781

782
  llvmVersion           :: IORef Int,
783

784
  nextWrapperNum        :: IORef (ModuleEnv Int),
tibbe's avatar
tibbe committed
785 786

  -- | Machine dependant flags (-m<blah> stuff)
787
  sseVersion            :: Maybe (Int, Int),  -- (major, minor)
788 789
  avx                   :: Bool,
  avx2                  :: Bool,
790 791 792 793
  avx512cd              :: Bool, -- Enable AVX-512 Conflict Detection Instructions.
  avx512er              :: Bool, -- Enable AVX-512 Exponential and Reciprocal Instructions.
  avx512f               :: Bool, -- Enable AVX-512 instructions.
  avx512pf              :: Bool, -- Enable AVX-512 PreFetch Instructions.
794