DynFlags.hs 215 KB
Newer Older
1
{-# LANGUAGE CPP #-}
2
{-# LANGUAGE FlexibleInstances #-}
Rufflewind's avatar
Rufflewind committed
3
{-# LANGUAGE ScopedTypeVariables #-}
4

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

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

21
module DynFlags (
22
        -- * Dynamic flags and associated configuration types
23
        DumpFlag(..),
24
        GeneralFlag(..),
25
        WarningFlag(..), WarnReason(..),
26
        Language(..),
27
        PlatformConstants(..),
Ian Lynagh's avatar
Ian Lynagh committed
28
        FatalMessager, LogAction, FlushOut(..), FlushErr(..),
29
        ProfAuto(..),
30
        glasgowExtsFlags,
31
        warningGroups, warningHierarchies,
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(..),
45
        OverridingBool(..), overrideWith,
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
        IgnorePackageFlag(..), TrustFlag(..),
53
        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,
61

62
        Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
63
        wayGeneralFlags, wayUnsetGeneralFlags,
ian@well-typed.com's avatar
ian@well-typed.com committed
64

65
66
        thisPackage, thisComponentId, thisUnitIdInsts,

67
        -- ** Safe Haskell
68
        SafeHaskellMode(..),
69
        safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
70
        packageTrustOn,
71
        safeDirectImpsReq, safeImplicitImpsReq,
72
        unsafeFlags, unsafeFlagsForInfer,
73

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


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

99
        getOpts,                        -- DynFlags -> (DynFlags -> [a]) -> [a]
100
        getVerbFlags,
Ian Lynagh's avatar
Ian Lynagh committed
101
102
        updOptLevel,
        setTmpDir,
103
        setUnitId,
Edsko de Vries's avatar
Edsko de Vries committed
104
        interpretPackageEnv,
Edward Z. Yang's avatar
Edward Z. Yang committed
105
        canonicalizeHomeModule,
Ian Lynagh's avatar
Ian Lynagh committed
106

107
        -- ** Parsing DynFlags
108
109
        parseDynamicFlagsCmdLine,
        parseDynamicFilePragma,
110
111
112
        parseDynamicFlagsFull,

        -- ** Available DynFlags
113
        allNonDeprecatedFlags,
114
115
116
        flagsAll,
        flagsDynamic,
        flagsPackage,
117
        flagsForCompletion,
118

119
        supportedLanguagesAndExtensions,
120
        languageExtensions,
121

122
        -- ** DynFlags C compiler options
Ian Lynagh's avatar
Ian Lynagh committed
123
        picCCOpts, picPOpts,
124
125

        -- * Compiler configuration suitable for display to the user
126
127
        compilerInfo,

128
#ifdef GHCI
129
        rtsIsProfiled,
130
#endif
131
        dynamicGhc,
132

133
#include "GHCConstantsHaskellExports.hs"
134
        bLOCK_SIZE_W,
135
        wORD_SIZE_IN_BITS,
136
137
        tAG_MASK,
        mAX_PTR_TAG,
138
        tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
139

140
141
        unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,

142
        -- * SSE and AVX
143
        isSseEnabled,
144
145
        isSse2Enabled,
        isSse4_2Enabled,
146
147
        isAvxEnabled,
        isAvx2Enabled,
148
149
150
151
        isAvx512cdEnabled,
        isAvx512erEnabled,
        isAvx512fEnabled,
        isAvx512pfEnabled,
152

Austin Seipp's avatar
Austin Seipp committed
153
        -- * Linker/compiler information
154
        LinkerInfo(..),
Austin Seipp's avatar
Austin Seipp committed
155
        CompilerInfo(..),
156
157
158
159
  ) where

#include "HsVersions.h"

Rufflewind's avatar
Rufflewind committed
160
161
162
163
164
165
166
167
168
169
#if defined mingw32_HOST_OS && !defined WINAPI
# if defined i386_HOST_ARCH
#  define WINAPI stdcall
# elif defined x86_64_HOST_ARCH
#  define WINAPI ccall
# else
#  error unknown architecture
# endif
#endif

170
import Platform
171
import PlatformConstants
172
import Module
Simon Marlow's avatar
Simon Marlow committed
173
import PackageConfig
174
import {-# SOURCE #-} Hooks
175
import {-# SOURCE #-} PrelNames ( mAIN )
176
import {-# SOURCE #-} Packages (PackageState, emptyPackageState)
Ian Lynagh's avatar
Ian Lynagh committed
177
import DriverPhases     ( Phase(..), phaseInputExt )
178
179
import Config
import CmdLineParser
180
import Constants
181
import Panic
182
import Util
Edsko de Vries's avatar
Edsko de Vries committed
183
import Maybes
184
import MonadUtils
185
import qualified Pretty
186
import SrcLoc
187
import BasicTypes       ( IntWithInf, treatZeroAsInf )
188
import FastString
Simon Marlow's avatar
Simon Marlow committed
189
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
190
import Foreign.C        ( CInt(..) )
191
import System.IO.Unsafe ( unsafeDupablePerformIO )
192
import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn )
193

194
import System.IO.Unsafe ( unsafePerformIO )
195
import Data.IORef
196
import Control.Arrow ((&&&))
ian@well-typed.com's avatar
ian@well-typed.com committed
197
import Control.Monad
198
199
200
201
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except
Rufflewind's avatar
Rufflewind committed
202
import Control.Exception (catch, throwIO)
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
203

204
import Data.Ord
205
import Data.Bits
206
import Data.Char
207
import Data.Int
208
import Data.List
209
210
import Data.Map (Map)
import qualified Data.Map as Map
211
212
import Data.Set (Set)
import qualified Data.Set as Set
213
import Data.Word
Ian Lynagh's avatar
Ian Lynagh committed
214
import System.FilePath
Edsko de Vries's avatar
Edsko de Vries committed
215
216
import System.Directory
import System.Environment (getEnv)
217
import System.IO
218
import System.IO.Error
Rufflewind's avatar
Rufflewind committed
219
220
221
222
223
224
225
226
#if defined MIN_VERSION_terminfo
import System.Console.Terminfo (SetupTermError, Terminal, getCapability,
                                setupTermFromEnv, termColors)
import System.Posix (queryTerminal, stdError)
#elif defined mingw32_HOST_OS
import System.Environment (lookupEnv)
import qualified Graphics.Win32 as Win32
#endif
227
228
import Text.ParserCombinators.ReadP hiding (char)
import Text.ParserCombinators.ReadP as R
229

230
231
232
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet

233
import GHC.Foreign (withCString, peekCString)
234
import qualified GHC.LanguageExtensions as LangExt
235

Moritz Angermann's avatar
Moritz Angermann committed
236
237
238
239
240
241
242
#if __GLASGOW_HASKELL__ >= 709
import Foreign
#else
import Foreign.Safe
#endif


243
244
245
246
247
248
249
-- 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:
--
250
251
--  * Flag Reference section generated from the modules in
--    utils/mkUserGuidePart/Options
252
--
253
--  * Flag description in docs/users_guide/using.rst provides a detailed
254
255
--    explanation of flags' usage.

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

268
269
270
271
272
273
274
-- Note [Adding a language extension]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- There are a few steps to adding (or removing) a language extension,
--
--  * Adding the extension to GHC.LanguageExtensions
--
275
276
--    The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
--    is the canonical list of language extensions known by GHC.
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
319
320
--
--  * 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.

321
322
323
-- -----------------------------------------------------------------------------
-- DynFlags

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

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

   deriving (Eq, Show, Enum)

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

   = Opt_DumpToFile                     -- ^ Append dump output to files instead of stdout.
413
   | Opt_D_faststring_stats
414
   | Opt_D_dump_minimal_imports
415
416
417
   | Opt_DoCoreLinting
   | Opt_DoStgLinting
   | Opt_DoCmmLinting
Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
418
   | Opt_DoAsmLinting
Peter Wortmann's avatar
Peter Wortmann committed
419
   | Opt_DoAnnotationLinting
420
   | Opt_NoLlvmMangler                 -- hidden flag
421

Ian Lynagh's avatar
Ian Lynagh committed
422
   | Opt_WarnIsError                    -- -Werror; makes warnings fatal
423
   | Opt_ShowWarnGroups                 -- Show the group a warning belongs to
424
   | Opt_HideSourcePaths                -- Hide module source/object paths
425

426
   | Opt_PrintExplicitForalls
unknown's avatar
unknown committed
427
   | Opt_PrintExplicitKinds
428
   | Opt_PrintExplicitCoercions
429
   | Opt_PrintExplicitRuntimeReps
430
   | Opt_PrintEqualityRelations
431
   | Opt_PrintUnicodeSyntax
432
   | Opt_PrintExpandedSynonyms
433
   | Opt_PrintPotentialInstances
eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
434
   | Opt_PrintTypecheckerElaboration
435

436
   -- optimisation opts
437
   | Opt_CallArity
438
   | Opt_Strictness
439
   | Opt_LateDmdAnal
440
441
   | Opt_KillAbsence
   | Opt_KillOneShot
442
   | Opt_FullLaziness
443
444
   | Opt_FloatIn
   | Opt_Specialise
445
   | Opt_SpecialiseAggressively
446
   | Opt_CrossModuleSpecialise
447
   | Opt_StaticArgumentTransformation
448
   | Opt_CSE
449
450
   | Opt_LiberateCase
   | Opt_SpecConstr
451
452
453
454
   | Opt_DoLambdaEtaExpansion
   | Opt_IgnoreAsserts
   | Opt_DoEtaReduction
   | Opt_CaseMerge
Sylvain Henry's avatar
Sylvain Henry committed
455
   | Opt_CaseFolding                    -- Constant folding through case-expressions
456
   | Opt_UnboxStrictFields
457
   | Opt_UnboxSmallStrictFields
458
   | Opt_DictsCheap
459
   | Opt_EnableRewriteRules             -- Apply rewrite rules during simplification
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
460
   | Opt_Vectorise
461
   | Opt_VectorisationAvoidance
Ian Lynagh's avatar
Ian Lynagh committed
462
463
   | Opt_RegsGraph                      -- do graph coloring register allocation
   | Opt_RegsIterative                  -- do iterative coalescing graph coloring register allocation
464
   | Opt_PedanticBottoms                -- Be picky about how we treat bottom
465
   | Opt_LlvmTBAA                       -- Use LLVM TBAA infastructure for improving AA (hidden flag)
466
   | Opt_LlvmPassVectorsInRegisters     -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
467
   | Opt_LlvmFillUndefWithGarbage       -- Testing for undef bugs (hidden flag)
468
   | Opt_IrrefutableTuples
469
   | Opt_CmmSink
470
   | Opt_CmmElimCommonBlocks
471
   | Opt_OmitYields
472
   | Opt_FunToThunk               -- allow WwLib.mkWorkerArgs to remove all value lambdas
473
474
   | Opt_DictsStrict                     -- be strict in argument dictionaries
   | Opt_DmdTxDictSel              -- use a special demand transformer for dictionary selectors
475
   | Opt_Loopification                  -- See Note [Self-recursive tail calls]
476
   | Opt_CprAnal
477
   | Opt_WorkerWrapper
478

479
480
481
482
   -- Interface files
   | Opt_IgnoreInterfacePragmas
   | Opt_OmitInterfacePragmas
   | Opt_ExposeAllUnfoldings
483
   | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
484

Ian Lynagh's avatar
Ian Lynagh committed
485
486
   -- profiling opts
   | Opt_AutoSccsOnIndividualCafs
487
   | Opt_ProfCountEntries
Ian Lynagh's avatar
Ian Lynagh committed
488

489
490
   -- misc opts
   | Opt_Pp
491
   | Opt_ForceRecomp
492
   | Opt_ExcessPrecision
493
   | Opt_EagerBlackHoling
494
495
   | Opt_NoHsMain
   | Opt_SplitObjs
496
   | Opt_SplitSections
497
   | Opt_StgStats
498
   | Opt_HideAllPackages
499
   | Opt_HideAllPluginPackages
500
   | Opt_PrintBindResult
501
   | Opt_Haddock
David Waern's avatar
David Waern committed
502
   | Opt_HaddockOptions
503
   | Opt_BreakOnException
504
   | Opt_BreakOnError
505
   | Opt_PrintEvldWithShow
506
   | Opt_PrintBindContents
507
508
   | Opt_GenManifest
   | Opt_EmbedManifest
Ian Lynagh's avatar
Ian Lynagh committed
509
   | Opt_SharedImplib
510
   | Opt_BuildingCabalPackage
511
   | Opt_IgnoreDotGhci
512
   | Opt_GhciSandbox
Ian Lynagh's avatar
Ian Lynagh committed
513
   | Opt_GhciHistory
514
   | Opt_LocalGhciHistory
515
   | Opt_HelpfulErrors
516
   | Opt_DeferTypeErrors
517
   | Opt_DeferTypedHoles
518
   | Opt_DeferOutOfScopeVariables
Ian Lynagh's avatar
Ian Lynagh committed
519
   | Opt_PIC
520
   | Opt_SccProfilingOn
ian@well-typed.com's avatar
ian@well-typed.com committed
521
   | Opt_Ticky
nfrisby's avatar
nfrisby committed
522
523
524
   | Opt_Ticky_Allocd
   | Opt_Ticky_LNE
   | Opt_Ticky_Dyn_Thunk
525
   | Opt_RPath
526
   | Opt_RelativeDynlibPaths
ian@well-typed.com's avatar
ian@well-typed.com committed
527
   | Opt_Hpc
528
   | Opt_FlatCache
529
   | Opt_ExternalInterpreter
Simon Marlow's avatar
Simon Marlow committed
530
   | Opt_OptimalApplicativeDo
531
   | Opt_VersionMacros
532

533
534
535
536
   -- PreInlining is on by default. The option is there just to see how
   -- bad things get if you turn it off!
   | Opt_SimplPreInlining

537
   -- output style opts
538
539
   | Opt_ErrorSpans -- Include full span info in error messages,
                    -- instead of just the start position.
540
   | Opt_PprCaseAsLet
Peter Wortmann's avatar
Peter Wortmann committed
541
   | Opt_PprShowTicks
542
   | Opt_ShowHoleConstraints
543

544
545
546
547
548
549
550
551
552
553
554
   -- 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
555
556
   | Opt_SuppressUnfoldings
   -- Suppress the details of even stable unfoldings
557
558
559
560
561
562
   | Opt_SuppressTypeSignatures
   -- Suppress unique ids on variables.
   -- Except for uniques, as some simplifier phases introduce new
   -- variables that have otherwise identical names.
   | Opt_SuppressUniques

563
   -- temporary flags
564
   | Opt_AutoLinkPackages
565
   | Opt_ImplicitImportQualified
566
567
568
569
570
571

   -- keeping stuff
   | Opt_KeepHiDiffs
   | Opt_KeepHcFiles
   | Opt_KeepSFiles
   | Opt_KeepTmpFiles
Jedai's avatar
Jedai committed
572
   | Opt_KeepRawTokenStream
573
   | Opt_KeepLlvmFiles
574
575
   | Opt_KeepHiFiles
   | Opt_KeepOFiles
576

577
578
   | Opt_BuildDynamicToo

579
   -- safe haskell flags
dterei's avatar
dterei committed
580
   | Opt_DistrustAllPackages
581
   | Opt_PackageTrust
582
   deriving (Eq, Show, Enum)
Ian Lynagh's avatar
Ian Lynagh committed
583

584
585
586
587
588
-- | 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

589
data WarningFlag =
590
-- See Note [Updating flag description in the User's Guide]
591
     Opt_WarnDuplicateExports
592
   | Opt_WarnDuplicateConstraints
593
   | Opt_WarnRedundantConstraints
594
595
596
597
598
   | Opt_WarnHiShadows
   | Opt_WarnImplicitPrelude
   | Opt_WarnIncompletePatterns
   | Opt_WarnIncompleteUniPatterns
   | Opt_WarnIncompletePatternsRecUpd
599
   | Opt_WarnOverflowedLiterals
600
   | Opt_WarnEmptyEnumerations
601
602
603
   | Opt_WarnMissingFields
   | Opt_WarnMissingImportList
   | Opt_WarnMissingMethods
manav's avatar
manav committed
604
605
   | Opt_WarnMissingSignatures
   | Opt_WarnMissingLocalSignatures
606
607
608
609
   | Opt_WarnNameShadowing
   | Opt_WarnOverlappingPatterns
   | Opt_WarnTypeDefaults
   | Opt_WarnMonomorphism
610
611
612
   | Opt_WarnUnusedTopBinds
   | Opt_WarnUnusedLocalBinds
   | Opt_WarnUnusedPatternBinds
613
614
   | Opt_WarnUnusedImports
   | Opt_WarnUnusedMatches
615
616
   | Opt_WarnUnusedTypePatterns
   | Opt_WarnUnusedForalls
617
618
   | Opt_WarnWarningsDeprecations
   | Opt_WarnDeprecatedFlags
619
   | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
620
   | Opt_WarnMissingMonadFailInstances -- since 8.0
621
   | Opt_WarnSemigroup -- since 8.0
622
623
624
625
626
627
628
629
630
631
632
   | Opt_WarnDodgyExports
   | Opt_WarnDodgyImports
   | Opt_WarnOrphans
   | Opt_WarnAutoOrphans
   | Opt_WarnIdentities
   | Opt_WarnTabs
   | Opt_WarnUnrecognisedPragmas
   | Opt_WarnDodgyForeignImports
   | Opt_WarnUnusedDoBind
   | Opt_WarnWrongDoBind
   | Opt_WarnAlternativeLayoutRuleTransitional
633
634
   | Opt_WarnUnsafe
   | Opt_WarnSafe
635
   | Opt_WarnTrustworthySafe
636
637
   | Opt_WarnMissedSpecs
   | Opt_WarnAllMissedSpecs
638
   | Opt_WarnUnsupportedCallingConventions
639
   | Opt_WarnUnsupportedLlvmVersion
640
   | Opt_WarnInlineRuleShadowing
641
   | Opt_WarnTypedHoles
thomasw's avatar
thomasw committed
642
   | Opt_WarnPartialTypeSignatures
manav's avatar
manav committed
643
   | Opt_WarnMissingExportedSignatures
carlostome's avatar
carlostome committed
644
   | Opt_WarnUntickedPromotedConstructors
645
   | Opt_WarnDerivingTypeable
646
   | Opt_WarnDeferredTypeErrors
647
   | Opt_WarnDeferredOutOfScopeVariables
648
   | Opt_WarnNonCanonicalMonadInstances   -- since 8.0
649
   | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
650
   | Opt_WarnNonCanonicalMonoidInstances  -- since 8.0
manav's avatar
manav committed
651
   | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
652
   | Opt_WarnUnrecognisedWarningFlags     -- since 8.0
653
   | Opt_WarnSimplifiableClassConstraints -- Since 8.2
654
   | Opt_WarnCPPUndef                     -- Since 8.2
655
   deriving (Eq, Show, Enum)
656

657
data Language = Haskell98 | Haskell2010
Oleg Grenrus's avatar
Oleg Grenrus committed
658
659
660
661
   deriving (Eq, Enum, Show)

instance Outputable Language where
    ppr = text . show
662

663
-- | The various Safe Haskell modes
664
665
data SafeHaskellMode
   = Sf_None
dterei's avatar
dterei committed
666
   | Sf_Unsafe
667
668
669
670
   | Sf_Trustworthy
   | Sf_Safe
   deriving (Eq)

Ian Lynagh's avatar
Ian Lynagh committed
671
instance Show SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
672
673
674
675
    show Sf_None         = "None"
    show Sf_Unsafe       = "Unsafe"
    show Sf_Trustworthy  = "Trustworthy"
    show Sf_Safe         = "Safe"
Ian Lynagh's avatar
Ian Lynagh committed
676

677
instance Outputable SafeHaskellMode where
Ian Lynagh's avatar
Ian Lynagh committed
678
    ppr = text . show
679

680
-- | Contains not only a collection of 'GeneralFlag's but also a plethora of
681
-- information relating to the compilation of a single file or GHC session
682
data DynFlags = DynFlags {
Ian Lynagh's avatar
Ian Lynagh committed
683
684
685
  ghcMode               :: GhcMode,
  ghcLink               :: GhcLink,
  hscTarget             :: HscTarget,
686
  settings              :: Settings,
687
  verbosity             :: Int,         -- ^ Verbosity level: see Note [Verbosity levels]
688
  optLevel              :: Int,         -- ^ Optimisation level
689
  debugLevel            :: Int,         -- ^ How much debug information to produce
690
691
  simplPhases           :: Int,         -- ^ Number of simplifier phases
  maxSimplIterations    :: Int,         -- ^ Max simplifier iterations
692
  maxPmCheckIterations  :: Int,         -- ^ Max no iterations for pm checking
Ian Lynagh's avatar
Ian Lynagh committed
693
  ruleCheck             :: Maybe String,
694
  strictnessBefore      :: [Int],       -- ^ Additional demand analysis
695

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

700
701
702
  enableTimeStats       :: Bool,        -- ^ Enable RTS timing statistics?
  ghcHeapSize           :: Maybe Int,   -- ^ The heap size to set.

703
704
  maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                        --   to show in type error messages
705
706
  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
                                        --   in non-exhaustiveness warnings
707
  simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
708
709
  specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
  specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
710
711
  specConstrRecursive   :: Int,         -- ^ Max number of specialisations for recursive types
                                        --   Not optional; otherwise ForceSpecConstr can diverge.
712
  liberateCaseThreshold :: Maybe Int,   -- ^ Threshold for LiberateCase
713
  floatLamArgs          :: Maybe Int,   -- ^ Arg count for lambda floating
714
                                        --   See CoreMonad.FloatOutSwitches
715

716
  historySize           :: Int,         -- ^ Simplification history size
717

Ian Lynagh's avatar
Ian Lynagh committed
718
719
720
  importPaths           :: [FilePath],
  mainModIs             :: Module,
  mainFunIs             :: Maybe String,
721
  reductionDepth        :: IntWithInf,   -- ^ Typechecker maximum stack depth
722
723
  solverIterations      :: IntWithInf,   -- ^ Number of iterations in the constraints solver
                                         --   Typically only 1 is needed
724

725
726
727
  thisInstalledUnitId   :: InstalledUnitId,
  thisComponentId_      :: Maybe ComponentId,
  thisUnitIdInsts_      :: Maybe [(ModuleName, Module)],
728
729

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

734
735
736
  -- For object splitting
  splitInfo             :: Maybe (String,Int),

737
  -- paths etc.
Ian Lynagh's avatar
Ian Lynagh committed
738
  objectDir             :: Maybe String,
739
  dylibInstallName      :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
740
741
  hiDir                 :: Maybe String,
  stubDir               :: Maybe String,
742
  dumpDir               :: Maybe String,
743

Ian Lynagh's avatar
Ian Lynagh committed
744
745
746
  objectSuf             :: String,
  hcSuf                 :: String,
  hiSuf                 :: String,
747

748
749
750
751
  canGenerateDynamicToo :: IORef Bool,
  dynObjectSuf          :: String,
  dynHiSuf              :: String,

752
753
754
755
756
757
758
759
  -- 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
760
  outputFile            :: Maybe String,
ian@well-typed.com's avatar
ian@well-typed.com committed
761
  dynOutputFile         :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
762
763
  outputHi              :: Maybe String,
  dynLibLoader          :: DynLibLoader,
764

765
  -- | This is set by 'DriverPipeline.runPipeline' based on where
Ian Lynagh's avatar
Ian Lynagh committed
766
767
  --    its output is going.
  dumpPrefix            :: Maybe FilePath,
768

769
770
  -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
  --    Set by @-ddump-file-prefix@
Ian Lynagh's avatar
Ian Lynagh committed
771
772
  dumpPrefixForce       :: Maybe FilePath,

773
  ldInputs              :: [Option],
774

Ian Lynagh's avatar
Ian Lynagh committed
775
776
777
778
779
  includePaths          :: [String],
  libraryPaths          :: [String],
  frameworkPaths        :: [String],    -- used on darwin only
  cmdlineFrameworks     :: [String],    -- ditto

780
  rtsOpts               :: Maybe String,
Ian Lynagh's avatar
Ian Lynagh committed
781
  rtsOptsEnabled        :: RtsOptsEnabled,
782
  rtsOptsSuggestions    :: Bool,
783

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

786
787
788
  -- Plugins
  pluginModNames        :: [ModuleName],
  pluginModNameOpts     :: [(ModuleName,String)],
Edward Z. Yang's avatar
Edward Z. Yang committed
789
  frontendPluginOpts    :: [String],
790

791
792
793
  -- GHC API hooks
  hooks                 :: Hooks,

794
795
796
797
798
799
  --  For ghc -M
  depMakefile           :: FilePath,
  depIncludePkgDeps     :: Bool,
  depExcludeMods        :: [ModuleName],
  depSuffixes           :: [String],

800
  --  Package flags
801
  extraPkgConfs         :: [PkgConfRef] -> [PkgConfRef],
802
        -- ^ The @-package-db@ flags given on the command line, in the order
Ian Lynagh's avatar
Ian Lynagh committed
803
        -- they appeared.
804

805
806
  ignorePackageFlags    :: [IgnorePackageFlag],
        -- ^ The @-ignore-package@ flags from the command line
Ian Lynagh's avatar
Ian Lynagh committed
807
  packageFlags          :: [PackageFlag],
808
        -- ^ The @-package@ and @-hide-package@ flags from the command-line
809
810
  pluginPackageFlags    :: [PackageFlag],
        -- ^ The @-plugin-package-id@ flags from command line
811
812
  trustFlags            :: [TrustFlag],
        -- ^ The @-trust@ and @-distrust@ flags
Edsko de Vries's avatar
Edsko de Vries committed
813
814
  packageEnv            :: Maybe FilePath,
        -- ^ Filepath to the package environment file (if overriding default)
815

816
  -- Package state
Ian Lynagh's avatar
Ian Lynagh committed
817
  -- NB. do not modify this field, it is calculated by
Edward Z. Yang's avatar
Edward Z. Yang committed
818
  -- Packages.initPackages
819
  pkgDatabase           :: Maybe [(FilePath, [PackageConfig])],
Ian Lynagh's avatar
Ian Lynagh committed
820
  pkgState              :: PackageState,
821

822
823
824
825
  -- Temporary files
  -- These have to be IORefs, because the defaultCleanupHandler needs to
  -- know what to clean when an exception happens
  filesToClean          :: IORef [FilePath],
826
  dirsToClean           :: IORef (Map FilePath FilePath),
827
  filesToNotIntermediateClean :: IORef [FilePath],
828
829
  -- The next available suffix to uniquely name a temp file, updated atomically
  nextTempSuffix        :: IORef Int,
830

831
832
833
  -- 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
834
  generatedDumps        :: IORef (Set FilePath),
835

836
  -- hsc dynamic flags
837
838
  dumpFlags             :: IntSet,
  generalFlags          :: IntSet,
839
  warningFlags          :: IntSet,