DynFlags.hs 189 KB
Newer Older
1
{-# LANGUAGE CPP #-}
2
{-# LANGUAGE FlexibleInstances #-}
3

dterei's avatar
dterei committed
4
-------------------------------------------------------------------------------
5
--
dterei's avatar
dterei committed
6
7
8
9
10
11
-- | 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.
12
13
14
--
-- (c) The University of Glasgow 2005
--
dterei's avatar
dterei committed
15
-------------------------------------------------------------------------------
16

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

20
module DynFlags (
21
        -- * Dynamic flags and associated configuration types
22
        DumpFlag(..),
23
        GeneralFlag(..),
24
        WarningFlag(..),
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,
triple's avatar
triple committed
31
        gopt, gopt_set, gopt_unset, setGeneralFlag', unSetGeneralFlag',
32
33
        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
        IgnorePackageFlag(..), TrustFlag(..),
49
        PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
50
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
51
        DynLibLoader(..),
52
53
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
54
        dynFlagDependencies,
55
        tablesNextToCode, mkTablesNextToCode,
Edward Z. Yang's avatar
Edward Z. Yang committed
56
        SigOf, getSigOf,
Ben Gamari's avatar
Ben Gamari committed
57
        makeDynFlagsConsistent,
58

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

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

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


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

94
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
95
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
96
97
        updOptLevel,
        setTmpDir,
98
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
99
        interpretPackageEnv,
Ian Lynagh's avatar
Ian Lynagh committed
100

101
        -- ** Parsing DynFlags
102
103
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
104
105
106
        parseDynamicFlagsFull,

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

113
        supportedLanguagesAndExtensions,
114
        languageExtensions,
115

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

        -- * 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, emptyPackageState)
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 BasicTypes       ( IntWithInf, treatZeroAsInf )
172
import FastString
Simon Marlow's avatar
Simon Marlow committed
173
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
174
import Foreign.C        ( CInt(..) )
175
import System.IO.Unsafe ( unsafeDupablePerformIO )
176
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessage )
177

178
import System.IO.Unsafe ( unsafePerformIO )
179
import Data.IORef
180
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
181
import Control.Monad
182
183
184
185
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
Edsko de Vries's avatar
Edsko de Vries committed
186
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
187

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

205
206
207
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

208
import GHC.Foreign (withCString, peekCString)
209
import qualified GHC.LanguageExtensions as LangExt
210

211
212
213
214
215
216
217
-- 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:
--
218
219
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
220
--
221
--  * Flag description in docs/users_guide/using.rst provides a detailed
222
223
--    explanation of flags' usage.

224
225
226
227
228
229
230
231
232
233
234
235
-- 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.

236
237
238
239
240
241
242
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
243
--    The Extension type in libraries/ghc-boot/GHC/LanguageExtensions.hs is
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
--    the canonical list of language extensions known by GHC.
--
--  * Adding a flag to DynFlags.xFlags
--
--    This is fairly self-explanatory. The name should be concise, memorable,
--    and consistent with any previous implementations of the similar idea in
--    other Haskell compilers.
--
--  * Adding the flag to the documentation
--
--    This is the same as any other flag. See
--    Note [Updating flag description in the User's Guide]
--
--  * Adding the flag to Cabal
--
--    The Cabal library has its own list of all language extensions supported
--    by all major compilers. This is the list that user code being uploaded
--    to Hackage is checked against to ensure language extension validity.
--    Consequently, it is very important that this list remains up-to-date.
--
--    To this end, there is a testsuite test (testsuite/tests/driver/T4437.hs)
--    whose job it is to ensure these GHC's extensions are consistent with
--    Cabal.
--
--    The recommended workflow is,
--
--     1. Temporarily add your new language extension to the
--        expectedGhcOnlyExtensions list in T4437 to ensure the test doesn't
--        break while Cabal is updated.
--
--     2. After your GHC change is accepted, submit a Cabal pull request adding
--        your new extension to Cabal's list (found in
--        Cabal/Language/Haskell/Extension.hs).
--
--     3. After your Cabal change is accepted, let the GHC developers know so
--        they can update the Cabal submodule and remove the extensions from
--        expectedGhcOnlyExtensions.
--
--  * Adding the flag to the GHC Wiki
--
--    There is a change log tracking language extension additions and removals
--    on the GHC wiki:  https://ghc.haskell.org/trac/ghc/wiki/LanguagePragmaHistory
--
--  See Trac #4437 and #8176.

289
290
291
-- -----------------------------------------------------------------------------
-- DynFlags

292
data DumpFlag
293
-- See Note [Updating flag description in the User's Guide]
294
295
296

   -- debugging flags
   = Opt_D_dump_cmm
297
298
299
300
301
   | 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
302
   | Opt_D_dump_cmm_switch
303
   | Opt_D_dump_cmm_proc
304
   | Opt_D_dump_cmm_sink
305
306
307
308
309
310
   | 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
311
   | Opt_D_dump_asm
312
313
314
315
316
   | 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
317
   | Opt_D_dump_asm_stats
318
   | Opt_D_dump_asm_expanded
319
   | Opt_D_dump_llvm
320
   | Opt_D_dump_core_stats
321
322
323
324
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
325
   | Opt_D_dump_rule_firings
326
   | Opt_D_dump_rule_rewrites
327
   | Opt_D_dump_simpl_trace
328
329
330
331
332
333
334
335
   | 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
336
   | Opt_D_dump_call_arity
337
   | Opt_D_dump_stranal
Joachim Breitner's avatar
Joachim Breitner committed
338
   | Opt_D_dump_strsigs
339
340
341
342
343
344
345
346
347
   | 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
348
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
349
350
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
351
   | Opt_D_dump_vt_trace
352
   | Opt_D_dump_splices
353
   | Opt_D_th_dec_file
354
355
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
356
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
357
   | Opt_D_dump_rtti
358
359
360
361
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
362
   | Opt_D_dump_mod_cycles
363
   | Opt_D_dump_mod_map
364
   | Opt_D_dump_view_pattern_commoning
365
   | Opt_D_verbose_core2core
366
   | Opt_D_dump_debug
367
368
369
370
371

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
375
   | Opt_D_faststring_stats
376
   | Opt_D_dump_minimal_imports
377
378
379
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
380
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
381
   | Opt_DoAnnotationLinting
382
   | Opt_NoLlvmMangler                 -- hidden flag
383

Ian Lynagh's avatar
Ian Lynagh committed
384
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
385

386
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
387
   | Opt_PrintExplicitKinds
388
389
   | Opt_PrintExplicitCoercions
   | Opt_PrintEqualityRelations
390
   | Opt_PrintUnicodeSyntax
391
   | Opt_PrintExpandedSynonyms
392
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
393
   | Opt_PrintTypecheckerElaboration
394

395
   -- optimisation opts
396
   | Opt_CallArity
397
   | Opt_Strictness
398
   | Opt_LateDmdAnal
399
400
   | Opt_KillAbsence
   | Opt_KillOneShot
401
   | Opt_FullLaziness
402
403
   | Opt_FloatIn
   | Opt_Specialise
404
   | Opt_SpecialiseAggressively
405
   | Opt_CrossModuleSpecialise
406
   | Opt_StaticArgumentTransformation
407
   | Opt_CSE
408
409
   | Opt_LiberateCase
   | Opt_SpecConstr
410
411
412
413
414
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
   | Opt_UnboxStrictFields
415
   | Opt_UnboxSmallStrictFields
416
   | Opt_DictsCheap
417
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
418
   | Opt_Vectorise
419
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
420
421
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
422
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
423
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
424
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
425
   | Opt_LlvmFillUndefWithGarbage       -- Testing for undef bugs (hidden flag)
426
   | Opt_IrrefutableTuples
427
   | Opt_CmmSink
428
   | Opt_CmmElimCommonBlocks
429
   | Opt_OmitYields
430
   | Opt_SimpleListLiterals
431
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
432
433
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
434
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
435
   | Opt_CprAnal
436
   | Opt_WorkerWrapper
437

438
439
440
441
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
442
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
443

Ian Lynagh's avatar
Ian Lynagh committed
444
445
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
446
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
447

448
449
   -- misc opts
   | Opt_Pp
450
   | Opt_ForceRecomp
451
   | Opt_ExcessPrecision
452
   | Opt_EagerBlackHoling
453
454
   | Opt_NoHsMain
   | Opt_SplitObjs
455
   | Opt_SplitSections
456
   | Opt_StgStats
457
   | Opt_HideAllPackages
458
   | Opt_HideAllPluginPackages
459
   | Opt_PrintBindResult
460
   | Opt_Haddock
David Waern's avatar
David Waern committed
461
   | Opt_HaddockOptions
462
   | Opt_BreakOnException
463
   | Opt_BreakOnError
464
   | Opt_PrintEvldWithShow
465
   | Opt_PrintBindContents
466
467
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
468
   | Opt_SharedImplib
469
   | Opt_BuildingCabalPackage
470
   | Opt_IgnoreDotGhci
471
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
472
   | Opt_GhciHistory
473
   | Opt_HelpfulErrors
474
   | Opt_DeferTypeErrors
475
   | Opt_DeferTypedHoles
Ian Lynagh's avatar
Ian Lynagh committed
476
   | Opt_PIC
477
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
478
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
479
480
481
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
482
   | Opt_RPath
483
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
484
   | Opt_Hpc
485
   | Opt_FlatCache
486
   | Opt_ExternalInterpreter
487

488
489
490
491
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

492
   -- output style opts
493
494
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
495
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
496
   | Opt_PprShowTicks
497

498
499
500
501
502
503
504
505
506
507
508
   -- 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
509
510
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
511
512
513
514
515
516
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

517
   -- temporary flags
518
   | Opt_AutoLinkPackages
519
   | Opt_ImplicitImportQualified
520
521
522
523
524
525

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
526
   | Opt_KeepRawTokenStream
527
   | Opt_KeepLlvmFiles
528

529
530
   | Opt_BuildDynamicToo

531
   -- safe haskell flags
dterei's avatar
dterei committed
532
   | Opt_DistrustAllPackages
533
   | Opt_PackageTrust
534
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
535

536
data WarningFlag =
537
-- See Note [Updating flag description in the User's Guide]
538
     Opt_WarnDuplicateExports
539
   | Opt_WarnDuplicateConstraints
540
   | Opt_WarnRedundantConstraints
541
542
543
544
545
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
546
   | Opt_WarnOverflowedLiterals
547
   | Opt_WarnEmptyEnumerations
548
549
550
551
552
553
554
555
556
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
   | Opt_WarnMissingSigs
   | Opt_WarnMissingLocalSigs
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
557
558
559
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
560
561
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
562
563
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
564
   | Opt_WarnContextQuantification -- remove in 8.2
565
566
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
567
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
568
   | Opt_WarnMissingMonadFailInstances -- since 8.0
569
   | Opt_WarnSemigroup -- since 8.0
570
571
572
573
574
575
576
577
578
579
580
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
581
582
   | Opt_WarnUnsafe
   | Opt_WarnSafe
583
   | Opt_WarnTrustworthySafe
584
585
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
586
   | Opt_WarnUnsupportedCallingConventions
587
   | Opt_WarnUnsupportedLlvmVersion
588
   | Opt_WarnInlineRuleShadowing
589
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
590
   | Opt_WarnPartialTypeSignatures
591
   | Opt_WarnMissingExportedSigs
carlostome's avatar
carlostome committed
592
   | Opt_WarnUntickedPromotedConstructors
593
   | Opt_WarnDerivingTypeable
594
   | Opt_WarnDeferredTypeErrors
595
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
596
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
597
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
598
   | Opt_WarnMissingPatSynSigs            -- since 8.0
599
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
600
   deriving (Eq, Show, Enum)
601

602
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
603
604
605
606
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
607

608
-- | The various Safe Haskell modes
609
610
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
611
   | Sf_Unsafe
612
613
614
615
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
616
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
617
618
619
620
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
621

622
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
623
    ppr = text . show
624

Edward Z. Yang's avatar
Edward Z. Yang committed
625
type SigOf = Map ModuleName Module
626
627

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

630
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
631
-- information relating to the compilation of a single file or GHC session
632
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
633
634
635
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
636
  settings              :: Settings,
637
638
  -- See Note [Signature parameters in TcGblEnv and DynFlags]
  sigOf                 :: SigOf,       -- ^ Compiling an hs-boot against impl.
639
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
640
  optLevel              :: Int,         -- ^ Optimisation level
641
  debugLevel            :: Int,         -- ^ How much debug information to produce
642
643
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
644
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
645
  ruleCheck             :: Maybe String,
646
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
647

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

652
653
654
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

655
656
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
657
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
658
659
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
660
661
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
662
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
663
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
664
                                        --   See CoreMonad.FloatOutSwitches
665

666
  historySize           :: Int,
667

Ian Lynagh's avatar
Ian Lynagh committed
668
669
670
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
671
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
672
673
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
674

675
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
676
677

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

682
683
684
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

685
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
686
  objectDir             :: Maybe String,
687
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
688
689
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
690
  dumpDir               :: Maybe String,
691

Ian Lynagh's avatar
Ian Lynagh committed
692
693
694
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
695

696
697
698
699
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

700
701
702
703
704
705
706
707
  -- 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
708
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
709
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
710
711
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
712

713
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
714
715
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
716

717
718
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
719
720
  dumpPrefixForce       :: Maybe FilePath,

721
  ldInputs              :: [Option],
722

Ian Lynagh's avatar
Ian Lynagh committed
723
724
725
726
727
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

728
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
729
  rtsOptsEnabled        :: RtsOptsEnabled,
730
  rtsOptsSuggestions    :: Bool,
731

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

734
735
736
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
737
  frontendPluginOpts    :: [String],
738

739
740
741
  -- GHC API hooks
  hooks                 :: Hooks,

742
743
744
745
746
747
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

748
  --  Package flags
749
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
750
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
751
        -- they appeared.
752

753
754
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
755
  packageFlags          :: [PackageFlag],
756
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
757
758
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
759
760
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
761
762
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
763

764
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
765
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
766
  -- Packages.initPackages
767
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
768
  pkgState              :: PackageState,
769

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

779
780
781
  -- Names of files which were generated from -ddump-to-file; used to
  -- track which ones we need to truncate because it's our first run
  -- through
782
  generatedDumps        :: IORef (Set FilePath),
783

784
  -- hsc dynamic flags
785
786
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
787
  warningFlags          :: IntSet,
788
  -- Don't change this without updating extensionFlags:
789
  language              :: Maybe Language,
790
791
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
792
793
  safeInfer             :: Bool,
  safeInferred          :: Bool,
794
795
796
  -- We store the location of where some extension and flags were turned on so
  -- we can produce accurate error messages when Safe Haskell fails due to
  -- them.
797
798
  thOnLoc               :: SrcSpan,
  newDerivOnLoc         :: SrcSpan,
799
  overlapInstLoc        :: SrcSpan,
800
  incoherentOnLoc       :: SrcSpan,
801
  pkgTrustOnLoc         :: SrcSpan,
802
803
  warnSafeOnLoc         :: SrcSpan,
  warnUnsafeOnLoc       :: SrcSpan,
804
  trustworthyOnLoc      :: SrcSpan,
805
  -- Don't change this without updating extensionFlags:
806
  extensions            :: [OnOff LangExt.Extension],
807
808
  -- extensionFlags should always be equal to
  --     flattenExtensionFlags language extensions
809
810
  -- LangExt.Extension is defined in libraries/ghc-boot so that it can be used
  -- by template-haskell
811
  extensionFlags        :: IntSet,
Ian Lynagh's avatar
Ian Lynagh committed
812

813
814
815
816
817
818
819
820
821
  -- Unfolding control
  -- See Note [Discounts and thresholds] in CoreUnfold
  ufCreationThreshold   :: Int,
  ufUseThreshold        :: Int,
  ufFunAppDiscount      :: Int,
  ufDictDiscount        :: Int,
  ufKeenessFactor       :: Float,
  ufDearOp              :: Int,

822
823
  maxWorkerArgs         :: Int,