DynFlags.hs 232 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(..),
27
        FatalMessager, LogAction, LogFinaliser, FlushOut(..), FlushErr(..),
28
        ProfAuto(..),
29
        glasgowExtsFlags,
30
        warningGroups, warningHierarchies,
Sylvain Henry's avatar
Sylvain Henry committed
31
        hasPprDebug, hasNoDebugOutput, hasNoStateHack, hasNoOptCoercion,
32
        dopt, dopt_set, dopt_unset,
triple's avatar
triple committed
33
        gopt, gopt_set, gopt_unset, setGeneralFlag', unSetGeneralFlag',
34
        wopt, wopt_set, wopt_unset,
35
        wopt_fatal,
36
        xopt, xopt_set, xopt_unset,
37
        lang_set,
38
        useUnicodeSyntax,
39
40
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
41
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
42
        DynFlags(..),
43
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
44
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
45
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
46
        HscTarget(..), isObjectTarget, defaultObjectTarget,
47
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
48
49
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
50
        PackageFlag(..), PackageArg(..), ModRenaming(..),
51
        packageFlagsChanged,
52
        IgnorePackageFlag(..), TrustFlag(..),
53
        PackageDBFlag(..), PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
54
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
55
        DynLibLoader(..),
56
57
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
58
        dynFlagDependencies,
59
        tablesNextToCode, mkTablesNextToCode,
Ben Gamari's avatar
Ben Gamari committed
60
        makeDynFlagsConsistent,
Rufflewind's avatar
Rufflewind committed
61
        shouldUseColor,
Andrew Martin's avatar
Andrew Martin committed
62
        shouldUseHexWordLiterals,
63
        positionIndependent,
64
        optimisationFlags,
65

66
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
67
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
68

69
70
        thisPackage, thisComponentId, thisUnitIdInsts,

Ben Gamari's avatar
Ben Gamari committed
71
72
73
        -- ** Log output
        putLogMsg,

74
        -- ** Safe Haskell
75
        SafeHaskellMode(..),
76
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
77
        packageTrustOn,
78
        safeDirectImpsReq, safeImplicitImpsReq,
79
        unsafeFlags, unsafeFlagsForInfer,
80

Moritz Angermann's avatar
Moritz Angermann committed
81
82
83
        -- ** LLVM Targets
        LlvmTarget(..), LlvmTargets,

84
        -- ** System tool settings and locations
85
        Settings(..),
86
        targetPlatform, programName, projectVersion,
87
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
Edsko de Vries's avatar
Edsko de Vries committed
88
        versionedAppDir,
89
90
        extraGccViaCFlags, systemPackageConfig,
        pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
Moritz Angermann's avatar
Moritz Angermann committed
91
92
        pgm_windres, pgm_libtool, pgm_ar, pgm_ranlib, pgm_lo, pgm_lc,
        pgm_lcc, pgm_i, opt_L, opt_P, opt_F, opt_c, opt_a, opt_l, opt_i,
niteria's avatar
niteria committed
93
        opt_P_signature,
Moritz Angermann's avatar
Moritz Angermann committed
94
        opt_windres, opt_lo, opt_lc, opt_lcc,
95

96
        -- ** Manipulating DynFlags
97
        addPluginModuleName,
98
        defaultDynFlags,                -- Settings -> DynFlags
99
        defaultWays,
ian@well-typed.com's avatar
ian@well-typed.com committed
100
        interpWays,
101
        interpreterProfiled, interpreterDynamic,
Ian Lynagh's avatar
Ian Lynagh committed
102
        initDynFlags,                   -- DynFlags -> IO DynFlags
Ian Lynagh's avatar
Ian Lynagh committed
103
        defaultFatalMessager,
104
        defaultLogAction,
105
        defaultLogActionHPrintDoc,
106
        defaultLogActionHPutStrDoc,
107
108
        defaultFlushOut,
        defaultFlushErr,
Ian Lynagh's avatar
Ian Lynagh committed
109

