DynFlags.hs 208 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(..), WarnReason(..),
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
        allNonDeprecatedFlags,
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
niteria's avatar
niteria committed
167
import UniqFM
Edsko de Vries's avatar
Edsko de Vries committed
168
import Maybes
169
import MonadUtils
170
import qualified Pretty
171
import SrcLoc
172
import BasicTypes       ( IntWithInf, treatZeroAsInf )
173
import FastString
Simon Marlow's avatar
Simon Marlow committed
174
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
175
import Foreign.C        ( CInt(..) )
176
import System.IO.Unsafe ( unsafeDupablePerformIO )
177
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn )
178

179
import System.IO.Unsafe ( unsafePerformIO )
180
import Data.IORef
181
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
182
import Control.Monad
183
184
185
186
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
187
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
188

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

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

209
import GHC.Foreign (withCString, peekCString)
210
import qualified GHC.LanguageExtensions as LangExt
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:
--
219
220
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
221
--
222
--  * Flag description in docs/users_guide/using.rst provides a detailed
223
224
--    explanation of flags' usage.

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

237
238
239
240
241
242
243
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
244
245
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
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
289
--
--  * 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.

290
291
292
-- -----------------------------------------------------------------------------
-- DynFlags

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

   -- debugging flags
   = Opt_D_dump_cmm
298
   | Opt_D_dump_cmm_from_stg
299
   | Opt_D_dump_cmm_raw
300
301
302
303
   | Opt_D_dump_cmm_verbose
   -- All of the cmm subflags (there are a lot!) automatically
   -- enabled if you run -ddump-cmm-verbose
   -- Each flag corresponds to exact stage of Cmm pipeline.
304
305
   | Opt_D_dump_cmm_cfg
   | Opt_D_dump_cmm_cbe
306
   | Opt_D_dump_cmm_switch
307
308
   | Opt_D_dump_cmm_proc
   | Opt_D_dump_cmm_sp
309
310
   | Opt_D_dump_cmm_sink
   | Opt_D_dump_cmm_caf
311
312
313
314
315
   | Opt_D_dump_cmm_procmap
   | Opt_D_dump_cmm_split
   | Opt_D_dump_cmm_info
   | Opt_D_dump_cmm_cps
   -- end cmm subflags
316
   | Opt_D_dump_asm
317
318
319
320
321
   | 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
322
   | Opt_D_dump_asm_stats
323
   | Opt_D_dump_asm_expanded
324
   | Opt_D_dump_llvm
325
   | Opt_D_dump_core_stats
326
327
328
329
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
330
   | Opt_D_dump_rule_firings
331
   | Opt_D_dump_rule_rewrites
332
   | Opt_D_dump_simpl_trace
333
334
335
336
337
338
339
340
   | 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
341
   | Opt_D_dump_call_arity
342
   | Opt_D_dump_stranal
manav's avatar
manav committed
343
   | Opt_D_dump_str_signatures
344
345
346
347
348
349
350
351
352
   | 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
353
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
354
355
   | Opt_D_dump_tc_trace
   | Opt_D_dump_if_trace
356
   | Opt_D_dump_vt_trace
357
   | Opt_D_dump_splices
358
   | Opt_D_th_dec_file
359
360
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
361
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
362
   | Opt_D_dump_rtti
363
364
365
366
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
367
   | Opt_D_dump_mod_cycles
368
   | Opt_D_dump_mod_map
369
   | Opt_D_dump_view_pattern_commoning
370
   | Opt_D_verbose_core2core
371
   | Opt_D_dump_debug
372
373
374
375
376

   deriving (Eq, Show, Enum)

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

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

Ian Lynagh's avatar
Ian Lynagh committed
389
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
390
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
391

392
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
393
   | Opt_PrintExplicitKinds
394
   | Opt_PrintExplicitCoercions
395
   | Opt_PrintExplicitRuntimeReps
396
   | Opt_PrintEqualityRelations
397
   | Opt_PrintUnicodeSyntax
398
   | Opt_PrintExpandedSynonyms
399
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
400
   | Opt_PrintTypecheckerElaboration
401

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

444
445
446
447
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
448
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
449

Ian Lynagh's avatar
Ian Lynagh committed
450
451
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
452
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
453

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

498
499
500
501
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

502
   -- output style opts
503
504
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
505
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
506
   | Opt_PprShowTicks
507

508
509
510
511
512
513
514
515
516
517
518
   -- 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
