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_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
   | Opt_PrintPotentialInstances
342

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

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

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

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

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

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

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

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

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

473 474
   | Opt_BuildDynamicToo

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

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

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

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

541
data Language = Haskell98 | Haskell2010
542
   deriving Enum
543

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

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

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

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

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

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

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

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

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
-- 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

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

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

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

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

724
  historySize           :: Int,
725

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

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

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

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

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

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

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

762 763 764 765 766 767 768 769
  -- 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
770
  outputFile            :: Maybe String,