110
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
111
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
112
113
        updOptLevel,
        setTmpDir,
114
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
115
        interpretPackageEnv,
Edward Z. Yang's avatar
Edward Z. Yang committed
116
        canonicalizeHomeModule,
Ian Lynagh's avatar
Ian Lynagh committed
117

118
        -- ** Parsing DynFlags
119
120
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
121
122
123
        parseDynamicFlagsFull,

        -- ** Available DynFlags
124
        allNonDeprecatedFlags,
125
126
127
        flagsAll,
        flagsDynamic,
        flagsPackage,
128
        flagsForCompletion,
129

130
        supportedLanguagesAndExtensions,
131
        languageExtensions,
132

133
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
134
        picCCOpts, picPOpts,
135
136

        -- * Compiler configuration suitable for display to the user
137
138
139
        compilerInfo,

        rtsIsProfiled,
140
        dynamicGhc,
141

142
#include "GHCConstantsHaskellExports.hs"
143
        bLOCK_SIZE_W,
144
        wORD_SIZE_IN_BITS,
145
146
        tAG_MASK,
        mAX_PTR_TAG,
147
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
148

149
150
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

151
        -- * SSE and AVX
152
        isSseEnabled,
153
154
        isSse2Enabled,
        isSse4_2Enabled,
155
156
        isBmiEnabled,
        isBmi2Enabled,
157
158
        isAvxEnabled,
        isAvx2Enabled,
159
160
161
162
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
163

Austin Seipp's avatar
Austin Seipp committed
164
        -- * Linker/compiler information
165
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
166
        CompilerInfo(..),
Douglas Wilson's avatar
Douglas Wilson committed
167
168

        -- * File cleanup
169
170
171
172
        FilesToClean(..), emptyFilesToClean,

        -- * Include specifications
        IncludeSpecs(..), addGlobalInclude, addQuoteInclude, flattenIncludes
173
174
175
176
  ) where

#include "HsVersions.h"

177
178
import GhcPrelude