519
520
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
521
522
523
524
525
526
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

527
   -- temporary flags
528
   | Opt_AutoLinkPackages
529
   | Opt_ImplicitImportQualified
530
531
532
533
534
535

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
536
   | Opt_KeepRawTokenStream
537
   | Opt_KeepLlvmFiles
538
539
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
540

541
542
   | Opt_BuildDynamicToo

543
   -- safe haskell flags
dterei's avatar
dterei committed
544
   | Opt_DistrustAllPackages
545
   | Opt_PackageTrust
546
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
547

548
549
550
551
552
-- | Used when outputting warnings: if a reason is given, it is
-- displayed. If a warning isn't controlled by a flag, this is made
-- explicit at the point of use.
data WarnReason = NoReason | Reason !WarningFlag

553
data WarningFlag =
554
-- See Note [Updating flag description in the User's Guide]
555
     Opt_WarnDuplicateExports
556
   | Opt_WarnDuplicateConstraints
557
   | Opt_WarnRedundantConstraints
558
559
560
561
562
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
563
   | Opt_WarnOverflowedLiterals
564
   | Opt_WarnEmptyEnumerations
565
566
567
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
568
569
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
570
571
572
573
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
574
575
576
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
577
578
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
579
580
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
581
   | Opt_WarnContextQuantification -- remove in 8.2
582
583
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
584
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
585
   | Opt_WarnMissingMonadFailInstances -- since 8.0
586
   | Opt_WarnSemigroup -- since 8.0
587
588
589
590
591
592
593
594
595
596
597
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
598
599
   | Opt_WarnUnsafe
   | Opt_WarnSafe
600
   | Opt_WarnTrustworthySafe
601
602
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
603
   | Opt_WarnUnsupportedCallingConventions
604
   | Opt_WarnUnsupportedLlvmVersion
605
   | Opt_WarnInlineRuleShadowing
606
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
607
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
608
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
609
   | Opt_WarnUntickedPromotedConstructors
610
   | Opt_WarnDerivingTypeable
611
   | Opt_WarnDeferredTypeErrors
612
   | Opt_WarnDeferredOutOfScopeVariables
613
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
614
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
615
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
616
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
617
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
618
   | Opt_WarnSimplifiableClassConstraints -- Since 8.2
619
   deriving (Eq, Show, Enum)
620

621
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
622
623
624
625
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
626

627
-- | The various Safe Haskell modes
628
629
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
630
   | Sf_Unsafe
631
632
633
634
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
635
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
636
637
638
639
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
640

641
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
642
    ppr = text . show
643

niteria's avatar
niteria committed
644
type SigOf = ModuleNameEnv Module
645
646

getSigOf :: DynFlags -> ModuleName -> Maybe Module
niteria's avatar
niteria committed
647
getSigOf dflags n = lookupUFM (sigOf dflags) n
648

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

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

671
672
673
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

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

687
  historySize           :: Int,         -- ^ Simplification history size
688

Ian Lynagh's avatar
Ian Lynagh committed
689
690
691
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
692
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
693
694
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
695

696
  thisPackage           :: UnitId,   -- ^ key of package currently being compiled
697
698

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

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

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

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

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

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

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

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

742
  ldInputs              :: [Option],
743

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

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

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

755
756
757
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
758
  frontendPluginOpts    :: [String],
759

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

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

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

774
775
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
776
  packageFlags          :: [PackageFlag],
777
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
778
779
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
780
781
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
782
783
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
784

785
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
786
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
787
  -- Packages.initPackages
788
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
789
  pkgState              :: PackageState,
790

791
792
793
794
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
795
  dirsToClean           :: IORef (Map FilePath FilePath),
796
  filesToNotIntermediateClean :: IORef [FilePath],
797
798
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
799

800
801
802
  -- 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
803
  generatedDumps        :: IORef (Set FilePath),
804

805
  -- hsc dynamic flags
806
807
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
808
  warningFlags          :: IntSet,
809
  -- Don't change this without updating extensionFlags:
810
  language              :: Maybe Language,
811
812
  -- | Safe Haskell mode
  safeHaskell           :: SafeHaskellMode,
813
814
  safeInfer             :: Bool,
  safeInferred          :: Bool,
815
816
817
  -- 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.
818
819
  thOnLoc               :: SrcSpan,
  newDerivOnLoc         :: SrcSpan,
820
  overlapInstLoc        :: SrcSpan,