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

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

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

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

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

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

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


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

91
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
92
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
93 94
        updOptLevel,
        setTmpDir,
95
        setPackageKey,
Edsko de Vries's avatar
Edsko de Vries committed
96
        interpretPackageEnv,
Ian Lynagh's avatar
Ian Lynagh committed
97

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

103 104 105 106
        -- ** Package key cache
        PackageKeyCache,
        ShPackageKey(..),

107
        -- ** Available DynFlags
108
        allFlags,
109 110 111
        flagsAll,
        flagsDynamic,
        flagsPackage,
112
        flagsForCompletion,
113

114
        supportedLanguagesAndExtensions,
115
        languageExtensions,
116

117
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
118
        picCCOpts, picPOpts,
119 120 121 122 123 124

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

        -- * Compiler configuration suitable for display to the user
125 126
        compilerInfo,

127
#ifdef GHCI
128
        rtsIsProfiled,
129
#endif
130
        dynamicGhc,
131 132

#include "../includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs"
133
        bLOCK_SIZE_W,
134
        wORD_SIZE_IN_BITS,
135 136
        tAG_MASK,
        mAX_PTR_TAG,
137
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
138

139 140
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

141
        -- * SSE and AVX
142
        isSseEnabled,
143 144
        isSse2Enabled,
        isSse4_2Enabled,
145 146
        isAvxEnabled,
        isAvx2Enabled,
147 148 149 150
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
151

Austin Seipp's avatar
Austin Seipp committed
152
        -- * Linker/compiler information
153
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
154
        CompilerInfo(..),
155 156 157 158
  ) where

#include "HsVersions.h"

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

187
import System.IO.Unsafe ( unsafePerformIO )
188
import Data.IORef
189
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
190
import Control.Monad
Edsko de Vries's avatar
Edsko de Vries committed
191
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
192

193
import Data.Bits
194
import Data.Char
195
import Data.Int
196
import Data.List
197 198
import Data.Map (Map)
import qualified Data.Map as Map
199 200
import Data.Set (Set)
import qualified Data.Set as Set
201
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
202
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
203 204
import System.Directory
import System.Environment (getEnv)
205
import System.IO
206
import System.IO.Error
207 208
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
209

210 211 212
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

213 214
import GHC.Foreign (withCString, peekCString)

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

228 229 230 231 232 233 234 235 236 237 238 239
-- 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.

240 241 242
-- -----------------------------------------------------------------------------
-- DynFlags

243
data DumpFlag
244
-- See Note [Updating flag description in the User's Guide]
245 246 247

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

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
326
   | Opt_D_faststring_stats
327
   | Opt_D_dump_minimal_imports
328 329 330
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
331
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
332
   | Opt_DoAnnotationLinting
333
   | Opt_NoLlvmMangler                 -- hidden flag
334

Ian Lynagh's avatar
Ian Lynagh committed
335
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
336

337
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
338
   | Opt_PrintExplicitKinds
339
   | Opt_PrintUnicodeSyntax
340
   | Opt_PrintExpandedSynonyms
341

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

383 384 385 386
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
387
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
388

Ian Lynagh's avatar
Ian Lynagh committed
389 390
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
391
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
392

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

431 432 433 434
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

435
   -- output style opts
436 437
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
438
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
439
   | Opt_PprShowTicks
440

441 442 443 444 445 446 447 448 449 450 451
   -- 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
452 453
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
454 455 456 457 458 459
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

460
   -- temporary flags
461
   | Opt_AutoLinkPackages
462
   | Opt_ImplicitImportQualified
463 464 465 466 467 468

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
469
   | Opt_KeepRawTokenStream
470
   | Opt_KeepLlvmFiles
471

472 473
   | Opt_BuildDynamicToo

474
   -- safe haskell flags
dterei's avatar
dterei committed
475
   | Opt_DistrustAllPackages
476 477
   | Opt_PackageTrust

Peter Wortmann's avatar
Peter Wortmann committed
478 479 480
   -- debugging flags
   | Opt_Debug

481
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
482

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

540
data Language = Haskell98 | Haskell2010
541
   deriving Enum
542

543
-- | The various Safe Haskell modes
544 545
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
546
   | Sf_Unsafe
547 548 549 550
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
551
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
552 553 554 555
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
556

557
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
558
    ppr = text . show
559

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

605 606
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
607
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
608 609 610
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
611
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
612
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
613
   | Opt_DeriveAnyClass           -- Allow deriving any class
614 615 616 617 618 619

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

Edward Z. Yang's avatar
Edward Z. Yang committed
661
type SigOf = Map ModuleName Module
662 663

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

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
-- NameCache updNameCache
type PackageKeyEnv = UniqFM
type PackageKeyCache = PackageKeyEnv ShPackageKey

-- | An elaborated representation of a 'PackageKey', which records
-- all of the components that go into the hashed 'PackageKey'.
data ShPackageKey
    = ShPackageKey {
          shPackageKeyUnitName          :: !UnitName,
          shPackageKeyLibraryName       :: !LibraryName,
          shPackageKeyInsts             :: ![(ModuleName, Module)],
          shPackageKeyFreeHoles         :: UniqSet ModuleName
      }
    | ShDefinitePackageKey {
          shPackageKey :: !PackageKey
      }
    deriving Eq

instance Outputable ShPackageKey where
    ppr (ShPackageKey pn vh insts fh)
        = ppr pn <+> ppr vh <+> ppr insts <+> parens (ppr fh)
    ppr (ShDefinitePackageKey pk) = ppr pk

689
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
690
-- information relating to the compilation of a single file or GHC session
691
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
692 693 694
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
695
  settings              :: Settings,
696 697
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
698
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
699 700 701
  optLevel              :: Int,         -- ^ Optimisation level
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
Ian Lynagh's avatar
Ian Lynagh committed
702
  ruleCheck             :: Maybe String,
703
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
704

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

709 710 711
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

712 713
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
714
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
715 716
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
717 718
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
719
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
720
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
721
                                        --   See CoreMonad.FloatOutSwitches
722

723
  historySize           :: Int,
724

725
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
726 727 728
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
729
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
730 731
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
732

733 734 735 736
  thisPackage           :: PackageKey,   -- ^ key of package currently being compiled
  thisLibraryName       :: LibraryName,
                            -- ^ the version hash which identifies the textual
                            --   package being compiled.
737 738

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

743 744 745
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

746
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
747
  objectDir             :: Maybe String,
748
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
749 750
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
751
  dumpDir               :: Maybe String,
752

Ian Lynagh's avatar
Ian Lynagh committed
753 754 755
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
756

757 758 759 760
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

761 762 763 764 765 766 767 768
  -- 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
769
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
770
  dynOutputFile         :: Maybe String,