The Backpack patch.
[ghc.git] / compiler / main / DynFlags.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE FlexibleInstances #-}
3
4 -------------------------------------------------------------------------------
5 --
6 -- | Dynamic flags
7 --
8 -- Most flags are dynamic flags, which means they can change from compilation
9 -- to compilation using @OPTIONS_GHC@ pragmas, and in a multi-session GHC each
10 -- session can be using different dynamic flags. Dynamic flags can also be set
11 -- at the prompt in GHCi.
12 --
13 -- (c) The University of Glasgow 2005
14 --
15 -------------------------------------------------------------------------------
16
17 {-# OPTIONS_GHC -fno-cse #-}
18 -- -fno-cse is needed for GLOBAL_VAR's to behave properly
19
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 dopt, dopt_set, dopt_unset,
31 gopt, gopt_set, gopt_unset, setGeneralFlag', unSetGeneralFlag',
32 wopt, wopt_set, wopt_unset,
33 xopt, xopt_set, xopt_unset,
34 lang_set,
35 useUnicodeSyntax,
36 whenGeneratingDynamicToo, ifGeneratingDynamicToo,
37 whenCannotGenerateDynamicToo,
38 dynamicTooMkDynamicDynFlags,
39 DynFlags(..),
40 FlagSpec(..),
41 HasDynFlags(..), ContainsDynFlags(..),
42 RtsOptsEnabled(..),
43 HscTarget(..), isObjectTarget, defaultObjectTarget,
44 targetRetainsAllBindings,
45 GhcMode(..), isOneShot,
46 GhcLink(..), isNoLink,
47 PackageFlag(..), PackageArg(..), ModRenaming(..),
48 IgnorePackageFlag(..), TrustFlag(..),
49 PkgConfRef(..),
50 Option(..), showOpt,
51 DynLibLoader(..),
52 fFlags, fLangFlags, xFlags,
53 wWarningFlags,
54 dynFlagDependencies,
55 tablesNextToCode, mkTablesNextToCode,
56 makeDynFlagsConsistent,
57 thisUnitIdComponentId,
58
59 Way(..), mkBuildTag, wayRTSOnly, addWay', updateWays,
60 wayGeneralFlags, wayUnsetGeneralFlags,
61
62 -- ** Safe Haskell
63 SafeHaskellMode(..),
64 safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
65 packageTrustOn,
66 safeDirectImpsReq, safeImplicitImpsReq,
67 unsafeFlags, unsafeFlagsForInfer,
68
69 -- ** System tool settings and locations
70 Settings(..),
71 targetPlatform, programName, projectVersion,
72 ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
73 versionedAppDir,
74 extraGccViaCFlags, systemPackageConfig,
75 pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
76 pgm_windres, pgm_libtool, pgm_lo, pgm_lc, pgm_i,
77 opt_L, opt_P, opt_F, opt_c, opt_a, opt_l, opt_i,
78 opt_windres, opt_lo, opt_lc,
79
80
81 -- ** Manipulating DynFlags
82 defaultDynFlags, -- Settings -> DynFlags
83 defaultWays,
84 interpWays,
85 interpreterProfiled, interpreterDynamic,
86 initDynFlags, -- DynFlags -> IO DynFlags
87 defaultFatalMessager,
88 defaultLogAction,
89 defaultLogActionHPrintDoc,
90 defaultLogActionHPutStrDoc,
91 defaultFlushOut,
92 defaultFlushErr,
93
94 getOpts, -- DynFlags -> (DynFlags -> [a]) -> [a]
95 getVerbFlags,
96 updOptLevel,
97 setTmpDir,
98 setUnitId,
99 interpretPackageEnv,
100 canonicalizeHomeModule,
101
102 -- ** Parsing DynFlags
103 parseDynamicFlagsCmdLine,
104 parseDynamicFilePragma,
105 parseDynamicFlagsFull,
106
107 -- ** Available DynFlags
108 allNonDeprecatedFlags,
109 flagsAll,
110 flagsDynamic,
111 flagsPackage,
112 flagsForCompletion,
113
114 supportedLanguagesAndExtensions,
115 languageExtensions,
116
117 -- ** DynFlags C compiler options
118 picCCOpts, picPOpts,
119
120 -- * Compiler configuration suitable for display to the user
121 compilerInfo,
122
123 #ifdef GHCI
124 rtsIsProfiled,
125 #endif
126 dynamicGhc,
127
128 #include "GHCConstantsHaskellExports.hs"
129 bLOCK_SIZE_W,
130 wORD_SIZE_IN_BITS,
131 tAG_MASK,
132 mAX_PTR_TAG,
133 tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD,
134
135 unsafeGlobalDynFlags, setUnsafeGlobalDynFlags,
136
137 -- * SSE and AVX
138 isSseEnabled,
139 isSse2Enabled,
140 isSse4_2Enabled,
141 isAvxEnabled,
142 isAvx2Enabled,
143 isAvx512cdEnabled,
144 isAvx512erEnabled,
145 isAvx512fEnabled,
146 isAvx512pfEnabled,
147
148 -- * Linker/compiler information
149 LinkerInfo(..),
150 CompilerInfo(..),
151 ) where
152
153 #include "HsVersions.h"
154
155 import Platform
156 import PlatformConstants
157 import Module
158 import PackageConfig
159 import {-# SOURCE #-} Hooks
160 import {-# SOURCE #-} PrelNames ( mAIN )
161 import {-# SOURCE #-} Packages (PackageState, emptyPackageState)
162 import DriverPhases ( Phase(..), phaseInputExt )
163 import Config
164 import CmdLineParser
165 import Constants
166 import Panic
167 import Util
168 import Maybes
169 import MonadUtils
170 import qualified Pretty
171 import SrcLoc
172 import BasicTypes ( IntWithInf, treatZeroAsInf )
173 import FastString
174 import Outputable
175 import Foreign.C ( CInt(..) )
176 import System.IO.Unsafe ( unsafeDupablePerformIO )
177 import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessageAnn )
178
179 import System.IO.Unsafe ( unsafePerformIO )
180 import Data.IORef
181 import Control.Arrow ((&&&))
182 import Control.Monad
183 import Control.Monad.Trans.Class
184 import Control.Monad.Trans.Writer
185 import Control.Monad.Trans.Reader
186 import Control.Monad.Trans.Except
187 import Control.Exception (throwIO)
188
189 import Data.Ord
190 import Data.Bits
191 import Data.Char
192 import Data.Int
193 import Data.List
194 import Data.Map (Map)
195 import qualified Data.Map as Map
196 import Data.Set (Set)
197 import qualified Data.Set as Set
198 import Data.Word
199 import System.FilePath
200 import System.Directory
201 import System.Environment (getEnv)
202 import System.IO
203 import System.IO.Error
204 import Text.ParserCombinators.ReadP hiding (char)
205 import Text.ParserCombinators.ReadP as R
206
207 import Data.IntSet (IntSet)
208 import qualified Data.IntSet as IntSet
209
210 import GHC.Foreign (withCString, peekCString)
211 import qualified GHC.LanguageExtensions as LangExt
212
213 -- Note [Updating flag description in the User's Guide]
214 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215 --
216 -- If you modify anything in this file please make sure that your changes are
217 -- described in the User's Guide. Usually at least two sections need to be
218 -- updated:
219 --
220 -- * Flag Reference section generated from the modules in
221 -- utils/mkUserGuidePart/Options
222 --
223 -- * Flag description in docs/users_guide/using.rst provides a detailed
224 -- explanation of flags' usage.
225
226 -- Note [Supporting CLI completion]
227 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228 --
229 -- The command line interface completion (in for example bash) is an easy way
230 -- for the developer to learn what flags are available from GHC.
231 -- GHC helps by separating which flags are available when compiling with GHC,
232 -- and which flags are available when using GHCi.
233 -- A flag is assumed to either work in both these modes, or only in one of them.
234 -- When adding or changing a flag, please consider for which mode the flag will
235 -- have effect, and annotate it accordingly. For Flags use defFlag, defGhcFlag,
236 -- defGhciFlag, and for FlagSpec use flagSpec or flagGhciSpec.
237
238 -- Note [Adding a language extension]
239 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240 --
241 -- There are a few steps to adding (or removing) a language extension,
242 --
243 -- * Adding the extension to GHC.LanguageExtensions
244 --
245 -- The Extension type in libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
246 -- is the canonical list of language extensions known by GHC.
247 --
248 -- * Adding a flag to DynFlags.xFlags
249 --
250 -- This is fairly self-explanatory. The name should be concise, memorable,
251 -- and consistent with any previous implementations of the similar idea in
252 -- other Haskell compilers.
253 --
254 -- * Adding the flag to the documentation
255 --
256 -- This is the same as any other flag. See
257 -- Note [Updating flag description in the User's Guide]
258 --
259 -- * Adding the flag to Cabal
260 --
261 -- The Cabal library has its own list of all language extensions supported
262 -- by all major compilers. This is the list that user code being uploaded
263 -- to Hackage is checked against to ensure language extension validity.
264 -- Consequently, it is very important that this list remains up-to-date.
265 --
266 -- To this end, there is a testsuite test (testsuite/tests/driver/T4437.hs)
267 -- whose job it is to ensure these GHC's extensions are consistent with
268 -- Cabal.
269 --
270 -- The recommended workflow is,
271 --
272 -- 1. Temporarily add your new language extension to the
273 -- expectedGhcOnlyExtensions list in T4437 to ensure the test doesn't
274 -- break while Cabal is updated.
275 --
276 -- 2. After your GHC change is accepted, submit a Cabal pull request adding
277 -- your new extension to Cabal's list (found in
278 -- Cabal/Language/Haskell/Extension.hs).
279 --
280 -- 3. After your Cabal change is accepted, let the GHC developers know so
281 -- they can update the Cabal submodule and remove the extensions from
282 -- expectedGhcOnlyExtensions.
283 --
284 -- * Adding the flag to the GHC Wiki
285 --
286 -- There is a change log tracking language extension additions and removals
287 -- on the GHC wiki: https://ghc.haskell.org/trac/ghc/wiki/LanguagePragmaHistory
288 --
289 -- See Trac #4437 and #8176.
290
291 -- -----------------------------------------------------------------------------
292 -- DynFlags
293
294 data DumpFlag
295 -- See Note [Updating flag description in the User's Guide]
296
297 -- debugging flags
298 = Opt_D_dump_cmm
299 | Opt_D_dump_cmm_from_stg
300 | Opt_D_dump_cmm_raw
301 | Opt_D_dump_cmm_verbose
302 -- All of the cmm subflags (there are a lot!) automatically
303 -- enabled if you run -ddump-cmm-verbose
304 -- Each flag corresponds to exact stage of Cmm pipeline.
305 | Opt_D_dump_cmm_cfg
306 | Opt_D_dump_cmm_cbe
307 | Opt_D_dump_cmm_switch
308 | Opt_D_dump_cmm_proc
309 | Opt_D_dump_cmm_sp
310 | Opt_D_dump_cmm_sink
311 | Opt_D_dump_cmm_caf
312 | Opt_D_dump_cmm_procmap
313 | Opt_D_dump_cmm_split
314 | Opt_D_dump_cmm_info
315 | Opt_D_dump_cmm_cps
316 -- end cmm subflags
317 | Opt_D_dump_asm
318 | Opt_D_dump_asm_native
319 | Opt_D_dump_asm_liveness
320 | Opt_D_dump_asm_regalloc
321 | Opt_D_dump_asm_regalloc_stages
322 | Opt_D_dump_asm_conflicts
323 | Opt_D_dump_asm_stats
324 | Opt_D_dump_asm_expanded
325 | Opt_D_dump_llvm
326 | Opt_D_dump_core_stats
327 | Opt_D_dump_deriv
328 | Opt_D_dump_ds
329 | Opt_D_dump_foreign
330 | Opt_D_dump_inlinings
331 | Opt_D_dump_rule_firings
332 | Opt_D_dump_rule_rewrites
333 | Opt_D_dump_simpl_trace
334 | Opt_D_dump_occur_anal
335 | Opt_D_dump_parsed
336 | Opt_D_dump_rn
337 | Opt_D_dump_shape
338 | Opt_D_dump_simpl
339 | Opt_D_dump_simpl_iterations
340 | Opt_D_dump_spec
341 | Opt_D_dump_prep
342 | Opt_D_dump_stg
343 | Opt_D_dump_call_arity
344 | Opt_D_dump_stranal
345 | Opt_D_dump_str_signatures
346 | Opt_D_dump_tc
347 | Opt_D_dump_types
348 | Opt_D_dump_rules
349 | Opt_D_dump_cse
350 | Opt_D_dump_worker_wrapper
351 | Opt_D_dump_rn_trace
352 | Opt_D_dump_rn_stats
353 | Opt_D_dump_opt_cmm
354 | Opt_D_dump_simpl_stats
355 | Opt_D_dump_cs_trace -- Constraint solver in type checker
356 | Opt_D_dump_tc_trace
357 | Opt_D_dump_if_trace
358 | Opt_D_dump_vt_trace
359 | Opt_D_dump_splices
360 | Opt_D_th_dec_file
361 | Opt_D_dump_BCOs
362 | Opt_D_dump_vect
363 | Opt_D_dump_ticked
364 | Opt_D_dump_rtti
365 | Opt_D_source_stats
366 | Opt_D_verbose_stg2stg
367 | Opt_D_dump_hi
368 | Opt_D_dump_hi_diffs
369 | Opt_D_dump_mod_cycles
370 | Opt_D_dump_mod_map
371 | Opt_D_dump_view_pattern_commoning
372 | Opt_D_verbose_core2core
373 | Opt_D_dump_debug
374
375 deriving (Eq, Show, Enum)
376
377 -- | Enumerates the simple on-or-off dynamic flags
378 data GeneralFlag
379 -- See Note [Updating flag description in the User's Guide]
380
381 = Opt_DumpToFile -- ^ Append dump output to files instead of stdout.
382 | Opt_D_faststring_stats
383 | Opt_D_dump_minimal_imports
384 | Opt_DoCoreLinting
385 | Opt_DoStgLinting
386 | Opt_DoCmmLinting
387 | Opt_DoAsmLinting
388 | Opt_DoAnnotationLinting
389 | Opt_NoLlvmMangler -- hidden flag
390
391 | Opt_WarnIsError -- -Werror; makes warnings fatal
392 | Opt_ShowWarnGroups -- Show the group a warning belongs to
393
394 | Opt_PrintExplicitForalls
395 | Opt_PrintExplicitKinds
396 | Opt_PrintExplicitCoercions
397 | Opt_PrintExplicitRuntimeReps
398 | Opt_PrintEqualityRelations
399 | Opt_PrintUnicodeSyntax
400 | Opt_PrintExpandedSynonyms
401 | Opt_PrintPotentialInstances
402 | Opt_PrintTypecheckerElaboration
403
404 -- optimisation opts
405 | Opt_CallArity
406 | Opt_Strictness
407 | Opt_LateDmdAnal
408 | Opt_KillAbsence
409 | Opt_KillOneShot
410 | Opt_FullLaziness
411 | Opt_FloatIn
412 | Opt_Specialise
413 | Opt_SpecialiseAggressively
414 | Opt_CrossModuleSpecialise
415 | Opt_StaticArgumentTransformation
416 | Opt_CSE
417 | Opt_LiberateCase
418 | Opt_SpecConstr
419 | Opt_DoLambdaEtaExpansion
420 | Opt_IgnoreAsserts
421 | Opt_DoEtaReduction
422 | Opt_CaseMerge
423 | Opt_UnboxStrictFields
424 | Opt_UnboxSmallStrictFields
425 | Opt_DictsCheap
426 | Opt_EnableRewriteRules -- Apply rewrite rules during simplification
427 | Opt_Vectorise
428 | Opt_VectorisationAvoidance
429 | Opt_RegsGraph -- do graph coloring register allocation
430 | Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
431 | Opt_PedanticBottoms -- Be picky about how we treat bottom
432 | Opt_LlvmTBAA -- Use LLVM TBAA infastructure for improving AA (hidden flag)
433 | Opt_LlvmPassVectorsInRegisters -- Pass SIMD vectors in registers (requires a patched LLVM) (hidden flag)
434 | Opt_LlvmFillUndefWithGarbage -- Testing for undef bugs (hidden flag)
435 | Opt_IrrefutableTuples
436 | Opt_CmmSink
437 | Opt_CmmElimCommonBlocks
438 | Opt_OmitYields
439 | Opt_FunToThunk -- allow WwLib.mkWorkerArgs to remove all value lambdas
440 | Opt_DictsStrict -- be strict in argument dictionaries
441 | Opt_DmdTxDictSel -- use a special demand transformer for dictionary selectors
442 | Opt_Loopification -- See Note [Self-recursive tail calls]
443 | Opt_CprAnal
444 | Opt_WorkerWrapper
445
446 -- Interface files
447 | Opt_IgnoreInterfacePragmas
448 | Opt_OmitInterfacePragmas
449 | Opt_ExposeAllUnfoldings
450 | Opt_WriteInterface -- forces .hi files to be written even with -fno-code
451
452 -- profiling opts
453 | Opt_AutoSccsOnIndividualCafs
454 | Opt_ProfCountEntries
455
456 -- misc opts
457 | Opt_Pp
458 | Opt_ForceRecomp
459 | Opt_ExcessPrecision
460 | Opt_EagerBlackHoling
461 | Opt_NoHsMain
462 | Opt_SplitObjs
463 | Opt_SplitSections
464 | Opt_StgStats
465 | Opt_HideAllPackages
466 | Opt_HideAllPluginPackages
467 | Opt_PrintBindResult
468 | Opt_Haddock
469 | Opt_HaddockOptions
470 | Opt_BreakOnException
471 | Opt_BreakOnError
472 | Opt_PrintEvldWithShow
473 | Opt_PrintBindContents
474 | Opt_GenManifest
475 | Opt_EmbedManifest
476 | Opt_SharedImplib
477 | Opt_BuildingCabalPackage
478 | Opt_IgnoreDotGhci
479 | Opt_GhciSandbox
480 | Opt_GhciHistory
481 | Opt_LocalGhciHistory
482 | Opt_HelpfulErrors
483 | Opt_DeferTypeErrors
484 | Opt_DeferTypedHoles
485 | Opt_DeferOutOfScopeVariables
486 | Opt_PIC
487 | Opt_SccProfilingOn
488 | Opt_Ticky
489 | Opt_Ticky_Allocd
490 | Opt_Ticky_LNE
491 | Opt_Ticky_Dyn_Thunk
492 | Opt_RPath
493 | Opt_RelativeDynlibPaths
494 | Opt_Hpc
495 | Opt_FlatCache
496 | Opt_ExternalInterpreter
497 | Opt_OptimalApplicativeDo
498 | Opt_VersionMacros
499
500 -- PreInlining is on by default. The option is there just to see how
501 -- bad things get if you turn it off!
502 | Opt_SimplPreInlining
503
504 -- output style opts
505 | Opt_ErrorSpans -- Include full span info in error messages,
506 -- instead of just the start position.
507 | Opt_PprCaseAsLet
508 | Opt_PprShowTicks
509
510 -- Suppress all coercions, them replacing with '...'
511 | Opt_SuppressCoercions
512 | Opt_SuppressVarKinds
513 -- Suppress module id prefixes on variables.
514 | Opt_SuppressModulePrefixes
515 -- Suppress type applications.
516 | Opt_SuppressTypeApplications
517 -- Suppress info such as arity and unfoldings on identifiers.
518 | Opt_SuppressIdInfo
519 -- Suppress separate type signatures in core, but leave types on
520 -- lambda bound vars
521 | Opt_SuppressUnfoldings
522 -- Suppress the details of even stable unfoldings
523 | Opt_SuppressTypeSignatures
524 -- Suppress unique ids on variables.
525 -- Except for uniques, as some simplifier phases introduce new
526 -- variables that have otherwise identical names.
527 | Opt_SuppressUniques
528
529 -- temporary flags
530 | Opt_AutoLinkPackages
531 | Opt_ImplicitImportQualified
532
533 -- keeping stuff
534 | Opt_KeepHiDiffs
535 | Opt_KeepHcFiles
536 | Opt_KeepSFiles
537 | Opt_KeepTmpFiles
538 | Opt_KeepRawTokenStream
539 | Opt_KeepLlvmFiles
540 | Opt_KeepHiFiles
541 | Opt_KeepOFiles
542
543 | Opt_BuildDynamicToo
544
545 -- safe haskell flags
546 | Opt_DistrustAllPackages
547 | Opt_PackageTrust
548 deriving (Eq, Show, Enum)
549
550 -- | Used when outputting warnings: if a reason is given, it is
551 -- displayed. If a warning isn't controlled by a flag, this is made
552 -- explicit at the point of use.
553 data WarnReason = NoReason | Reason !WarningFlag
554
555 data WarningFlag =
556 -- See Note [Updating flag description in the User's Guide]
557 Opt_WarnDuplicateExports
558 | Opt_WarnDuplicateConstraints
559 | Opt_WarnRedundantConstraints
560 | Opt_WarnHiShadows
561 | Opt_WarnImplicitPrelude
562 | Opt_WarnIncompletePatterns
563 | Opt_WarnIncompleteUniPatterns
564 | Opt_WarnIncompletePatternsRecUpd
565 | Opt_WarnOverflowedLiterals
566 | Opt_WarnEmptyEnumerations
567 | Opt_WarnMissingFields
568 | Opt_WarnMissingImportList
569 | Opt_WarnMissingMethods
570 | Opt_WarnMissingSignatures
571 | Opt_WarnMissingLocalSignatures
572 | Opt_WarnNameShadowing
573 | Opt_WarnOverlappingPatterns
574 | Opt_WarnTypeDefaults
575 | Opt_WarnMonomorphism
576 | Opt_WarnUnusedTopBinds
577 | Opt_WarnUnusedLocalBinds
578 | Opt_WarnUnusedPatternBinds
579 | Opt_WarnUnusedImports
580 | Opt_WarnUnusedMatches
581 | Opt_WarnUnusedTypePatterns
582 | Opt_WarnUnusedForalls
583 | Opt_WarnContextQuantification -- remove in 8.2
584 | Opt_WarnWarningsDeprecations
585 | Opt_WarnDeprecatedFlags
586 | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
587 | Opt_WarnMissingMonadFailInstances -- since 8.0
588 | Opt_WarnSemigroup -- since 8.0
589 | Opt_WarnDodgyExports
590 | Opt_WarnDodgyImports
591 | Opt_WarnOrphans
592 | Opt_WarnAutoOrphans
593 | Opt_WarnIdentities
594 | Opt_WarnTabs
595 | Opt_WarnUnrecognisedPragmas
596 | Opt_WarnDodgyForeignImports
597 | Opt_WarnUnusedDoBind
598 | Opt_WarnWrongDoBind
599 | Opt_WarnAlternativeLayoutRuleTransitional
600 | Opt_WarnUnsafe
601 | Opt_WarnSafe
602 | Opt_WarnTrustworthySafe
603 | Opt_WarnMissedSpecs
604 | Opt_WarnAllMissedSpecs
605 | Opt_WarnUnsupportedCallingConventions
606 | Opt_WarnUnsupportedLlvmVersion
607 | Opt_WarnInlineRuleShadowing
608 | Opt_WarnTypedHoles
609 | Opt_WarnPartialTypeSignatures
610 | Opt_WarnMissingExportedSignatures
611 | Opt_WarnUntickedPromotedConstructors
612 | Opt_WarnDerivingTypeable
613 | Opt_WarnDeferredTypeErrors
614 | Opt_WarnDeferredOutOfScopeVariables
615 | Opt_WarnNonCanonicalMonadInstances -- since 8.0
616 | Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
617 | Opt_WarnNonCanonicalMonoidInstances -- since 8.0
618 | Opt_WarnMissingPatternSynonymSignatures -- since 8.0
619 | Opt_WarnUnrecognisedWarningFlags -- since 8.0
620 | Opt_WarnSimplifiableClassConstraints -- Since 8.2
621 deriving (Eq, Show, Enum)
622
623 data Language = Haskell98 | Haskell2010
624 deriving (Eq, Enum, Show)
625
626 instance Outputable Language where
627 ppr = text . show
628
629 -- | The various Safe Haskell modes
630 data SafeHaskellMode
631 = Sf_None
632 | Sf_Unsafe
633 | Sf_Trustworthy
634 | Sf_Safe
635 deriving (Eq)
636
637 instance Show SafeHaskellMode where
638 show Sf_None = "None"
639 show Sf_Unsafe = "Unsafe"
640 show Sf_Trustworthy = "Trustworthy"
641 show Sf_Safe = "Safe"
642
643 instance Outputable SafeHaskellMode where
644 ppr = text . show
645
646 -- | Contains not only a collection of 'GeneralFlag's but also a plethora of
647 -- information relating to the compilation of a single file or GHC session
648 data DynFlags = DynFlags {
649 ghcMode :: GhcMode,
650 ghcLink :: GhcLink,
651 hscTarget :: HscTarget,
652 settings :: Settings,
653 verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
654 optLevel :: Int, -- ^ Optimisation level
655 debugLevel :: Int, -- ^ How much debug information to produce
656 simplPhases :: Int, -- ^ Number of simplifier phases
657 maxSimplIterations :: Int, -- ^ Max simplifier iterations
658 maxPmCheckIterations :: Int, -- ^ Max no iterations for pm checking
659 ruleCheck :: Maybe String,
660 strictnessBefore :: [Int], -- ^ Additional demand analysis
661
662 parMakeCount :: Maybe Int, -- ^ The number of modules to compile in parallel
663 -- in --make mode, where Nothing ==> compile as
664 -- many in parallel as there are CPUs.
665
666 enableTimeStats :: Bool, -- ^ Enable RTS timing statistics?
667 ghcHeapSize :: Maybe Int, -- ^ The heap size to set.
668
669 maxRelevantBinds :: Maybe Int, -- ^ Maximum number of bindings from the type envt
670 -- to show in type error messages
671 maxUncoveredPatterns :: Int, -- ^ Maximum number of unmatched patterns to show
672 -- in non-exhaustiveness warnings
673 simplTickFactor :: Int, -- ^ Multiplier for simplifier ticks
674 specConstrThreshold :: Maybe Int, -- ^ Threshold for SpecConstr
675 specConstrCount :: Maybe Int, -- ^ Max number of specialisations for any one function
676 specConstrRecursive :: Int, -- ^ Max number of specialisations for recursive types
677 -- Not optional; otherwise ForceSpecConstr can diverge.
678 liberateCaseThreshold :: Maybe Int, -- ^ Threshold for LiberateCase
679 floatLamArgs :: Maybe Int, -- ^ Arg count for lambda floating
680 -- See CoreMonad.FloatOutSwitches
681
682 historySize :: Int, -- ^ Simplification history size
683
684 importPaths :: [FilePath],
685 mainModIs :: Module,
686 mainFunIs :: Maybe String,
687 reductionDepth :: IntWithInf, -- ^ Typechecker maximum stack depth
688 solverIterations :: IntWithInf, -- ^ Number of iterations in the constraints solver
689 -- Typically only 1 is needed
690
691 thisPackage :: UnitId, -- ^ unit id of package currently being compiled.
692 -- Not properly initialized until initPackages
693 thisUnitIdInsts :: [(ModuleName, Module)],
694
695 -- ways
696 ways :: [Way], -- ^ Way flags from the command line
697 buildTag :: String, -- ^ The global \"way\" (e.g. \"p\" for prof)
698 rtsBuildTag :: String, -- ^ The RTS \"way\"
699
700 -- For object splitting
701 splitInfo :: Maybe (String,Int),
702
703 -- paths etc.
704 objectDir :: Maybe String,
705 dylibInstallName :: Maybe String,
706 hiDir :: Maybe String,
707 stubDir :: Maybe String,
708 dumpDir :: Maybe String,
709
710 objectSuf :: String,
711 hcSuf :: String,
712 hiSuf :: String,
713
714 canGenerateDynamicToo :: IORef Bool,
715 dynObjectSuf :: String,
716 dynHiSuf :: String,
717
718 -- Packages.isDllName needs to know whether a call is within a
719 -- single DLL or not. Normally it does this by seeing if the call
720 -- is to the same package, but for the ghc package, we split the
721 -- package between 2 DLLs. The dllSplit tells us which sets of
722 -- modules are in which package.
723 dllSplitFile :: Maybe FilePath,
724 dllSplit :: Maybe [Set String],
725
726 outputFile :: Maybe String,
727 dynOutputFile :: Maybe String,
728 outputHi :: Maybe String,
729 dynLibLoader :: DynLibLoader,
730
731 -- | This is set by 'DriverPipeline.runPipeline' based on where
732 -- its output is going.
733 dumpPrefix :: Maybe FilePath,
734
735 -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
736 -- Set by @-ddump-file-prefix@
737 dumpPrefixForce :: Maybe FilePath,
738
739 ldInputs :: [Option],
740
741 includePaths :: [String],
742 libraryPaths :: [String],
743 frameworkPaths :: [String], -- used on darwin only
744 cmdlineFrameworks :: [String], -- ditto
745
746 rtsOpts :: Maybe String,
747 rtsOptsEnabled :: RtsOptsEnabled,
748 rtsOptsSuggestions :: Bool,
749
750 hpcDir :: String, -- ^ Path to store the .mix files
751
752 -- Plugins
753 pluginModNames :: [ModuleName],
754 pluginModNameOpts :: [(ModuleName,String)],
755 frontendPluginOpts :: [String],
756
757 -- GHC API hooks
758 hooks :: Hooks,
759
760 -- For ghc -M
761 depMakefile :: FilePath,
762 depIncludePkgDeps :: Bool,
763 depExcludeMods :: [ModuleName],
764 depSuffixes :: [String],
765
766 -- Package flags
767 extraPkgConfs :: [PkgConfRef] -> [PkgConfRef],
768 -- ^ The @-package-db@ flags given on the command line, in the order
769 -- they appeared.
770
771 ignorePackageFlags :: [IgnorePackageFlag],
772 -- ^ The @-ignore-package@ flags from the command line
773 packageFlags :: [PackageFlag],
774 -- ^ The @-package@ and @-hide-package@ flags from the command-line
775 pluginPackageFlags :: [PackageFlag],
776 -- ^ The @-plugin-package-id@ flags from command line
777 trustFlags :: [TrustFlag],
778 -- ^ The @-trust@ and @-distrust@ flags
779 packageEnv :: Maybe FilePath,
780 -- ^ Filepath to the package environment file (if overriding default)
781
782 -- Package state
783 -- NB. do not modify this field, it is calculated by
784 -- Packages.initPackages
785 pkgDatabase :: Maybe [(FilePath, [PackageConfig])],
786 pkgState :: PackageState,
787
788 -- Temporary files
789 -- These have to be IORefs, because the defaultCleanupHandler needs to
790 -- know what to clean when an exception happens
791 filesToClean :: IORef [FilePath],
792 dirsToClean :: IORef (Map FilePath FilePath),
793 filesToNotIntermediateClean :: IORef [FilePath],
794 -- The next available suffix to uniquely name a temp file, updated atomically
795 nextTempSuffix :: IORef Int,
796
797 -- Names of files which were generated from -ddump-to-file; used to
798 -- track which ones we need to truncate because it's our first run
799 -- through
800 generatedDumps :: IORef (Set FilePath),
801
802 -- hsc dynamic flags
803 dumpFlags :: IntSet,
804 generalFlags :: IntSet,
805 warningFlags :: IntSet,
806 -- Don't change this without updating extensionFlags:
807 language :: Maybe Language,
808 -- | Safe Haskell mode
809 safeHaskell :: SafeHaskellMode,
810 safeInfer :: Bool,
811 safeInferred :: Bool,
812 -- We store the location of where some extension and flags were turned on so
813 -- we can produce accurate error messages when Safe Haskell fails due to
814 -- them.
815 thOnLoc :: SrcSpan,
816 newDerivOnLoc :: SrcSpan,
817 overlapInstLoc :: SrcSpan,
818 incoherentOnLoc :: SrcSpan,
819 pkgTrustOnLoc :: SrcSpan,
820 warnSafeOnLoc :: SrcSpan,
821 warnUnsafeOnLoc :: SrcSpan,
822 trustworthyOnLoc :: SrcSpan,
823 -- Don't change this without updating extensionFlags:
824 extensions :: [OnOff LangExt.Extension],
825 -- extensionFlags should always be equal to
826 -- flattenExtensionFlags language extensions
827 -- LangExt.Extension is defined in libraries/ghc-boot so that it can be used
828 -- by template-haskell
829 extensionFlags :: IntSet,
830
831 -- Unfolding control
832 -- See Note [Discounts and thresholds] in CoreUnfold
833 ufCreationThreshold :: Int,
834 ufUseThreshold :: Int,
835 ufFunAppDiscount :: Int,
836 ufDictDiscount :: Int,
837 ufKeenessFactor :: Float,
838 ufDearOp :: Int,
839
840 maxWorkerArgs :: Int,
841
842 ghciHistSize :: Int,
843
844 -- | MsgDoc output action: use "ErrUtils" instead of this if you can
845 log_action :: LogAction,
846 flushOut :: FlushOut,
847 flushErr :: FlushErr,
848
849 haddockOptions :: Maybe String,
850
851 -- | GHCi scripts specified by -ghci-script, in reverse order
852 ghciScripts :: [String],
853
854 -- Output style options
855 pprUserLength :: Int,
856 pprCols :: Int,
857 traceLevel :: Int, -- Standard level is 1. Less verbose is 0.
858
859 useUnicode :: Bool,
860
861 -- | what kind of {-# SCC #-} to add automatically
862 profAuto :: ProfAuto,
863
864 interactivePrint :: Maybe String,
865
866 nextWrapperNum :: IORef (ModuleEnv Int),
867
868 -- | Machine dependant flags (-m<blah> stuff)
869 sseVersion :: Maybe SseVersion,
870 avx :: Bool,
871 avx2 :: Bool,
872 avx512cd :: Bool, -- Enable AVX-512 Conflict Detection Instructions.
873 avx512er :: Bool, -- Enable AVX-512 Exponential and Reciprocal Instructions.
874 avx512f :: Bool, -- Enable AVX-512 instructions.
875 avx512pf :: Bool, -- Enable AVX-512 PreFetch Instructions.
876
877 -- | Run-time linker information (what options we need, etc.)
878 rtldInfo :: IORef (Maybe LinkerInfo),
879
880 -- | Run-time compiler information
881 rtccInfo :: IORef (Maybe CompilerInfo),
882
883 -- Constants used to control the amount of optimization done.
884
885 -- | Max size, in bytes, of inline array allocations.
886 maxInlineAllocSize :: Int,
887
888 -- | Only inline memcpy if it generates no more than this many
889 -- pseudo (roughly: Cmm) instructions.
890 maxInlineMemcpyInsns :: Int,
891
892 -- | Only inline memset if it generates no more than this many
893 -- pseudo (roughly: Cmm) instructions.
894 maxInlineMemsetInsns :: Int,
895
896 -- | Reverse the order of error messages in GHC/GHCi
897 reverseErrors :: Bool,
898
899 -- | Unique supply configuration for testing build determinism
900 initialUnique :: Int,
901 uniqueIncrement :: Int
902 }
903
904 class HasDynFlags m where
905 getDynFlags :: m DynFlags
906
907 {- It would be desirable to have the more generalised
908
909 instance (MonadTrans t, Monad m, HasDynFlags m) => HasDynFlags (t m) where
910 getDynFlags = lift getDynFlags
911
912 instance definition. However, that definition would overlap with the
913 `HasDynFlags (GhcT m)` instance. Instead we define instances for a
914 couple of common Monad transformers explicitly. -}
915
916 instance (Monoid a, Monad m, HasDynFlags m) => HasDynFlags (WriterT a m) where
917 getDynFlags = lift getDynFlags
918
919 instance (Monad m, HasDynFlags m) => HasDynFlags (ReaderT a m) where
920 getDynFlags = lift getDynFlags
921
922 instance (Monad m, HasDynFlags m) => HasDynFlags (MaybeT m) where
923 getDynFlags = lift getDynFlags
924
925 instance (Monad m, HasDynFlags m) => HasDynFlags (ExceptT e m) where
926 getDynFlags = lift getDynFlags
927
928 class ContainsDynFlags t where
929 extractDynFlags :: t -> DynFlags
930
931 data ProfAuto
932 = NoProfAuto -- ^ no SCC annotations added
933 | ProfAutoAll -- ^ top-level and nested functions are annotated
934 | ProfAutoTop -- ^ top-level functions annotated only
935 | ProfAutoExports -- ^ exported functions annotated only
936 | ProfAutoCalls -- ^ annotate call-sites
937 deriving (Eq,Enum)
938
939 data Settings = Settings {
940 sTargetPlatform :: Platform, -- Filled in by SysTools
941 sGhcUsagePath :: FilePath, -- Filled in by SysTools
942 sGhciUsagePath :: FilePath, -- ditto
943 sTopDir :: FilePath,
944 sTmpDir :: String, -- no trailing '/'
945 sProgramName :: String,
946 sProjectVersion :: String,
947 -- You shouldn't need to look things up in rawSettings directly.
948 -- They should have their own fields instead.
949 sRawSettings :: [(String, String)],
950 sExtraGccViaCFlags :: [String],
951 sSystemPackageConfig :: FilePath,
952 sLdSupportsCompactUnwind :: Bool,
953 sLdSupportsBuildId :: Bool,
954 sLdSupportsFilelist :: Bool,
955 sLdIsGnuLd :: Bool,
956 -- commands for particular phases
957 sPgm_L :: String,
958 sPgm_P :: (String,[Option]),
959 sPgm_F :: String,
960 sPgm_c :: (String,[Option]),
961 sPgm_s :: (String,[Option]),
962 sPgm_a :: (String,[Option]),
963 sPgm_l :: (String,[Option]),
964 sPgm_dll :: (String,[Option]),
965 sPgm_T :: String,
966 sPgm_windres :: String,
967 sPgm_libtool :: String,
968 sPgm_lo :: (String,[Option]), -- LLVM: opt llvm optimiser
969 sPgm_lc :: (String,[Option]), -- LLVM: llc static compiler
970 sPgm_i :: String,
971 -- options for particular phases
972 sOpt_L :: [String],
973 sOpt_P :: [String],
974 sOpt_F :: [String],
975 sOpt_c :: [String],
976 sOpt_a :: [String],
977 sOpt_l :: [String],
978 sOpt_windres :: [String],
979 sOpt_lo :: [String], -- LLVM: llvm optimiser
980 sOpt_lc :: [String], -- LLVM: llc static compiler
981 sOpt_i :: [String], -- iserv options
982
983 sPlatformConstants :: PlatformConstants
984 }
985
986 targetPlatform :: DynFlags -> Platform
987 targetPlatform dflags = sTargetPlatform (settings dflags)
988 programName :: DynFlags -> String
989 programName dflags = sProgramName (settings dflags)
990 projectVersion :: DynFlags -> String
991 projectVersion dflags = sProjectVersion (settings dflags)
992 ghcUsagePath :: DynFlags -> FilePath
993 ghcUsagePath dflags = sGhcUsagePath (settings dflags)
994 ghciUsagePath :: DynFlags -> FilePath
995 ghciUsagePath dflags = sGhciUsagePath (settings dflags)
996 topDir :: DynFlags -> FilePath
997 topDir dflags = sTopDir (settings dflags)
998 tmpDir :: DynFlags -> String
999 tmpDir dflags = sTmpDir (settings dflags)
1000 rawSettings :: DynFlags -> [(String, String)]
1001 rawSettings dflags = sRawSettings (settings dflags)
1002 extraGccViaCFlags :: DynFlags -> [String]
1003 extraGccViaCFlags dflags = sExtraGccViaCFlags (settings dflags)
1004 systemPackageConfig :: DynFlags -> FilePath
1005 systemPackageConfig dflags = sSystemPackageConfig (settings dflags)
1006 pgm_L :: DynFlags -> String
1007 pgm_L dflags = sPgm_L (settings dflags)
1008 pgm_P :: DynFlags -> (String,[Option])
1009 pgm_P dflags = sPgm_P (settings dflags)
1010 pgm_F :: DynFlags -> String
1011 pgm_F dflags = sPgm_F (settings dflags)
1012 pgm_c :: DynFlags -> (String,[Option])
1013 pgm_c dflags = sPgm_c (settings dflags)
1014 pgm_s :: DynFlags -> (String,[Option])
1015 pgm_s dflags = sPgm_s (settings dflags)
1016 pgm_a :: DynFlags -> (String,[Option])
1017 pgm_a dflags = sPgm_a (settings dflags)
1018 pgm_l :: DynFlags -> (String,[Option])
1019 pgm_l dflags = sPgm_l (settings dflags)
1020 pgm_dll :: DynFlags -> (String,[Option])
1021 pgm_dll dflags = sPgm_dll (settings dflags)
1022 pgm_T :: DynFlags -> String
1023 pgm_T dflags = sPgm_T (settings dflags)
1024 pgm_windres :: DynFlags -> String
1025 pgm_windres dflags = sPgm_windres (settings dflags)
1026 pgm_libtool :: DynFlags -> String
1027 pgm_libtool dflags = sPgm_libtool (settings dflags)
1028 pgm_lo :: DynFlags -> (String,[Option])
1029 pgm_lo dflags = sPgm_lo (settings dflags)
1030 pgm_lc :: DynFlags -> (String,[Option])
1031 pgm_lc dflags = sPgm_lc (settings dflags)
1032 pgm_i :: DynFlags -> String
1033 pgm_i dflags = sPgm_i (settings dflags)
1034 opt_L :: DynFlags -> [String]
1035 opt_L dflags = sOpt_L (settings dflags)
1036 opt_P :: DynFlags -> [String]
1037 opt_P dflags = concatMap (wayOptP (targetPlatform dflags)) (ways dflags)
1038 ++ sOpt_P (settings dflags)
1039 opt_F :: DynFlags -> [String]
1040 opt_F dflags = sOpt_F (settings dflags)
1041 opt_c :: DynFlags -> [String]
1042 opt_c dflags = concatMap (wayOptc (targetPlatform dflags)) (ways dflags)
1043 ++ sOpt_c (settings dflags)
1044 opt_a :: DynFlags -> [String]
1045 opt_a dflags = sOpt_a (settings dflags)
1046 opt_l :: DynFlags -> [String]
1047 opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags)
1048 ++ sOpt_l (settings dflags)
1049 opt_windres :: DynFlags -> [String]
1050 opt_windres dflags = sOpt_windres (settings dflags)
1051 opt_lo :: DynFlags -> [String]
1052 opt_lo dflags = sOpt_lo (settings dflags)
1053 opt_lc :: DynFlags -> [String]
1054 opt_lc dflags = sOpt_lc (settings dflags)
1055 opt_i :: DynFlags -> [String]
1056 opt_i dflags = sOpt_i (settings dflags)
1057
1058 -- | The directory for this version of ghc in the user's app directory
1059 -- (typically something like @~/.ghc/x86_64-linux-7.6.3@)
1060 --
1061 versionedAppDir :: DynFlags -> MaybeT IO FilePath
1062 versionedAppDir dflags = do
1063 -- Make sure we handle the case the HOME isn't set (see #11678)
1064 appdir <- tryMaybeT $ getAppUserDataDirectory (programName dflags)
1065 return $ appdir </> versionedFilePath dflags
1066
1067 -- | A filepath like @x86_64-linux-7.6.3@ with the platform string to use when
1068 -- constructing platform-version-dependent files that need to co-exist.
1069 --
1070 versionedFilePath :: DynFlags -> FilePath
1071 versionedFilePath dflags = TARGET_ARCH
1072 ++ '-':TARGET_OS
1073 ++ '-':projectVersion dflags
1074 -- NB: This functionality is reimplemented in Cabal, so if you
1075 -- change it, be sure to update Cabal.
1076
1077 -- | The target code type of the compilation (if any).
1078 --
1079 -- Whenever you change the target, also make sure to set 'ghcLink' to
1080 -- something sensible.
1081 --
1082 -- 'HscNothing' can be used to avoid generating any output, however, note
1083 -- that:
1084 --
1085 -- * If a program uses Template Haskell the typechecker may try to run code
1086 -- from an imported module. This will fail if no code has been generated
1087 -- for this module. You can use 'GHC.needsTemplateHaskell' to detect
1088 -- whether this might be the case and choose to either switch to a
1089 -- different target or avoid typechecking such modules. (The latter may be
1090 -- preferable for security reasons.)
1091 --
1092 data HscTarget
1093 = HscC -- ^ Generate C code.
1094 | HscAsm -- ^ Generate assembly using the native code generator.
1095 | HscLlvm -- ^ Generate assembly using the llvm code generator.
1096 | HscInterpreted -- ^ Generate bytecode. (Requires 'LinkInMemory')
1097 | HscNothing -- ^ Don't generate any code. See notes above.
1098 deriving (Eq, Show)
1099
1100 -- | Will this target result in an object file on the disk?
1101 isObjectTarget :: HscTarget -> Bool
1102 isObjectTarget HscC = True
1103 isObjectTarget HscAsm = True
1104 isObjectTarget HscLlvm = True
1105 isObjectTarget _ = False
1106
1107 -- | Does this target retain *all* top-level bindings for a module,
1108 -- rather than just the exported bindings, in the TypeEnv and compiled
1109 -- code (if any)? In interpreted mode we do this, so that GHCi can
1110 -- call functions inside a module. In HscNothing mode we also do it,
1111 -- so that Haddock can get access to the GlobalRdrEnv for a module
1112 -- after typechecking it.
1113 targetRetainsAllBindings :: HscTarget -> Bool
1114 targetRetainsAllBindings HscInterpreted = True
1115 targetRetainsAllBindings HscNothing = True
1116 targetRetainsAllBindings _ = False
1117
1118 -- | The 'GhcMode' tells us whether we're doing multi-module
1119 -- compilation (controlled via the "GHC" API) or one-shot
1120 -- (single-module) compilation. This makes a difference primarily to
1121 -- the "Finder": in one-shot mode we look for interface files for
1122 -- imported modules, but in multi-module mode we look for source files
1123 -- in order to check whether they need to be recompiled.
1124 data GhcMode
1125 = CompManager -- ^ @\-\-make@, GHCi, etc.
1126 | OneShot -- ^ @ghc -c Foo.hs@
1127 | MkDepend -- ^ @ghc -M@, see "Finder" for why we need this
1128 deriving Eq
1129
1130 instance Outputable GhcMode where
1131 ppr CompManager = text "CompManager"
1132 ppr OneShot = text "OneShot"
1133 ppr MkDepend = text "MkDepend"
1134
1135 isOneShot :: GhcMode -> Bool
1136 isOneShot OneShot = True
1137 isOneShot _other = False
1138
1139 -- | What to do in the link step, if there is one.
1140 data GhcLink
1141 = NoLink -- ^ Don't link at all
1142 | LinkBinary -- ^ Link object code into a binary
1143 | LinkInMemory -- ^ Use the in-memory dynamic linker (works for both
1144 -- bytecode and object code).
1145 | LinkDynLib -- ^ Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
1146 | LinkStaticLib -- ^ Link objects into a static lib
1147 deriving (Eq, Show)
1148
1149 isNoLink :: GhcLink -> Bool
1150 isNoLink NoLink = True
1151 isNoLink _ = False
1152
1153 -- | We accept flags which make packages visible, but how they select
1154 -- the package varies; this data type reflects what selection criterion
1155 -- is used.
1156 data PackageArg =
1157 PackageArg String -- ^ @-package@, by 'PackageName'
1158 | UnitIdArg UnitId -- ^ @-package-id@, by 'UnitId'
1159 deriving (Eq, Show)
1160 instance Outputable PackageArg where
1161 ppr (PackageArg pn) = text "package" <+> text pn
1162 ppr (UnitIdArg uid) = text "unit" <+> ppr uid
1163
1164 -- | Represents the renaming that may be associated with an exposed
1165 -- package, e.g. the @rns@ part of @-package "foo (rns)"@.
1166 --
1167 -- Here are some example parsings of the package flags (where
1168 -- a string literal is punned to be a 'ModuleName':
1169 --
1170 -- * @-package foo@ is @ModRenaming True []@
1171 -- * @-package foo ()@ is @ModRenaming False []@
1172 -- * @-package foo (A)@ is @ModRenaming False [("A", "A")]@
1173 -- * @-package foo (A as B)@ is @ModRenaming False [("A", "B")]@
1174 -- * @-package foo with (A as B)@ is @ModRenaming True [("A", "B")]@
1175 data ModRenaming = ModRenaming {
1176 modRenamingWithImplicit :: Bool, -- ^ Bring all exposed modules into scope?
1177 modRenamings :: [(ModuleName, ModuleName)] -- ^ Bring module @m@ into scope
1178 -- under name @n@.
1179 } deriving (Eq)
1180 instance Outputable ModRenaming where
1181 ppr (ModRenaming b rns) = ppr b <+> parens (ppr rns)
1182
1183 -- | Flags for manipulating the set of non-broken packages.
1184 newtype IgnorePackageFlag = IgnorePackage String -- ^ @-ignore-package@
1185 deriving (Eq)
1186
1187 -- | Flags for manipulating package trust.
1188 data TrustFlag
1189 = TrustPackage String -- ^ @-trust@
1190 | DistrustPackage String -- ^ @-distrust@
1191 deriving (Eq)
1192
1193 -- | Flags for manipulating packages visibility.
1194 data PackageFlag
1195 = ExposePackage String PackageArg ModRenaming -- ^ @-package@, @-package-id@
1196 | HidePackage String -- ^ @-hide-package@
1197 deriving (Eq)
1198 -- NB: equality instance is used by InteractiveUI to test if
1199 -- package flags have changed.
1200
1201 instance Outputable PackageFlag where
1202 ppr (ExposePackage n arg rn) = text n <> braces (ppr arg <+> ppr rn)
1203 ppr (HidePackage str) = text "-hide-package" <+> text str
1204
1205 defaultHscTarget :: Platform -> HscTarget
1206 defaultHscTarget = defaultObjectTarget
1207
1208 -- | The 'HscTarget' value corresponding to the default way to create
1209 -- object files on the current platform.
1210 defaultObjectTarget :: Platform -> HscTarget
1211 defaultObjectTarget platform
1212 | platformUnregisterised platform = HscC
1213 | cGhcWithNativeCodeGen == "YES" = HscAsm
1214 | otherwise = HscLlvm
1215
1216 tablesNextToCode :: DynFlags -> Bool
1217 tablesNextToCode dflags
1218 = mkTablesNextToCode (platformUnregisterised (targetPlatform dflags))
1219
1220 -- Determines whether we will be compiling
1221 -- info tables that reside just before the entry code, or with an
1222 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
1223 -- includes/rts/storage/InfoTables.h.
1224 mkTablesNextToCode :: Bool -> Bool
1225 mkTablesNextToCode unregisterised
1226 = not unregisterised && cGhcEnableTablesNextToCode == "YES"
1227
1228 data DynLibLoader
1229 = Deployable
1230 | SystemDependent
1231 deriving Eq
1232
1233 data RtsOptsEnabled = RtsOptsNone | RtsOptsSafeOnly | RtsOptsAll
1234 deriving (Show)
1235
1236 -----------------------------------------------------------------------------
1237 -- Ways
1238
1239 -- The central concept of a "way" is that all objects in a given
1240 -- program must be compiled in the same "way". Certain options change
1241 -- parameters of the virtual machine, eg. profiling adds an extra word
1242 -- to the object header, so profiling objects cannot be linked with
1243 -- non-profiling objects.
1244
1245 -- After parsing the command-line options, we determine which "way" we
1246 -- are building - this might be a combination way, eg. profiling+threaded.
1247
1248 -- We then find the "build-tag" associated with this way, and this
1249 -- becomes the suffix used to find .hi files and libraries used in
1250 -- this compilation.
1251
1252 data Way
1253 = WayCustom String -- for GHC API clients building custom variants
1254 | WayThreaded
1255 | WayDebug
1256 | WayProf
1257 | WayEventLog
1258 | WayDyn
1259 deriving (Eq, Ord, Show)
1260
1261 allowed_combination :: [Way] -> Bool
1262 allowed_combination way = and [ x `allowedWith` y
1263 | x <- way, y <- way, x < y ]
1264 where
1265 -- Note ordering in these tests: the left argument is
1266 -- <= the right argument, according to the Ord instance
1267 -- on Way above.
1268
1269 -- dyn is allowed with everything
1270 _ `allowedWith` WayDyn = True
1271 WayDyn `allowedWith` _ = True
1272
1273 -- debug is allowed with everything
1274 _ `allowedWith` WayDebug = True
1275 WayDebug `allowedWith` _ = True
1276
1277 (WayCustom {}) `allowedWith` _ = True
1278 WayThreaded `allowedWith` WayProf = True
1279 WayThreaded `allowedWith` WayEventLog = True
1280 WayProf `allowedWith` WayEventLog = True
1281 _ `allowedWith` _ = False
1282
1283 mkBuildTag :: [Way] -> String
1284 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
1285
1286 wayTag :: Way -> String
1287 wayTag (WayCustom xs) = xs
1288 wayTag WayThreaded = "thr"
1289 wayTag WayDebug = "debug"
1290 wayTag WayDyn = "dyn"
1291 wayTag WayProf = "p"
1292 wayTag WayEventLog = "l"
1293
1294 wayRTSOnly :: Way -> Bool
1295 wayRTSOnly (WayCustom {}) = False
1296 wayRTSOnly WayThreaded = True
1297 wayRTSOnly WayDebug = True
1298 wayRTSOnly WayDyn = False
1299 wayRTSOnly WayProf = False
1300 wayRTSOnly WayEventLog = True
1301
1302 wayDesc :: Way -> String
1303 wayDesc (WayCustom xs) = xs
1304 wayDesc WayThreaded = "Threaded"
1305 wayDesc WayDebug = "Debug"
1306 wayDesc WayDyn = "Dynamic"
1307 wayDesc WayProf = "Profiling"
1308 wayDesc WayEventLog = "RTS Event Logging"
1309
1310 -- Turn these flags on when enabling this way
1311 wayGeneralFlags :: Platform -> Way -> [GeneralFlag]
1312 wayGeneralFlags _ (WayCustom {}) = []
1313 wayGeneralFlags _ WayThreaded = []
1314 wayGeneralFlags _ WayDebug = []
1315 wayGeneralFlags _ WayDyn = [Opt_PIC]
1316 -- We could get away without adding -fPIC when compiling the
1317 -- modules of a program that is to be linked with -dynamic; the
1318 -- program itself does not need to be position-independent, only
1319 -- the libraries need to be. HOWEVER, GHCi links objects into a
1320 -- .so before loading the .so using the system linker. Since only
1321 -- PIC objects can be linked into a .so, we have to compile even
1322 -- modules of the main program with -fPIC when using -dynamic.
1323 wayGeneralFlags _ WayProf = [Opt_SccProfilingOn]
1324 wayGeneralFlags _ WayEventLog = []
1325
1326 -- Turn these flags off when enabling this way
1327 wayUnsetGeneralFlags :: Platform -> Way -> [GeneralFlag]
1328 wayUnsetGeneralFlags _ (WayCustom {}) = []
1329 wayUnsetGeneralFlags _ WayThreaded = []
1330 wayUnsetGeneralFlags _ WayDebug = []
1331 wayUnsetGeneralFlags _ WayDyn = [-- There's no point splitting objects
1332 -- when we're going to be dynamically
1333 -- linking. Plus it breaks compilation
1334 -- on OSX x86.
1335 Opt_SplitObjs,
1336 -- If splitobjs wasn't useful for this,
1337 -- assume sections aren't either.
1338 Opt_SplitSections]
1339 wayUnsetGeneralFlags _ WayProf = []
1340 wayUnsetGeneralFlags _ WayEventLog = []
1341
1342 wayOptc :: Platform -> Way -> [String]
1343 wayOptc _ (WayCustom {}) = []
1344 wayOptc platform WayThreaded = case platformOS platform of
1345 OSOpenBSD -> ["-pthread"]
1346 OSNetBSD -> ["-pthread"]
1347 _ -> []
1348 wayOptc _ WayDebug = []
1349 wayOptc _ WayDyn = []
1350 wayOptc _ WayProf = ["-DPROFILING"]
1351 wayOptc _ WayEventLog = ["-DTRACING"]
1352
1353 wayOptl :: Platform -> Way -> [String]
1354 wayOptl _ (WayCustom {}) = []
1355 wayOptl platform WayThreaded =
1356 case platformOS platform of
1357 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
1358 -- which GHC has some problems with. It's currently not clear whether
1359 -- the problems are our fault or theirs, but it seems that using the
1360 -- alternative 1:1 threading library libthr works around it:
1361 OSFreeBSD -> ["-lthr"]
1362 OSOpenBSD -> ["-pthread"]
1363 OSNetBSD -> ["-pthread"]
1364 _ -> []
1365 wayOptl _ WayDebug = []
1366 wayOptl _ WayDyn = []
1367 wayOptl _ WayProf = []
1368 wayOptl _ WayEventLog = []
1369
1370 wayOptP :: Platform -> Way -> [String]
1371 wayOptP _ (WayCustom {}) = []
1372 wayOptP _ WayThreaded = []
1373 wayOptP _ WayDebug = []
1374 wayOptP _ WayDyn = []
1375 wayOptP _ WayProf = ["-DPROFILING"]
1376 wayOptP _ WayEventLog = ["-DTRACING"]
1377
1378 whenGeneratingDynamicToo :: MonadIO m => DynFlags -> m () -> m ()
1379 whenGeneratingDynamicToo dflags f = ifGeneratingDynamicToo dflags f (return ())
1380
1381 ifGeneratingDynamicToo :: MonadIO m => DynFlags -> m a -> m a -> m a
1382 ifGeneratingDynamicToo dflags f g = generateDynamicTooConditional dflags f g g
1383
1384 whenCannotGenerateDynamicToo :: MonadIO m => DynFlags -> m () -> m ()
1385 whenCannotGenerateDynamicToo dflags f
1386 = ifCannotGenerateDynamicToo dflags f (return ())
1387
1388 ifCannotGenerateDynamicToo :: MonadIO m => DynFlags -> m a -> m a -> m a
1389 ifCannotGenerateDynamicToo dflags f g
1390 = generateDynamicTooConditional dflags g f g
1391
1392 generateDynamicTooConditional :: MonadIO m
1393 => DynFlags -> m a -> m a -> m a -> m a
1394 generateDynamicTooConditional dflags canGen cannotGen notTryingToGen
1395 = if gopt Opt_BuildDynamicToo dflags
1396 then do let ref = canGenerateDynamicToo dflags
1397 b <- liftIO $ readIORef ref
1398 if b then canGen else cannotGen
1399 else notTryingToGen
1400
1401 dynamicTooMkDynamicDynFlags :: DynFlags -> DynFlags
1402 dynamicTooMkDynamicDynFlags dflags0
1403 = let dflags1 = addWay' WayDyn dflags0
1404 dflags2 = dflags1 {
1405 outputFile = dynOutputFile dflags1,
1406 hiSuf = dynHiSuf dflags1,
1407 objectSuf = dynObjectSuf dflags1
1408 }
1409 dflags3 = updateWays dflags2
1410 dflags4 = gopt_unset dflags3 Opt_BuildDynamicToo
1411 in dflags4
1412
1413 -----------------------------------------------------------------------------
1414
1415 -- | Used by 'GHC.runGhc' to partially initialize a new 'DynFlags' value
1416 initDynFlags :: DynFlags -> IO DynFlags
1417 initDynFlags dflags = do
1418 let -- We can't build with dynamic-too on Windows, as labels before
1419 -- the fork point are different depending on whether we are
1420 -- building dynamically or not.
1421 platformCanGenerateDynamicToo
1422 = platformOS (targetPlatform dflags) /= OSMinGW32
1423 refCanGenerateDynamicToo <- newIORef platformCanGenerateDynamicToo
1424 refNextTempSuffix <- newIORef 0
1425 refFilesToClean <- newIORef []
1426 refDirsToClean <- newIORef Map.empty
1427 refFilesToNotIntermediateClean <- newIORef []
1428 refGeneratedDumps <- newIORef Set.empty
1429 refRtldInfo <- newIORef Nothing
1430 refRtccInfo <- newIORef Nothing
1431 wrapperNum <- newIORef emptyModuleEnv
1432 canUseUnicode <- do let enc = localeEncoding
1433 str = "‘’"
1434 (withCString enc str $ \cstr ->
1435 do str' <- peekCString enc cstr
1436 return (str == str'))
1437 `catchIOError` \_ -> return False
1438 return dflags{
1439 canGenerateDynamicToo = refCanGenerateDynamicToo,
1440 nextTempSuffix = refNextTempSuffix,
1441 filesToClean = refFilesToClean,
1442 dirsToClean = refDirsToClean,
1443 filesToNotIntermediateClean = refFilesToNotIntermediateClean,
1444 generatedDumps = refGeneratedDumps,
1445 nextWrapperNum = wrapperNum,
1446 useUnicode = canUseUnicode,
1447 rtldInfo = refRtldInfo,
1448 rtccInfo = refRtccInfo
1449 }
1450
1451 -- | The normal 'DynFlags'. Note that they are not suitable for use in this form
1452 -- and must be fully initialized by 'GHC.runGhc' first.
1453 defaultDynFlags :: Settings -> DynFlags
1454 defaultDynFlags mySettings =
1455 -- See Note [Updating flag description in the User's Guide]
1456 DynFlags {
1457 ghcMode = CompManager,
1458 ghcLink = LinkBinary,
1459 hscTarget = defaultHscTarget (sTargetPlatform mySettings),
1460 verbosity = 0,
1461 optLevel = 0,
1462 debugLevel = 0,
1463 simplPhases = 2,
1464 maxSimplIterations = 4,
1465 maxPmCheckIterations = 2000000,
1466 ruleCheck = Nothing,
1467 maxRelevantBinds = Just 6,
1468 maxUncoveredPatterns = 4,
1469 simplTickFactor = 100,
1470 specConstrThreshold = Just 2000,
1471 specConstrCount = Just 3,
1472 specConstrRecursive = 3,
1473 liberateCaseThreshold = Just 2000,
1474 floatLamArgs = Just 0, -- Default: float only if no fvs
1475
1476 historySize = 20,
1477 strictnessBefore = [],
1478
1479 parMakeCount = Just 1,
1480
1481 enableTimeStats = False,
1482 ghcHeapSize = Nothing,
1483
1484 importPaths = ["."],
1485 mainModIs = mAIN,
1486 mainFunIs = Nothing,
1487 reductionDepth = treatZeroAsInf mAX_REDUCTION_DEPTH,
1488 solverIterations = treatZeroAsInf mAX_SOLVER_ITERATIONS,
1489
1490 thisPackage = mainUnitId,
1491 thisUnitIdInsts = [],
1492
1493 objectDir = Nothing,
1494 dylibInstallName = Nothing,
1495 hiDir = Nothing,
1496 stubDir = Nothing,
1497 dumpDir = Nothing,
1498
1499 objectSuf = phaseInputExt StopLn,
1500 hcSuf = phaseInputExt HCc,
1501 hiSuf = "hi",
1502
1503 canGenerateDynamicToo = panic "defaultDynFlags: No canGenerateDynamicToo",
1504 dynObjectSuf = "dyn_" ++ phaseInputExt StopLn,
1505 dynHiSuf = "dyn_hi",
1506
1507 dllSplitFile = Nothing,
1508 dllSplit = Nothing,
1509
1510 pluginModNames = [],
1511 pluginModNameOpts = [],
1512 frontendPluginOpts = [],
1513 hooks = emptyHooks,
1514
1515 outputFile = Nothing,
1516 dynOutputFile = Nothing,
1517 outputHi = Nothing,
1518 dynLibLoader = SystemDependent,
1519 dumpPrefix = Nothing,
1520 dumpPrefixForce = Nothing,
1521 ldInputs = [],
1522 includePaths = [],
1523 libraryPaths = [],
1524 frameworkPaths = [],
1525 cmdlineFrameworks = [],
1526 rtsOpts = Nothing,
1527 rtsOptsEnabled = RtsOptsSafeOnly,
1528 rtsOptsSuggestions = True,
1529
1530 hpcDir = ".hpc",
1531
1532 extraPkgConfs = id,
1533 packageFlags = [],
1534 pluginPackageFlags = [],
1535 ignorePackageFlags = [],
1536 trustFlags = [],
1537 packageEnv = Nothing,
1538 pkgDatabase = Nothing,
1539 -- This gets filled in with GHC.setSessionDynFlags
1540 pkgState = emptyPackageState,
1541 ways = defaultWays mySettings,
1542 buildTag = mkBuildTag (defaultWays mySettings),
1543 rtsBuildTag = mkBuildTag (defaultWays mySettings),
1544 splitInfo = Nothing,
1545 settings = mySettings,
1546 -- ghc -M values
1547 depMakefile = "Makefile",
1548 depIncludePkgDeps = False,
1549 depExcludeMods = [],
1550 depSuffixes = [],
1551 -- end of ghc -M values
1552 nextTempSuffix = panic "defaultDynFlags: No nextTempSuffix",
1553 filesToClean = panic "defaultDynFlags: No filesToClean",
1554 dirsToClean = panic "defaultDynFlags: No dirsToClean",
1555 filesToNotIntermediateClean = panic "defaultDynFlags: No filesToNotIntermediateClean",
1556 generatedDumps = panic "defaultDynFlags: No generatedDumps",
1557 haddockOptions = Nothing,
1558 dumpFlags = IntSet.empty,
1559 generalFlags = IntSet.fromList (map fromEnum (defaultFlags mySettings)),
1560 warningFlags = IntSet.fromList (map fromEnum standardWarnings),
1561 ghciScripts = [],
1562 language = Nothing,
1563 safeHaskell = Sf_None,
1564 safeInfer = True,
1565 safeInferred = True,
1566 thOnLoc = noSrcSpan,
1567 newDerivOnLoc = noSrcSpan,
1568 overlapInstLoc = noSrcSpan,
1569 incoherentOnLoc = noSrcSpan,
1570 pkgTrustOnLoc = noSrcSpan,
1571 warnSafeOnLoc = noSrcSpan,
1572 warnUnsafeOnLoc = noSrcSpan,
1573 trustworthyOnLoc = noSrcSpan,
1574 extensions = [],
1575 extensionFlags = flattenExtensionFlags Nothing [],
1576
1577 -- The ufCreationThreshold threshold must be reasonably high to
1578 -- take account of possible discounts.
1579 -- E.g. 450 is not enough in 'fulsom' for Interval.sqr to inline
1580 -- into Csg.calc (The unfolding for sqr never makes it into the
1581 -- interface file.)
1582 ufCreationThreshold = 750,
1583 ufUseThreshold = 60,
1584 ufFunAppDiscount = 60,
1585 -- Be fairly keen to inline a function if that means
1586 -- we'll be able to pick the right method from a dictionary
1587 ufDictDiscount = 30,
1588 ufKeenessFactor = 1.5,
1589 ufDearOp = 40,
1590
1591 maxWorkerArgs = 10,
1592
1593 ghciHistSize = 50, -- keep a log of length 50 by default
1594
1595 log_action = defaultLogAction,
1596 flushOut = defaultFlushOut,
1597 flushErr = defaultFlushErr,
1598 pprUserLength = 5,
1599 pprCols = 100,
1600 useUnicode = False,
1601 traceLevel = 1,
1602 profAuto = NoProfAuto,
1603 interactivePrint = Nothing,
1604 nextWrapperNum = panic "defaultDynFlags: No nextWrapperNum",
1605 sseVersion = Nothing,
1606 avx = False,
1607 avx2 = False,
1608 avx512cd = False,
1609 avx512er = False,
1610 avx512f = False,
1611 avx512pf = False,
1612 rtldInfo = panic "defaultDynFlags: no rtldInfo",
1613 rtccInfo = panic "defaultDynFlags: no rtccInfo",
1614
1615 maxInlineAllocSize = 128,
1616 maxInlineMemcpyInsns = 32,
1617 maxInlineMemsetInsns = 32,
1618
1619 initialUnique = 0,
1620 uniqueIncrement = 1,
1621
1622 reverseErrors = False
1623 }
1624
1625 defaultWays :: Settings -> [Way]
1626 defaultWays settings = if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings)
1627 then [WayDyn]
1628 else []
1629
1630 interpWays :: [Way]
1631 interpWays
1632 | dynamicGhc = [WayDyn]
1633 | rtsIsProfiled = [WayProf]
1634 | otherwise = []
1635
1636 interpreterProfiled :: DynFlags -> Bool
1637 interpreterProfiled dflags
1638 | gopt Opt_ExternalInterpreter dflags = gopt Opt_SccProfilingOn dflags
1639 | otherwise = rtsIsProfiled
1640
1641 interpreterDynamic :: DynFlags -> Bool
1642 interpreterDynamic dflags
1643 | gopt Opt_ExternalInterpreter dflags = WayDyn `elem` ways dflags
1644 | otherwise = dynamicGhc
1645
1646 --------------------------------------------------------------------------
1647
1648 type FatalMessager = String -> IO ()
1649
1650 type LogAction = DynFlags
1651 -> WarnReason
1652 -> Severity
1653 -> SrcSpan
1654 -> PprStyle
1655 -> MsgDoc
1656 -> IO ()
1657
1658 defaultFatalMessager :: FatalMessager
1659 defaultFatalMessager = hPutStrLn stderr
1660
1661 defaultLogAction :: LogAction
1662 defaultLogAction dflags reason severity srcSpan style msg
1663 = case severity of
1664 SevOutput -> printSDoc msg style
1665 SevDump -> printSDoc (msg $$ blankLine) style
1666 SevInteractive -> putStrSDoc msg style
1667 SevInfo -> printErrs msg style
1668 SevFatal -> printErrs msg style
1669 _ -> do hPutChar stderr '\n'
1670 printErrs message style
1671 -- careful (#2302): printErrs prints in UTF-8,
1672 -- whereas converting to string first and using
1673 -- hPutStr would just emit the low 8 bits of
1674 -- each unicode char.
1675 where printSDoc = defaultLogActionHPrintDoc dflags stdout
1676 printErrs = defaultLogActionHPrintDoc dflags stderr
1677 putStrSDoc = defaultLogActionHPutStrDoc dflags stdout
1678 -- Pretty print the warning flag, if any (#10752)
1679 message = mkLocMessageAnn flagMsg severity srcSpan msg
1680 flagMsg = case reason of
1681 NoReason -> Nothing
1682 Reason flag -> (\spec -> "-W" ++ flagSpecName spec ++ flagGrp flag) <$>
1683 flagSpecOf flag
1684
1685 flagGrp flag
1686 | gopt Opt_ShowWarnGroups dflags =
1687 case smallestGroups flag of
1688 [] -> ""
1689 groups -> " (in " ++ intercalate ", " (map ("-W"++) groups) ++ ")"
1690 | otherwise = ""
1691
1692 defaultLogActionHPrintDoc :: DynFlags -> Handle -> SDoc -> PprStyle -> IO ()
1693 defaultLogActionHPrintDoc dflags h d sty
1694 = defaultLogActionHPutStrDoc dflags h (d $$ text "") sty
1695 -- Adds a newline
1696
1697 defaultLogActionHPutStrDoc :: DynFlags -> Handle -> SDoc -> PprStyle -> IO ()
1698 defaultLogActionHPutStrDoc dflags h d sty
1699 = Pretty.printDoc_ Pretty.PageMode (pprCols dflags) h doc
1700 where -- Don't add a newline at the end, so that successive
1701 -- calls to this log-action can output all on the same line
1702 doc = runSDoc d (initSDocContext dflags sty)
1703
1704 newtype FlushOut = FlushOut (IO ())
1705
1706 defaultFlushOut :: FlushOut
1707 defaultFlushOut = FlushOut $ hFlush stdout
1708
1709 newtype FlushErr = FlushErr (IO ())
1710
1711 defaultFlushErr :: FlushErr
1712 defaultFlushErr = FlushErr $ hFlush stderr
1713
1714 {-
1715 Note [Verbosity levels]
1716 ~~~~~~~~~~~~~~~~~~~~~~~
1717 0 | print errors & warnings only
1718 1 | minimal verbosity: print "compiling M ... done." for each module.
1719 2 | equivalent to -dshow-passes
1720 3 | equivalent to existing "ghc -v"
1721 4 | "ghc -v -ddump-most"
1722 5 | "ghc -v -ddump-all"
1723 -}
1724
1725 data OnOff a = On a
1726 | Off a
1727 deriving (Eq, Show)
1728
1729 instance Outputable a => Outputable (OnOff a) where
1730 ppr (On x) = text "On" <+> ppr x
1731 ppr (Off x) = text "Off" <+> ppr x
1732
1733 -- OnOffs accumulate in reverse order, so we use foldr in order to
1734 -- process them in the right order
1735 flattenExtensionFlags :: Maybe Language -> [OnOff LangExt.Extension] -> IntSet
1736 flattenExtensionFlags ml = foldr f defaultExtensionFlags
1737 where f (On f) flags = IntSet.insert (fromEnum f) flags
1738 f (Off f) flags = IntSet.delete (fromEnum f) flags
1739 defaultExtensionFlags = IntSet.fromList (map fromEnum (languageExtensions ml))
1740
1741 languageExtensions :: Maybe Language -> [LangExt.Extension]
1742
1743 languageExtensions Nothing
1744 -- Nothing => the default case
1745 = LangExt.NondecreasingIndentation -- This has been on by default for some time
1746 : delete LangExt.DatatypeContexts -- The Haskell' committee decided to
1747 -- remove datatype contexts from the
1748 -- language:
1749 -- http://www.haskell.org/pipermail/haskell-prime/2011-January/003335.html
1750 (languageExtensions (Just Haskell2010))
1751
1752 -- NB: MonoPatBinds is no longer the default
1753
1754 languageExtensions (Just Haskell98)
1755 = [LangExt.ImplicitPrelude,
1756 LangExt.MonomorphismRestriction,
1757 LangExt.NPlusKPatterns,
1758 LangExt.DatatypeContexts,
1759 LangExt.TraditionalRecordSyntax,
1760 LangExt.NondecreasingIndentation
1761 -- strictly speaking non-standard, but we always had this
1762 -- on implicitly before the option was added in 7.1, and
1763 -- turning it off breaks code, so we're keeping it on for
1764 -- backwards compatibility. Cabal uses -XHaskell98 by
1765 -- default unless you specify another language.
1766 ]
1767
1768 languageExtensions (Just Haskell2010)
1769 = [LangExt.ImplicitPrelude,
1770 LangExt.MonomorphismRestriction,
1771 LangExt.DatatypeContexts,
1772 LangExt.TraditionalRecordSyntax,
1773 LangExt.EmptyDataDecls,
1774 LangExt.ForeignFunctionInterface,
1775 LangExt.PatternGuards,
1776 LangExt.DoAndIfThenElse,
1777 LangExt.RelaxedPolyRec]
1778
1779 -- | Test whether a 'DumpFlag' is set
1780 dopt :: DumpFlag -> DynFlags -> Bool
1781 dopt f dflags = (fromEnum f `IntSet.member` dumpFlags dflags)
1782 || (verbosity dflags >= 4 && enableIfVerbose f)
1783 where enableIfVerbose Opt_D_dump_tc_trace = False
1784 enableIfVerbose Opt_D_dump_rn_trace = False
1785 enableIfVerbose Opt_D_dump_cs_trace = False
1786 enableIfVerbose Opt_D_dump_if_trace = False
1787 enableIfVerbose Opt_D_dump_vt_trace = False
1788 enableIfVerbose Opt_D_dump_tc = False
1789 enableIfVerbose Opt_D_dump_rn = False
1790 enableIfVerbose Opt_D_dump_shape = False
1791 enableIfVerbose Opt_D_dump_rn_stats = False
1792 enableIfVerbose Opt_D_dump_hi_diffs = False
1793 enableIfVerbose Opt_D_verbose_core2core = False
1794 enableIfVerbose Opt_D_verbose_stg2stg = False
1795 enableIfVerbose Opt_D_dump_splices = False
1796 enableIfVerbose Opt_D_th_dec_file = False
1797 enableIfVerbose Opt_D_dump_rule_firings = False
1798 enableIfVerbose Opt_D_dump_rule_rewrites = False
1799 enableIfVerbose Opt_D_dump_simpl_trace = False
1800 enableIfVerbose Opt_D_dump_rtti = False
1801 enableIfVerbose Opt_D_dump_inlinings = False
1802 enableIfVerbose Opt_D_dump_core_stats = False
1803 enableIfVerbose Opt_D_dump_asm_stats = False
1804 enableIfVerbose Opt_D_dump_types = False
1805 enableIfVerbose Opt_D_dump_simpl_iterations = False
1806 enableIfVerbose Opt_D_dump_ticked = False
1807 enableIfVerbose Opt_D_dump_view_pattern_commoning = False
1808 enableIfVerbose Opt_D_dump_mod_cycles = False
1809 enableIfVerbose Opt_D_dump_mod_map = False
1810 enableIfVerbose _ = True
1811
1812 -- | Set a 'DumpFlag'
1813 dopt_set :: DynFlags -> DumpFlag -> DynFlags
1814 dopt_set dfs f = dfs{ dumpFlags = IntSet.insert (fromEnum f) (dumpFlags dfs) }
1815
1816 -- | Unset a 'DumpFlag'
1817 dopt_unset :: DynFlags -> DumpFlag -> DynFlags
1818 dopt_unset dfs f = dfs{ dumpFlags = IntSet.delete (fromEnum f) (dumpFlags dfs) }
1819
1820 -- | Test whether a 'GeneralFlag' is set
1821 gopt :: GeneralFlag -> DynFlags -> Bool
1822 gopt f dflags = fromEnum f `IntSet.member` generalFlags dflags
1823
1824 -- | Set a 'GeneralFlag'
1825 gopt_set :: DynFlags -> GeneralFlag -> DynFlags
1826 gopt_set dfs f = dfs{ generalFlags = IntSet.insert (fromEnum f) (generalFlags dfs) }
1827
1828 -- | Unset a 'GeneralFlag'
1829 gopt_unset :: DynFlags -> GeneralFlag -> DynFlags
1830 gopt_unset dfs f = dfs{ generalFlags = IntSet.delete (fromEnum f) (generalFlags dfs) }
1831
1832 -- | Test whether a 'WarningFlag' is set
1833 wopt :: WarningFlag -> DynFlags -> Bool
1834 wopt f dflags = fromEnum f `IntSet.member` warningFlags dflags
1835
1836 -- | Set a 'WarningFlag'
1837 wopt_set :: DynFlags -> WarningFlag -> DynFlags
1838 wopt_set dfs f = dfs{ warningFlags = IntSet.insert (fromEnum f) (warningFlags dfs) }
1839
1840 -- | Unset a 'WarningFlag'
1841 wopt_unset :: DynFlags -> WarningFlag -> DynFlags
1842 wopt_unset dfs f = dfs{ warningFlags = IntSet.delete (fromEnum f) (warningFlags dfs) }
1843
1844 -- | Test whether a 'LangExt.Extension' is set
1845 xopt :: LangExt.Extension -> DynFlags -> Bool
1846 xopt f dflags = fromEnum f `IntSet.member` extensionFlags dflags
1847
1848 -- | Set a 'LangExt.Extension'
1849 xopt_set :: DynFlags -> LangExt.Extension -> DynFlags
1850 xopt_set dfs f
1851 = let onoffs = On f : extensions dfs
1852 in dfs { extensions = onoffs,
1853 extensionFlags = flattenExtensionFlags (language dfs) onoffs }
1854
1855 -- | Unset a 'LangExt.Extension'
1856 xopt_unset :: DynFlags -> LangExt.Extension -> DynFlags
1857 xopt_unset dfs f
1858 = let onoffs = Off f : extensions dfs
1859 in dfs { extensions = onoffs,
1860 extensionFlags = flattenExtensionFlags (language dfs) onoffs }
1861
1862 lang_set :: DynFlags -> Maybe Language -> DynFlags
1863 lang_set dflags lang =
1864 dflags {
1865 language = lang,
1866 extensionFlags = flattenExtensionFlags lang (extensions dflags)
1867 }
1868
1869 -- | An internal helper to check whether to use unicode syntax for output.
1870 --
1871 -- Note: You should very likely be using 'Outputable.unicodeSyntax' instead
1872 -- of this function.
1873 useUnicodeSyntax :: DynFlags -> Bool
1874 useUnicodeSyntax = gopt Opt_PrintUnicodeSyntax
1875
1876 -- | Set the Haskell language standard to use
1877 setLanguage :: Language -> DynP ()
1878 setLanguage l = upd (`lang_set` Just l)
1879
1880 -- | Some modules have dependencies on others through the DynFlags rather than textual imports
1881 dynFlagDependencies :: DynFlags -> [ModuleName]
1882 dynFlagDependencies = pluginModNames
1883
1884 -- | Is the -fpackage-trust mode on
1885 packageTrustOn :: DynFlags -> Bool
1886 packageTrustOn = gopt Opt_PackageTrust
1887
1888 -- | Is Safe Haskell on in some way (including inference mode)
1889 safeHaskellOn :: DynFlags -> Bool
1890 safeHaskellOn dflags = safeHaskell dflags /= Sf_None || safeInferOn dflags
1891
1892 -- | Is the Safe Haskell safe language in use
1893 safeLanguageOn :: DynFlags -> Bool
1894 safeLanguageOn dflags = safeHaskell dflags == Sf_Safe
1895
1896 -- | Is the Safe Haskell safe inference mode active
1897 safeInferOn :: DynFlags -> Bool
1898 safeInferOn = safeInfer
1899
1900 -- | Test if Safe Imports are on in some form
1901 safeImportsOn :: DynFlags -> Bool
1902 safeImportsOn dflags = safeHaskell dflags == Sf_Unsafe ||
1903 safeHaskell dflags == Sf_Trustworthy ||
1904 safeHaskell dflags == Sf_Safe
1905
1906 -- | Set a 'Safe Haskell' flag
1907 setSafeHaskell :: SafeHaskellMode -> DynP ()
1908 setSafeHaskell s = updM f
1909 where f dfs = do
1910 let sf = safeHaskell dfs
1911 safeM <- combineSafeFlags sf s
1912 case s of
1913 Sf_Safe -> return $ dfs { safeHaskell = safeM, safeInfer = False }
1914 -- leave safe inferrence on in Trustworthy mode so we can warn
1915 -- if it could have been inferred safe.
1916 Sf_Trustworthy -> do
1917 l <- getCurLoc
1918 return $ dfs { safeHaskell = safeM, trustworthyOnLoc = l }
1919 -- leave safe inference on in Unsafe mode as well.
1920 _ -> return $ dfs { safeHaskell = safeM }
1921
1922 -- | Are all direct imports required to be safe for this Safe Haskell mode?
1923 -- Direct imports are when the code explicitly imports a module
1924 safeDirectImpsReq :: DynFlags -> Bool
1925 safeDirectImpsReq d = safeLanguageOn d
1926
1927 -- | Are all implicit imports required to be safe for this Safe Haskell mode?
1928 -- Implicit imports are things in the prelude. e.g System.IO when print is used.
1929 safeImplicitImpsReq :: DynFlags -> Bool
1930 safeImplicitImpsReq d = safeLanguageOn d
1931
1932 -- | Combine two Safe Haskell modes correctly. Used for dealing with multiple flags.
1933 -- This makes Safe Haskell very much a monoid but for now I prefer this as I don't
1934 -- want to export this functionality from the module but do want to export the
1935 -- type constructors.
1936 combineSafeFlags :: SafeHaskellMode -> SafeHaskellMode -> DynP SafeHaskellMode
1937 combineSafeFlags a b | a == Sf_None = return b
1938 | b == Sf_None = return a
1939 | a == b = return a
1940 | otherwise = addErr errm >> pure a
1941 where errm = "Incompatible Safe Haskell flags! ("
1942 ++ show a ++ ", " ++ show b ++ ")"
1943
1944 -- | A list of unsafe flags under Safe Haskell. Tuple elements are:
1945 -- * name of the flag
1946 -- * function to get srcspan that enabled the flag
1947 -- * function to test if the flag is on
1948 -- * function to turn the flag off
1949 unsafeFlags, unsafeFlagsForInfer
1950 :: [(String, DynFlags -> SrcSpan, DynFlags -> Bool, DynFlags -> DynFlags)]
1951 unsafeFlags = [ ("-XGeneralizedNewtypeDeriving", newDerivOnLoc,
1952 xopt LangExt.GeneralizedNewtypeDeriving,
1953 flip xopt_unset LangExt.GeneralizedNewtypeDeriving)
1954 , ("-XTemplateHaskell", thOnLoc,
1955 xopt LangExt.TemplateHaskell,
1956 flip xopt_unset LangExt.TemplateHaskell)
1957 ]
1958 unsafeFlagsForInfer = unsafeFlags
1959
1960
1961 -- | Retrieve the options corresponding to a particular @opt_*@ field in the correct order
1962 getOpts :: DynFlags -- ^ 'DynFlags' to retrieve the options from
1963 -> (DynFlags -> [a]) -- ^ Relevant record accessor: one of the @opt_*@ accessors
1964 -> [a] -- ^ Correctly ordered extracted options
1965 getOpts dflags opts = reverse (opts dflags)
1966 -- We add to the options from the front, so we need to reverse the list
1967
1968 -- | Gets the verbosity flag for the current verbosity level. This is fed to
1969 -- other tools, so GHC-specific verbosity flags like @-ddump-most@ are not included
1970 getVerbFlags :: DynFlags -> [String]
1971 getVerbFlags dflags
1972 | verbosity dflags >= 4 = ["-v"]
1973 | otherwise = []
1974
1975 setObjectDir, setHiDir, setStubDir, setDumpDir, setOutputDir,
1976 setDynObjectSuf, setDynHiSuf,
1977 setDylibInstallName,
1978 setObjectSuf, setHiSuf, setHcSuf, parseDynLibLoaderMode,
1979 setPgmP, addOptl, addOptc, addOptP,
1980 addCmdlineFramework, addHaddockOpts, addGhciScript,
1981 setInteractivePrint
1982 :: String -> DynFlags -> DynFlags
1983 setOutputFile, setDynOutputFile, setOutputHi, setDumpPrefixForce
1984 :: Maybe String -> DynFlags -> DynFlags
1985
1986 setObjectDir f d = d { objectDir = Just f}
1987 setHiDir f d = d { hiDir = Just f}
1988 setStubDir f d = d { stubDir = Just f, includePaths = f : includePaths d }
1989 -- -stubdir D adds an implicit -I D, so that gcc can find the _stub.h file
1990 -- \#included from the .hc file when compiling via C (i.e. unregisterised
1991 -- builds).
1992 setDumpDir f d = d { dumpDir = Just f}
1993 setOutputDir f = setObjectDir f . setHiDir f . setStubDir f . setDumpDir f
1994 setDylibInstallName f d = d { dylibInstallName = Just f}
1995
1996 setObjectSuf f d = d { objectSuf = f}
1997 setDynObjectSuf f d = d { dynObjectSuf = f}
1998 setHiSuf f d = d { hiSuf = f}
1999 setDynHiSuf f d = d { dynHiSuf = f}
2000 setHcSuf f d = d { hcSuf = f}
2001
2002 setOutputFile f d = d { outputFile = f}
2003 setDynOutputFile f d = d { dynOutputFile = f}
2004 setOutputHi f d = d { outputHi = f}
2005
2006 parseUnitIdInsts :: String -> [(ModuleName, Module)]
2007 parseUnitIdInsts str = case filter ((=="").snd) (readP_to_S parse str) of
2008 [(r, "")] -> r
2009 _ -> throwGhcException $ CmdLineError ("Can't parse -instantiated-with: " ++ str)
2010 where parse = sepBy parseEntry (R.char ',')
2011 parseEntry = do
2012 n <- parseModuleName
2013 _ <- R.char '='
2014 m <- parseModuleId
2015 return (n, m)
2016
2017 setUnitIdInsts :: String -> DynFlags -> DynFlags
2018 setUnitIdInsts s d = updateWithInsts (parseUnitIdInsts s) d
2019
2020 updateWithInsts :: [(ModuleName, Module)] -> DynFlags -> DynFlags
2021 updateWithInsts insts d =
2022 -- Overwrite the instances, the instances are "indefinite"
2023 d { thisPackage =
2024 if not (null insts) && all (\(x,y) -> mkHoleModule x == y) insts
2025 then newUnitId (unitIdComponentId (thisPackage d)) insts
2026 else thisPackage d
2027 , thisUnitIdInsts = insts
2028 }
2029
2030 addPluginModuleName :: String -> DynFlags -> DynFlags
2031 addPluginModuleName name d = d { pluginModNames = (mkModuleName name) : (pluginModNames d) }
2032
2033 addPluginModuleNameOption :: String -> DynFlags -> DynFlags
2034 addPluginModuleNameOption optflag d = d { pluginModNameOpts = (mkModuleName m, option) : (pluginModNameOpts d) }
2035 where (m, rest) = break (== ':') optflag
2036 option = case rest of
2037 [] -> "" -- should probably signal an error
2038 (_:plug_opt) -> plug_opt -- ignore the ':' from break
2039
2040 addFrontendPluginOption :: String -> DynFlags -> DynFlags
2041 addFrontendPluginOption s d = d { frontendPluginOpts = s : frontendPluginOpts d }
2042
2043 parseDynLibLoaderMode f d =
2044 case splitAt 8 f of
2045 ("deploy", "") -> d { dynLibLoader = Deployable }
2046 ("sysdep", "") -> d { dynLibLoader = SystemDependent }
2047 _ -> throwGhcException (CmdLineError ("Unknown dynlib loader: " ++ f))
2048
2049 setDumpPrefixForce f d = d { dumpPrefixForce = f}
2050
2051 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
2052 -- Config.hs should really use Option.
2053 setPgmP f = let (pgm:args) = words f in alterSettings (\s -> s { sPgm_P = (pgm, map Option args)})
2054 addOptl f = alterSettings (\s -> s { sOpt_l = f : sOpt_l s})
2055 addOptc f = alterSettings (\s -> s { sOpt_c = f : sOpt_c s})
2056 addOptP f = alterSettings (\s -> s { sOpt_P = f : sOpt_P s})
2057
2058
2059 setDepMakefile :: FilePath -> DynFlags -> DynFlags
2060 setDepMakefile f d = d { depMakefile = f }
2061
2062 setDepIncludePkgDeps :: Bool -> DynFlags -> DynFlags
2063 setDepIncludePkgDeps b d = d { depIncludePkgDeps = b }
2064
2065 addDepExcludeMod :: String -> DynFlags -> DynFlags
2066 addDepExcludeMod m d
2067 = d { depExcludeMods = mkModuleName m : depExcludeMods d }
2068
2069 addDepSuffix :: FilePath -> DynFlags -> DynFlags
2070 addDepSuffix s d = d { depSuffixes = s : depSuffixes d }
2071
2072 addCmdlineFramework f d = d { cmdlineFrameworks = f : cmdlineFrameworks d}
2073
2074 addHaddockOpts f d = d { haddockOptions = Just f}
2075
2076 addGhciScript f d = d { ghciScripts = f : ghciScripts d}
2077
2078 setInteractivePrint f d = d { interactivePrint = Just f}
2079
2080 -- -----------------------------------------------------------------------------
2081 -- Command-line options
2082
2083 -- | When invoking external tools as part of the compilation pipeline, we
2084 -- pass these a sequence of options on the command-line. Rather than
2085 -- just using a list of Strings, we use a type that allows us to distinguish
2086 -- between filepaths and 'other stuff'. The reason for this is that
2087 -- this type gives us a handle on transforming filenames, and filenames only,
2088 -- to whatever format they're expected to be on a particular platform.
2089 data Option
2090 = FileOption -- an entry that _contains_ filename(s) / filepaths.
2091 String -- a non-filepath prefix that shouldn't be
2092 -- transformed (e.g., "/out=")
2093 String -- the filepath/filename portion
2094 | Option String
2095 deriving ( Eq )
2096
2097 showOpt :: Option -> String
2098 showOpt (FileOption pre f) = pre ++ f
2099 showOpt (Option s) = s
2100
2101 -----------------------------------------------------------------------------
2102 -- Setting the optimisation level
2103
2104 updOptLevel :: Int -> DynFlags -> DynFlags
2105 -- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
2106 updOptLevel n dfs
2107 = dfs2{ optLevel = final_n }
2108 where
2109 final_n = max 0 (min 2 n) -- Clamp to 0 <= n <= 2
2110 dfs1 = foldr (flip gopt_unset) dfs remove_gopts
2111 dfs2 = foldr (flip gopt_set) dfs1 extra_gopts
2112
2113 extra_gopts = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
2114 remove_gopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
2115
2116 {- **********************************************************************
2117 %* *
2118 DynFlags parser
2119 %* *
2120 %********************************************************************* -}
2121
2122 -- -----------------------------------------------------------------------------
2123 -- Parsing the dynamic flags.
2124
2125
2126 -- | Parse dynamic flags from a list of command line arguments. Returns the
2127 -- the parsed 'DynFlags', the left-over arguments, and a list of warnings.
2128 -- Throws a 'UsageError' if errors occurred during parsing (such as unknown
2129 -- flags or missing arguments).
2130 parseDynamicFlagsCmdLine :: MonadIO m => DynFlags -> [Located String]
2131 -> m (DynFlags, [Located String], [Located String])
2132 -- ^ Updated 'DynFlags', left-over arguments, and
2133 -- list of warnings.
2134 parseDynamicFlagsCmdLine = parseDynamicFlagsFull flagsAll True
2135
2136
2137 -- | Like 'parseDynamicFlagsCmdLine' but does not allow the package flags
2138 -- (-package, -hide-package, -ignore-package, -hide-all-packages, -package-db).
2139 -- Used to parse flags set in a modules pragma.
2140 parseDynamicFilePragma :: MonadIO m => DynFlags -> [Located String]
2141 -> m (DynFlags, [Located String], [Located String])
2142 -- ^ Updated 'DynFlags', left-over arguments, and
2143 -- list of warnings.
2144 parseDynamicFilePragma = parseDynamicFlagsFull flagsDynamic False
2145
2146
2147 -- | Parses the dynamically set flags for GHC. This is the most general form of
2148 -- the dynamic flag parser that the other methods simply wrap. It allows
2149 -- saying which flags are valid flags and indicating if we are parsing
2150 -- arguments from the command line or from a file pragma.
2151 parseDynamicFlagsFull :: MonadIO m
2152 => [Flag (CmdLineP DynFlags)] -- ^ valid flags to match against
2153 -> Bool -- ^ are the arguments from the command line?
2154 -> DynFlags -- ^ current dynamic flags
2155 -> [Located String] -- ^ arguments to parse
2156 -> m (DynFlags, [Located String], [Located String])
2157 parseDynamicFlagsFull activeFlags cmdline dflags0 args = do
2158 let ((leftover, errs, warns), dflags1)
2159 = runCmdLine (processArgs activeFlags args) dflags0
2160
2161 -- See Note [Handling errors when parsing commandline flags]
2162 unless (null errs) $ liftIO $ throwGhcExceptionIO $
2163 errorsToGhcException . map (showPpr dflags0 . getLoc &&& unLoc) $ errs
2164
2165 -- check for disabled flags in safe haskell
2166 let (dflags2, sh_warns) = safeFlagCheck cmdline dflags1
2167 dflags3 = updateWays dflags2
2168 theWays = ways dflags3
2169
2170 unless (allowed_combination theWays) $ liftIO $
2171 throwGhcExceptionIO (CmdLineError ("combination not supported: " ++
2172 intercalate "/" (map wayDesc theWays)))
2173
2174 let chooseOutput
2175 | isJust (outputFile dflags3) -- Only iff user specified -o ...
2176 , not (isJust (dynOutputFile dflags3)) -- but not -dyno
2177 = return $ dflags3 { dynOutputFile = Just $ dynOut (fromJust $ outputFile dflags3) }
2178 | otherwise
2179 = return dflags3
2180 where
2181 dynOut = flip addExtension (dynObjectSuf dflags3) . dropExtension
2182 dflags4 <- ifGeneratingDynamicToo dflags3 chooseOutput (return dflags3)
2183
2184 let (dflags5, consistency_warnings) = makeDynFlagsConsistent dflags4
2185
2186 dflags6 <- case dllSplitFile dflags5 of
2187 Nothing -> return (dflags5 { dllSplit = Nothing })
2188 Just f ->
2189 case dllSplit dflags5 of
2190 Just _ ->
2191 -- If dllSplit is out of date then it would have
2192 -- been set to Nothing. As it's a Just, it must be
2193 -- up-to-date.
2194 return dflags5
2195 Nothing ->
2196 do xs <- liftIO $ readFile f
2197 let ss = map (Set.fromList . words) (lines xs)
2198 return $ dflags5 { dllSplit = Just ss }
2199
2200 -- Set timer stats & heap size
2201 when (enableTimeStats dflags6) $ liftIO enableTimingStats
2202 case (ghcHeapSize dflags6) of
2203 Just x -> liftIO (setHeapSize x)
2204 _ -> return ()
2205
2206 liftIO $ setUnsafeGlobalDynFlags dflags6
2207
2208 return (dflags6, leftover, consistency_warnings ++ sh_warns ++ warns)
2209
2210 updateWays :: DynFlags -> DynFlags
2211 updateWays dflags
2212 = let theWays = sort $ nub $ ways dflags
2213 in dflags {
2214 ways = theWays,
2215 buildTag = mkBuildTag (filter (not . wayRTSOnly) theWays),
2216 rtsBuildTag = mkBuildTag theWays
2217 }
2218
2219 -- | Check (and potentially disable) any extensions that aren't allowed
2220 -- in safe mode.
2221 --
2222 -- The bool is to indicate if we are parsing command line flags (false means
2223 -- file pragma). This allows us to generate better warnings.
2224 safeFlagCheck :: Bool -> DynFlags -> (DynFlags, [Located String])
2225 safeFlagCheck _ dflags | safeLanguageOn dflags = (dflagsUnset, warns)
2226 where
2227 -- Handle illegal flags under safe language.
2228 (dflagsUnset, warns) = foldl check_method (dflags, []) unsafeFlags
2229
2230 check_method (df, warns) (str,loc,test,fix)
2231 | test df = (fix df, warns ++ safeFailure (loc df) str)
2232 | otherwise = (df, warns)
2233
2234 safeFailure loc str
2235 = [L loc $ str ++ " is not allowed in Safe Haskell; ignoring "
2236 ++ str]
2237
2238 safeFlagCheck cmdl dflags =
2239 case (safeInferOn dflags) of
2240 True | safeFlags -> (dflags', warn)
2241 True -> (dflags' { safeInferred = False }, warn)
2242 False -> (dflags', warn)
2243
2244 where
2245 -- dynflags and warn for when -fpackage-trust by itself with no safe
2246 -- haskell flag
2247 (dflags', warn)
2248 | safeHaskell dflags == Sf_None && not cmdl && packageTrustOn dflags
2249 = (gopt_unset dflags Opt_PackageTrust, pkgWarnMsg)
2250 | otherwise = (dflags, [])
2251
2252 pkgWarnMsg = [L (pkgTrustOnLoc dflags') $
2253 "-fpackage-trust ignored;" ++
2254 " must be specified with a Safe Haskell flag"]
2255
2256 -- Have we inferred Unsafe? See Note [HscMain . Safe Haskell Inference]
2257 safeFlags = all (\(_,_,t,_) -> not $ t dflags) unsafeFlagsForInfer
2258
2259
2260 {- **********************************************************************
2261 %* *
2262 DynFlags specifications
2263 %* *
2264 %********************************************************************* -}
2265
2266 -- | All dynamic flags option strings without the deprecated ones.
2267 -- These are the user facing strings for enabling and disabling options.
2268 allNonDeprecatedFlags :: [String]
2269 allNonDeprecatedFlags = allFlagsDeps False
2270
2271 -- | All flags with possibility to filter deprecated ones
2272 allFlagsDeps :: Bool -> [String]
2273 allFlagsDeps keepDeprecated = [ '-':flagName flag
2274 | (deprecated, flag) <- flagsAllDeps
2275 , ok (flagOptKind flag)
2276 , keepDeprecated || not (isDeprecated deprecated)]
2277 where ok (PrefixPred _ _) = False
2278 ok _ = True
2279 isDeprecated Deprecated = True
2280 isDeprecated _ = False
2281
2282 {-
2283 - Below we export user facing symbols for GHC dynamic flags for use with the
2284 - GHC API.
2285 -}
2286
2287 -- All dynamic flags present in GHC.
2288 flagsAll :: [Flag (CmdLineP DynFlags)]
2289 flagsAll = map snd flagsAllDeps
2290
2291 -- All dynamic flags present in GHC with deprecation information.
2292 flagsAllDeps :: [(Deprecation, Flag (CmdLineP DynFlags))]
2293 flagsAllDeps = package_flags_deps ++ dynamic_flags_deps
2294
2295
2296 -- All dynamic flags, minus package flags, present in GHC.
2297 flagsDynamic :: [Flag (CmdLineP DynFlags)]
2298 flagsDynamic = map snd dynamic_flags_deps
2299
2300 -- ALl package flags present in GHC.
2301 flagsPackage :: [Flag (CmdLineP DynFlags)]
2302 flagsPackage = map snd package_flags_deps
2303
2304 ----------------Helpers to make flags and keep deprecation information----------
2305
2306 type FlagMaker m = String -> OptKind m -> Flag m
2307 type DynFlagMaker = FlagMaker (CmdLineP DynFlags)
2308 data Deprecation = NotDeprecated | Deprecated deriving (Eq, Ord)
2309
2310 -- Make a non-deprecated flag
2311 make_ord_flag :: DynFlagMaker -> String -> OptKind (CmdLineP DynFlags)
2312 -> (Deprecation, Flag (CmdLineP DynFlags))
2313 make_ord_flag fm name kind = (NotDeprecated, fm name kind)
2314
2315 -- Make a deprecated flag
2316 make_dep_flag :: DynFlagMaker -> String -> OptKind (CmdLineP DynFlags) -> String
2317 -> (Deprecation, Flag (CmdLineP DynFlags))
2318 make_dep_flag fm name kind message = (Deprecated,
2319 fm name $ add_dep_message kind message)
2320
2321 add_dep_message :: OptKind (CmdLineP DynFlags) -> String
2322 -> OptKind (CmdLineP DynFlags)
2323 add_dep_message (NoArg f) message = NoArg $ f >> deprecate message
2324 add_dep_message (HasArg f) message = HasArg $ \s -> f s >> deprecate message
2325 add_dep_message (SepArg f) message = SepArg $ \s -> f s >> deprecate message
2326 add_dep_message (Prefix f) message = Prefix $ \s -> f s >> deprecate message
2327 add_dep_message (OptPrefix f) message =
2328 OptPrefix $ \s -> f s >> deprecate message
2329 add_dep_message (OptIntSuffix f) message =
2330 OptIntSuffix $ \oi -> f oi >> deprecate message
2331 add_dep_message (IntSuffix f) message =
2332 IntSuffix $ \i -> f i >> deprecate message
2333 add_dep_message (FloatSuffix f) message =
2334 FloatSuffix $ \fl -> f fl >> deprecate message
2335 add_dep_message (PassFlag f) message =
2336 PassFlag $ \s -> f s >> deprecate message
2337 add_dep_message (AnySuffix f) message =
2338 AnySuffix $ \s -> f s >> deprecate message
2339 add_dep_message (PrefixPred pred f) message =
2340 PrefixPred pred $ \s -> f s >> deprecate message
2341 add_dep_message (AnySuffixPred pred f) message =
2342 AnySuffixPred pred $ \s -> f s >> deprecate message
2343
2344 ----------------------- The main flags themselves ------------------------------
2345 -- See Note [Updating flag description in the User's Guide]
2346 -- See Note [Supporting CLI completion]
2347 dynamic_flags_deps :: [(Deprecation, Flag (CmdLineP DynFlags))]
2348 dynamic_flags_deps = [
2349 make_dep_flag defFlag "n" (NoArg $ return ())
2350 "The -n flag is deprecated and no longer has any effect"
2351 , make_ord_flag defFlag "cpp" (NoArg (setExtensionFlag LangExt.Cpp))
2352 , make_ord_flag defFlag "F" (NoArg (setGeneralFlag Opt_Pp))
2353 , (Deprecated, defFlag "#include"
2354 (HasArg (\_s ->
2355 addWarn ("-#include and INCLUDE pragmas are " ++
2356 "deprecated: They no longer have any effect"))))
2357 , make_ord_flag defFlag "v" (OptIntSuffix setVerbosity)
2358
2359 , make_ord_flag defGhcFlag "j" (OptIntSuffix
2360 (\n -> case n of
2361 Just n
2362 | n > 0 -> upd (\d -> d { parMakeCount = Just n })
2363 | otherwise -> addErr "Syntax: -j[n] where n > 0"
2364 Nothing -> upd (\d -> d { parMakeCount = Nothing })))
2365 -- When the number of parallel builds
2366 -- is omitted, it is the same
2367 -- as specifing that the number of
2368 -- parallel builds is equal to the
2369 -- result of getNumProcessors
2370 , make_ord_flag defFlag "instantiated-with" (sepArg setUnitIdInsts)
2371
2372 -- RTS options -------------------------------------------------------------
2373 , make_ord_flag defFlag "H" (HasArg (\s -> upd (\d ->
2374 d { ghcHeapSize = Just $ fromIntegral (decodeSize s)})))
2375
2376 , make_ord_flag defFlag "Rghc-timing" (NoArg (upd (\d ->
2377 d { enableTimeStats = True })))
2378
2379 ------- ways ---------------------------------------------------------------
2380 , make_ord_flag defGhcFlag "prof" (NoArg (addWay WayProf))
2381 , make_ord_flag defGhcFlag "eventlog" (NoArg (addWay WayEventLog))
2382 , make_dep_flag defGhcFlag "smp"
2383 (NoArg $ addWay WayThreaded) "Use -threaded instead"
2384 , make_ord_flag defGhcFlag "debug" (NoArg (addWay WayDebug))
2385 , make_ord_flag defGhcFlag "threaded" (NoArg (addWay WayThreaded))
2386
2387 , make_ord_flag defGhcFlag "ticky"
2388 (NoArg (setGeneralFlag Opt_Ticky >> addWay WayDebug))
2389
2390 -- -ticky enables ticky-ticky code generation, and also implies -debug which
2391 -- is required to get the RTS ticky support.
2392
2393 ----- Linker --------------------------------------------------------
2394 , make_ord_flag defGhcFlag "static" (NoArg removeWayDyn)
2395 , make_ord_flag defGhcFlag "dynamic" (NoArg (addWay WayDyn))
2396 , make_ord_flag defGhcFlag "rdynamic" $ noArg $
2397 #ifdef linux_HOST_OS
2398 addOptl "-rdynamic"
2399 #elif defined (mingw32_HOST_OS)
2400 addOptl "-Wl,--export-all-symbols"
2401 #else
2402 -- ignored for compat w/ gcc:
2403 id
2404 #endif
2405 , make_ord_flag defGhcFlag "relative-dynlib-paths"
2406 (NoArg (setGeneralFlag Opt_RelativeDynlibPaths))
2407
2408 ------- Specific phases --------------------------------------------
2409 -- need to appear before -pgmL to be parsed as LLVM flags.
2410 , make_ord_flag defFlag "pgmlo"
2411 (hasArg (\f -> alterSettings (\s -> s { sPgm_lo = (f,[])})))
2412 , make_ord_flag defFlag "pgmlc"
2413 (hasArg (\f -> alterSettings (\s -> s { sPgm_lc = (f,[])})))
2414 , make_ord_flag defFlag "pgmi"
2415 (hasArg (\f -> alterSettings (\s -> s { sPgm_i = f})))
2416 , make_ord_flag defFlag "pgmL"
2417 (hasArg (\f -> alterSettings (\s -> s { sPgm_L = f})))
2418 , make_ord_flag defFlag "pgmP"
2419 (hasArg setPgmP)
2420 , make_ord_flag defFlag "pgmF"
2421 (hasArg (\f -> alterSettings (\s -> s { sPgm_F = f})))
2422 , make_ord_flag defFlag "pgmc"
2423 (hasArg (\f -> alterSettings (\s -> s { sPgm_c = (f,[])})))
2424 , make_ord_flag defFlag "pgms"
2425 (hasArg (\f -> alterSettings (\s -> s { sPgm_s = (f,[])})))
2426 , make_ord_flag defFlag "pgma"
2427 (hasArg (\f -> alterSettings (\s -> s { sPgm_a = (f,[])})))
2428 , make_ord_flag defFlag "pgml"
2429 (hasArg (\f -> alterSettings (\s -> s { sPgm_l = (f,[])})))
2430 , make_ord_flag defFlag "pgmdll"
2431 (hasArg (\f -> alterSettings (\s -> s { sPgm_dll = (f,[])})))
2432 , make_ord_flag defFlag "pgmwindres"
2433 (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
2434 , make_ord_flag defFlag "pgmlibtool"
2435 (hasArg (\f -> alterSettings (\s -> s { sPgm_libtool = f})))
2436
2437 -- need to appear before -optl/-opta to be parsed as LLVM flags.
2438 , make_ord_flag defFlag "optlo"
2439 (hasArg (\f -> alterSettings (\s -> s { sOpt_lo = f : sOpt_lo s})))
2440 , make_ord_flag defFlag "optlc"
2441 (hasArg (\f -> alterSettings (\s -> s { sOpt_lc = f : sOpt_lc s})))
2442 , make_ord_flag defFlag "opti"
2443 (hasArg (\f -> alterSettings (\s -> s { sOpt_i = f : sOpt_i s})))
2444 , make_ord_flag defFlag "optL"
2445 (hasArg (\f -> alterSettings (\s -> s { sOpt_L = f : sOpt_L s})))
2446 , make_ord_flag defFlag "optP"
2447 (hasArg addOptP)
2448 , make_ord_flag defFlag "optF"
2449 (hasArg (\f -> alterSettings (\s -> s { sOpt_F = f : sOpt_F s})))
2450 , make_ord_flag defFlag "optc"
2451 (hasArg addOptc)
2452 , make_ord_flag defFlag "opta"
2453 (hasArg (\f -> alterSettings (\s -> s { sOpt_a = f : sOpt_a s})))
2454 , make_ord_flag defFlag "optl"
2455 (hasArg addOptl)
2456 , make_ord_flag defFlag "optwindres"
2457 (hasArg (\f ->
2458 alterSettings (\s -> s { sOpt_windres = f : sOpt_windres s})))
2459
2460 , make_ord_flag defGhcFlag "split-objs"
2461 (NoArg (if can_split
2462 then setGeneralFlag Opt_SplitObjs
2463 else addWarn "ignoring -fsplit-objs"))
2464
2465 , make_ord_flag defGhcFlag "split-sections"
2466 (noArgM (\dflags -> do
2467 if platformHasSubsectionsViaSymbols (targetPlatform dflags)
2468 then do addErr $
2469 "-split-sections is not useful on this platform " ++
2470 "since it always uses subsections via symbols."
2471 return dflags
2472 else return (gopt_set dflags Opt_SplitSections)))
2473
2474 -------- ghc -M -----------------------------------------------------
2475 , make_ord_flag defGhcFlag "dep-suffix" (hasArg addDepSuffix)
2476 , make_ord_flag defGhcFlag "dep-makefile" (hasArg setDepMakefile)
2477 , make_ord_flag defGhcFlag "include-pkg-deps"
2478 (noArg (setDepIncludePkgDeps True))
2479 , make_ord_flag defGhcFlag "exclude-module" (hasArg addDepExcludeMod)
2480
2481 -------- Linking ----------------------------------------------------
2482 , make_ord_flag defGhcFlag "no-link"
2483 (noArg (\d -> d { ghcLink=NoLink }))
2484 , make_ord_flag defGhcFlag "shared"
2485 (noArg (\d -> d { ghcLink=LinkDynLib }))
2486 , make_ord_flag defGhcFlag "staticlib"
2487 (noArg (\d -> d { ghcLink=LinkStaticLib }))
2488 , make_ord_flag defGhcFlag "dynload" (hasArg parseDynLibLoaderMode)
2489 , make_ord_flag defGhcFlag "dylib-install-name" (hasArg setDylibInstallName)
2490 -- -dll-split is an internal flag, used only during the GHC build
2491 , make_ord_flag defHiddenFlag "dll-split"
2492 (hasArg (\f d -> d { dllSplitFile = Just f, dllSplit = Nothing }))
2493
2494 ------- Libraries ---------------------------------------------------
2495 , make_ord_flag defFlag "L" (Prefix addLibraryPath)
2496 , make_ord_flag defFlag "l" (hasArg (addLdInputs . Option . ("-l" ++)))
2497
2498 ------- Frameworks --------------------------------------------------
2499 -- -framework-path should really be -F ...
2500 , make_ord_flag defFlag "framework-path" (HasArg addFrameworkPath)
2501 , make_ord_flag defFlag "framework" (hasArg addCmdlineFramework)
2502
2503 ------- Output Redirection ------------------------------------------
2504 , make_ord_flag defGhcFlag "odir" (hasArg setObjectDir)
2505 , make_ord_flag defGhcFlag "o" (sepArg (setOutputFile . Just))
2506 , make_ord_flag defGhcFlag "dyno"
2507 (sepArg (setDynOutputFile . Just))
2508 , make_ord_flag defGhcFlag "ohi"
2509 (hasArg (setOutputHi . Just ))
2510 , make_ord_flag defGhcFlag "osuf" (hasArg setObjectSuf)
2511 , make_ord_flag defGhcFlag "dynosuf" (hasArg setDynObjectSuf)
2512 , make_ord_flag defGhcFlag "hcsuf" (hasArg setHcSuf)
2513 , make_ord_flag defGhcFlag "hisuf" (hasArg setHiSuf)
2514 , make_ord_flag defGhcFlag "dynhisuf" (hasArg setDynHiSuf)
2515 , make_ord_flag defGhcFlag "hidir" (hasArg setHiDir)
2516 , make_ord_flag defGhcFlag "tmpdir" (hasArg setTmpDir)
2517 , make_ord_flag defGhcFlag "stubdir" (hasArg setStubDir)
2518 , make_ord_flag defGhcFlag "dumpdir" (hasArg setDumpDir)
2519 , make_ord_flag defGhcFlag "outputdir" (hasArg setOutputDir)
2520 , make_ord_flag defGhcFlag "ddump-file-prefix"
2521 (hasArg (setDumpPrefixForce . Just))
2522
2523 , make_ord_flag defGhcFlag "dynamic-too"
2524 (NoArg (setGeneralFlag Opt_BuildDynamicToo))
2525
2526 ------- Keeping temporary files -------------------------------------
2527 -- These can be singular (think ghc -c) or plural (think ghc --make)
2528 , make_ord_flag defGhcFlag "keep-hc-file"
2529 (NoArg (setGeneralFlag Opt_KeepHcFiles))
2530 , make_ord_flag defGhcFlag "keep-hc-files"
2531 (NoArg (setGeneralFlag Opt_KeepHcFiles))
2532 , make_ord_flag defGhcFlag "keep-s-file"
2533 (NoArg (setGeneralFlag Opt_KeepSFiles))
2534 , make_ord_flag defGhcFlag "keep-s-files"
2535 (NoArg (setGeneralFlag Opt_KeepSFiles))
2536 , make_ord_flag defGhcFlag "keep-llvm-file"
2537 (NoArg $ setObjTarget HscLlvm >> setGeneralFlag Opt_KeepLlvmFiles)
2538 , make_ord_flag defGhcFlag "keep-llvm-files"
2539 (NoArg $ setObjTarget HscLlvm >> setGeneralFlag Opt_KeepLlvmFiles)
2540 -- This only makes sense as plural
2541 , make_ord_flag defGhcFlag "keep-tmp-files"
2542 (NoArg (setGeneralFlag Opt_KeepTmpFiles))
2543 , make_ord_flag defGhcFlag "keep-hi-file"
2544 (NoArg (setGeneralFlag Opt_KeepHiFiles))
2545 , make_ord_flag defGhcFlag "no-keep-hi-file"
2546 (NoArg (unSetGeneralFlag Opt_KeepHiFiles))
2547 , make_ord_flag defGhcFlag "keep-hi-files"
2548 (NoArg (setGeneralFlag Opt_KeepHiFiles))
2549 , make_ord_flag defGhcFlag "no-keep-hi-files"
2550 (NoArg (unSetGeneralFlag Opt_KeepHiFiles))
2551 , make_ord_flag defGhcFlag "keep-o-file"
2552 (NoArg (setGeneralFlag Opt_KeepOFiles))
2553 , make_ord_flag defGhcFlag "no-keep-o-file"
2554 (NoArg (unSetGeneralFlag Opt_KeepOFiles))
2555 , make_ord_flag defGhcFlag "keep-o-files"
2556 (NoArg (setGeneralFlag Opt_KeepOFiles))
2557 , make_ord_flag defGhcFlag "no-keep-o-files"
2558 (NoArg (unSetGeneralFlag Opt_KeepOFiles))
2559
2560 ------- Miscellaneous ----------------------------------------------
2561 , make_ord_flag defGhcFlag "no-auto-link-packages"
2562 (NoArg (unSetGeneralFlag Opt_AutoLinkPackages))
2563 , make_ord_flag defGhcFlag "no-hs-main"
2564 (NoArg (setGeneralFlag Opt_NoHsMain))
2565 , make_ord_flag defGhcFlag "with-rtsopts"
2566 (HasArg setRtsOpts)
2567 , make_ord_flag defGhcFlag "rtsopts"
2568 (NoArg (setRtsOptsEnabled RtsOptsAll))
2569 , make_ord_flag defGhcFlag "rtsopts=all"
2570 (NoArg (setRtsOptsEnabled RtsOptsAll))
2571 , make_ord_flag defGhcFlag "rtsopts=some"
2572 (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
2573 , make_ord_flag defGhcFlag "rtsopts=none"
2574 (NoArg (setRtsOptsEnabled RtsOptsNone))
2575 , make_ord_flag defGhcFlag "no-rtsopts"
2576 (NoArg (setRtsOptsEnabled RtsOptsNone))
2577 , make_ord_flag defGhcFlag "no-rtsopts-suggestions"
2578 (noArg (\d -> d {rtsOptsSuggestions = False}))
2579
2580 , make_ord_flag defGhcFlag "main-is" (SepArg setMainIs)
2581 , make_ord_flag defGhcFlag "haddock" (NoArg (setGeneralFlag Opt_Haddock))
2582 , make_ord_flag defGhcFlag "haddock-opts" (hasArg addHaddockOpts)
2583 , make_ord_flag defGhcFlag "hpcdir" (SepArg setOptHpcDir)
2584 , make_ord_flag defGhciFlag "ghci-script" (hasArg addGhciScript)
2585 , make_ord_flag defGhciFlag "interactive-print" (hasArg setInteractivePrint)
2586 , make_ord_flag defGhcFlag "ticky-allocd"
2587 (NoArg (setGeneralFlag Opt_Ticky_Allocd))
2588 , make_ord_flag defGhcFlag "ticky-LNE"
2589 (NoArg (setGeneralFlag Opt_Ticky_LNE))
2590 , make_ord_flag defGhcFlag "ticky-dyn-thunk"
2591 (NoArg (setGeneralFlag Opt_Ticky_Dyn_Thunk))
2592 ------- recompilation checker --------------------------------------
2593 , make_dep_flag defGhcFlag "recomp"
2594 (NoArg $ unSetGeneralFlag Opt_ForceRecomp)
2595 "Use -fno-force-recomp instead"
2596 , make_dep_flag defGhcFlag "no-recomp"
2597 (NoArg $ setGeneralFlag Opt_ForceRecomp) "Use -fforce-recomp instead"
2598 , make_ord_flag defFlag "freverse-errors"
2599 (noArg (\d -> d {reverseErrors = True} ))
2600 , make_ord_flag defFlag "fno-reverse-errors"
2601 (noArg (\d -> d {reverseErrors = False} ))
2602
2603 ------ HsCpp opts ---------------------------------------------------
2604 , make_ord_flag defFlag "D" (AnySuffix (upd . addOptP))
2605 , make_ord_flag defFlag "U" (AnySuffix (upd . addOptP))
2606
2607 ------- Include/Import Paths ----------------------------------------
2608 , make_ord_flag defFlag "I" (Prefix addIncludePath)
2609 , make_ord_flag defFlag "i" (OptPrefix addImportPath)
2610
2611 ------ Output style options -----------------------------------------
2612 , make_ord_flag defFlag "dppr-user-length" (intSuffix (\n d ->
2613 d { pprUserLength = n }))
2614 , make_ord_flag defFlag "dppr-cols" (intSuffix (\n d ->
2615 d { pprCols = n }))
2616 , make_ord_flag defGhcFlag "dtrace-level" (intSuffix (\n d ->
2617 d { traceLevel = n }))
2618 -- Suppress all that is suppressable in core dumps.
2619 -- Except for uniques, as some simplifier phases introduce new variables that
2620 -- have otherwise identical names.
2621 , make_ord_flag defGhcFlag "dsuppress-all"
2622 (NoArg $ do setGeneralFlag Opt_SuppressCoercions
2623 setGeneralFlag Opt_SuppressVarKinds
2624 setGeneralFlag Opt_SuppressModulePrefixes
2625 setGeneralFlag Opt_SuppressTypeApplications
2626 setGeneralFlag Opt_SuppressIdInfo
2627 setGeneralFlag Opt_SuppressTypeSignatures)
2628
2629 ------ Debugging ----------------------------------------------------
2630 , make_ord_flag defGhcFlag "dstg-stats"
2631 (NoArg (setGeneralFlag Opt_StgStats))
2632
2633 , make_ord_flag defGhcFlag "ddump-cmm"
2634 (setDumpFlag Opt_D_dump_cmm)
2635 , make_ord_flag defGhcFlag "ddump-cmm-from-stg"
2636 (setDumpFlag Opt_D_dump_cmm_from_stg)
2637 , make_ord_flag defGhcFlag "ddump-cmm-raw"
2638 (setDumpFlag Opt_D_dump_cmm_raw)
2639 , make_ord_flag defGhcFlag "ddump-cmm-verbose"
2640 (setDumpFlag Opt_D_dump_cmm_verbose)
2641 , make_ord_flag defGhcFlag "ddump-cmm-cfg"
2642 (setDumpFlag Opt_D_dump_cmm_cfg)
2643 , make_ord_flag defGhcFlag "ddump-cmm-cbe"
2644 (setDumpFlag Opt_D_dump_cmm_cbe)
2645 , make_ord_flag defGhcFlag "ddump-cmm-switch"
2646 (setDumpFlag Opt_D_dump_cmm_switch)
2647 , make_ord_flag defGhcFlag "ddump-cmm-proc"
2648 (setDumpFlag Opt_D_dump_cmm_proc)
2649 , make_ord_flag defGhcFlag "ddump-cmm-sp"
2650 (setDumpFlag Opt_D_dump_cmm_sp)
2651 , make_ord_flag defGhcFlag "ddump-cmm-sink"
2652 (setDumpFlag Opt_D_dump_cmm_sink)
2653 , make_ord_flag defGhcFlag "ddump-cmm-caf"
2654 (setDumpFlag Opt_D_dump_cmm_caf)
2655 , make_ord_flag defGhcFlag "ddump-cmm-procmap"
2656 (setDumpFlag Opt_D_dump_cmm_procmap)
2657 , make_ord_flag defGhcFlag "ddump-cmm-split"
2658 (setDumpFlag Opt_D_dump_cmm_split)
2659 , make_ord_flag defGhcFlag "ddump-cmm-info"
2660 (setDumpFlag Opt_D_dump_cmm_info)
2661 , make_ord_flag defGhcFlag "ddump-cmm-cps"
2662 (setDumpFlag Opt_D_dump_cmm_cps)
2663 , make_ord_flag defGhcFlag "ddump-core-stats"
2664 (setDumpFlag Opt_D_dump_core_stats)
2665 , make_ord_flag defGhcFlag "ddump-asm"
2666 (setDumpFlag Opt_D_dump_asm)
2667 , make_ord_flag defGhcFlag "ddump-asm-native"
2668 (setDumpFlag Opt_D_dump_asm_native)
2669 , make_ord_flag defGhcFlag "ddump-asm-liveness"
2670 (setDumpFlag Opt_D_dump_asm_liveness)
2671 , make_ord_flag defGhcFlag "ddump-asm-regalloc"
2672 (setDumpFlag Opt_D_dump_asm_regalloc)
2673 , make_ord_flag defGhcFlag "ddump-asm-conflicts"
2674 (setDumpFlag Opt_D_dump_asm_conflicts)
2675 , make_ord_flag defGhcFlag "ddump-asm-regalloc-stages"
2676 (setDumpFlag Opt_D_dump_asm_regalloc_stages)
2677 , make_ord_flag defGhcFlag "ddump-asm-stats"
2678 (setDumpFlag Opt_D_dump_asm_stats)
2679 , make_ord_flag defGhcFlag "ddump-asm-expanded"
2680 (setDumpFlag Opt_D_dump_asm_expanded)
2681 , make_ord_flag defGhcFlag "ddump-llvm"
2682 (NoArg $ setObjTarget HscLlvm >> setDumpFlag' Opt_D_dump_llvm)
2683 , make_ord_flag defGhcFlag "ddump-deriv"
2684 (setDumpFlag Opt_D_dump_deriv)
2685 , make_ord_flag defGhcFlag "ddump-ds"
2686 (setDumpFlag Opt_D_dump_ds)
2687 , make_ord_flag defGhcFlag "ddump-foreign"
2688 (setDumpFlag Opt_D_dump_foreign)
2689 , make_ord_flag defGhcFlag "ddump-inlinings"
2690 (setDumpFlag Opt_D_dump_inlinings)
2691 , make_ord_flag defGhcFlag "ddump-rule-firings"
2692 (setDumpFlag Opt_D_dump_rule_firings)
2693 , make_ord_flag defGhcFlag "ddump-rule-rewrites"
2694 (setDumpFlag Opt_D_dump_rule_rewrites)
2695 , make_ord_flag defGhcFlag "ddump-simpl-trace"
2696 (setDumpFlag Opt_D_dump_simpl_trace)
2697 , make_ord_flag defGhcFlag "ddump-occur-anal"
2698 (setDumpFlag Opt_D_dump_occur_anal)
2699 , make_ord_flag defGhcFlag "ddump-parsed"
2700 (setDumpFlag Opt_D_dump_parsed)
2701 , make_ord_flag defGhcFlag "ddump-rn"
2702 (setDumpFlag Opt_D_dump_rn)
2703 , make_ord_flag defGhcFlag "ddump-simpl"
2704 (setDumpFlag Opt_D_dump_simpl)
2705 , make_ord_flag defGhcFlag "ddump-simpl-iterations"
2706 (setDumpFlag Opt_D_dump_simpl_iterations)
2707 , make_ord_flag defGhcFlag "ddump-spec"
2708 (setDumpFlag Opt_D_dump_spec)
2709 , make_ord_flag defGhcFlag "ddump-prep"
2710 (setDumpFlag Opt_D_dump_prep)
2711 , make_ord_flag defGhcFlag "ddump-stg"
2712 (setDumpFlag Opt_D_dump_stg)
2713 , make_ord_flag defGhcFlag "ddump-call-arity"
2714 (setDumpFlag Opt_D_dump_call_arity)
2715 , make_ord_flag defGhcFlag "ddump-stranal"
2716 (setDumpFlag Opt_D_dump_stranal)
2717 , make_ord_flag defGhcFlag "ddump-str-signatures"
2718 (setDumpFlag Opt_D_dump_str_signatures)
2719 , make_ord_flag defGhcFlag "ddump-tc"
2720 (setDumpFlag Opt_D_dump_tc)
2721 , make_ord_flag defGhcFlag "ddump-types"
2722 (setDumpFlag Opt_D_dump_types)
2723 , make_ord_flag defGhcFlag "ddump-rules"
2724 (setDumpFlag Opt_D_dump_rules)
2725 , make_ord_flag defGhcFlag "ddump-cse"
2726 (setDumpFlag Opt_D_dump_cse)
2727 , make_ord_flag defGhcFlag "ddump-worker-wrapper"
2728 (setDumpFlag Opt_D_dump_worker_wrapper)
2729 , make_ord_flag defGhcFlag "ddump-rn-trace"
2730 (setDumpFlag Opt_D_dump_rn_trace)
2731 , make_ord_flag defGhcFlag "ddump-shape"
2732 (setDumpFlag Opt_D_dump_shape)
2733 , make_ord_flag defGhcFlag "ddump-if-trace"
2734 (setDumpFlag Opt_D_dump_if_trace)
2735 , make_ord_flag defGhcFlag "ddump-cs-trace"
2736 (setDumpFlag Opt_D_dump_cs_trace)
2737 , make_ord_flag defGhcFlag "ddump-tc-trace"
2738 (NoArg (do setDumpFlag' Opt_D_dump_tc_trace
2739 setDumpFlag' Opt_D_dump_cs_trace))
2740 , make_ord_flag defGhcFlag "ddump-vt-trace"
2741 (setDumpFlag Opt_D_dump_vt_trace)
2742 , make_ord_flag defGhcFlag "ddump-splices"
2743 (setDumpFlag Opt_D_dump_splices)
2744 , make_ord_flag defGhcFlag "dth-dec-file"
2745 (setDumpFlag Opt_D_th_dec_file)
2746
2747 , make_ord_flag defGhcFlag "ddump-rn-stats"
2748 (setDumpFlag Opt_D_dump_rn_stats)
2749 , make_ord_flag defGhcFlag "ddump-opt-cmm"
2750 (setDumpFlag Opt_D_dump_opt_cmm)
2751 , make_ord_flag defGhcFlag "ddump-simpl-stats"
2752 (setDumpFlag Opt_D_dump_simpl_stats)
2753 , make_ord_flag defGhcFlag "ddump-bcos"
2754 (setDumpFlag Opt_D_dump_BCOs)
2755 , make_ord_flag defGhcFlag "dsource-stats"
2756 (setDumpFlag Opt_D_source_stats)
2757 , make_ord_flag defGhcFlag "dverbose-core2core"
2758 (NoArg $ setVerbosity (Just 2) >> setVerboseCore2Core)
2759 , make_ord_flag defGhcFlag "dverbose-stg2stg"
2760 (setDumpFlag Opt_D_verbose_stg2stg)
2761 , make_ord_flag defGhcFlag "ddump-hi"
2762 (setDumpFlag Opt_D_dump_hi)
2763 , make_ord_flag defGhcFlag "ddump-minimal-imports"
2764 (NoArg (setGeneralFlag Opt_D_dump_minimal_imports))
2765 , make_ord_flag defGhcFlag "ddump-vect"
2766 (setDumpFlag Opt_D_dump_vect)
2767 , make_ord_flag defGhcFlag "ddump-hpc"
2768 (setDumpFlag Opt_D_dump_ticked) -- back compat
2769 , make_ord_flag defGhcFlag "ddump-ticked"
2770 (setDumpFlag Opt_D_dump_ticked)
2771 , make_ord_flag defGhcFlag "ddump-mod-cycles"
2772 (setDumpFlag Opt_D_dump_mod_cycles)
2773 , make_ord_flag defGhcFlag "ddump-mod-map"
2774 (setDumpFlag Opt_D_dump_mod_map)
2775 , make_ord_flag defGhcFlag "ddump-view-pattern-commoning"
2776 (setDumpFlag Opt_D_dump_view_pattern_commoning)
2777 , make_ord_flag defGhcFlag "ddump-to-file"
2778 (NoArg (setGeneralFlag Opt_DumpToFile))
2779 , make_ord_flag defGhcFlag "ddump-hi-diffs"
2780 (setDumpFlag Opt_D_dump_hi_diffs)
2781 , make_ord_flag defGhcFlag "ddump-rtti"
2782 (setDumpFlag Opt_D_dump_rtti)
2783 , make_ord_flag defGhcFlag "dcore-lint"
2784 (NoArg (setGeneralFlag Opt_DoCoreLinting))
2785 , make_ord_flag defGhcFlag "dstg-lint"
2786 (NoArg (setGeneralFlag Opt_DoStgLinting))
2787 , make_ord_flag defGhcFlag "dcmm-lint"
2788 (NoArg (setGeneralFlag Opt_DoCmmLinting))
2789 , make_ord_flag defGhcFlag "dasm-lint"
2790 (NoArg (setGeneralFlag Opt_DoAsmLinting))
2791 , make_ord_flag defGhcFlag "dannot-lint"
2792 (NoArg (setGeneralFlag Opt_DoAnnotationLinting))
2793 , make_ord_flag defGhcFlag "dshow-passes"
2794 (NoArg $ forceRecompile >> (setVerbosity $ Just 2))
2795 , make_ord_flag defGhcFlag "dfaststring-stats"
2796 (NoArg (setGeneralFlag Opt_D_faststring_stats))
2797 , make_ord_flag defGhcFlag "dno-llvm-mangler"
2798 (NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag
2799 , make_ord_flag defGhcFlag "ddump-debug" (setDumpFlag Opt_D_dump_debug)
2800
2801 ------ Machine dependant (-m<blah>) stuff ---------------------------
2802
2803 , make_ord_flag defGhcFlag "msse" (noArg (\d ->
2804 d { sseVersion = Just SSE1 }))
2805 , make_ord_flag defGhcFlag "msse2" (noArg (\d ->
2806 d { sseVersion = Just SSE2 }))
2807 , make_ord_flag defGhcFlag "msse3" (noArg (\d ->
2808 d { sseVersion = Just SSE3 }))
2809 , make_ord_flag defGhcFlag "msse4" (noArg (\d ->
2810 d { sseVersion = Just SSE4 }))
2811 , make_ord_flag defGhcFlag "msse4.2" (noArg (\d ->
2812 d { sseVersion = Just SSE42 }))
2813 , make_ord_flag defGhcFlag "mavx" (noArg (\d -> d { avx = True }))
2814 , make_ord_flag defGhcFlag "mavx2" (noArg (\d -> d { avx2 = True }))
2815 , make_ord_flag defGhcFlag "mavx512cd" (noArg (\d ->
2816 d { avx512cd = True }))
2817 , make_ord_flag defGhcFlag "mavx512er" (noArg (\d ->
2818 d { avx512er = True }))
2819 , make_ord_flag defGhcFlag "mavx512f" (noArg (\d -> d { avx512f = True }))
2820 , make_ord_flag defGhcFlag "mavx512pf" (noArg (\d ->
2821 d { avx512pf = True }))
2822
2823 ------ Warning opts -------------------------------------------------
2824 , make_ord_flag defFlag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
2825 , make_ord_flag defFlag "Werror" (NoArg (setGeneralFlag Opt_WarnIsError))
2826 , make_ord_flag defFlag "Wwarn" (NoArg (unSetGeneralFlag Opt_WarnIsError))
2827 , make_dep_flag defFlag "Wnot" (NoArg (upd (\d ->
2828 d {warningFlags = IntSet.empty})))
2829 "Use -w or -Wno-everything instead"
2830 , make_ord_flag defFlag "w" (NoArg (upd (\d ->
2831 d {warningFlags = IntSet.empty})))
2832
2833 -- New-style uniform warning sets
2834 --
2835 -- Note that -Weverything > -Wall > -Wextra > -Wdefault > -Wno-everything
2836 , make_ord_flag defFlag "Weverything" (NoArg (mapM_
2837 setWarningFlag minusWeverythingOpts))
2838 , make_ord_flag defFlag "Wno-everything"
2839 (NoArg (upd (\d -> d {warningFlags = IntSet.empty})))
2840
2841 , make_ord_flag defFlag "Wall" (NoArg (mapM_
2842 setWarningFlag minusWallOpts))
2843 , make_ord_flag defFlag "Wno-all" (NoArg (mapM_
2844 unSetWarningFlag minusWallOpts))
2845
2846 , make_ord_flag defFlag "Wextra" (NoArg (mapM_
2847 setWarningFlag minusWOpts))
2848 , make_ord_flag defFlag "Wno-extra" (NoArg (mapM_
2849 unSetWarningFlag minusWOpts))
2850
2851 , make_ord_flag defFlag "Wdefault" (NoArg (mapM_
2852 setWarningFlag standardWarnings))
2853 , make_ord_flag defFlag "Wno-default" (NoArg (mapM_
2854 unSetWarningFlag standardWarnings))
2855
2856 , make_ord_flag defFlag "Wcompat" (NoArg (mapM_
2857 setWarningFlag minusWcompatOpts))
2858 , make_ord_flag defFlag "Wno-compat" (NoArg (mapM_
2859 unSetWarningFlag minusWcompatOpts))
2860
2861 ------ Plugin flags ------------------------------------------------
2862 , make_ord_flag defGhcFlag "fplugin-opt" (hasArg addPluginModuleNameOption)
2863 , make_ord_flag defGhcFlag "fplugin" (hasArg addPluginModuleName)
2864 , make_ord_flag defGhcFlag "ffrontend-opt" (hasArg addFrontendPluginOption)
2865
2866 ------ Optimisation flags ------------------------------------------
2867 , make_ord_flag defGhcFlag "O" (noArgM (setOptLevel 1))
2868 , make_dep_flag defGhcFlag "Onot" (noArgM $ setOptLevel 0 )
2869 "Use -O0 instead"
2870 , make_ord_flag defGhcFlag "Odph" (noArgM setDPHOpt)
2871 , make_ord_flag defGhcFlag "O" (optIntSuffixM (\mb_n ->
2872 setOptLevel (mb_n `orElse` 1)))
2873 -- If the number is missing, use 1
2874
2875
2876 , make_ord_flag defFlag "fmax-relevant-binds"
2877 (intSuffix (\n d -> d { maxRelevantBinds = Just n }))
2878 , make_ord_flag defFlag "fno-max-relevant-binds"
2879 (noArg (\d -> d { maxRelevantBinds = Nothing }))
2880 , make_ord_flag defFlag "fmax-uncovered-patterns"
2881 (intSuffix (\n d -> d { maxUncoveredPatterns = n }))
2882 , make_ord_flag defFlag "fsimplifier-phases"
2883 (intSuffix (\n d -> d { simplPhases = n }))
2884 , make_ord_flag defFlag "fmax-simplifier-iterations"
2885 (intSuffix (\n d -> d { maxSimplIterations = n }))
2886 , make_ord_flag defFlag "fmax-pmcheck-iterations"
2887 (intSuffix (\n d -> d{ maxPmCheckIterations = n }))
2888 , make_ord_flag defFlag "fsimpl-tick-factor"
2889 (intSuffix (\n d -> d { simplTickFactor = n }))
2890 , make_ord_flag defFlag "fspec-constr-threshold"
2891 (intSuffix (\n d -> d { specConstrThreshold = Just n }))
2892 , make_ord_flag defFlag "fno-spec-constr-threshold"
2893 (noArg (\d -> d { specConstrThreshold = Nothing }))
2894 , make_ord_flag defFlag "fspec-constr-count"
2895 (intSuffix (\n d -> d { specConstrCount = Just n }))
2896 , make_ord_flag defFlag "fno-spec-constr-count"
2897 (noArg (\d -> d { specConstrCount = Nothing }))
2898 , make_ord_flag defFlag "fspec-constr-recursive"
2899 (intSuffix (\n d -> d { specConstrRecursive = n }))
2900 , make_ord_flag defFlag "fliberate-case-threshold"
2901 (intSuffix (\n d -> d { liberateCaseThreshold = Just n }))
2902 , make_ord_flag defFlag "fno-liberate-case-threshold"
2903 (noArg (\d -> d { liberateCaseThreshold = Nothing }))
2904 , make_ord_flag defFlag "frule-check"
2905 (sepArg (\s d -> d { ruleCheck = Just s }))
2906 , make_ord_flag defFlag "freduction-depth"
2907 (intSuffix (\n d -> d { reductionDepth = treatZeroAsInf n }))
2908 , make_ord_flag defFlag "fconstraint-solver-iterations"
2909 (intSuffix (\n d -> d { solverIterations = treatZeroAsInf n }))
2910 , (Deprecated, defFlag "fcontext-stack"
2911 (intSuffixM (\n d ->
2912 do { deprecate $ "use -freduction-depth=" ++ show n ++ " instead"
2913 ; return $ d { reductionDepth = treatZeroAsInf n } })))
2914 , (Deprecated, defFlag "ftype-function-depth"
2915 (intSuffixM (\n d ->
2916 do { deprecate $ "use -freduction-depth=" ++ show n ++ " instead"
2917 ; return $ d { reductionDepth = treatZeroAsInf n } })))
2918 , make_ord_flag defFlag "fstrictness-before"
2919 (intSuffix (\n d -> d { strictnessBefore = n : strictnessBefore d }))
2920 , make_ord_flag defFlag "ffloat-lam-args"
2921 (intSuffix (\n d -> d { floatLamArgs = Just n }))
2922 , make_ord_flag defFlag "ffloat-all-lams"
2923 (noArg (\d -> d { floatLamArgs = Nothing }))
2924 , make_ord_flag defFlag "fhistory-size"
2925 (intSuffix (\n d -> d { historySize = n }))
2926 , make_ord_flag defFlag "funfolding-creation-threshold"
2927 (intSuffix (\n d -> d {ufCreationThreshold = n}))
2928 , make_ord_flag defFlag "funfolding-use-threshold"
2929 (intSuffix (\n d -> d {ufUseThreshold = n}))
2930 , make_ord_flag defFlag "funfolding-fun-discount"
2931 (intSuffix (\n d -> d {ufFunAppDiscount = n}))
2932 , make_ord_flag defFlag "funfolding-dict-discount"
2933 (intSuffix (\n d -> d {ufDictDiscount = n}))
2934 , make_ord_flag defFlag "funfolding-keeness-factor"
2935 (floatSuffix (\n d -> d {ufKeenessFactor = n}))
2936 , make_ord_flag defFlag "fmax-worker-args"
2937 (intSuffix (\n d -> d {maxWorkerArgs = n}))
2938 , make_ord_flag defGhciFlag "fghci-hist-size"
2939 (intSuffix (\n d -> d {ghciHistSize = n}))
2940 , make_ord_flag defGhcFlag "fmax-inline-alloc-size"
2941 (intSuffix (\n d -> d { maxInlineAllocSize = n }))
2942 , make_ord_flag defGhcFlag "fmax-inline-memcpy-insns"
2943 (intSuffix (\n d -> d { maxInlineMemcpyInsns = n }))
2944 , make_ord_flag defGhcFlag "fmax-inline-memset-insns"
2945 (intSuffix (\n d -> d { maxInlineMemsetInsns = n }))
2946 , make_ord_flag defGhcFlag "dinitial-unique"
2947 (intSuffix (\n d -> d { initialUnique = n }))
2948 , make_ord_flag defGhcFlag "dunique-increment"
2949 (intSuffix (\n d -> d { uniqueIncrement = n }))
2950
2951 ------ Profiling ----------------------------------------------------
2952
2953 -- OLD profiling flags
2954 , make_dep_flag defGhcFlag "auto-all"
2955 (noArg (\d -> d { profAuto = ProfAutoAll } ))
2956 "Use -fprof-auto instead"
2957 , make_dep_flag defGhcFlag "no-auto-all"
2958 (noArg (\d -> d { profAuto = NoProfAuto } ))
2959 "Use -fno-prof-auto instead"
2960 , make_dep_flag defGhcFlag "auto"
2961 (noArg (\d -> d { profAuto = ProfAutoExports } ))
2962 "Use -fprof-auto-exported instead"
2963 , make_dep_flag defGhcFlag "no-auto"
2964 (noArg (\d -> d { profAuto = NoProfAuto } ))
2965 "Use -fno-prof-auto instead"
2966 , make_dep_flag defGhcFlag "caf-all"
2967 (NoArg (setGeneralFlag Opt_AutoSccsOnIndividualCafs))
2968 "Use -fprof-cafs instead"
2969 , make_dep_flag defGhcFlag "no-caf-all"
2970 (NoArg (unSetGeneralFlag Opt_AutoSccsOnIndividualCafs))
2971 "Use -fno-prof-cafs instead"
2972
2973 -- NEW profiling flags
2974 , make_ord_flag defGhcFlag "fprof-auto"
2975 (noArg (\d -> d { profAuto = ProfAutoAll } ))
2976 , make_ord_flag defGhcFlag "fprof-auto-top"
2977 (noArg (\d -> d { profAuto = ProfAutoTop } ))
2978 , make_ord_flag defGhcFlag "fprof-auto-exported"
2979 (noArg (\d -> d { profAuto = ProfAutoExports } ))
2980 , make_ord_flag defGhcFlag "fprof-auto-calls"
2981 (noArg (\d -> d { profAuto = ProfAutoCalls } ))
2982 , make_ord_flag defGhcFlag "fno-prof-auto"
2983 (noArg (\d -> d { profAuto = NoProfAuto } ))
2984
2985 ------ Compiler flags -----------------------------------------------
2986
2987 , make_ord_flag defGhcFlag "fasm" (NoArg (setObjTarget HscAsm))
2988 , make_ord_flag defGhcFlag "fvia-c" (NoArg
2989 (addWarn $ "The -fvia-c flag does nothing; " ++
2990 "it will be removed in a future GHC release"))
2991 , make_ord_flag defGhcFlag "fvia-C" (NoArg
2992 (addWarn $ "The -fvia-C flag does nothing; " ++
2993 "it will be removed in a future GHC release"))
2994 , make_ord_flag defGhcFlag "fllvm" (NoArg (setObjTarget HscLlvm))
2995
2996 , make_ord_flag defFlag "fno-code" (NoArg ((upd $ \d ->
2997 d { ghcLink=NoLink }) >> setTarget HscNothing))
2998 , make_ord_flag defFlag "fbyte-code" (NoArg (setTarget HscInterpreted))
2999 , make_ord_flag defFlag "fobject-code" (NoArg (setTargetWithPlatform
3000 defaultHscTarget))
3001 , make_dep_flag defFlag "fglasgow-exts"
3002 (NoArg enableGlasgowExts) "Use individual extensions instead"
3003 , make_dep_flag defFlag "fno-glasgow-exts"
3004 (NoArg disableGlasgowExts) "Use individual extensions instead"
3005 , make_ord_flag defFlag "Wunused-binds" (NoArg enableUnusedBinds)
3006 , make_ord_flag defFlag "Wno-unused-binds" (NoArg disableUnusedBinds)
3007 , make_ord_flag defHiddenFlag "fwarn-unused-binds" (NoArg enableUnusedBinds)
3008 , make_ord_flag defHiddenFlag "fno-warn-unused-binds" (NoArg
3009 disableUnusedBinds)
3010
3011 ------ Safe Haskell flags -------------------------------------------
3012 , make_ord_flag defFlag "fpackage-trust" (NoArg setPackageTrust)
3013 , make_ord_flag defFlag "fno-safe-infer" (noArg (\d ->
3014 d { safeInfer = False }))
3015 , make_ord_flag defGhcFlag "fPIC" (NoArg (setGeneralFlag Opt_PIC))
3016 , make_ord_flag defGhcFlag "fno-PIC" (NoArg (unSetGeneralFlag Opt_PIC))
3017
3018 ------ Debugging flags ----------------------------------------------
3019 , make_ord_flag defGhcFlag "g" (OptIntSuffix setDebugLevel)
3020 ]
3021 ++ map (mkFlag turnOn "" setGeneralFlag ) negatableFlagsDeps
3022 ++ map (mkFlag turnOff "no-" unSetGeneralFlag ) negatableFlagsDeps
3023 ++ map (mkFlag turnOn "d" setGeneralFlag ) dFlagsDeps
3024 ++ map (mkFlag turnOff "dno-" unSetGeneralFlag ) dFlagsDeps
3025 ++ map (mkFlag turnOn "f" setGeneralFlag ) fFlagsDeps
3026 ++ map (mkFlag turnOff "fno-" unSetGeneralFlag ) fFlagsDeps
3027 ++ map (mkFlag turnOn "W" setWarningFlag ) wWarningFlagsDeps
3028 ++ map (mkFlag turnOff "Wno-" unSetWarningFlag ) wWarningFlagsDeps
3029 ++ map (mkFlag turnOn "fwarn-" setWarningFlag . hideFlag)
3030 wWarningFlagsDeps
3031 ++ map (mkFlag turnOff "fno-warn-" unSetWarningFlag . hideFlag)
3032 wWarningFlagsDeps
3033 ++ [ (NotDeprecated, unrecognisedWarning "W"),
3034 (Deprecated, unrecognisedWarning "fwarn-"),
3035 (Deprecated, unrecognisedWarning "fno-warn-") ]
3036 ++ map (mkFlag turnOn "f" setExtensionFlag ) fLangFlagsDeps
3037 ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlagsDeps
3038 ++ map (mkFlag turnOn "X" setExtensionFlag ) xFlagsDeps
3039 ++ map (mkFlag turnOff "XNo" unSetExtensionFlag) xFlagsDeps
3040 ++ map (mkFlag turnOn "X" setLanguage ) languageFlagsDeps
3041 ++ map (mkFlag turnOn "X" setSafeHaskell ) safeHaskellFlagsDeps
3042 ++ [ make_dep_flag defFlag "XGenerics"
3043 (NoArg $ return ())
3044 ("it does nothing; look into -XDefaultSignatures " ++
3045 "and -XDeriveGeneric for generic programming support.")
3046 , make_dep_flag defFlag "XNoGenerics"
3047 (NoArg $ return ())
3048 ("it does nothing; look into -XDefaultSignatures and " ++
3049 "-XDeriveGeneric for generic programming support.") ]
3050
3051 -- | This is where we handle unrecognised warning flags. We only issue a warning
3052 -- if -Wunrecognised-warning-flags is set. See Trac #11429 for context.
3053 unrecognisedWarning :: String -> Flag (CmdLineP DynFlags)
3054 unrecognisedWarning prefix = defHiddenFlag prefix (Prefix action)
3055 where
3056 action :: String -> EwM (CmdLineP DynFlags) ()
3057 action flag = do
3058 f <- wopt Opt_WarnUnrecognisedWarningFlags <$> liftEwM getCmdLineState
3059 when f $ addWarn $ "unrecognised warning flag: -" ++ prefix ++ flag
3060
3061 -- See Note [Supporting CLI completion]
3062 package_flags_deps :: [(Deprecation, Flag (CmdLineP DynFlags))]
3063 package_flags_deps = [
3064 ------- Packages ----------------------------------------------------
3065 make_ord_flag defFlag "package-db"
3066 (HasArg (addPkgConfRef . PkgConfFile))
3067 , make_ord_flag defFlag "clear-package-db" (NoArg clearPkgConf)
3068 , make_ord_flag defFlag "no-global-package-db" (NoArg removeGlobalPkgConf)
3069 , make_ord_flag defFlag "no-user-package-db" (NoArg removeUserPkgConf)
3070 , make_ord_flag defFlag "global-package-db"
3071 (NoArg (addPkgConfRef GlobalPkgConf))
3072 , make_ord_flag defFlag "user-package-db"
3073 (NoArg (addPkgConfRef UserPkgConf))
3074 -- backwards compat with GHC<=7.4 :
3075 , make_dep_flag defFlag "package-conf"
3076 (HasArg $ addPkgConfRef . PkgConfFile) "Use -package-db instead"
3077 , make_dep_flag defFlag "no-user-package-conf"
3078 (NoArg removeUserPkgConf) "Use -no-user-package-db instead"
3079 , make_ord_flag defGhcFlag "package-name" (HasArg $ \name -> do
3080 upd (setUnitId name))
3081 -- TODO: Since we JUST deprecated
3082 -- -this-package-key, let's keep this
3083 -- undeprecated for another cycle.
3084 -- Deprecate this eventually.
3085 -- deprecate "Use -this-unit-id instead")
3086 , make_dep_flag defGhcFlag "this-package-key" (HasArg $ upd . setUnitId)
3087 "Use -this-unit-id instead"
3088 , make_ord_flag defGhcFlag "this-unit-id" (hasArg setUnitId)
3089 , make_ord_flag defFlag "package" (HasArg exposePackage)
3090 , make_ord_flag defFlag "plugin-package-id" (HasArg exposePluginPackageId)
3091 , make_ord_flag defFlag "plugin-package" (HasArg exposePluginPackage)
3092 , make_ord_flag defFlag "package-id" (HasArg exposePackageId)
3093 , make_ord_flag defFlag "hide-package" (HasArg hidePackage)
3094 , make_ord_flag defFlag "hide-all-packages"
3095 (NoArg (setGeneralFlag Opt_HideAllPackages))
3096 , make_ord_flag defFlag "hide-all-plugin-packages"
3097 (NoArg (setGeneralFlag Opt_HideAllPluginPackages))
3098 , make_ord_flag defFlag "package-env" (HasArg setPackageEnv)
3099 , make_ord_flag defFlag "ignore-package" (HasArg ignorePackage)
3100 , make_dep_flag defFlag "syslib" (HasArg exposePackage) "Use -package instead"
3101 , make_ord_flag defFlag "distrust-all-packages"
3102 (NoArg (setGeneralFlag Opt_DistrustAllPackages))
3103 , make_ord_flag defFlag "trust" (HasArg trustPackage)
3104 , make_ord_flag defFlag "distrust" (HasArg distrustPackage)
3105 ]
3106 where
3107 setPackageEnv env = upd $ \s -> s { packageEnv = Just env }
3108
3109 -- | Make a list of flags for shell completion.
3110 -- Filter all available flags into two groups, for interactive GHC vs all other.
3111 flagsForCompletion :: Bool -> [String]
3112 flagsForCompletion isInteractive
3113 = [ '-':flagName flag
3114 | flag <- flagsAll
3115 , modeFilter (flagGhcMode flag)
3116 ]
3117 where
3118 modeFilter AllModes = True
3119 modeFilter OnlyGhci = isInteractive
3120 modeFilter OnlyGhc = not isInteractive
3121 modeFilter HiddenFlag = False
3122
3123 type TurnOnFlag = Bool -- True <=> we are turning the flag on
3124 -- False <=> we are turning the flag off
3125 turnOn :: TurnOnFlag; turnOn = True
3126 turnOff :: TurnOnFlag; turnOff = False
3127
3128 data FlagSpec flag
3129 = FlagSpec
3130 { flagSpecName :: String -- ^ Flag in string form
3131 , flagSpecFlag :: flag -- ^ Flag in internal form
3132 , flagSpecAction :: (TurnOnFlag -> DynP ())
3133 -- ^ Extra action to run when the flag is found
3134 -- Typically, emit a warning or error
3135 , flagSpecGhcMode :: GhcFlagMode
3136 -- ^ In which ghc mode the flag has effect
3137 }
3138
3139 -- | Define a new flag.
3140 flagSpec :: String -> flag -> (Deprecation, FlagSpec flag)
3141 flagSpec name flag = flagSpec' name flag nop
3142
3143 -- | Define a new flag with an effect.
3144 flagSpec' :: String -> flag -> (TurnOnFlag -> DynP ())
3145 -> (Deprecation, FlagSpec flag)
3146 flagSpec' name flag act = (NotDeprecated, FlagSpec name flag act AllModes)
3147
3148 -- | Define a new deprecated flag with an effect.
3149 depFlagSpecOp :: String -> flag -> (TurnOnFlag -> DynP ()) -> String
3150 -> (Deprecation, FlagSpec flag)
3151 depFlagSpecOp name flag act dep =
3152 (Deprecated, snd (flagSpec' name flag (\f -> act f >> deprecate dep)))
3153
3154 -- | Define a new deprecated flag.
3155 depFlagSpec :: String -> flag -> String
3156 -> (Deprecation, FlagSpec flag)
3157 depFlagSpec name flag dep = depFlagSpecOp name flag nop dep
3158
3159 -- | Define a new deprecated flag with an effect where the deprecation message
3160 -- depends on the flag value
3161 depFlagSpecOp' :: String
3162 -> flag
3163 -> (TurnOnFlag -> DynP ())
3164 -> (TurnOnFlag -> String)
3165 -> (Deprecation, FlagSpec flag)
3166 depFlagSpecOp' name flag act dep =
3167 (Deprecated, FlagSpec name flag (\f -> act f >> (deprecate $ dep f))
3168 AllModes)
3169
3170 -- | Define a new deprecated flag where the deprecation message
3171 -- depends on the flag value
3172 depFlagSpec' :: String
3173 -> flag
3174 -> (TurnOnFlag -> String)
3175 -> (Deprecation, FlagSpec flag)
3176 depFlagSpec' name flag dep = depFlagSpecOp' name flag nop dep
3177
3178
3179 -- | Define a new deprecated flag where the deprecation message
3180 -- is shown depending on the flag value
3181 depFlagSpecCond :: String
3182 -> flag
3183 -> (TurnOnFlag -> Bool)
3184 -> String
3185 -> (Deprecation, FlagSpec flag)
3186 depFlagSpecCond name flag cond dep =
3187 (Deprecated, FlagSpec name flag (\f -> when (cond f) $ deprecate dep)
3188 AllModes)
3189
3190 -- | Define a new flag for GHCi.
3191 flagGhciSpec :: String -> flag -> (Deprecation, FlagSpec flag)
3192 flagGhciSpec name flag = flagGhciSpec' name flag nop
3193
3194 -- | Define a new flag for GHCi with an effect.
3195 flagGhciSpec' :: String -> flag -> (TurnOnFlag -> DynP ())
3196 -> (Deprecation, FlagSpec flag)
3197 flagGhciSpec' name flag act = (NotDeprecated, FlagSpec name flag act OnlyGhci)
3198
3199 -- | Define a new flag invisible to CLI completion.
3200 flagHiddenSpec :: String -> flag -> (Deprecation, FlagSpec flag)
3201 flagHiddenSpec name flag = flagHiddenSpec' name flag nop
3202
3203 -- | Define a new flag invisible to CLI completion with an effect.
3204 flagHiddenSpec' :: String -> flag -> (TurnOnFlag -> DynP ())
3205 -> (Deprecation, FlagSpec flag)
3206 flagHiddenSpec' name flag act = (NotDeprecated, FlagSpec name flag act
3207 HiddenFlag)
3208
3209 -- | Hide a 'FlagSpec' from being displayed in @--show-options@.
3210 --
3211 -- This is for example useful for flags that are obsolete, but should not
3212 -- (yet) be deprecated for compatibility reasons.
3213 hideFlag :: (Deprecation, FlagSpec a) -> (Deprecation, FlagSpec a)
3214 hideFlag (dep, fs) = (dep, fs { flagSpecGhcMode = HiddenFlag })
3215
3216 mkFlag :: TurnOnFlag -- ^ True <=> it should be turned on
3217 -> String -- ^ The flag prefix
3218 -> (flag -> DynP ()) -- ^ What to do when the flag is found
3219 -> (Deprecation, FlagSpec flag) -- ^ Specification of
3220 -- this particular flag
3221 -> (Deprecation, Flag (CmdLineP DynFlags))
3222 mkFlag turn_on flagPrefix f (dep, (FlagSpec name flag extra_action mode))
3223 = (dep,
3224 Flag (flagPrefix ++ name) (NoArg (f flag >> extra_action turn_on)) mode)
3225
3226 deprecatedForExtension :: String -> TurnOnFlag -> String
3227 deprecatedForExtension lang turn_on
3228 = "use -X" ++ flag ++
3229 " or pragma {-# LANGUAGE " ++ flag ++ " #-} instead"
3230 where
3231 flag | turn_on = lang
3232 | otherwise = "No" ++ lang
3233
3234 useInstead :: String -> TurnOnFlag -> String
3235 useInstead flag turn_on
3236 = "Use -f" ++ no ++ flag ++ " instead"
3237 where
3238 no = if turn_on then "" else "no-"
3239
3240 nop :: TurnOnFlag -> DynP ()
3241 nop _ = return ()
3242
3243 -- | Find the 'FlagSpec' for a 'WarningFlag'.
3244 flagSpecOf :: WarningFlag -> Maybe (FlagSpec WarningFlag)
3245 flagSpecOf flag = listToMaybe $ filter check wWarningFlags
3246 where
3247 check fs = flagSpecFlag fs == flag
3248
3249 -- | These @-W\<blah\>@ flags can all be reversed with @-Wno-\<blah\>@
3250 wWarningFlags :: [FlagSpec WarningFlag]
3251 wWarningFlags = map snd (sortBy (comparing fst) wWarningFlagsDeps)
3252
3253 wWarningFlagsDeps :: [(Deprecation, FlagSpec WarningFlag)]
3254 wWarningFlagsDeps = [
3255 -- See Note [Updating flag description in the User's Guide]
3256 -- See Note [Supporting CLI completion]
3257 -- Please keep the list of flags below sorted alphabetically
3258 flagSpec "alternative-layout-rule-transitional"
3259 Opt_WarnAlternativeLayoutRuleTransitional,
3260 depFlagSpec "amp" Opt_WarnAMP
3261 "it has no effect",
3262 depFlagSpec "auto-orphans" Opt_WarnAutoOrphans
3263 "it has no effect",
3264 flagSpec "deferred-type-errors" Opt_WarnDeferredTypeErrors,
3265 flagSpec "deferred-out-of-scope-variables"
3266 Opt_WarnDeferredOutOfScopeVariables,
3267 flagSpec "deprecations" Opt_WarnWarningsDeprecations,
3268 flagSpec "deprecated-flags" Opt_WarnDeprecatedFlags,
3269 flagSpec "deriving-typeable" Opt_WarnDerivingTypeable,
3270 flagSpec "dodgy-exports" Opt_WarnDodgyExports,
3271 flagSpec "dodgy-foreign-imports" Opt_WarnDodgyForeignImports,
3272 flagSpec "dodgy-imports" Opt_WarnDodgyImports,
3273 flagSpec "empty-enumerations" Opt_WarnEmptyEnumerations,
3274 depFlagSpec "context-quantification" Opt_WarnContextQuantification
3275 "it is subsumed by an error message that cannot be disabled",
3276 depFlagSpec "duplicate-constraints" Opt_WarnDuplicateConstraints
3277 "it is subsumed by -Wredundant-constraints",
3278 flagSpec "redundant-constraints" Opt_WarnRedundantConstraints,
3279 flagSpec "duplicate-exports" Opt_WarnDuplicateExports,
3280 flagSpec "hi-shadowing" Opt_WarnHiShadows,
3281 flagSpec "implicit-prelude" Opt_WarnImplicitPrelude,
3282 flagSpec "incomplete-patterns" Opt_WarnIncompletePatterns,
3283 flagSpec "incomplete-record-updates" Opt_WarnIncompletePatternsRecUpd,
3284 flagSpec "incomplete-uni-patterns" Opt_WarnIncompleteUniPatterns,
3285 flagSpec "inline-rule-shadowing" Opt_WarnInlineRuleShadowing,
3286 flagSpec "identities" Opt_WarnIdentities,
3287 flagSpec "missing-fields" Opt_WarnMissingFields,
3288 flagSpec "missing-import-lists" Opt_WarnMissingImportList,
3289 depFlagSpec "missing-local-sigs" Opt_WarnMissingLocalSignatures
3290 "it is replaced by -Wmissing-local-signatures",
3291 flagSpec "missing-local-signatures" Opt_WarnMissingLocalSignatures,
3292 flagSpec "missing-methods" Opt_WarnMissingMethods,
3293 flagSpec "missing-monadfail-instances" Opt_WarnMissingMonadFailInstances,
3294 flagSpec "semigroup" Opt_WarnSemigroup,
3295 flagSpec "missing-signatures" Opt_WarnMissingSignatures,
3296 depFlagSpec "missing-exported-sigs" Opt_WarnMissingExportedSignatures
3297 "it is replaced by -Wmissing-exported-signatures",
3298 flagSpec "missing-exported-signatures" Opt_WarnMissingExportedSignatures,
3299 flagSpec "monomorphism-restriction" Opt_WarnMonomorphism,
3300 flagSpec "name-shadowing" Opt_WarnNameShadowing,
3301 flagSpec "noncanonical-monad-instances"
3302 Opt_WarnNonCanonicalMonadInstances,
3303 flagSpec "noncanonical-monadfail-instances"
3304 Opt_WarnNonCanonicalMonadFailInstances,
3305 flagSpec "noncanonical-monoid-instances"
3306 Opt_WarnNonCanonicalMonoidInstances,
3307 flagSpec "orphans" Opt_WarnOrphans,
3308 flagSpec "overflowed-literals" Opt_WarnOverflowedLiterals,
3309 flagSpec "overlapping-patterns" Opt_WarnOverlappingPatterns,
3310 flagSpec "missed-specialisations" Opt_WarnMissedSpecs,
3311 flagSpec "missed-specializations" Opt_WarnMissedSpecs,
3312 flagSpec "all-missed-specialisations" Opt_WarnAllMissedSpecs,
3313 flagSpec "all-missed-specializations" Opt_WarnAllMissedSpecs,
3314 flagSpec' "safe" Opt_WarnSafe setWarnSafe,
3315 flagSpec "trustworthy-safe" Opt_WarnTrustworthySafe,
3316 flagSpec "tabs" Opt_WarnTabs,
3317 flagSpec "type-defaults" Opt_WarnTypeDefaults,
3318 flagSpec "typed-holes" Opt_WarnTypedHoles,
3319 flagSpec "partial-type-signatures" Opt_WarnPartialTypeSignatures,
3320 flagSpec "unrecognised-pragmas" Opt_WarnUnrecognisedPragmas,
3321 flagSpec' "unsafe" Opt_WarnUnsafe setWarnUnsafe,
3322 flagSpec "unsupported-calling-conventions"
3323 Opt_WarnUnsupportedCallingConventions,
3324 flagSpec "unsupported-llvm-version" Opt_WarnUnsupportedLlvmVersion,
3325 flagSpec "unticked-promoted-constructors"
3326 Opt_WarnUntickedPromotedConstructors,
3327 flagSpec "unused-do-bind" Opt_WarnUnusedDoBind,
3328 flagSpec "unused-foralls" Opt_WarnUnusedForalls,
3329 flagSpec "unused-imports" Opt_WarnUnusedImports,
3330 flagSpec "unused-local-binds" Opt_WarnUnusedLocalBinds,
3331 flagSpec "unused-matches" Opt_WarnUnusedMatches,
3332 flagSpec "unused-pattern-binds" Opt_WarnUnusedPatternBinds,
3333 flagSpec "unused-top-binds" Opt_WarnUnusedTopBinds,
3334 flagSpec "unused-type-patterns" Opt_WarnUnusedTypePatterns,
3335 flagSpec "warnings-deprecations" Opt_WarnWarningsDeprecations,
3336 flagSpec "wrong-do-bind" Opt_WarnWrongDoBind,
3337 flagSpec "missing-pattern-synonym-signatures"
3338 Opt_WarnMissingPatternSynonymSignatures,
3339 flagSpec "simplifiable-class-constraints" Opt_WarnSimplifiableClassConstraints,
3340 flagSpec "unrecognised-warning-flags" Opt_WarnUnrecognisedWarningFlags ]
3341
3342 -- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@
3343 negatableFlagsDeps :: [(Deprecation, FlagSpec GeneralFlag)]
3344 negatableFlagsDeps = [
3345 flagGhciSpec "ignore-dot-ghci" Opt_IgnoreDotGhci ]
3346
3347 -- | These @-d\<blah\>@ flags can all be reversed with @-dno-\<blah\>@
3348 dFlagsDeps :: [(Deprecation, FlagSpec GeneralFlag)]
3349 dFlagsDeps = [
3350 -- See Note [Updating flag description in the User's Guide]
3351 -- See Note [Supporting CLI completion]
3352 -- Please keep the list of flags below sorted alphabetically
3353 flagSpec "ppr-case-as-let" Opt_PprCaseAsLet,
3354 flagSpec "ppr-ticks" Opt_PprShowTicks,
3355 flagSpec "suppress-coercions" Opt_SuppressCoercions,
3356 flagSpec "suppress-idinfo" Opt_SuppressIdInfo,
3357 flagSpec "suppress-unfoldings" Opt_SuppressUnfoldings,
3358 flagSpec "suppress-module-prefixes" Opt_SuppressModulePrefixes,
3359 flagSpec "suppress-type-applications" Opt_SuppressTypeApplications,
3360 flagSpec "suppress-type-signatures" Opt_SuppressTypeSignatures,
3361 flagSpec "suppress-uniques" Opt_SuppressUniques,
3362 flagSpec "suppress-var-kinds" Opt_SuppressVarKinds]
3363
3364 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
3365 fFlags :: [FlagSpec GeneralFlag]
3366 fFlags = map snd fFlagsDeps
3367
3368 fFlagsDeps :: [(Deprecation, FlagSpec GeneralFlag)]
3369 fFlagsDeps = [
3370 -- See Note [Updating flag description in the User's Guide]
3371 -- See Note [Supporting CLI completion]
3372 -- Please keep the list of flags below sorted alphabetically
3373 flagGhciSpec "break-on-error" Opt_BreakOnError,
3374 flagGhciSpec "break-on-exception" Opt_BreakOnException,
3375 flagSpec "building-cabal-package" Opt_BuildingCabalPackage,
3376 flagSpec "call-arity" Opt_CallArity,
3377 flagSpec "case-merge" Opt_CaseMerge,
3378 flagSpec "cmm-elim-common-blocks" Opt_CmmElimCommonBlocks,
3379 flagSpec "cmm-sink" Opt_CmmSink,
3380 flagSpec "cse" Opt_CSE,
3381 flagSpec "cpr-anal" Opt_CprAnal,
3382 flagSpec "defer-type-errors" Opt_DeferTypeErrors,
3383 flagSpec "defer-typed-holes" Opt_DeferTypedHoles,
3384 flagSpec "defer-out-of-scope-variables" Opt_DeferOutOfScopeVariables,
3385 flagSpec "dicts-cheap" Opt_DictsCheap,
3386 flagSpec "dicts-strict" Opt_DictsStrict,
3387 flagSpec "dmd-tx-dict-sel" Opt_DmdTxDictSel,
3388 flagSpec "do-eta-reduction" Opt_DoEtaReduction,
3389 flagSpec "do-lambda-eta-expansion" Opt_DoLambdaEtaExpansion,
3390 flagSpec "eager-blackholing" Opt_EagerBlackHoling,
3391 flagSpec "embed-manifest" Opt_EmbedManifest,
3392 flagSpec "enable-rewrite-rules" Opt_EnableRewriteRules,
3393 flagSpec "error-spans" Opt_ErrorSpans,
3394 flagSpec "excess-precision" Opt_ExcessPrecision,
3395 flagSpec "expose-all-unfoldings" Opt_ExposeAllUnfoldings,
3396 flagSpec "external-interpreter" Opt_ExternalInterpreter,
3397 flagSpec "flat-cache" Opt_FlatCache,
3398 flagSpec "float-in" Opt_FloatIn,
3399 flagSpec "force-recomp" Opt_ForceRecomp,
3400 flagSpec "full-laziness" Opt_FullLaziness,
3401 flagSpec "fun-to-thunk" Opt_FunToThunk,
3402 flagSpec "gen-manifest" Opt_GenManifest,
3403 flagSpec "ghci-history" Opt_GhciHistory,
3404 flagGhciSpec "local-ghci-history" Opt_LocalGhciHistory,
3405 flagSpec "ghci-sandbox" Opt_GhciSandbox,
3406 flagSpec "helpful-errors" Opt_HelpfulErrors,
3407 flagSpec "hpc" Opt_Hpc,
3408 flagSpec "ignore-asserts" Opt_IgnoreAsserts,
3409 flagSpec "ignore-interface-pragmas" Opt_IgnoreInterfacePragmas,
3410 flagGhciSpec "implicit-import-qualified" Opt_ImplicitImportQualified,
3411 flagSpec "irrefutable-tuples" Opt_IrrefutableTuples,
3412 flagSpec "kill-absence" Opt_KillAbsence,
3413 flagSpec "kill-one-shot" Opt_KillOneShot,
3414 flagSpec "late-dmd-anal" Opt_LateDmdAnal,
3415 flagSpec "liberate-case" Opt_LiberateCase,
3416 flagHiddenSpec "llvm-pass-vectors-in-regs" Opt_LlvmPassVectorsInRegisters,
3417 flagHiddenSpec "llvm-tbaa" Opt_LlvmTBAA,
3418 flagHiddenSpec "llvm-fill-undef-with-garbage" Opt_LlvmFillUndefWithGarbage,
3419 flagSpec "loopification" Opt_Loopification,
3420 flagSpec "omit-interface-pragmas" Opt_OmitInterfacePragmas,
3421 flagSpec "omit-yields" Opt_OmitYields,
3422 flagSpec "optimal-applicative-do" Opt_OptimalApplicativeDo,
3423 flagSpec "pedantic-bottoms" Opt_PedanticBottoms,
3424 flagSpec "pre-inlining" Opt_SimplPreInlining,
3425 flagGhciSpec "print-bind-contents" Opt_PrintBindContents,
3426 flagGhciSpec "print-bind-result" Opt_PrintBindResult,
3427 flagGhciSpec "print-evld-with-show" Opt_PrintEvldWithShow,
3428 flagSpec "print-explicit-foralls" Opt_PrintExplicitForalls,
3429 flagSpec "print-explicit-kinds" Opt_PrintExplicitKinds,
3430 flagSpec "print-explicit-coercions" Opt_PrintExplicitCoercions,
3431 flagSpec "print-explicit-runtime-reps" Opt_PrintExplicitRuntimeReps,
3432 flagSpec "print-equality-relations" Opt_PrintEqualityRelations,
3433 flagSpec "print-unicode-syntax" Opt_PrintUnicodeSyntax,
3434 flagSpec "print-expanded-synonyms" Opt_PrintExpandedSynonyms,
3435 flagSpec "print-potential-instances" Opt_PrintPotentialInstances,
3436 flagSpec "print-typechecker-elaboration" Opt_PrintTypecheckerElaboration,
3437 flagSpec "prof-cafs" Opt_AutoSccsOnIndividualCafs,
3438 flagSpec "prof-count-entries" Opt_ProfCountEntries,
3439 flagSpec "regs-graph" Opt_RegsGraph,
3440 flagSpec "regs-iterative" Opt_RegsIterative,
3441 depFlagSpec' "rewrite-rules" Opt_EnableRewriteRules
3442 (useInstead "enable-rewrite-rules"),
3443 flagSpec "shared-implib" Opt_SharedImplib,
3444 flagSpec "spec-constr" Opt_SpecConstr,
3445 flagSpec "specialise" Opt_Specialise,
3446 flagSpec "specialize" Opt_Specialise,
3447 flagSpec "specialise-aggressively" Opt_SpecialiseAggressively,
3448 flagSpec "specialize-aggressively" Opt_SpecialiseAggressively,
3449 flagSpec "cross-module-specialise" Opt_CrossModuleSpecialise,
3450 flagSpec "cross-module-specialize" Opt_CrossModuleSpecialise,
3451 flagSpec "static-argument-transformation" Opt_StaticArgumentTransformation,
3452 flagSpec "strictness" Opt_Strictness,
3453 flagSpec "use-rpaths" Opt_RPath,
3454 flagSpec "write-interface" Opt_WriteInterface,
3455 flagSpec "unbox-small-strict-fields" Opt_UnboxSmallStrictFields,
3456 flagSpec "unbox-strict-fields" Opt_UnboxStrictFields,
3457 flagSpec "vectorisation-avoidance" Opt_VectorisationAvoidance,
3458 flagSpec "vectorise" Opt_Vectorise,
3459 flagSpec "version-macros" Opt_VersionMacros,
3460 flagSpec "worker-wrapper" Opt_WorkerWrapper,
3461 flagSpec "show-warning-groups" Opt_ShowWarnGroups
3462 ]
3463
3464 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
3465 fLangFlags :: [FlagSpec LangExt.Extension]
3466 fLangFlags = map snd fLangFlagsDeps
3467
3468 fLangFlagsDeps :: [(Deprecation, FlagSpec LangExt.Extension)]
3469 fLangFlagsDeps = [
3470 -- See Note [Updating flag description in the User's Guide]
3471 -- See Note [Supporting CLI completion]
3472 depFlagSpecOp' "th" LangExt.TemplateHaskell
3473 checkTemplateHaskellOk
3474 (deprecatedForExtension "TemplateHaskell"),
3475 depFlagSpec' "fi" LangExt.ForeignFunctionInterface
3476 (deprecatedForExtension "ForeignFunctionInterface"),
3477 depFlagSpec' "ffi" LangExt.ForeignFunctionInterface
3478 (deprecatedForExtension "ForeignFunctionInterface"),
3479 depFlagSpec' "arrows" LangExt.Arrows
3480 (deprecatedForExtension "Arrows"),
3481 depFlagSpec' "implicit-prelude" LangExt.ImplicitPrelude
3482 (deprecatedForExtension "ImplicitPrelude"),
3483 depFlagSpec' "bang-patterns" LangExt.BangPatterns
3484 (deprecatedForExtension "BangPatterns"),
3485 depFlagSpec' "monomorphism-restriction" LangExt.MonomorphismRestriction
3486 (deprecatedForExtension "MonomorphismRestriction"),
3487 depFlagSpec' "mono-pat-binds" LangExt.MonoPatBinds
3488 (deprecatedForExtension "MonoPatBinds"),
3489 depFlagSpec' "extended-default-rules" LangExt.ExtendedDefaultRules
3490 (deprecatedForExtension "ExtendedDefaultRules"),
3491 depFlagSpec' "implicit-params" LangExt.ImplicitParams
3492 (deprecatedForExtension "ImplicitParams"),
3493 depFlagSpec' "scoped-type-variables" LangExt.ScopedTypeVariables
3494 (deprecatedForExtension "ScopedTypeVariables"),
3495 depFlagSpec' "parr" LangExt.ParallelArrays
3496 (deprecatedForExtension "ParallelArrays"),
3497 depFlagSpec' "PArr" LangExt.ParallelArrays
3498 (deprecatedForExtension "ParallelArrays"),
3499 depFlagSpec' "allow-overlapping-instances" LangExt.OverlappingInstances
3500 (deprecatedForExtension "OverlappingInstances"),
3501 depFlagSpec' "allow-undecidable-instances" LangExt.UndecidableInstances
3502 (deprecatedForExtension "UndecidableInstances"),
3503 depFlagSpec' "allow-incoherent-instances" LangExt.IncoherentInstances
3504 (deprecatedForExtension "IncoherentInstances")
3505 ]
3506
3507 supportedLanguages :: [String]
3508 supportedLanguages = map (flagSpecName . snd) languageFlagsDeps
3509
3510 supportedLanguageOverlays :: [String]
3511 supportedLanguageOverlays = map (flagSpecName . snd) safeHaskellFlagsDeps
3512
3513 supportedExtensions :: [String]
3514 supportedExtensions = concatMap toFlagSpecNamePair xFlags
3515 where
3516 toFlagSpecNamePair flg
3517 #ifndef GHCI
3518 -- make sure that `ghc --supported-extensions` omits
3519 -- "TemplateHaskell" when it's known to be unsupported. See also
3520 -- GHC #11102 for rationale
3521 | flagSpecFlag flg == LangExt.TemplateHaskell = [noName]
3522 #endif
3523 | otherwise = [name, noName]
3524 where
3525 noName = "No" ++ name
3526 name = flagSpecName flg
3527
3528 supportedLanguagesAndExtensions :: [String]
3529 supportedLanguagesAndExtensions =
3530 supportedLanguages ++ supportedLanguageOverlays ++ supportedExtensions
3531
3532 -- | These -X<blah> flags cannot be reversed with -XNo<blah>
3533 languageFlagsDeps :: [(Deprecation, FlagSpec Language)]
3534 languageFlagsDeps = [
3535 flagSpec "Haskell98" Haskell98,
3536 flagSpec "Haskell2010" Haskell2010
3537 ]
3538
3539 -- | These -X<blah> flags cannot be reversed with -XNo<blah>
3540 -- They are used to place hard requirements on what GHC Haskell language
3541 -- features can be used.
3542 safeHaskellFlagsDeps :: [(Deprecation, FlagSpec SafeHaskellMode)]
3543 safeHaskellFlagsDeps = [mkF Sf_Unsafe, mkF Sf_Trustworthy, mkF Sf_Safe]
3544 where mkF flag = flagSpec (show flag) flag
3545
3546 -- | These -X<blah> flags can all be reversed with -XNo<blah>
3547 xFlags :: [FlagSpec LangExt.Extension]
3548 xFlags = map snd xFlagsDeps
3549
3550 xFlagsDeps :: [(Deprecation, FlagSpec LangExt.Extension)]
3551 xFlagsDeps = [
3552 -- See Note [Updating flag description in the User's Guide]
3553 -- See Note [Supporting CLI completion]
3554 -- See Note [Adding a language extension]
3555 -- Please keep the list of flags below sorted alphabetically
3556 flagSpec "AllowAmbiguousTypes" LangExt.AllowAmbiguousTypes,
3557 flagSpec "AlternativeLayoutRule" LangExt.AlternativeLayoutRule,
3558 flagSpec "AlternativeLayoutRuleTransitional"
3559 LangExt.AlternativeLayoutRuleTransitional,
3560 flagSpec "Arrows" LangExt.Arrows,
3561 flagSpec "AutoDeriveTypeable" LangExt.AutoDeriveTypeable,
3562 flagSpec "BangPatterns" LangExt.BangPatterns,
3563 flagSpec "BinaryLiterals" LangExt.BinaryLiterals,
3564 flagSpec "CApiFFI" LangExt.CApiFFI,
3565 flagSpec "CPP" LangExt.Cpp,
3566 flagSpec "ConstrainedClassMethods" LangExt.ConstrainedClassMethods,
3567 flagSpec "ConstraintKinds" LangExt.ConstraintKinds,
3568 flagSpec "DataKinds" LangExt.DataKinds,
3569 depFlagSpecCond "DatatypeContexts" LangExt.DatatypeContexts
3570 id
3571 ("It was widely considered a misfeature, " ++
3572 "and has been removed from the Haskell language."),
3573 flagSpec "DefaultSignatures" LangExt.DefaultSignatures,
3574 flagSpec "DeriveAnyClass" LangExt.DeriveAnyClass,
3575 flagSpec "DeriveDataTypeable" LangExt.DeriveDataTypeable,
3576 flagSpec "DeriveFoldable" LangExt.DeriveFoldable,
3577 flagSpec "DeriveFunctor" LangExt.DeriveFunctor,
3578 flagSpec "DeriveGeneric" LangExt.DeriveGeneric,
3579 flagSpec "DeriveLift" LangExt.DeriveLift,
3580 flagSpec "DeriveTraversable" LangExt.DeriveTraversable,
3581 flagSpec "DerivingStrategies" LangExt.DerivingStrategies,
3582 flagSpec "DisambiguateRecordFields" LangExt.DisambiguateRecordFields,
3583 flagSpec "DoAndIfThenElse" LangExt.DoAndIfThenElse,
3584 depFlagSpec' "DoRec" LangExt.RecursiveDo
3585 (deprecatedForExtension "RecursiveDo"),
3586 flagSpec "DuplicateRecordFields" LangExt.DuplicateRecordFields,
3587 flagSpec "EmptyCase" LangExt.EmptyCase,
3588 flagSpec "EmptyDataDecls" LangExt.EmptyDataDecls,
3589 flagSpec "ExistentialQuantification" LangExt.ExistentialQuantification,
3590 flagSpec "ExplicitForAll" LangExt.ExplicitForAll,
3591 flagSpec "ExplicitNamespaces" LangExt.ExplicitNamespaces,
3592 flagSpec "ExtendedDefaultRules" LangExt.ExtendedDefaultRules,
3593 flagSpec "FlexibleContexts" LangExt.FlexibleContexts,
3594 flagSpec "FlexibleInstances" LangExt.FlexibleInstances,
3595 flagSpec "ForeignFunctionInterface" LangExt.ForeignFunctionInterface,
3596 flagSpec "FunctionalDependencies" LangExt.FunctionalDependencies,
3597 flagSpec "GADTSyntax" LangExt.GADTSyntax,
3598 flagSpec "GADTs" LangExt.GADTs,
3599 flagSpec "GHCForeignImportPrim" LangExt.GHCForeignImportPrim,
3600 flagSpec' "GeneralizedNewtypeDeriving" LangExt.GeneralizedNewtypeDeriving
3601 setGenDeriving,
3602 flagSpec "ImplicitParams" LangExt.ImplicitParams,
3603 flagSpec "ImplicitPrelude" LangExt.ImplicitPrelude,
3604 flagSpec "ImpredicativeTypes" LangExt.ImpredicativeTypes,
3605 flagSpec' "IncoherentInstances" LangExt.IncoherentInstances
3606 setIncoherentInsts,
3607 flagSpec "TypeFamilyDependencies" LangExt.TypeFamilyDependencies,
3608 flagSpec "InstanceSigs" LangExt.InstanceSigs,
3609 flagSpec "ApplicativeDo" LangExt.ApplicativeDo,
3610 flagSpec "InterruptibleFFI" LangExt.InterruptibleFFI,
3611 flagSpec "JavaScriptFFI" LangExt.JavaScriptFFI,
3612 flagSpec "KindSignatures" LangExt.KindSignatures,
3613 flagSpec "LambdaCase" LangExt.LambdaCase,
3614 flagSpec "LiberalTypeSynonyms" LangExt.LiberalTypeSynonyms,
3615 flagSpec "MagicHash" LangExt.MagicHash,
3616 flagSpec "MonadComprehensions" LangExt.MonadComprehensions,
3617 flagSpec "MonadFailDesugaring" LangExt.MonadFailDesugaring,
3618 flagSpec "MonoLocalBinds" LangExt.MonoLocalBinds,
3619 depFlagSpecCond "MonoPatBinds" LangExt.MonoPatBinds
3620 id
3621 "Experimental feature now removed; has no effect",
3622 flagSpec "MonomorphismRestriction" LangExt.MonomorphismRestriction,
3623 flagSpec "MultiParamTypeClasses" LangExt.MultiParamTypeClasses,
3624 flagSpec "MultiWayIf" LangExt.MultiWayIf,
3625 flagSpec "NPlusKPatterns" LangExt.NPlusKPatterns,
3626 flagSpec "NamedFieldPuns" LangExt.RecordPuns,
3627 flagSpec "NamedWildCards" LangExt.NamedWildCards,
3628 flagSpec "NegativeLiterals" LangExt.NegativeLiterals,
3629 flagSpec "NondecreasingIndentation" LangExt.NondecreasingIndentation,
3630 depFlagSpec' "NullaryTypeClasses" LangExt.NullaryTypeClasses
3631 (deprecatedForExtension "MultiParamTypeClasses"),
3632 flagSpec "NumDecimals" LangExt.NumDecimals,
3633 depFlagSpecOp "OverlappingInstances" LangExt.OverlappingInstances
3634 setOverlappingInsts
3635 "instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS",
3636 flagSpec "OverloadedLabels" LangExt.OverloadedLabels,
3637 flagSpec "OverloadedLists" LangExt.OverloadedLists,
3638 flagSpec "OverloadedStrings" LangExt.OverloadedStrings,
3639 flagSpec "PackageImports" LangExt.PackageImports,
3640 flagSpec "ParallelArrays" LangExt.ParallelArrays,
3641 flagSpec "ParallelListComp" LangExt.ParallelListComp,
3642 flagSpec "PartialTypeSignatures" LangExt.PartialTypeSignatures,
3643 flagSpec "PatternGuards" LangExt.PatternGuards,
3644 depFlagSpec' "PatternSignatures" LangExt.ScopedTypeVariables
3645 (deprecatedForExtension "ScopedTypeVariables"),
3646 flagSpec "PatternSynonyms" LangExt.PatternSynonyms,
3647 flagSpec "PolyKinds" LangExt.PolyKinds,
3648 flagSpec "PolymorphicComponents" LangExt.RankNTypes,
3649 flagSpec "PostfixOperators" LangExt.PostfixOperators,
3650 flagSpec "QuasiQuotes" LangExt.QuasiQuotes,
3651 flagSpec "Rank2Types" LangExt.RankNTypes,
3652 flagSpec "RankNTypes" LangExt.RankNTypes,
3653 flagSpec "RebindableSyntax" LangExt.RebindableSyntax,
3654 depFlagSpec' "RecordPuns" LangExt.RecordPuns
3655 (deprecatedForExtension "NamedFieldPuns"),
3656 flagSpec "RecordWildCards" LangExt.RecordWildCards,
3657 flagSpec "RecursiveDo" LangExt.RecursiveDo,
3658 flagSpec "RelaxedLayout" LangExt.RelaxedLayout,
3659 depFlagSpecCond "RelaxedPolyRec" LangExt.RelaxedPolyRec
3660 not
3661 "You can't turn off RelaxedPolyRec any more",
3662 flagSpec "RoleAnnotations" LangExt.RoleAnnotations,
3663 flagSpec "ScopedTypeVariables" LangExt.ScopedTypeVariables,
3664 flagSpec "StandaloneDeriving" LangExt.StandaloneDeriving,
3665 flagSpec "StaticPointers" LangExt.StaticPointers,
3666 flagSpec "Strict" LangExt.Strict,
3667 flagSpec "StrictData" LangExt.StrictData,
3668 flagSpec' "TemplateHaskell" LangExt.TemplateHaskell
3669 checkTemplateHaskellOk,
3670 flagSpec "TemplateHaskellQuotes" LangExt.TemplateHaskellQuotes,
3671 flagSpec "TraditionalRecordSyntax" LangExt.TraditionalRecordSyntax,
3672 flagSpec "TransformListComp" LangExt.TransformListComp,
3673 flagSpec "TupleSections" LangExt.TupleSections,
3674 flagSpec "TypeApplications" LangExt.TypeApplications,
3675 flagSpec "TypeInType" LangExt.TypeInType,
3676 flagSpec "TypeFamilies" LangExt.TypeFamilies,
3677 flagSpec "TypeOperators" LangExt.TypeOperators,
3678 flagSpec "TypeSynonymInstances" LangExt.TypeSynonymInstances,
3679 flagSpec "UnboxedTuples" LangExt.UnboxedTuples,
3680 flagSpec "UnboxedSums" LangExt.UnboxedSums,
3681 flagSpec "UndecidableInstances" LangExt.UndecidableInstances,
3682 flagSpec "UndecidableSuperClasses" LangExt.UndecidableSuperClasses,
3683 flagSpec "UnicodeSyntax" LangExt.UnicodeSyntax,
3684 flagSpec "UnliftedFFITypes" LangExt.UnliftedFFITypes,
3685 flagSpec "ViewPatterns" LangExt.ViewPatterns
3686 ]
3687
3688 defaultFlags :: Settings -> [GeneralFlag]
3689 defaultFlags settings
3690 -- See Note [Updating flag description in the User's Guide]
3691 = [ Opt_AutoLinkPackages,
3692 Opt_EmbedManifest,
3693 Opt_FlatCache,
3694 Opt_GenManifest,
3695 Opt_GhciHistory,
3696 Opt_GhciSandbox,
3697 Opt_HelpfulErrors,
3698 Opt_KeepHiFiles,
3699 Opt_KeepOFiles,
3700 Opt_OmitYields,
3701 Opt_PrintBindContents,
3702 Opt_ProfCountEntries,
3703 Opt_RPath,
3704 Opt_SharedImplib,
3705 Opt_SimplPreInlining,
3706 Opt_VersionMacros
3707 ]
3708
3709 ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
3710 -- The default -O0 options
3711
3712 ++ default_PIC platform
3713
3714 ++ concatMap (wayGeneralFlags platform) (defaultWays settings)
3715
3716 where platform = sTargetPlatform settings
3717
3718 default_PIC :: Platform -> [GeneralFlag]
3719 default_PIC platform =
3720 case (platformOS platform, platformArch platform) of
3721 (OSDarwin, ArchX86_64) -> [Opt_PIC]
3722 (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
3723 -- OpenBSD since 5.3 release
3724 -- (1 May 2013) we need to
3725 -- always generate PIC. See
3726 -- #10597 for more
3727 -- information.
3728 _ -> []
3729
3730 -- General flags that are switched on/off when other general flags are switched
3731 -- on
3732 impliedGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)]
3733 impliedGFlags = [(Opt_DeferTypeErrors, turnOn, Opt_DeferTypedHoles)
3734 ,(Opt_DeferTypeErrors, turnOn, Opt_DeferOutOfScopeVariables)
3735 ,(Opt_Strictness, turnOn, Opt_WorkerWrapper)
3736 ]
3737
3738 -- General flags that are switched on/off when other general flags are switched
3739 -- off
3740 impliedOffGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)]
3741 impliedOffGFlags = [(Opt_Strictness, turnOff, Opt_WorkerWrapper)]
3742
3743 impliedXFlags :: [(LangExt.Extension, TurnOnFlag, LangExt.Extension)]
3744 impliedXFlags
3745 -- See Note [Updating flag description in the User's Guide]
3746 = [ (LangExt.RankNTypes, turnOn, LangExt.ExplicitForAll)
3747 , (LangExt.ScopedTypeVariables, turnOn, LangExt.ExplicitForAll)
3748 , (LangExt.LiberalTypeSynonyms, turnOn, LangExt.ExplicitForAll)
3749 , (LangExt.ExistentialQuantification, turnOn, LangExt.ExplicitForAll)
3750 , (LangExt.FlexibleInstances, turnOn, LangExt.TypeSynonymInstances)
3751 , (LangExt.FunctionalDependencies, turnOn, LangExt.MultiParamTypeClasses)
3752 , (LangExt.MultiParamTypeClasses, turnOn, LangExt.ConstrainedClassMethods) -- c.f. Trac #7854
3753 , (LangExt.TypeFamilyDependencies, turnOn, LangExt.TypeFamilies)
3754
3755 , (LangExt.RebindableSyntax, turnOff, LangExt.ImplicitPrelude) -- NB: turn off!
3756
3757 , (LangExt.GADTs, turnOn, LangExt.GADTSyntax)
3758 , (LangExt.GADTs, turnOn, LangExt.MonoLocalBinds)
3759 , (LangExt.TypeFamilies, turnOn, LangExt.MonoLocalBinds)
3760
3761 , (LangExt.TypeFamilies, turnOn, LangExt.KindSignatures) -- Type families use kind signatures
3762 , (LangExt.PolyKinds, turnOn, LangExt.KindSignatures) -- Ditto polymorphic kinds
3763 , (LangExt.TypeInType, turnOn, LangExt.DataKinds)
3764 , (LangExt.TypeInType, turnOn, LangExt