DynFlags.hs 172 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, programName, projectVersion,
69
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
Edsko de Vries's avatar
Edsko de Vries committed
70
        versionedAppDir,
71 72
        extraGccViaCFlags, systemPackageConfig,
        pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
73
        pgm_sysman, pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
Ian Lynagh's avatar
Ian Lynagh committed
74
        opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
75
        opt_windres, opt_lo, opt_lc,
76 77


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

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

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

        -- ** Available DynFlags
103
        allFlags,
104 105 106
        flagsAll,
        flagsDynamic,
        flagsPackage,
107
        flagsForCompletion,
108

109
        supportedLanguagesAndExtensions,
110
        languageExtensions,
111

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

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

        -- * Compiler configuration suitable for display to the user
120 121
        compilerInfo,

122
#ifdef GHCI
123
        rtsIsProfiled,
124
#endif
125
        dynamicGhc,
126 127

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

134 135
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

#include "HsVersions.h"

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

179
import System.IO.Unsafe ( unsafePerformIO )
180
import Data.IORef
ian@well-typed.com's avatar
ian@well-typed.com committed
181
import Control.Monad
Edsko de Vries's avatar
Edsko de Vries committed
182
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
183

184
import Data.Bits
185
import Data.Char
186
import Data.Int
187
import Data.List
188 189
import Data.Map (Map)
import qualified Data.Map as Map
190 191
import Data.Set (Set)
import qualified Data.Set as Set
192
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
193
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
194 195
import System.Directory
import System.Environment (getEnv)
196
import System.IO
197
import System.IO.Error
198 199
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
200

201 202 203
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

204 205
import GHC.Foreign (withCString, peekCString)

206 207 208 209 210 211 212 213 214 215 216 217 218
-- 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.

219 220 221 222 223 224 225 226 227 228 229 230
-- 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.

231 232 233
-- -----------------------------------------------------------------------------
-- DynFlags

234
data DumpFlag
235
-- See Note [Updating flag description in the User's Guide]
236 237 238

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

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
316
   | Opt_D_faststring_stats
317
   | Opt_D_dump_minimal_imports
318 319 320
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
321
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
322
   | Opt_DoAnnotationLinting
323
   | Opt_NoLlvmMangler                 -- hidden flag
324

Ian Lynagh's avatar
Ian Lynagh committed
325
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
326

327
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
328
   | Opt_PrintExplicitKinds
329

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

369 370 371 372
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
373
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
374

Ian Lynagh's avatar
Ian Lynagh committed
375 376
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
377
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
378

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

419 420 421 422
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

423
   -- output style opts
424 425
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
426
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
427
   | Opt_PprShowTicks
428

429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
   -- 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

446
   -- temporary flags
447
   | Opt_AutoLinkPackages
448
   | Opt_ImplicitImportQualified
449 450 451 452 453 454

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
455
   | Opt_KeepRawTokenStream
456
   | Opt_KeepLlvmFiles
457

458 459
   | Opt_BuildDynamicToo

460
   -- safe haskell flags
dterei's avatar
dterei committed
461
   | Opt_DistrustAllPackages
462 463
   | Opt_PackageTrust

Peter Wortmann's avatar
Peter Wortmann committed
464 465 466
   -- debugging flags
   | Opt_Debug

467
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
468

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

523
data Language = Haskell98 | Haskell2010
524
   deriving Enum
525

526
-- | The various Safe Haskell modes
527 528
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
529
   | Sf_Unsafe
530 531 532 533
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
534
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
535 536 537 538
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
539

540
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
541
    ppr = text . show
542

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

588 589
   | Opt_StandaloneDeriving
   | Opt_DeriveDataTypeable
590
   | Opt_AutoDeriveTypeable       -- Automatic derivation of Typeable
591 592 593
   | Opt_DeriveFunctor
   | Opt_DeriveTraversable
   | Opt_DeriveFoldable
594
   | Opt_DeriveGeneric            -- Allow deriving Generic/1
dreixel's avatar
dreixel committed
595
   | Opt_DefaultSignatures        -- Allow extra signatures for defmeths
596
   | Opt_DeriveAnyClass           -- Allow deriving any class
597 598 599 600 601 602

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

643 644 645 646 647 648 649 650 651 652 653
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

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

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

674 675 676
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

688
  historySize           :: Int,
689

690
  cmdlineHcIncludes     :: [String],    -- ^ @\-\#includes@
Ian Lynagh's avatar
Ian Lynagh committed
691 692 693
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
694
  ctxtStkDepth          :: Int,         -- ^ Typechecker context stack depth
695
  tyFunStkDepth         :: Int,         -- ^ Typechecker type function stack depth
696

697
  thisPackage           :: PackageKey,   -- ^ name of package currently being compiled
698 699

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

704 705 706
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

707
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
708
  objectDir             :: Maybe String,
709
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
710 711
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
712
  dumpDir               :: Maybe String,
713

Ian Lynagh's avatar
Ian Lynagh committed
714 715 716
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
717

718 719 720 721
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

722 723 724 725 726 727 728 729
  -- 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
730
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
731
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
732 733
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
734

735
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
736 737
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
738

739 740
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
741 742
  dumpPrefixForce       :: Maybe FilePath,

743
  ldInputs              :: [Option],
744

Ian Lynagh's avatar
Ian Lynagh committed
745 746 747 748 749
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

750
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
751
  rtsOptsEnabled        :: RtsOptsEnabled,
752

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

755 756 757 758
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],

759 760 761
  -- GHC API hooks
  hooks                 :: Hooks,

762 763 764 765 766 767
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

768
  --  Package flags
769
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
770
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
771
        -- they appeared.
772

Ian Lynagh's avatar
Ian Lynagh committed
773
  packageFlags          :: [PackageFlag],
774
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
Edsko de Vries's avatar
Edsko de Vries committed
775 776
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
777

778
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
779
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
780
  -- Packages.initPackages
781
  pkgDatabase           :: Maybe [PackageConfig],
Ian Lynagh's avatar
Ian Lynagh committed
782
  pkgState              :: PackageState,
783

784 785 786 787
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],