179
import Platform
180
import PlatformConstants
181
import Module
Simon Marlow's avatar
Simon Marlow committed
182
import PackageConfig
Matthew Pickering's avatar
Matthew Pickering committed
183
import {-# SOURCE #-} Plugins
184
import {-# SOURCE #-} Hooks
185
import {-# SOURCE #-} PrelNames ( mAIN )
186
import {-# SOURCE #-} Packages (PackageState, emptyPackageState)
Ian Lynagh's avatar
Ian Lynagh committed
187
import DriverPhases     ( Phase(..), phaseInputExt )
188
import Config
189
190
import CmdLineParser hiding (WarnReason(..))
import qualified CmdLineParser as Cmd
191
import Constants
192
import Panic
Rufflewind's avatar
Rufflewind committed
193
import qualified PprColour as Col
194
import Util
Edsko de Vries's avatar
Edsko de Vries committed
195
import Maybes
196
import MonadUtils
197
import qualified Pretty
198
import SrcLoc
199
import BasicTypes       ( IntWithInf, treatZeroAsInf )
200
import FastString
niteria's avatar
niteria committed
201
import Fingerprint
Simon Marlow's avatar
Simon Marlow committed
202
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
203
import Foreign.C        ( CInt(..) )
204
import System.IO.Unsafe ( unsafeDupablePerformIO )
Rufflewind's avatar
Rufflewind committed
205
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn
206
207
                               , getCaretDiagnostic, dumpSDoc )
import Json
208
import SysTools.Terminal ( stderrSupportsAnsiColors )
209
import SysTools.BaseDir ( expandTopDir )
210

211
import System.IO.Unsafe ( unsafePerformIO )
212
import Data.IORef
213
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
214
import Control.Monad
215
216
217
218
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
219
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
220

221
import Data.Ord
222
import Data.Bits
223
import Data.Char
224
import Data.Int
225
import Data.List
226
227
import Data.Map (Map)
import qualified Data.Map as Map
228
229
import Data.Set (Set)
import qualified Data.Set as Set
230
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
231
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
232
import System.Directory
Rufflewind's avatar
Rufflewind committed
233
import System.Environment (getEnv, lookupEnv)
234
import System.IO
235
import System.IO.Error
236
237
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
238

239
240
import EnumSet (EnumSet)
import qualified EnumSet
241

242
import GHC.Foreign (withCString, peekCString)
243
import qualified GHC.LanguageExtensions as LangExt
244

245
import Foreign (Ptr) -- needed for 2nd stage
Moritz Angermann's avatar
Moritz Angermann committed
246

247
248
249
250
-- Note [Updating flag description in the User's Guide]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- If you modify anything in this file please make sure that your changes are
Ben Gamari's avatar
Ben Gamari committed
251
252
-- described in the User's Guide. Please update the flag description in the
-- users guide (docs/users_guide) whenever you add or change a flag.
253

254
255
256
257
258
259
260
261
262
263
264
265
-- 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.

266
267
268
269
270
271
272
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
273
274
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
--
--  * 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.

319
320
321
-- -----------------------------------------------------------------------------
-- DynFlags

322
data DumpFlag
323
-- See Note [Updating flag description in the User's Guide]
324
325
326

   -- debugging flags
   = Opt_D_dump_cmm
327
   | Opt_D_dump_cmm_from_stg
328
   | Opt_D_dump_cmm_raw
329
330
331
332
   | 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.
333
334
   | Opt_D_dump_cmm_cfg
   | Opt_D_dump_cmm_cbe
335
   | Opt_D_dump_cmm_switch
336
337
   | Opt_D_dump_cmm_proc
   | Opt_D_dump_cmm_sp
338
339
   | Opt_D_dump_cmm_sink
   | Opt_D_dump_cmm_caf
340
341
342
343
344
   | Opt_D_dump_cmm_procmap
   | Opt_D_dump_cmm_split
   | Opt_D_dump_cmm_info
   | Opt_D_dump_cmm_cps
   -- end cmm subflags
345
   | Opt_D_dump_asm
346
347
348
349
350
   | 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
351
   | Opt_D_dump_asm_stats
352
   | Opt_D_dump_asm_expanded
353
   | Opt_D_dump_llvm
354
   | Opt_D_dump_core_stats
355
356
   | Opt_D_dump_deriv
   | Opt_D_dump_ds
Simon Peyton Jones's avatar
Simon Peyton Jones committed
357
   | Opt_D_dump_ds_preopt
358
359
   | Opt_D_dump_foreign
   | Opt_D_dump_inlinings
360
   | Opt_D_dump_rule_firings
361
   | Opt_D_dump_rule_rewrites
362
   | Opt_D_dump_simpl_trace
363
364
   | Opt_D_dump_occur_anal
   | Opt_D_dump_parsed
365
   | Opt_D_dump_parsed_ast
366
   | Opt_D_dump_rn
367
   | Opt_D_dump_rn_ast
Edward Z. Yang's avatar
Edward Z. Yang committed
368
   | Opt_D_dump_shape
369
370
371
372
373
   | Opt_D_dump_simpl
   | Opt_D_dump_simpl_iterations
   | Opt_D_dump_spec
   | Opt_D_dump_prep
   | Opt_D_dump_stg
374
   | Opt_D_dump_call_arity
375
   | Opt_D_dump_exitify
376
   | Opt_D_dump_stranal
manav's avatar
manav committed
377
   | Opt_D_dump_str_signatures
378
   | Opt_D_dump_tc
379
   | Opt_D_dump_tc_ast
380
381
382
383
384
385
386
387
   | 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
388
   | Opt_D_dump_cs_trace -- Constraint solver in type checker
389
   | Opt_D_dump_tc_trace
390
   | Opt_D_dump_ec_trace -- Pattern match exhaustiveness checker
391
   | Opt_D_dump_if_trace
392
   | Opt_D_dump_vt_trace
393
   | Opt_D_dump_splices
394
   | Opt_D_th_dec_file
395
396
   | Opt_D_dump_BCOs
   | Opt_D_dump_vect
397
   | Opt_D_dump_ticked
pepe's avatar
pepe committed
398
   | Opt_D_dump_rtti
399
400
401
402
   | Opt_D_source_stats
   | Opt_D_verbose_stg2stg
   | Opt_D_dump_hi
   | Opt_D_dump_hi_diffs
403
   | Opt_D_dump_mod_cycles
404
   | Opt_D_dump_mod_map
Ben Gamari's avatar
Ben Gamari committed
405
   | Opt_D_dump_timings
406
   | Opt_D_dump_view_pattern_commoning
407
   | Opt_D_verbose_core2core
408
   | Opt_D_dump_debug
409
   | Opt_D_dump_json
Sylvain Henry's avatar
Sylvain Henry committed
410
411
   | Opt_D_ppr_debug
   | Opt_D_no_debug_output
412
413
   deriving (Eq, Show, Enum)

414

415
416
-- | Enumerates the simple on-or-off dynamic flags
data GeneralFlag
417
-- See Note [Updating flag description in the User's Guide]
418
419

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
420
   | Opt_D_faststring_stats
421
   | Opt_D_dump_minimal_imports
422
423
424
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
425
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
426
   | Opt_DoAnnotationLinting
427
   | Opt_NoLlvmMangler                 -- hidden flag
Moritz Angermann's avatar
Moritz Angermann committed
428
   | Opt_FastLlvm                      -- hidden flag
429

Ian Lynagh's avatar
Ian Lynagh committed
430
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
431
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
432
   | Opt_HideSourcePaths                -- Hide module source/object paths
433

434
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
435
   | Opt_PrintExplicitKinds
436
   | Opt_PrintExplicitCoercions
437
   | Opt_PrintExplicitRuntimeReps
438
   | Opt_PrintEqualityRelations
439
   | Opt_PrintUnicodeSyntax
440
   | Opt_PrintExpandedSynonyms
441
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
442
   | Opt_PrintTypecheckerElaboration
443

444
   -- optimisation opts
445
   | Opt_CallArity
446
   | Opt_Exitification
447
   | Opt_Strictness
Ömer Sinan Ağacan's avatar
Ömer Sinan Ağacan committed
448
   | Opt_LateDmdAnal                    -- #6087
449
450
   | Opt_KillAbsence
   | Opt_KillOneShot
451
   | Opt_FullLaziness
452
   | Opt_FloatIn
453
   | Opt_LateSpecialise
454
   | Opt_Specialise
455
   | Opt_SpecialiseAggressively
456
   | Opt_CrossModuleSpecialise
457
   | Opt_StaticArgumentTransformation
458
   | Opt_CSE
459
   | Opt_StgCSE
460
461
   | Opt_LiberateCase
   | Opt_SpecConstr
Simon Peyton Jones's avatar
Simon Peyton Jones committed
462
   | Opt_SpecConstrKeen
463
464
465
466
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
Sylvain Henry's avatar
Sylvain Henry committed
467
   | Opt_CaseFolding                    -- Constant folding through case-expressions
468
   | Opt_UnboxStrictFields
469
   | Opt_UnboxSmallStrictFields
470
   | Opt_DictsCheap
471
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
472
   | Opt_Vectorise
473
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
474
475
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
476
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
477
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
478
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
479
   | Opt_LlvmFillUndefWithGarbage       -- Testing for undef bugs (hidden flag)
480
   | Opt_IrrefutableTuples
481
   | Opt_CmmSink
482
   | Opt_CmmElimCommonBlocks
483
   | Opt_OmitYields
484
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
485
486
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
487
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
488
   | Opt_CprAnal
489
   | Opt_WorkerWrapper
490
   | Opt_SolveConstantDicts
Ben Gamari's avatar
Ben Gamari committed
491
   | Opt_AlignmentSanitisation
Ben Gamari's avatar
Ben Gamari committed
492
   | Opt_CatchBottoms
493

494
495
496
497
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

498
499
500
501
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
502
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
503

Ian Lynagh's avatar
Ian Lynagh committed
504
505
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
506
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
507

508
509
   -- misc opts
   | Opt_Pp
510
   | Opt_ForceRecomp
511
512
   | Opt_IgnoreOptimChanges
   | Opt_IgnoreHpcChanges
513
   | Opt_ExcessPrecision
514
   | Opt_EagerBlackHoling
515
516
   | Opt_NoHsMain
   | Opt_SplitObjs
517
   | Opt_SplitSections
518
   | Opt_StgStats
519
   | Opt_HideAllPackages
520
   | Opt_HideAllPluginPackages
521
   | Opt_PrintBindResult
522
   | Opt_Haddock
David Waern's avatar
David Waern committed
523
   | Opt_HaddockOptions
524
   | Opt_BreakOnException
525
   | Opt_BreakOnError
526
   | Opt_PrintEvldWithShow
527
   | Opt_PrintBindContents
528
529
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
530
   | Opt_SharedImplib
531
   | Opt_BuildingCabalPackage
532
   | Opt_IgnoreDotGhci
533
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
534
   | Opt_GhciHistory
535
   | Opt_LocalGhciHistory
Matthew Pickering's avatar
Matthew Pickering committed
536
   | Opt_NoIt
537
   | Opt_HelpfulErrors
538
   | Opt_DeferTypeErrors
539
   | Opt_DeferTypedHoles
540
   | Opt_DeferOutOfScopeVariables
541
542
543
   | Opt_PIC                         -- ^ @-fPIC@
   | Opt_PIE                         -- ^ @-fPIE@
   | Opt_PICExecutable               -- ^ @-pie@
Simon Marlow's avatar
Simon Marlow committed
544
   | Opt_ExternalDynamicRefs
545
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
546
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
547
548
549
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
550
   | Opt_RPath
551
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
552
   | Opt_Hpc
553
   | Opt_FlatCache
554
   | Opt_ExternalInterpreter
Simon Marlow's avatar
Simon Marlow committed
555
   | Opt_OptimalApplicativeDo
556
   | Opt_VersionMacros
Simon Marlow's avatar
Simon Marlow committed
557
   | Opt_WholeArchiveHsLibs
558

559
   -- output style opts
560
561
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
Rufflewind's avatar
Rufflewind committed
562
   | Opt_DiagnosticsShowCaret -- Show snippets of offending code
563
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
564
   | Opt_PprShowTicks
565
   | Opt_ShowHoleConstraints
566
   | Opt_NoShowValidSubstitutions
567
   | Opt_UnclutterValidSubstitutions
568
   | Opt_NoSortValidSubstitutions
569
   | Opt_AbstractRefSubstitutions
570
   | Opt_ShowLoadedModules
Andrew Martin's avatar
Andrew Martin committed
571
   | Opt_HexWordLiterals -- See Note [Print Hexadecimal Literals]
572

573
574
575
576
577
578
579
580
581
582
583
   -- 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
584
585
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
586
587
588
589
590
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques
591
   | Opt_SuppressStgFreeVars
592
   | Opt_SuppressTicks     -- Replaces Opt_PprShowTicks
593
   | Opt_SuppressTimestamps -- ^ Suppress timestamps in dumps
594

595
   -- temporary flags
596
   | Opt_AutoLinkPackages
597
   | Opt_ImplicitImportQualified
598
599
600
601
602
603

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
604
   | Opt_KeepRawTokenStream
605
   | Opt_KeepLlvmFiles
606
607
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
608

609
610
   | Opt_BuildDynamicToo

611
   -- safe haskell flags
dterei's avatar
dterei committed
612
   | Opt_DistrustAllPackages
613
   | Opt_PackageTrust
Sylvain Henry's avatar
Sylvain Henry committed
614
615
616

   | Opt_G_NoStateHack
   | Opt_G_NoOptCoercion
617
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
-- Check whether a flag should be considered an "optimisation flag"
-- for purposes of recompilation avoidance (see
-- Note [Ignoring some flag changes] in FlagChecker). Being listed here is
-- not a guarantee that the flag has no other effect. We could, and
-- perhaps should, separate out the flags that have some minor impact on
-- program semantics and/or error behavior (e.g., assertions), but
-- then we'd need to go to extra trouble (and an additional flag)
-- to allow users to ignore the optimisation level even though that
-- means ignoring some change.
optimisationFlags :: EnumSet GeneralFlag
optimisationFlags = EnumSet.fromList
   [ Opt_CallArity
   , Opt_Strictness
   , Opt_LateDmdAnal
   , Opt_KillAbsence
   , Opt_KillOneShot
   , Opt_FullLaziness
   , Opt_FloatIn
637
   , Opt_LateSpecialise
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
   , Opt_Specialise
   , Opt_SpecialiseAggressively
   , Opt_CrossModuleSpecialise
   , Opt_StaticArgumentTransformation
   , Opt_CSE
   , Opt_StgCSE
   , Opt_LiberateCase
   , Opt_SpecConstr
   , Opt_SpecConstrKeen
   , Opt_DoLambdaEtaExpansion
   , Opt_IgnoreAsserts
   , Opt_DoEtaReduction
   , Opt_CaseMerge
   , Opt_CaseFolding
   , Opt_UnboxStrictFields
   , Opt_UnboxSmallStrictFields
   , Opt_DictsCheap
   , Opt_EnableRewriteRules
   , Opt_Vectorise
   , Opt_VectorisationAvoidance
   , Opt_RegsGraph
   , Opt_RegsIterative
   , Opt_PedanticBottoms
   , Opt_LlvmTBAA
   , Opt_LlvmPassVectorsInRegisters
   , Opt_LlvmFillUndefWithGarbage
   , Opt_IrrefutableTuples
   , Opt_CmmSink
   , Opt_CmmElimCommonBlocks
   , Opt_OmitYields
   , Opt_FunToThunk
   , Opt_DictsStrict
   , Opt_DmdTxDictSel
   , Opt_Loopification
   , Opt_CprAnal
   , Opt_WorkerWrapper
   , Opt_SolveConstantDicts
   , Opt_CatchBottoms
   , Opt_IgnoreAsserts
   ]

679
680
681
-- | 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.
682
683
684
685
686
687
data WarnReason
  = NoReason
  -- | Warning was enabled with the flag
  | Reason !WarningFlag
  -- | Warning was made an error because of -Werror or -Werror=WarningFlag
  | ErrReason !(Maybe WarningFlag)
Richard Eisenberg's avatar
Richard Eisenberg committed
688
689
  deriving Show

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
-- | Used to differentiate the scope an include needs to apply to.
-- We have to split the include paths to avoid accidentally forcing recursive
-- includes since -I overrides the system search paths. See Trac #14312.
data IncludeSpecs
  = IncludeSpecs { includePathsQuote  :: [String]
                 , includePathsGlobal :: [String]
                 }
  deriving Show

-- | Append to the list of includes a path that shall be included using `-I`
-- when the C compiler is called. These paths override system search paths.
addGlobalInclude :: IncludeSpecs -> [String] -> IncludeSpecs
addGlobalInclude spec paths  = let f = includePathsGlobal spec
                               in spec { includePathsGlobal = f ++ paths }

-- | Append to the list of includes a path that shall be included using
-- `-iquote` when the C compiler is called. These paths only apply when quoted
-- includes are used. e.g. #include "foo.h"
addQuoteInclude :: IncludeSpecs -> [String] -> IncludeSpecs
addQuoteInclude spec paths  = let f = includePathsQuote spec
                              in spec { includePathsQuote = f ++ paths }

-- | Concatenate and flatten the list of global and quoted includes returning
-- just a flat list of paths.
flattenIncludes :: IncludeSpecs -> [String]
flattenIncludes specs = includePathsQuote specs ++ includePathsGlobal specs

Richard Eisenberg's avatar
Richard Eisenberg committed
717
718
instance Outputable WarnReason where
  ppr = text . show
719

720
721
722
instance ToJson WarnReason where
  json NoReason = JSNull
  json (Reason wf) = JSString (show wf)
723
724
  json (ErrReason Nothing) = JSString "Opt_WarnIsError"
  json (ErrReason (Just wf)) = JSString (show wf)
725

726
data WarningFlag =
727
-- See Note [Updating flag description in the User's Guide]
728
     Opt_WarnDuplicateExports
729
   | Opt_WarnDuplicateConstraints
730
   | Opt_WarnRedundantConstraints
731
732
733
734
735
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
736
   | Opt_WarnOverflowedLiterals
737
   | Opt_WarnEmptyEnumerations
738
739
740
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
741
742
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
743
744
745
746
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
747
748
749
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
750
751
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
752
753
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
754
755
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
756
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
757
   | Opt_WarnMissingMonadFailInstances -- since 8.0
758
   | Opt_WarnSemigroup -- since 8.0
759
760
761
762
763
764
765
766
767
768
769
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
770
771
   | Opt_WarnUnsafe
   | Opt_WarnSafe
772
   | Opt_WarnTrustworthySafe
773
774
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
775
   | Opt_WarnUnsupportedCallingConventions
776
   | Opt_WarnUnsupportedLlvmVersion
777
   | Opt_WarnInlineRuleShadowing
778
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
779
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
780
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
781
   | Opt_WarnUntickedPromotedConstructors
782
   | Opt_WarnDerivingTypeable
783
   | Opt_WarnDeferredTypeErrors
784
   | Opt_WarnDeferredOutOfScopeVariables
785
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
786
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
787
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
788
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
789
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
790
   | Opt_WarnSimplifiableClassConstraints -- Since 8.2
791
   | Opt_WarnCPPUndef                     -- Since 8.2
Richard Eisenberg's avatar
Richard Eisenberg committed
792
   | Opt_WarnUnbangedStrictPatterns       -- Since 8.2
Yuras's avatar
Yuras committed
793
   | Opt_WarnMissingHomeModules           -- Since 8.2
794
   | Opt_WarnPartialFields                -- Since 8.4
795
   | Opt_WarnMissingExportList
796
   deriving (Eq, Show, Enum)
797

798
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
799
800
801
802
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
803

804
-- | The various Safe Haskell modes
805
806
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
807
   | Sf_Unsafe
808
809
810
811
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
812
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
813
814
815
816
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
817

818
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
819
    ppr = text . show
820

821
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
822
-- information relating to the compilation of a single file or GHC session
823
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
824
825
826
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
827
  settings              :: Settings,
Moritz Angermann's avatar
Moritz Angermann committed
828
  llvmTargets           :: LlvmTargets,
829
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
830
  optLevel              :: Int,         -- ^ Optimisation level
831
  debugLevel            :: Int,         -- ^ How much debug information to produce
832
833
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
834
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
835
  ruleCheck             :: Maybe String,
836
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
837

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

842
843
844
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

845
846
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
847
848
  maxValidSubstitutions :: Maybe Int,   -- ^ Maximum number of substitutions to
                                        --   show in typed hole error messages
849
850
851
852
853
854
  maxRefSubstitutions   :: Maybe Int,   -- ^ Maximum number of refinement
                                        --   substitutions to show in typed hole
                                        --   error messages
  refLevelSubstitutions :: Maybe Int,   -- ^ Maximum level of refinement for
                                        --   refinement substitutions in typed
                                        --   typed hole error messages
855
856
  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
                                        --   in non-exhaustiveness warnings
857
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
858
859
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
860
861
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
862
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
863
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating