DynFlags.hs 167 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,
54
        SigOf(..), getSigOf,
55

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, unsafeFlagsForInfer,
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
        updOptLevel,
        setTmpDir,
93
        setPackageKey,
Ian Lynagh's avatar
Ian Lynagh committed
94

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

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

107
        supportedLanguagesAndExtensions,
108
        languageExtensions,
109

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

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

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

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

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

132 133
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

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

181
import Data.Bits
182
import Data.Char
183
import Data.Int
184
import Data.List
185 186
import Data.Map (Map)
import qualified Data.Map as Map
187
import Data.Maybe
188 189
import Data.Set (Set)
import qualified Data.Set as Set
190
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
191
import System.FilePath
192
import System.IO
193
import System.IO.Error
194 195
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
196

197 198 199
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

200 201
import GHC.Foreign (withCString, peekCString)

202 203 204 205 206 207 208 209 210 211 212 213 214
-- 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.

215 216 217 218 219 220 221 222 223 224 225 226
-- 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.

227 228 229
-- -----------------------------------------------------------------------------
-- DynFlags

230
data DumpFlag
231
-- See Note [Updating flag description in the User's Guide]
232 233 234

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

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
310
   | Opt_D_faststring_stats
311
   | Opt_D_dump_minimal_imports
312 313 314
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
315
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
316
   | Opt_DoAnnotationLinting
317
   | Opt_NoLlvmMangler                 -- hidden flag
318

Ian Lynagh's avatar
Ian Lynagh committed
319
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
320

321
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
322
   | Opt_PrintExplicitKinds
323

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

363 364 365 366
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
367
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
368

Ian Lynagh's avatar
Ian Lynagh committed
369 370
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
371
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
372

373 374
   -- misc opts
   | Opt_Pp
375
   | Opt_ForceRecomp
376
   | Opt_ExcessPrecision
377
   | Opt_EagerBlackHoling
378 379 380
   | Opt_NoHsMain
   | Opt_SplitObjs
   | Opt_StgStats
381
   | Opt_HideAllPackages
382
   | Opt_PrintBindResult
383
   | Opt_Haddock
David Waern's avatar
David Waern committed
384
   | Opt_HaddockOptions
385
   | Opt_Hpc_No_Auto
386
   | Opt_BreakOnException
387
   | Opt_BreakOnError
388
   | Opt_PrintEvldWithShow
389
   | Opt_PrintBindContents
390 391
   | Opt_GenManifest
   | Opt_EmbedManifest
392
   | Opt_EmitExternalCore
Ian Lynagh's avatar
Ian Lynagh committed
393
   | Opt_SharedImplib
394
   | Opt_BuildingCabalPackage
395
   | Opt_IgnoreDotGhci
396
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
397
   | Opt_GhciHistory
398
   | Opt_HelpfulErrors
399
   | Opt_DeferTypeErrors
400
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
401
   | Opt_Parallel
Ian Lynagh's avatar
Ian Lynagh committed
402
   | Opt_GranMacros
Ian Lynagh's avatar
Ian Lynagh committed
403
   | Opt_PIC
404
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
405
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
406 407 408
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
ian@well-typed.com's avatar
ian@well-typed.com committed
409
   | Opt_Static
410
   | Opt_RPath
411
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
412
   | Opt_Hpc
413
   | Opt_FlatCache
414

415 416 417 418
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

419
   -- output style opts
420 421
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
422
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
423
   | Opt_PprShowTicks
424

425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
   -- 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

442
   -- temporary flags
443
   | Opt_AutoLinkPackages
444
   | Opt_ImplicitImportQualified
445 446 447 448 449 450

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
451
   | Opt_KeepRawTokenStream
452
   | Opt_KeepLlvmFiles
453

454 455
   | Opt_BuildDynamicToo

456
   -- safe haskell flags
dterei's avatar
dterei committed
457
   | Opt_DistrustAllPackages
458 459
   | Opt_PackageTrust

Peter Wortmann's avatar
Peter Wortmann committed
460 461 462
   -- debugging flags
   | Opt_Debug

463
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
464

465
data WarningFlag =
466
-- See Note [Updating flag description in the User's Guide]
467
     Opt_WarnDuplicateExports
468
   | Opt_WarnDuplicateConstraints
469 470 471 472 473
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
474
   | Opt_WarnOverflowedLiterals
475
   | Opt_WarnEmptyEnumerations
476 477 478 479 480 481 482 483 484 485 486 487
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
   | Opt_WarnUnusedBinds
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
488
   | Opt_WarnContextQuantification
489 490
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
491
   | Opt_WarnAMP
492 493 494 495 496 497 498 499 500 501 502
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
503 504
   | Opt_WarnUnsafe
   | Opt_WarnSafe
505
   | Opt_WarnTrustworthySafe
Ian Lynagh's avatar
Ian Lynagh committed
506
   | Opt_WarnPointlessPragmas
507
   | Opt_WarnUnsupportedCallingConventions
508
   | Opt_WarnUnsupportedLlvmVersion
509
   | Opt_WarnInlineRuleShadowing
510
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
511
   | Opt_WarnPartialTypeSignatures
512
   | Opt_WarnMissingExportedSigs
carlostome's avatar
carlostome committed
513
   | Opt_WarnUntickedPromotedConstructors
514
   deriving (Eq, Show, Enum)
515

516
data Language = Haskell98 | Haskell2010
517
   deriving Enum
518

519
-- | The various Safe Haskell modes
520 521
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
522
   | Sf_Unsafe
523 524 525 526
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
527
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
528 529 530 531
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
532

533
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
534
    ppr = text . show
535

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

581 582
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
583
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
584 585 586
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
587
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
588
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
589
   | Opt_DeriveAnyClass           -- Allow deriving any class
590 591 592 593 594 595

   | Opt_TypeSynonymInstances
   | Opt_FlexibleContexts
   | Opt_FlexibleInstances
   | Opt_ConstrainedClassMethods
   | Opt_MultiParamTypeClasses
596
   | Opt_NullaryTypeClasses
597 598 599 600 601 602
   | Opt_FunctionalDependencies
   | Opt_UnicodeSyntax
   | Opt_ExistentialQuantification
   | Opt_MagicHash
   | Opt_EmptyDataDecls
   | Opt_KindSignatures
603
   | Opt_RoleAnnotations
604 605
   | Opt_ParallelListComp
   | Opt_TransformListComp
606
   | Opt_MonadComprehensions
607 608 609 610 611 612 613 614 615
   | Opt_GeneralizedNewtypeDeriving
   | Opt_RecursiveDo
   | Opt_PostfixOperators
   | Opt_TupleSections
   | Opt_PatternGuards
   | Opt_LiberalTypeSynonyms
   | Opt_RankNTypes
   | Opt_ImpredicativeTypes
   | Opt_TypeOperators
616
   | Opt_ExplicitNamespaces
617 618 619 620 621
   | Opt_PackageImports
   | Opt_ExplicitForAll
   | Opt_AlternativeLayoutRule
   | Opt_AlternativeLayoutRuleTransitional
   | Opt_DatatypeContexts
622
   | Opt_NondecreasingIndentation
623
   | Opt_RelaxedLayout
624
   | Opt_TraditionalRecordSyntax
625
   | Opt_LambdaCase
626
   | Opt_MultiWayIf
627
   | Opt_BinaryLiterals
628
   | Opt_NegativeLiterals
629
   | Opt_EmptyCase
cactus's avatar
cactus committed
630
   | Opt_PatternSynonyms
thomasw's avatar
thomasw committed
631 632
   | Opt_PartialTypeSignatures
   | Opt_NamedWildcards
Facundo Domínguez's avatar
Facundo Domínguez committed
633
   | Opt_StaticPointers
634
   deriving (Eq, Enum, Show)
635

636 637 638 639 640 641 642 643 644 645 646
data SigOf = NotSigOf
           | SigOf Module
           | SigOfMap (Map ModuleName Module)

getSigOf :: DynFlags -> ModuleName -> Maybe Module
getSigOf dflags n =
    case sigOf dflags of
        NotSigOf -> Nothing
        SigOf m -> Just m
        SigOfMap m -> Map.lookup n m

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

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

667 668 669
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

670 671
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
672
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
673 674
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
675 676
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
677
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
678
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
679
                                        --   See CoreMonad.FloatOutSwitches
680

681
  historySize           :: Int,
682

683
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
684 685 686
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
687
  ctxtStkDepth          :: Int,         -- ^ Typechecker context stack depth
688
  tyFunStkDepth         :: Int,         -- ^ Typechecker type function stack depth
689

690
  thisPackage           :: PackageKey,   -- ^ name of package currently being compiled
691 692

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

697 698 699
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

700
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
701
  objectDir             :: Maybe String,
702
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
703 704
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
705
  dumpDir               :: Maybe String,
706

Ian Lynagh's avatar
Ian Lynagh committed
707 708 709
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
710

711 712 713 714
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

715 716 717 718 719 720 721 722
  -- 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
723
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
724
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
725 726
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
727

728
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
729 730
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
731

732 733
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
734 735
  dumpPrefixForce       :: Maybe FilePath,

736
  ldInputs              :: [Option],
737

Ian Lynagh's avatar
Ian Lynagh committed
738 739 740 741 742
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

743
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
744
  rtsOptsEnabled        :: RtsOptsEnabled,
745

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

748 749 750 751
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],

752 753 754
  -- GHC API hooks
  hooks                 :: Hooks,

755 756 757 758 759 760
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

761
  --  Package flags
762
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
763
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
764
        -- they appeared.
765

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

769
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
770
  -- NB. do not modify this field, it is calculated by
771
  -- Packages.initPackages and Packages.updatePackages.
772
  pkgDatabase           :: Maybe [PackageConfig],
Ian Lynagh's avatar
Ian Lynagh committed
773
  pkgState              :: PackageState,
774

775 776 777 778
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
779
  dirsToClean           :: IORef (Map FilePath FilePath),
780
  filesToNotIntermediateClean :: IORef [FilePath],
781 782
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
783

784 785 786 787 788
  -- 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),

789
  -- hsc dynamic flags
790 791
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
792
  warningFlags          :: IntSet,
793
  -- Don't change this without updating extensionFlags:
Ian Lynagh's avatar