DynFlags.hs 240 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, 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, wopt_set_fatal, wopt_unset_fatal,
36
        xopt, xopt_set, xopt_unset,
37
        lang_set,
38
        useUnicodeSyntax,
39
        useStarIsType,
40 41
        whenGeneratingDynamicToo, ifGeneratingDynamicToo,
        whenCannotGenerateDynamicToo,
42
        dynamicTooMkDynamicDynFlags,
Ian Lynagh's avatar
Ian Lynagh committed
43
        DynFlags(..),
44
        FlagSpec(..),
Ian Lynagh's avatar
Ian Lynagh committed
45
        HasDynFlags(..), ContainsDynFlags(..),
Ian Lynagh's avatar
Ian Lynagh committed
46
        RtsOptsEnabled(..),
Ian Lynagh's avatar
Ian Lynagh committed
47
        HscTarget(..), isObjectTarget, defaultObjectTarget,
48
        targetRetainsAllBindings,
Ian Lynagh's avatar
Ian Lynagh committed
49 50
        GhcMode(..), isOneShot,
        GhcLink(..), isNoLink,
51
        PackageFlag(..), PackageArg(..), ModRenaming(..),
52
        packageFlagsChanged,
53
        IgnorePackageFlag(..), TrustFlag(..),
54
        PackageDBFlag(..), PkgConfRef(..),
Ian Lynagh's avatar
Ian Lynagh committed
55
        Option(..), showOpt,
Ian Lynagh's avatar
Ian Lynagh committed
56
        DynLibLoader(..),
57 58
        fFlags, fLangFlags, xFlags,
        wWarningFlags,
59
        dynFlagDependencies,
60
        tablesNextToCode, mkTablesNextToCode,
Ben Gamari's avatar
Ben Gamari committed
61
        makeDynFlagsConsistent,
Rufflewind's avatar
Rufflewind committed
62
        shouldUseColor,
Andrew Martin's avatar
Andrew Martin committed
63
        shouldUseHexWordLiterals,
64
        positionIndependent,
65
        optimisationFlags,
66

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

70 71
        thisPackage, thisComponentId, thisUnitIdInsts,

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

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

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

85
        -- ** System tool settings and locations
86
        Settings(..),
87
        targetPlatform, programName, projectVersion,
88
        ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
Edsko de Vries's avatar
Edsko de Vries committed
89
        versionedAppDir,
90 91
        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
92 93
        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
94
        opt_P_signature,
Moritz Angermann's avatar
Moritz Angermann committed
95
        opt_windres, opt_lo, opt_lc, opt_lcc,
96

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

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

120
        -- ** Parsing DynFlags
121 122
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
123 124 125
        parseDynamicFlagsFull,

        -- ** Available DynFlags
126
        allNonDeprecatedFlags,
127 128 129
        flagsAll,
        flagsDynamic,
        flagsPackage,
130
        flagsForCompletion,
131

132
        supportedLanguagesAndExtensions,
133
        languageExtensions,
134

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

        -- * Compiler configuration suitable for display to the user
139 140 141
        compilerInfo,

        rtsIsProfiled,
142
        dynamicGhc,
143

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

151 152
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

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

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

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

        -- * Include specifications
174 175 176 177 178
        IncludeSpecs(..), addGlobalInclude, addQuoteInclude, flattenIncludes,


        -- * Make use of the Cmm CFG
        CfgWeights(..), backendMaintainsCfg
179 180 181 182
  ) where

#include "HsVersions.h"

183 184
import GhcPrelude

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

217
import System.IO.Unsafe ( unsafePerformIO )
218
import Data.IORef
219
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
220
import Control.Monad
221 222 223 224
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
225
import Control.Exception (throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
226

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

245 246
import EnumSet (EnumSet)
import qualified EnumSet
247

248
import GHC.Foreign (withCString, peekCString)
249
import qualified GHC.LanguageExtensions as LangExt
250

David Eichmann's avatar
David Eichmann committed
251
#if defined(GHCI)
252
import Foreign (Ptr) -- needed for 2nd stage
David Eichmann's avatar
David Eichmann committed
253
#endif
Moritz Angermann's avatar
Moritz Angermann committed
254

255 256 257 258
-- 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
259 260
-- 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.
261

262 263 264 265 266 267 268 269 270 271 272 273
-- 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.

274 275 276 277 278 279 280
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
281 282
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
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 319 320 321 322 323 324 325 326
--
--  * 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.

327 328 329
-- -----------------------------------------------------------------------------
-- DynFlags

330
data DumpFlag
331
-- See Note [Updating flag description in the User's Guide]
332 333 334

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

422

423 424
-- | Enumerates the simple on-or-off dynamic flags
data GeneralFlag
425
-- See Note [Updating flag description in the User's Guide]
426 427

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
428
   | Opt_D_faststring_stats
429
   | Opt_D_dump_minimal_imports
430 431 432
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
433
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
434
   | Opt_DoAnnotationLinting
435
   | Opt_NoLlvmMangler                 -- hidden flag
Moritz Angermann's avatar
Moritz Angermann committed
436
   | Opt_FastLlvm                      -- hidden flag
437

Ian Lynagh's avatar
Ian Lynagh committed
438
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
439
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
440
   | Opt_HideSourcePaths                -- Hide module source/object paths
441

442
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
443
   | Opt_PrintExplicitKinds
444
   | Opt_PrintExplicitCoercions
445
   | Opt_PrintExplicitRuntimeReps
446
   | Opt_PrintEqualityRelations
447
   | Opt_PrintUnicodeSyntax
448
   | Opt_PrintExpandedSynonyms
449
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
450
   | Opt_PrintTypecheckerElaboration
451

452
   -- optimisation opts
453
   | Opt_CallArity
454
   | Opt_Exitification
455
   | Opt_Strictness
Ömer Sinan Ağacan's avatar
Ömer Sinan Ağacan committed
456
   | Opt_LateDmdAnal                    -- #6087
457 458
   | Opt_KillAbsence
   | Opt_KillOneShot
459
   | Opt_FullLaziness
460
   | Opt_FloatIn
461
   | Opt_LateSpecialise
462
   | Opt_Specialise
463
   | Opt_SpecialiseAggressively
464
   | Opt_CrossModuleSpecialise
465
   | Opt_StaticArgumentTransformation
466
   | Opt_CSE
467
   | Opt_StgCSE
468 469
   | Opt_LiberateCase
   | Opt_SpecConstr
Simon Peyton Jones's avatar
Simon Peyton Jones committed
470
   | Opt_SpecConstrKeen
471 472 473 474
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
Sylvain Henry's avatar
Sylvain Henry committed
475
   | Opt_CaseFolding                    -- Constant folding through case-expressions
476
   | Opt_UnboxStrictFields
477
   | Opt_UnboxSmallStrictFields
478
   | Opt_DictsCheap
479
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
Ian Lynagh's avatar
Ian Lynagh committed
480 481
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
482
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
483
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
484
   | Opt_LlvmFillUndefWithGarbage       -- Testing for undef bugs (hidden flag)
485
   | Opt_IrrefutableTuples
486
   | Opt_CmmSink
487
   | Opt_CmmElimCommonBlocks
488
   | Opt_AsmShortcutting
489
   | Opt_OmitYields
490
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
491 492
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
493
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
494 495
   | Opt_CfgBlocklayout             -- ^ Use the cfg based block layout algorithm.
   | Opt_WeightlessBlocklayout         -- ^ Layout based on last instruction per block.
496
   | Opt_CprAnal
497
   | Opt_WorkerWrapper
498
   | Opt_SolveConstantDicts
Ben Gamari's avatar
Ben Gamari committed
499
   | Opt_AlignmentSanitisation
Ben Gamari's avatar
Ben Gamari committed
500
   | Opt_CatchBottoms
Sylvain Henry's avatar
Sylvain Henry committed
501
   | Opt_NumConstantFolding
502

503 504 505 506
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

507 508 509 510
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
511
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
512

Ian Lynagh's avatar
Ian Lynagh committed
513 514
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
515
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
516

517 518
   -- misc opts
   | Opt_Pp
519
   | Opt_ForceRecomp
520 521
   | Opt_IgnoreOptimChanges
   | Opt_IgnoreHpcChanges
522
   | Opt_ExcessPrecision
523
   | Opt_EagerBlackHoling
524 525
   | Opt_NoHsMain
   | Opt_SplitObjs
526
   | Opt_SplitSections
527
   | Opt_StgStats
528
   | Opt_HideAllPackages
529
   | Opt_HideAllPluginPackages
530
   | Opt_PrintBindResult
531
   | Opt_Haddock
David Waern's avatar
David Waern committed
532
   | Opt_HaddockOptions
533
   | Opt_BreakOnException
534
   | Opt_BreakOnError
535
   | Opt_PrintEvldWithShow
536
   | Opt_PrintBindContents
537 538
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
539
   | Opt_SharedImplib
540
   | Opt_BuildingCabalPackage
541
   | Opt_IgnoreDotGhci
542
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
543
   | Opt_GhciHistory
544
   | Opt_GhciLeakCheck
545
   | Opt_LocalGhciHistory
Matthew Pickering's avatar
Matthew Pickering committed
546
   | Opt_NoIt
547
   | Opt_HelpfulErrors
548
   | Opt_DeferTypeErrors
549
   | Opt_DeferTypedHoles
550
   | Opt_DeferOutOfScopeVariables
551 552 553
   | Opt_PIC                         -- ^ @-fPIC@
   | Opt_PIE                         -- ^ @-fPIE@
   | Opt_PICExecutable               -- ^ @-pie@
Simon Marlow's avatar
Simon Marlow committed
554
   | Opt_ExternalDynamicRefs
555
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
556
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
557 558 559
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
560
   | Opt_RPath
561
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
562
   | Opt_Hpc
563
   | Opt_FlatCache
564
   | Opt_ExternalInterpreter
Simon Marlow's avatar
Simon Marlow committed
565
   | Opt_OptimalApplicativeDo
566
   | Opt_VersionMacros
Simon Marlow's avatar
Simon Marlow committed
567
   | Opt_WholeArchiveHsLibs
568 569 570 571 572 573 574
   -- copy all libs into a single folder prior to linking binaries
   -- this should elivate the excessive command line limit restrictions
   -- on windows, by only requiring a single -L argument instead of
   -- one for each dependency.  At the time of this writing, gcc
   -- forwards all -L flags to the collect2 command without using a
   -- response file and as such breaking apart.
   | Opt_SingleLibFolder
Simon Marlow's avatar
Simon Marlow committed
575
   | Opt_KeepCAFs
576

577
   -- output style opts
578 579
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
Rufflewind's avatar
Rufflewind committed
580
   | Opt_DiagnosticsShowCaret -- Show snippets of offending code
581
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
582
   | Opt_PprShowTicks
583
   | Opt_ShowHoleConstraints
584 585 586 587 588 589 590 591 592 593 594
    -- Options relating to the display of valid hole fits
    -- when generating an error message for a typed hole
    -- See Note [Valid hole fits include] in TcHoleErrors.hs
   | Opt_ShowValidHoleFits
   | Opt_SortValidHoleFits
   | Opt_SortBySizeHoleFits
   | Opt_SortBySubsumHoleFits
   | Opt_AbstractRefHoleFits
   | Opt_UnclutterValidHoleFits
   | Opt_ShowTypeAppOfHoleFits
   | Opt_ShowTypeAppVarsOfHoleFits
595
   | Opt_ShowDocsOfHoleFits
596 597 598 599
   | Opt_ShowTypeOfHoleFits
   | Opt_ShowProvOfHoleFits
   | Opt_ShowMatchesOfHoleFits

600
   | Opt_ShowLoadedModules
Andrew Martin's avatar
Andrew Martin committed
601
   | Opt_HexWordLiterals -- See Note [Print Hexadecimal Literals]
602

603 604 605 606 607 608 609 610 611 612 613
   -- 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
614 615
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
616 617 618 619 620
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques
621
   | Opt_SuppressStgExts
622
   | Opt_SuppressTicks     -- Replaces Opt_PprShowTicks
623
   | Opt_SuppressTimestamps -- ^ Suppress timestamps in dumps
624

625
   -- temporary flags
626
   | Opt_AutoLinkPackages
627
   | Opt_ImplicitImportQualified
628 629

   -- keeping stuff
Roland Senn's avatar
Roland Senn committed
630
   | Opt_KeepHscppFiles
631 632 633 634
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
635
   | Opt_KeepRawTokenStream
636
   | Opt_KeepLlvmFiles
637 638
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
639

640 641
   | Opt_BuildDynamicToo

642
   -- safe haskell flags
dterei's avatar
dterei committed
643
   | Opt_DistrustAllPackages
644
   | Opt_PackageTrust
Sylvain Henry's avatar
Sylvain Henry committed
645 646 647

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

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
-- 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
668
   , Opt_LateSpecialise
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
   , 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_RegsGraph
   , Opt_RegsIterative
   , Opt_PedanticBottoms
   , Opt_LlvmTBAA
   , Opt_LlvmFillUndefWithGarbage
   , Opt_IrrefutableTuples
   , Opt_CmmSink
   , Opt_CmmElimCommonBlocks
695
   , Opt_AsmShortcutting
696 697 698 699 700
   , Opt_OmitYields
   , Opt_FunToThunk
   , Opt_DictsStrict
   , Opt_DmdTxDictSel
   , Opt_Loopification
701 702
   , Opt_CfgBlocklayout
   , Opt_WeightlessBlocklayout
703 704 705 706 707 708 709
   , Opt_CprAnal
   , Opt_WorkerWrapper
   , Opt_SolveConstantDicts
   , Opt_CatchBottoms
   , Opt_IgnoreAsserts
   ]

710 711 712
-- | 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.
713 714 715 716 717 718
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
719 720
  deriving Show

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
-- | 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
748 749
instance Outputable WarnReason where
  ppr = text . show
750

751 752 753
instance ToJson WarnReason where
  json NoReason = JSNull
  json (Reason wf) = JSString (show wf)
754 755
  json (ErrReason Nothing) = JSString "Opt_WarnIsError"
  json (ErrReason (Just wf)) = JSString (show wf)
756

757
data WarningFlag =
758
-- See Note [Updating flag description in the User's Guide]
759
     Opt_WarnDuplicateExports
760
   | Opt_WarnDuplicateConstraints
761
   | Opt_WarnRedundantConstraints
762 763 764 765 766
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
767
   | Opt_WarnOverflowedLiterals
768
   | Opt_WarnEmptyEnumerations
769 770 771
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
772 773
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
774 775 776 777
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
778 779 780
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
781 782
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
783 784
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
785 786
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
787
   | Opt_WarnMissingMonadFailInstances -- since 8.0
788
   | Opt_WarnSemigroup -- since 8.0
789 790 791 792 793 794 795 796 797 798 799
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
800 801
   | Opt_WarnUnsafe
   | Opt_WarnSafe
802
   | Opt_WarnTrustworthySafe
803 804
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
805
   | Opt_WarnUnsupportedCallingConventions
806
   | Opt_WarnUnsupportedLlvmVersion
807
   | Opt_WarnInlineRuleShadowing
808
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
809
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
810
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
811
   | Opt_WarnUntickedPromotedConstructors
812
   | Opt_WarnDerivingTypeable
813
   | Opt_WarnDeferredTypeErrors
814
   | Opt_WarnDeferredOutOfScopeVariables
815
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
816
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
817
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
818
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
819
   | Opt_WarnUnrecognisedWarningFlags