Merge branch 'master' of darcs.haskell.org:/srv/darcs//ghc
[ghc.git] / compiler / main / DynFlags.hs
1 -------------------------------------------------------------------------------
2 --
3 -- | Dynamic flags
4 --
5 -- Most flags are dynamic flags, which means they can change from compilation
6 -- to compilation using @OPTIONS_GHC@ pragmas, and in a multi-session GHC each
7 -- session can be using different dynamic flags. Dynamic flags can also be set
8 -- at the prompt in GHCi.
9 --
10 -- (c) The University of Glasgow 2005
11 --
12 -------------------------------------------------------------------------------
13
14 {-# OPTIONS_GHC -fno-warn-missing-fields #-}
15 -- So that tracingSettings works properly
16
17 module DynFlags (
18 -- * Dynamic flags and associated configuration types
19 DynFlag(..),
20 WarningFlag(..),
21 ExtensionFlag(..),
22 Language(..),
23 FatalMessager, LogAction, FlushOut(..), FlushErr(..),
24 ProfAuto(..),
25 glasgowExtsFlags,
26 dopt,
27 dopt_set,
28 dopt_unset,
29 wopt,
30 wopt_set,
31 wopt_unset,
32 xopt,
33 xopt_set,
34 xopt_unset,
35 lang_set,
36 DynFlags(..),
37 HasDynFlags(..), ContainsDynFlags(..),
38 RtsOptsEnabled(..),
39 HscTarget(..), isObjectTarget, defaultObjectTarget,
40 targetRetainsAllBindings,
41 GhcMode(..), isOneShot,
42 GhcLink(..), isNoLink,
43 PackageFlag(..),
44 PkgConfRef(..),
45 Option(..), showOpt,
46 DynLibLoader(..),
47 fFlags, fWarningFlags, fLangFlags, xFlags,
48 wayNames, dynFlagDependencies,
49
50 printOutputForUser, printInfoForUser,
51
52 -- ** Safe Haskell
53 SafeHaskellMode(..),
54 safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
55 packageTrustOn,
56 safeDirectImpsReq, safeImplicitImpsReq,
57 unsafeFlags,
58
59 -- ** System tool settings and locations
60 Settings(..),
61 targetPlatform,
62 ghcUsagePath, ghciUsagePath, topDir, tmpDir, rawSettings,
63 extraGccViaCFlags, systemPackageConfig,
64 pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
65 pgm_sysman, pgm_windres, pgm_lo, pgm_lc,
66 opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
67 opt_windres, opt_lo, opt_lc,
68
69
70 -- ** Manipulating DynFlags
71 defaultDynFlags, -- Settings -> DynFlags
72 initDynFlags, -- DynFlags -> IO DynFlags
73 defaultFatalMessager,
74 defaultLogAction,
75 defaultLogActionHPrintDoc,
76 defaultFlushOut,
77 defaultFlushErr,
78
79 getOpts, -- DynFlags -> (DynFlags -> [a]) -> [a]
80 getVerbFlags,
81 updOptLevel,
82 setTmpDir,
83 setPackageName,
84 doingTickyProfiling,
85
86 -- ** Parsing DynFlags
87 parseDynamicFlagsCmdLine,
88 parseDynamicFilePragma,
89 parseDynamicFlagsFull,
90
91 -- ** Available DynFlags
92 allFlags,
93 flagsAll,
94 flagsDynamic,
95 flagsPackage,
96
97 supportedLanguagesAndExtensions,
98
99 -- ** DynFlag C compiler options
100 picCCOpts, picPOpts,
101
102 -- * Configuration of the stg-to-stg passes
103 StgToDo(..),
104 getStgToDo,
105
106 -- * Compiler configuration suitable for display to the user
107 compilerInfo,
108
109 #ifdef GHCI
110 -- Only in stage 2 can we be sure that the RTS
111 -- exposes the appropriate runtime boolean
112 rtsIsProfiled,
113 #endif
114 -- ** Only for use in the tracing functions in Outputable
115 tracingDynFlags,
116 ) where
117
118 #include "HsVersions.h"
119
120 import Platform
121 import Module
122 import PackageConfig
123 import PrelNames ( mAIN )
124 import StaticFlags
125 import {-# SOURCE #-} Packages (PackageState)
126 import DriverPhases ( Phase(..), phaseInputExt )
127 import Config
128 import CmdLineParser
129 import Constants ( mAX_CONTEXT_REDUCTION_DEPTH )
130 import Panic
131 import Util
132 import Maybes ( orElse )
133 import qualified Pretty
134 import SrcLoc
135 import FastString
136 import Outputable
137 #ifdef GHCI
138 import Foreign.C ( CInt(..) )
139 #endif
140 import {-# SOURCE #-} ErrUtils ( Severity(..), MsgDoc, mkLocMessage )
141
142 #ifdef GHCI
143 import System.IO.Unsafe ( unsafePerformIO )
144 #endif
145 import Data.IORef
146 import Control.Monad ( when )
147
148 import Data.Char
149 import Data.List
150 import Data.Map (Map)
151 import qualified Data.Map as Map
152 import Data.Set (Set)
153 import qualified Data.Set as Set
154 import System.FilePath
155 import System.IO
156
157 import Data.IntSet (IntSet)
158 import qualified Data.IntSet as IntSet
159
160 -- -----------------------------------------------------------------------------
161 -- DynFlags
162
163 -- | Enumerates the simple on-or-off dynamic flags
164 data DynFlag
165
166 -- debugging flags
167 = Opt_D_dump_cmm
168 | Opt_D_dump_raw_cmm
169 | Opt_D_dump_cmmz
170 -- All of the cmmz subflags (there are a lot!) Automatically
171 -- enabled if you run -ddump-cmmz
172 | Opt_D_dump_cmmz_cfg
173 | Opt_D_dump_cmmz_cbe
174 | Opt_D_dump_cmmz_proc
175 | Opt_D_dump_cmmz_spills
176 | Opt_D_dump_cmmz_rewrite
177 | Opt_D_dump_cmmz_dead
178 | Opt_D_dump_cmmz_stub
179 | Opt_D_dump_cmmz_sp
180 | Opt_D_dump_cmmz_procmap
181 | Opt_D_dump_cmmz_split
182 | Opt_D_dump_cmmz_lower
183 | Opt_D_dump_cmmz_info
184 | Opt_D_dump_cmmz_cafs
185 -- end cmmz subflags
186 | Opt_D_dump_cps_cmm
187 | Opt_D_dump_cvt_cmm
188 | Opt_D_dump_asm
189 | Opt_D_dump_asm_native
190 | Opt_D_dump_asm_liveness
191 | Opt_D_dump_asm_coalesce
192 | Opt_D_dump_asm_regalloc
193 | Opt_D_dump_asm_regalloc_stages
194 | Opt_D_dump_asm_conflicts
195 | Opt_D_dump_asm_stats
196 | Opt_D_dump_asm_expanded
197 | Opt_D_dump_llvm
198 | Opt_D_dump_core_stats
199 | Opt_D_dump_cpranal
200 | Opt_D_dump_deriv
201 | Opt_D_dump_ds
202 | Opt_D_dump_flatC
203 | Opt_D_dump_foreign
204 | Opt_D_dump_inlinings
205 | Opt_D_dump_rule_firings
206 | Opt_D_dump_rule_rewrites
207 | Opt_D_dump_occur_anal
208 | Opt_D_dump_parsed
209 | Opt_D_dump_rn
210 | Opt_D_dump_core_pipeline -- TODO FIXME: dump after simplifier stats
211 | Opt_D_dump_simpl
212 | Opt_D_dump_simpl_iterations
213 | Opt_D_dump_simpl_phases
214 | Opt_D_dump_spec
215 | Opt_D_dump_prep
216 | Opt_D_dump_stg
217 | Opt_D_dump_stranal
218 | Opt_D_dump_tc
219 | Opt_D_dump_types
220 | Opt_D_dump_rules
221 | Opt_D_dump_cse
222 | Opt_D_dump_worker_wrapper
223 | Opt_D_dump_rn_trace
224 | Opt_D_dump_rn_stats
225 | Opt_D_dump_opt_cmm
226 | Opt_D_dump_simpl_stats
227 | Opt_D_dump_cs_trace -- Constraint solver in type checker
228 | Opt_D_dump_tc_trace
229 | Opt_D_dump_if_trace
230 | Opt_D_dump_vt_trace
231 | Opt_D_dump_splices
232 | Opt_D_dump_BCOs
233 | Opt_D_dump_vect
234 | Opt_D_dump_avoid_vect
235 | Opt_D_dump_ticked
236 | Opt_D_dump_rtti
237 | Opt_D_source_stats
238 | Opt_D_verbose_core2core
239 | Opt_D_verbose_stg2stg
240 | Opt_D_dump_hi
241 | Opt_D_dump_hi_diffs
242 | Opt_D_dump_minimal_imports
243 | Opt_D_dump_mod_cycles
244 | Opt_D_dump_view_pattern_commoning
245 | Opt_D_faststring_stats
246 | Opt_DumpToFile -- ^ Append dump output to files instead of stdout.
247 | Opt_D_no_debug_output
248 | Opt_DoCoreLinting
249 | Opt_DoStgLinting
250 | Opt_DoCmmLinting
251 | Opt_DoAsmLinting
252 | Opt_NoLlvmMangler -- hidden flag
253
254 | Opt_WarnIsError -- -Werror; makes warnings fatal
255
256 | Opt_PrintExplicitForalls
257
258 -- optimisation opts
259 | Opt_Strictness
260 | Opt_FullLaziness
261 | Opt_FloatIn
262 | Opt_Specialise
263 | Opt_StaticArgumentTransformation
264 | Opt_CSE
265 | Opt_LiberateCase
266 | Opt_SpecConstr
267 | Opt_DoLambdaEtaExpansion
268 | Opt_IgnoreAsserts
269 | Opt_DoEtaReduction
270 | Opt_CaseMerge
271 | Opt_UnboxStrictFields
272 | Opt_DictsCheap
273 | Opt_EnableRewriteRules -- Apply rewrite rules during simplification
274 | Opt_Vectorise
275 | Opt_AvoidVect
276 | Opt_RegsGraph -- do graph coloring register allocation
277 | Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
278 | Opt_PedanticBottoms -- Be picky about how we treat bottom
279 | Opt_LlvmTBAA -- Use LLVM TBAA infastructure for improving AA (hidden flag)
280 | Opt_RegLiveness -- Use the STG Reg liveness information (hidden flag)
281 | Opt_IrrefutableTuples
282
283 -- Interface files
284 | Opt_IgnoreInterfacePragmas
285 | Opt_OmitInterfacePragmas
286 | Opt_ExposeAllUnfoldings
287
288 -- profiling opts
289 | Opt_AutoSccsOnIndividualCafs
290 | Opt_ProfCountEntries
291
292 -- misc opts
293 | Opt_Pp
294 | Opt_ForceRecomp
295 | Opt_ExcessPrecision
296 | Opt_EagerBlackHoling
297 | Opt_NoHsMain
298 | Opt_SplitObjs
299 | Opt_StgStats
300 | Opt_HideAllPackages
301 | Opt_PrintBindResult
302 | Opt_Haddock
303 | Opt_HaddockOptions
304 | Opt_Hpc_No_Auto
305 | Opt_BreakOnException
306 | Opt_BreakOnError
307 | Opt_PrintEvldWithShow
308 | Opt_PrintBindContents
309 | Opt_GenManifest
310 | Opt_EmbedManifest
311 | Opt_EmitExternalCore
312 | Opt_SharedImplib
313 | Opt_BuildingCabalPackage
314 | Opt_SSE2
315 | Opt_SSE4_2
316 | Opt_IgnoreDotGhci
317 | Opt_GhciSandbox
318 | Opt_GhciHistory
319 | Opt_HelpfulErrors
320 | Opt_DeferTypeErrors
321 | Opt_Parallel
322 | Opt_GranMacros
323 | Opt_PIC
324 | Opt_SccProfilingOn
325
326 -- output style opts
327 | Opt_PprCaseAsLet
328
329 -- temporary flags
330 | Opt_RunCPS
331 | Opt_RunCPSZ
332 | Opt_AutoLinkPackages
333 | Opt_ImplicitImportQualified
334 | Opt_TryNewCodeGen
335
336 -- keeping stuff
337 | Opt_KeepHiDiffs
338 | Opt_KeepHcFiles
339 | Opt_KeepSFiles
340 | Opt_KeepTmpFiles
341 | Opt_KeepRawTokenStream
342 | Opt_KeepLlvmFiles
343
344 -- safe haskell flags
345 | Opt_DistrustAllPackages
346 | Opt_PackageTrust
347
348 deriving (Eq, Show, Enum)
349
350 data WarningFlag =
351 Opt_WarnDuplicateExports
352 | Opt_WarnHiShadows
353 | Opt_WarnImplicitPrelude
354 | Opt_WarnIncompletePatterns
355 | Opt_WarnIncompleteUniPatterns
356 | Opt_WarnIncompletePatternsRecUpd
357 | Opt_WarnMissingFields
358 | Opt_WarnMissingImportList
359 | Opt_WarnMissingMethods
360 | Opt_WarnMissingSigs
361 | Opt_WarnMissingLocalSigs
362 | Opt_WarnNameShadowing
363 | Opt_WarnOverlappingPatterns
364 | Opt_WarnTypeDefaults
365 | Opt_WarnMonomorphism
366 | Opt_WarnUnusedBinds
367 | Opt_WarnUnusedImports
368 | Opt_WarnUnusedMatches
369 | Opt_WarnWarningsDeprecations
370 | Opt_WarnDeprecatedFlags
371 | Opt_WarnDodgyExports
372 | Opt_WarnDodgyImports
373 | Opt_WarnOrphans
374 | Opt_WarnAutoOrphans
375 | Opt_WarnIdentities
376 | Opt_WarnTabs
377 | Opt_WarnUnrecognisedPragmas
378 | Opt_WarnDodgyForeignImports
379 | Opt_WarnLazyUnliftedBindings
380 | Opt_WarnUnusedDoBind
381 | Opt_WarnWrongDoBind
382 | Opt_WarnAlternativeLayoutRuleTransitional
383 | Opt_WarnUnsafe
384 | Opt_WarnSafe
385 | Opt_WarnPointlessPragmas
386 | Opt_WarnUnsupportedCallingConventions
387 | Opt_WarnInlineRuleShadowing
388 deriving (Eq, Show, Enum)
389
390 data Language = Haskell98 | Haskell2010
391 deriving Enum
392
393 -- | The various Safe Haskell modes
394 data SafeHaskellMode
395 = Sf_None
396 | Sf_Unsafe
397 | Sf_Trustworthy
398 | Sf_Safe
399 | Sf_SafeInferred
400 deriving (Eq)
401
402 instance Show SafeHaskellMode where
403 show Sf_None = "None"
404 show Sf_Unsafe = "Unsafe"
405 show Sf_Trustworthy = "Trustworthy"
406 show Sf_Safe = "Safe"
407 show Sf_SafeInferred = "Safe-Inferred"
408
409 instance Outputable SafeHaskellMode where
410 ppr = text . show
411
412 data ExtensionFlag
413 = Opt_Cpp
414 | Opt_OverlappingInstances
415 | Opt_UndecidableInstances
416 | Opt_IncoherentInstances
417 | Opt_MonomorphismRestriction
418 | Opt_MonoPatBinds
419 | Opt_MonoLocalBinds
420 | Opt_RelaxedPolyRec -- Deprecated
421 | Opt_ExtendedDefaultRules -- Use GHC's extended rules for defaulting
422 | Opt_ForeignFunctionInterface
423 | Opt_UnliftedFFITypes
424 | Opt_InterruptibleFFI
425 | Opt_CApiFFI
426 | Opt_GHCForeignImportPrim
427 | Opt_ParallelArrays -- Syntactic support for parallel arrays
428 | Opt_Arrows -- Arrow-notation syntax
429 | Opt_TemplateHaskell
430 | Opt_QuasiQuotes
431 | Opt_ImplicitParams
432 | Opt_ImplicitPrelude
433 | Opt_ScopedTypeVariables
434 | Opt_UnboxedTuples
435 | Opt_BangPatterns
436 | Opt_TypeFamilies
437 | Opt_OverloadedStrings
438 | Opt_DisambiguateRecordFields
439 | Opt_RecordWildCards
440 | Opt_RecordPuns
441 | Opt_ViewPatterns
442 | Opt_GADTs
443 | Opt_GADTSyntax
444 | Opt_NPlusKPatterns
445 | Opt_DoAndIfThenElse
446 | Opt_RebindableSyntax
447 | Opt_ConstraintKinds
448 | Opt_PolyKinds -- Kind polymorphism
449 | Opt_DataKinds -- Datatype promotion
450 | Opt_InstanceSigs
451
452 | Opt_StandaloneDeriving
453 | Opt_DeriveDataTypeable
454 | Opt_DeriveFunctor
455 | Opt_DeriveTraversable
456 | Opt_DeriveFoldable
457 | Opt_DeriveGeneric -- Allow deriving Generic/1
458 | Opt_DefaultSignatures -- Allow extra signatures for defmeths
459
460 | Opt_TypeSynonymInstances
461 | Opt_FlexibleContexts
462 | Opt_FlexibleInstances
463 | Opt_ConstrainedClassMethods
464 | Opt_MultiParamTypeClasses
465 | Opt_FunctionalDependencies
466 | Opt_UnicodeSyntax
467 | Opt_PolymorphicComponents
468 | Opt_ExistentialQuantification
469 | Opt_MagicHash
470 | Opt_EmptyDataDecls
471 | Opt_KindSignatures
472 | Opt_ParallelListComp
473 | Opt_TransformListComp
474 | Opt_MonadComprehensions
475 | Opt_GeneralizedNewtypeDeriving
476 | Opt_RecursiveDo
477 | Opt_PostfixOperators
478 | Opt_TupleSections
479 | Opt_PatternGuards
480 | Opt_LiberalTypeSynonyms
481 | Opt_Rank2Types
482 | Opt_RankNTypes
483 | Opt_ImpredicativeTypes
484 | Opt_TypeOperators
485 | Opt_ExplicitNamespaces
486 | Opt_PackageImports
487 | Opt_ExplicitForAll
488 | Opt_AlternativeLayoutRule
489 | Opt_AlternativeLayoutRuleTransitional
490 | Opt_DatatypeContexts
491 | Opt_NondecreasingIndentation
492 | Opt_RelaxedLayout
493 | Opt_TraditionalRecordSyntax
494 | Opt_LambdaCase
495 | Opt_MultiWayIf
496 deriving (Eq, Enum, Show)
497
498 -- | Contains not only a collection of 'DynFlag's but also a plethora of
499 -- information relating to the compilation of a single file or GHC session
500 data DynFlags = DynFlags {
501 ghcMode :: GhcMode,
502 ghcLink :: GhcLink,
503 hscTarget :: HscTarget,
504 settings :: Settings,
505 hscOutName :: String, -- ^ Name of the output file
506 extCoreName :: String, -- ^ Name of the .hcr output file
507 verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
508 optLevel :: Int, -- ^ Optimisation level
509 simplPhases :: Int, -- ^ Number of simplifier phases
510 maxSimplIterations :: Int, -- ^ Max simplifier iterations
511 shouldDumpSimplPhase :: Maybe String,
512 ruleCheck :: Maybe String,
513 strictnessBefore :: [Int], -- ^ Additional demand analysis
514
515 simplTickFactor :: Int, -- ^ Multiplier for simplifier ticks
516 specConstrThreshold :: Maybe Int, -- ^ Threshold for SpecConstr
517 specConstrCount :: Maybe Int, -- ^ Max number of specialisations for any one function
518 liberateCaseThreshold :: Maybe Int, -- ^ Threshold for LiberateCase
519 floatLamArgs :: Maybe Int, -- ^ Arg count for lambda floating
520 -- See CoreMonad.FloatOutSwitches
521
522 cmdlineHcIncludes :: [String], -- ^ @\-\#includes@
523 importPaths :: [FilePath],
524 mainModIs :: Module,
525 mainFunIs :: Maybe String,
526 ctxtStkDepth :: Int, -- ^ Typechecker context stack depth
527
528 thisPackage :: PackageId, -- ^ name of package currently being compiled
529
530 -- ways
531 ways :: [Way], -- ^ Way flags from the command line
532 buildTag :: String, -- ^ The global \"way\" (e.g. \"p\" for prof)
533 rtsBuildTag :: String, -- ^ The RTS \"way\"
534
535 -- For object splitting
536 splitInfo :: Maybe (String,Int),
537
538 -- paths etc.
539 objectDir :: Maybe String,
540 dylibInstallName :: Maybe String,
541 hiDir :: Maybe String,
542 stubDir :: Maybe String,
543 dumpDir :: Maybe String,
544
545 objectSuf :: String,
546 hcSuf :: String,
547 hiSuf :: String,
548
549 outputFile :: Maybe String,
550 outputHi :: Maybe String,
551 dynLibLoader :: DynLibLoader,
552
553 -- | This is set by 'DriverPipeline.runPipeline' based on where
554 -- its output is going.
555 dumpPrefix :: Maybe FilePath,
556
557 -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
558 -- Set by @-ddump-file-prefix@
559 dumpPrefixForce :: Maybe FilePath,
560
561 includePaths :: [String],
562 libraryPaths :: [String],
563 frameworkPaths :: [String], -- used on darwin only
564 cmdlineFrameworks :: [String], -- ditto
565
566 rtsOpts :: Maybe String,
567 rtsOptsEnabled :: RtsOptsEnabled,
568
569 hpcDir :: String, -- ^ Path to store the .mix files
570
571 -- Plugins
572 pluginModNames :: [ModuleName],
573 pluginModNameOpts :: [(ModuleName,String)],
574
575 -- For ghc -M
576 depMakefile :: FilePath,
577 depIncludePkgDeps :: Bool,
578 depExcludeMods :: [ModuleName],
579 depSuffixes :: [String],
580
581 -- Package flags
582 extraPkgConfs :: [PkgConfRef] -> [PkgConfRef],
583 -- ^ The @-package-db@ flags given on the command line, in the order
584 -- they appeared.
585
586 packageFlags :: [PackageFlag],
587 -- ^ The @-package@ and @-hide-package@ flags from the command-line
588
589 -- Package state
590 -- NB. do not modify this field, it is calculated by
591 -- Packages.initPackages and Packages.updatePackages.
592 pkgDatabase :: Maybe [PackageConfig],
593 pkgState :: PackageState,
594
595 -- Temporary files
596 -- These have to be IORefs, because the defaultCleanupHandler needs to
597 -- know what to clean when an exception happens
598 filesToClean :: IORef [FilePath],
599 dirsToClean :: IORef (Map FilePath FilePath),
600
601 -- Names of files which were generated from -ddump-to-file; used to
602 -- track which ones we need to truncate because it's our first run
603 -- through
604 generatedDumps :: IORef (Set FilePath),
605
606 -- hsc dynamic flags
607 flags :: IntSet,
608 warningFlags :: IntSet,
609 -- Don't change this without updating extensionFlags:
610 language :: Maybe Language,
611 -- | Safe Haskell mode
612 safeHaskell :: SafeHaskellMode,
613 -- We store the location of where some extension and flags were turned on so
614 -- we can produce accurate error messages when Safe Haskell fails due to
615 -- them.
616 thOnLoc :: SrcSpan,
617 newDerivOnLoc :: SrcSpan,
618 pkgTrustOnLoc :: SrcSpan,
619 warnSafeOnLoc :: SrcSpan,
620 warnUnsafeOnLoc :: SrcSpan,
621 -- Don't change this without updating extensionFlags:
622 extensions :: [OnOff ExtensionFlag],
623 -- extensionFlags should always be equal to
624 -- flattenExtensionFlags language extensions
625 extensionFlags :: IntSet,
626
627 -- | MsgDoc output action: use "ErrUtils" instead of this if you can
628 log_action :: LogAction,
629 flushOut :: FlushOut,
630 flushErr :: FlushErr,
631
632 haddockOptions :: Maybe String,
633 ghciScripts :: [String],
634
635 -- Output style options
636 pprUserLength :: Int,
637 pprCols :: Int,
638 traceLevel :: Int, -- Standard level is 1. Less verbose is 0.
639
640 -- | what kind of {-# SCC #-} to add automatically
641 profAuto :: ProfAuto,
642
643 interactivePrint :: Maybe String,
644
645 llvmVersion :: IORef (Int)
646 }
647
648 class HasDynFlags m where
649 getDynFlags :: m DynFlags
650
651 class ContainsDynFlags t where
652 extractDynFlags :: t -> DynFlags
653
654 data ProfAuto
655 = NoProfAuto -- ^ no SCC annotations added
656 | ProfAutoAll -- ^ top-level and nested functions are annotated
657 | ProfAutoTop -- ^ top-level functions annotated only
658 | ProfAutoExports -- ^ exported functions annotated only
659 | ProfAutoCalls -- ^ annotate call-sites
660 deriving (Enum)
661
662 data Settings = Settings {
663 sTargetPlatform :: Platform, -- Filled in by SysTools
664 sGhcUsagePath :: FilePath, -- Filled in by SysTools
665 sGhciUsagePath :: FilePath, -- ditto
666 sTopDir :: FilePath,
667 sTmpDir :: String, -- no trailing '/'
668 -- You shouldn't need to look things up in rawSettings directly.
669 -- They should have their own fields instead.
670 sRawSettings :: [(String, String)],
671 sExtraGccViaCFlags :: [String],
672 sSystemPackageConfig :: FilePath,
673 -- commands for particular phases
674 sPgm_L :: String,
675 sPgm_P :: (String,[Option]),
676 sPgm_F :: String,
677 sPgm_c :: (String,[Option]),
678 sPgm_s :: (String,[Option]),
679 sPgm_a :: (String,[Option]),
680 sPgm_l :: (String,[Option]),
681 sPgm_dll :: (String,[Option]),
682 sPgm_T :: String,
683 sPgm_sysman :: String,
684 sPgm_windres :: String,
685 sPgm_lo :: (String,[Option]), -- LLVM: opt llvm optimiser
686 sPgm_lc :: (String,[Option]), -- LLVM: llc static compiler
687 -- options for particular phases
688 sOpt_L :: [String],
689 sOpt_P :: [String],
690 sOpt_F :: [String],
691 sOpt_c :: [String],
692 sOpt_a :: [String],
693 sOpt_l :: [String],
694 sOpt_windres :: [String],
695 sOpt_lo :: [String], -- LLVM: llvm optimiser
696 sOpt_lc :: [String] -- LLVM: llc static compiler
697
698 }
699
700 targetPlatform :: DynFlags -> Platform
701 targetPlatform dflags = sTargetPlatform (settings dflags)
702
703 ghcUsagePath :: DynFlags -> FilePath
704 ghcUsagePath dflags = sGhcUsagePath (settings dflags)
705 ghciUsagePath :: DynFlags -> FilePath
706 ghciUsagePath dflags = sGhciUsagePath (settings dflags)
707 topDir :: DynFlags -> FilePath
708 topDir dflags = sTopDir (settings dflags)
709 tmpDir :: DynFlags -> String
710 tmpDir dflags = sTmpDir (settings dflags)
711 rawSettings :: DynFlags -> [(String, String)]
712 rawSettings dflags = sRawSettings (settings dflags)
713 extraGccViaCFlags :: DynFlags -> [String]
714 extraGccViaCFlags dflags = sExtraGccViaCFlags (settings dflags)
715 systemPackageConfig :: DynFlags -> FilePath
716 systemPackageConfig dflags = sSystemPackageConfig (settings dflags)
717 pgm_L :: DynFlags -> String
718 pgm_L dflags = sPgm_L (settings dflags)
719 pgm_P :: DynFlags -> (String,[Option])
720 pgm_P dflags = sPgm_P (settings dflags)
721 pgm_F :: DynFlags -> String
722 pgm_F dflags = sPgm_F (settings dflags)
723 pgm_c :: DynFlags -> (String,[Option])
724 pgm_c dflags = sPgm_c (settings dflags)
725 pgm_s :: DynFlags -> (String,[Option])
726 pgm_s dflags = sPgm_s (settings dflags)
727 pgm_a :: DynFlags -> (String,[Option])
728 pgm_a dflags = sPgm_a (settings dflags)
729 pgm_l :: DynFlags -> (String,[Option])
730 pgm_l dflags = sPgm_l (settings dflags)
731 pgm_dll :: DynFlags -> (String,[Option])
732 pgm_dll dflags = sPgm_dll (settings dflags)
733 pgm_T :: DynFlags -> String
734 pgm_T dflags = sPgm_T (settings dflags)
735 pgm_sysman :: DynFlags -> String
736 pgm_sysman dflags = sPgm_sysman (settings dflags)
737 pgm_windres :: DynFlags -> String
738 pgm_windres dflags = sPgm_windres (settings dflags)
739 pgm_lo :: DynFlags -> (String,[Option])
740 pgm_lo dflags = sPgm_lo (settings dflags)
741 pgm_lc :: DynFlags -> (String,[Option])
742 pgm_lc dflags = sPgm_lc (settings dflags)
743 opt_L :: DynFlags -> [String]
744 opt_L dflags = sOpt_L (settings dflags)
745 opt_P :: DynFlags -> [String]
746 opt_P dflags = sOpt_P (settings dflags)
747 opt_F :: DynFlags -> [String]
748 opt_F dflags = sOpt_F (settings dflags)
749 opt_c :: DynFlags -> [String]
750 opt_c dflags = sOpt_c (settings dflags)
751 opt_a :: DynFlags -> [String]
752 opt_a dflags = sOpt_a (settings dflags)
753 opt_l :: DynFlags -> [String]
754 opt_l dflags = sOpt_l (settings dflags)
755 opt_windres :: DynFlags -> [String]
756 opt_windres dflags = sOpt_windres (settings dflags)
757 opt_lo :: DynFlags -> [String]
758 opt_lo dflags = sOpt_lo (settings dflags)
759 opt_lc :: DynFlags -> [String]
760 opt_lc dflags = sOpt_lc (settings dflags)
761
762 wayNames :: DynFlags -> [WayName]
763 wayNames = map wayName . ways
764
765 -- | The target code type of the compilation (if any).
766 --
767 -- Whenever you change the target, also make sure to set 'ghcLink' to
768 -- something sensible.
769 --
770 -- 'HscNothing' can be used to avoid generating any output, however, note
771 -- that:
772 --
773 -- * This will not run the desugaring step, thus no warnings generated in
774 -- this step will be output. In particular, this includes warnings related
775 -- to pattern matching. You can run the desugarer manually using
776 -- 'GHC.desugarModule'.
777 --
778 -- * If a program uses Template Haskell the typechecker may try to run code
779 -- from an imported module. This will fail if no code has been generated
780 -- for this module. You can use 'GHC.needsTemplateHaskell' to detect
781 -- whether this might be the case and choose to either switch to a
782 -- different target or avoid typechecking such modules. (The latter may be
783 -- preferable for security reasons.)
784 --
785 data HscTarget
786 = HscC -- ^ Generate C code.
787 | HscAsm -- ^ Generate assembly using the native code generator.
788 | HscLlvm -- ^ Generate assembly using the llvm code generator.
789 | HscInterpreted -- ^ Generate bytecode. (Requires 'LinkInMemory')
790 | HscNothing -- ^ Don't generate any code. See notes above.
791 deriving (Eq, Show)
792
793 showHscTargetFlag :: HscTarget -> String
794 showHscTargetFlag HscC = "-fvia-c"
795 showHscTargetFlag HscAsm = "-fasm"
796 showHscTargetFlag HscLlvm = "-fllvm"
797 showHscTargetFlag HscInterpreted = "-fbyte-code"
798 showHscTargetFlag HscNothing = "-fno-code"
799
800 -- | Will this target result in an object file on the disk?
801 isObjectTarget :: HscTarget -> Bool
802 isObjectTarget HscC = True
803 isObjectTarget HscAsm = True
804 isObjectTarget HscLlvm = True
805 isObjectTarget _ = False
806
807 -- | Does this target retain *all* top-level bindings for a module,
808 -- rather than just the exported bindings, in the TypeEnv and compiled
809 -- code (if any)? In interpreted mode we do this, so that GHCi can
810 -- call functions inside a module. In HscNothing mode we also do it,
811 -- so that Haddock can get access to the GlobalRdrEnv for a module
812 -- after typechecking it.
813 targetRetainsAllBindings :: HscTarget -> Bool
814 targetRetainsAllBindings HscInterpreted = True
815 targetRetainsAllBindings HscNothing = True
816 targetRetainsAllBindings _ = False
817
818 -- | The 'GhcMode' tells us whether we're doing multi-module
819 -- compilation (controlled via the "GHC" API) or one-shot
820 -- (single-module) compilation. This makes a difference primarily to
821 -- the "Finder": in one-shot mode we look for interface files for
822 -- imported modules, but in multi-module mode we look for source files
823 -- in order to check whether they need to be recompiled.
824 data GhcMode
825 = CompManager -- ^ @\-\-make@, GHCi, etc.
826 | OneShot -- ^ @ghc -c Foo.hs@
827 | MkDepend -- ^ @ghc -M@, see "Finder" for why we need this
828 deriving Eq
829
830 instance Outputable GhcMode where
831 ppr CompManager = ptext (sLit "CompManager")
832 ppr OneShot = ptext (sLit "OneShot")
833 ppr MkDepend = ptext (sLit "MkDepend")
834
835 isOneShot :: GhcMode -> Bool
836 isOneShot OneShot = True
837 isOneShot _other = False
838
839 -- | What to do in the link step, if there is one.
840 data GhcLink
841 = NoLink -- ^ Don't link at all
842 | LinkBinary -- ^ Link object code into a binary
843 | LinkInMemory -- ^ Use the in-memory dynamic linker (works for both
844 -- bytecode and object code).
845 | LinkDynLib -- ^ Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
846 deriving (Eq, Show)
847
848 isNoLink :: GhcLink -> Bool
849 isNoLink NoLink = True
850 isNoLink _ = False
851
852 -- Is it worth evaluating this Bool and caching it in the DynFlags value
853 -- during initDynFlags?
854 doingTickyProfiling :: DynFlags -> Bool
855 doingTickyProfiling _ = opt_Ticky
856 -- XXX -ticky is a static flag, because it implies -debug which is also
857 -- static. If the way flags were made dynamic, we could fix this.
858
859 data PackageFlag
860 = ExposePackage String
861 | ExposePackageId String
862 | HidePackage String
863 | IgnorePackage String
864 | TrustPackage String
865 | DistrustPackage String
866 deriving Eq
867
868 defaultHscTarget :: HscTarget
869 defaultHscTarget = defaultObjectTarget
870
871 -- | The 'HscTarget' value corresponding to the default way to create
872 -- object files on the current platform.
873 defaultObjectTarget :: HscTarget
874 defaultObjectTarget
875 | cGhcUnregisterised == "YES" = HscC
876 | cGhcWithNativeCodeGen == "YES" = HscAsm
877 | otherwise = HscLlvm
878
879 data DynLibLoader
880 = Deployable
881 | SystemDependent
882 deriving Eq
883
884 data RtsOptsEnabled = RtsOptsNone | RtsOptsSafeOnly | RtsOptsAll
885 deriving (Show)
886
887 -- | Used by 'GHC.newSession' to partially initialize a new 'DynFlags' value
888 initDynFlags :: DynFlags -> IO DynFlags
889 initDynFlags dflags = do
890 -- someday these will be dynamic flags
891 ways <- readIORef v_Ways
892 refFilesToClean <- newIORef []
893 refDirsToClean <- newIORef Map.empty
894 refGeneratedDumps <- newIORef Set.empty
895 refLlvmVersion <- newIORef 28
896 return dflags{
897 ways = ways,
898 buildTag = mkBuildTag (filter (not . wayRTSOnly) ways),
899 rtsBuildTag = mkBuildTag ways,
900 filesToClean = refFilesToClean,
901 dirsToClean = refDirsToClean,
902 generatedDumps = refGeneratedDumps,
903 llvmVersion = refLlvmVersion
904 }
905
906 -- | The normal 'DynFlags'. Note that they is not suitable for use in this form
907 -- and must be fully initialized by 'GHC.newSession' first.
908 defaultDynFlags :: Settings -> DynFlags
909 defaultDynFlags mySettings =
910 DynFlags {
911 ghcMode = CompManager,
912 ghcLink = LinkBinary,
913 hscTarget = defaultHscTarget,
914 hscOutName = "",
915 extCoreName = "",
916 verbosity = 0,
917 optLevel = 0,
918 simplPhases = 2,
919 maxSimplIterations = 4,
920 shouldDumpSimplPhase = Nothing,
921 ruleCheck = Nothing,
922 simplTickFactor = 100,
923 specConstrThreshold = Just 2000,
924 specConstrCount = Just 3,
925 liberateCaseThreshold = Just 2000,
926 floatLamArgs = Just 0, -- Default: float only if no fvs
927 strictnessBefore = [],
928
929 cmdlineHcIncludes = [],
930 importPaths = ["."],
931 mainModIs = mAIN,
932 mainFunIs = Nothing,
933 ctxtStkDepth = mAX_CONTEXT_REDUCTION_DEPTH,
934
935 thisPackage = mainPackageId,
936
937 objectDir = Nothing,
938 dylibInstallName = Nothing,
939 hiDir = Nothing,
940 stubDir = Nothing,
941 dumpDir = Nothing,
942
943 objectSuf = phaseInputExt StopLn,
944 hcSuf = phaseInputExt HCc,
945 hiSuf = "hi",
946
947 pluginModNames = [],
948 pluginModNameOpts = [],
949
950 outputFile = Nothing,
951 outputHi = Nothing,
952 dynLibLoader = SystemDependent,
953 dumpPrefix = Nothing,
954 dumpPrefixForce = Nothing,
955 includePaths = [],
956 libraryPaths = [],
957 frameworkPaths = [],
958 cmdlineFrameworks = [],
959 rtsOpts = Nothing,
960 rtsOptsEnabled = RtsOptsSafeOnly,
961
962 hpcDir = ".hpc",
963
964 extraPkgConfs = id,
965 packageFlags = [],
966 pkgDatabase = Nothing,
967 pkgState = panic "no package state yet: call GHC.setSessionDynFlags",
968 ways = panic "defaultDynFlags: No ways",
969 buildTag = panic "defaultDynFlags: No buildTag",
970 rtsBuildTag = panic "defaultDynFlags: No rtsBuildTag",
971 splitInfo = Nothing,
972 settings = mySettings,
973 -- ghc -M values
974 depMakefile = "Makefile",
975 depIncludePkgDeps = False,
976 depExcludeMods = [],
977 depSuffixes = [],
978 -- end of ghc -M values
979 filesToClean = panic "defaultDynFlags: No filesToClean",
980 dirsToClean = panic "defaultDynFlags: No dirsToClean",
981 generatedDumps = panic "defaultDynFlags: No generatedDumps",
982 haddockOptions = Nothing,
983 flags = IntSet.fromList (map fromEnum (defaultFlags (sTargetPlatform mySettings))),
984 warningFlags = IntSet.fromList (map fromEnum standardWarnings),
985 ghciScripts = [],
986 language = Nothing,
987 safeHaskell = Sf_SafeInferred,
988 thOnLoc = noSrcSpan,
989 newDerivOnLoc = noSrcSpan,
990 pkgTrustOnLoc = noSrcSpan,
991 warnSafeOnLoc = noSrcSpan,
992 warnUnsafeOnLoc = noSrcSpan,
993 extensions = [],
994 extensionFlags = flattenExtensionFlags Nothing [],
995 log_action = defaultLogAction,
996 flushOut = defaultFlushOut,
997 flushErr = defaultFlushErr,
998 pprUserLength = 5,
999 pprCols = 100,
1000 traceLevel = 1,
1001 profAuto = NoProfAuto,
1002 llvmVersion = panic "defaultDynFlags: No llvmVersion",
1003 interactivePrint = Nothing
1004 }
1005
1006 --------------------------------------------------------------------------
1007 -- Do not use tracingDynFlags!
1008 -- tracingDynFlags is a hack, necessary because we need to be able to
1009 -- show SDocs when tracing, but we don't always have DynFlags available.
1010 -- Do not use it if you can help it. It will not reflect options set
1011 -- by the commandline flags, and all fields may be either wrong or
1012 -- undefined.
1013 tracingDynFlags :: DynFlags
1014 tracingDynFlags = defaultDynFlags tracingSettings
1015
1016 tracingSettings :: Settings
1017 tracingSettings = trace "panic: Settings not defined in tracingDynFlags" $
1018 Settings { sTargetPlatform = tracingPlatform }
1019 -- Missing flags give a nice error
1020
1021 tracingPlatform :: Platform
1022 tracingPlatform = Platform { platformWordSize = 4, platformOS = OSUnknown }
1023 -- Missing flags give a nice error
1024 --------------------------------------------------------------------------
1025
1026 type FatalMessager = String -> IO ()
1027 type LogAction = DynFlags -> Severity -> SrcSpan -> PprStyle -> MsgDoc -> IO ()
1028
1029 defaultFatalMessager :: FatalMessager
1030 defaultFatalMessager = hPutStrLn stderr
1031
1032 defaultLogAction :: LogAction
1033 defaultLogAction dflags severity srcSpan style msg
1034 = case severity of
1035 SevOutput -> printSDoc msg style
1036 SevDump -> printSDoc (msg $$ blankLine) style
1037 SevInfo -> printErrs msg style
1038 SevFatal -> printErrs msg style
1039 _ -> do hPutChar stderr '\n'
1040 printErrs (mkLocMessage severity srcSpan msg) style
1041 -- careful (#2302): printErrs prints in UTF-8, whereas
1042 -- converting to string first and using hPutStr would
1043 -- just emit the low 8 bits of each unicode char.
1044 where printSDoc = defaultLogActionHPrintDoc dflags stdout
1045 printErrs = defaultLogActionHPrintDoc dflags stderr
1046
1047 defaultLogActionHPrintDoc :: DynFlags -> Handle -> SDoc -> PprStyle -> IO ()
1048 defaultLogActionHPrintDoc dflags h d sty
1049 = do let doc = runSDoc d (initSDocContext dflags sty)
1050 Pretty.printDoc Pretty.PageMode (pprCols dflags) h doc
1051 hFlush h
1052
1053 newtype FlushOut = FlushOut (IO ())
1054
1055 defaultFlushOut :: FlushOut
1056 defaultFlushOut = FlushOut $ hFlush stdout
1057
1058 newtype FlushErr = FlushErr (IO ())
1059
1060 defaultFlushErr :: FlushErr
1061 defaultFlushErr = FlushErr $ hFlush stderr
1062
1063 printOutputForUser :: DynFlags -> PrintUnqualified -> SDoc -> IO ()
1064 printOutputForUser = printSevForUser SevOutput
1065
1066 printInfoForUser :: DynFlags -> PrintUnqualified -> SDoc -> IO ()
1067 printInfoForUser = printSevForUser SevInfo
1068
1069 printSevForUser :: Severity -> DynFlags -> PrintUnqualified -> SDoc -> IO ()
1070 printSevForUser sev dflags unqual doc
1071 = log_action dflags dflags sev noSrcSpan (mkUserStyle unqual AllTheWay) doc
1072
1073 {-
1074 Note [Verbosity levels]
1075 ~~~~~~~~~~~~~~~~~~~~~~~
1076 0 | print errors & warnings only
1077 1 | minimal verbosity: print "compiling M ... done." for each module.
1078 2 | equivalent to -dshow-passes
1079 3 | equivalent to existing "ghc -v"
1080 4 | "ghc -v -ddump-most"
1081 5 | "ghc -v -ddump-all"
1082 -}
1083
1084 data OnOff a = On a
1085 | Off a
1086
1087 -- OnOffs accumulate in reverse order, so we use foldr in order to
1088 -- process them in the right order
1089 flattenExtensionFlags :: Maybe Language -> [OnOff ExtensionFlag] -> IntSet
1090 flattenExtensionFlags ml = foldr f defaultExtensionFlags
1091 where f (On f) flags = IntSet.insert (fromEnum f) flags
1092 f (Off f) flags = IntSet.delete (fromEnum f) flags
1093 defaultExtensionFlags = IntSet.fromList (map fromEnum (languageExtensions ml))
1094
1095 languageExtensions :: Maybe Language -> [ExtensionFlag]
1096
1097 languageExtensions Nothing
1098 -- Nothing => the default case
1099 = Opt_NondecreasingIndentation -- This has been on by default for some time
1100 : delete Opt_DatatypeContexts -- The Haskell' committee decided to
1101 -- remove datatype contexts from the
1102 -- language:
1103 -- http://www.haskell.org/pipermail/haskell-prime/2011-January/003335.html
1104 (languageExtensions (Just Haskell2010))
1105
1106 -- NB: MonoPatBinds is no longer the default
1107
1108 languageExtensions (Just Haskell98)
1109 = [Opt_ImplicitPrelude,
1110 Opt_MonomorphismRestriction,
1111 Opt_NPlusKPatterns,
1112 Opt_DatatypeContexts,
1113 Opt_TraditionalRecordSyntax,
1114 Opt_NondecreasingIndentation
1115 -- strictly speaking non-standard, but we always had this
1116 -- on implicitly before the option was added in 7.1, and
1117 -- turning it off breaks code, so we're keeping it on for
1118 -- backwards compatibility. Cabal uses -XHaskell98 by
1119 -- default unless you specify another language.
1120 ]
1121
1122 languageExtensions (Just Haskell2010)
1123 = [Opt_ImplicitPrelude,
1124 Opt_MonomorphismRestriction,
1125 Opt_DatatypeContexts,
1126 Opt_TraditionalRecordSyntax,
1127 Opt_EmptyDataDecls,
1128 Opt_ForeignFunctionInterface,
1129 Opt_PatternGuards,
1130 Opt_DoAndIfThenElse,
1131 Opt_RelaxedPolyRec]
1132
1133 -- | Test whether a 'DynFlag' is set
1134 dopt :: DynFlag -> DynFlags -> Bool
1135 dopt f dflags = fromEnum f `IntSet.member` flags dflags
1136
1137 -- | Set a 'DynFlag'
1138 dopt_set :: DynFlags -> DynFlag -> DynFlags
1139 dopt_set dfs f = dfs{ flags = IntSet.insert (fromEnum f) (flags dfs) }
1140
1141 -- | Unset a 'DynFlag'
1142 dopt_unset :: DynFlags -> DynFlag -> DynFlags
1143 dopt_unset dfs f = dfs{ flags = IntSet.delete (fromEnum f) (flags dfs) }
1144
1145 -- | Test whether a 'WarningFlag' is set
1146 wopt :: WarningFlag -> DynFlags -> Bool
1147 wopt f dflags = fromEnum f `IntSet.member` warningFlags dflags
1148
1149 -- | Set a 'WarningFlag'
1150 wopt_set :: DynFlags -> WarningFlag -> DynFlags
1151 wopt_set dfs f = dfs{ warningFlags = IntSet.insert (fromEnum f) (warningFlags dfs) }
1152
1153 -- | Unset a 'WarningFlag'
1154 wopt_unset :: DynFlags -> WarningFlag -> DynFlags
1155 wopt_unset dfs f = dfs{ warningFlags = IntSet.delete (fromEnum f) (warningFlags dfs) }
1156
1157 -- | Test whether a 'ExtensionFlag' is set
1158 xopt :: ExtensionFlag -> DynFlags -> Bool
1159 xopt f dflags = fromEnum f `IntSet.member` extensionFlags dflags
1160
1161 -- | Set a 'ExtensionFlag'
1162 xopt_set :: DynFlags -> ExtensionFlag -> DynFlags
1163 xopt_set dfs f
1164 = let onoffs = On f : extensions dfs
1165 in dfs { extensions = onoffs,
1166 extensionFlags = flattenExtensionFlags (language dfs) onoffs }
1167
1168 -- | Unset a 'ExtensionFlag'
1169 xopt_unset :: DynFlags -> ExtensionFlag -> DynFlags
1170 xopt_unset dfs f
1171 = let onoffs = Off f : extensions dfs
1172 in dfs { extensions = onoffs,
1173 extensionFlags = flattenExtensionFlags (language dfs) onoffs }
1174
1175 lang_set :: DynFlags -> Maybe Language -> DynFlags
1176 lang_set dflags lang =
1177 dflags {
1178 language = lang,
1179 extensionFlags = flattenExtensionFlags lang (extensions dflags)
1180 }
1181
1182 -- | Set the Haskell language standard to use
1183 setLanguage :: Language -> DynP ()
1184 setLanguage l = upd (`lang_set` Just l)
1185
1186 -- | Some modules have dependencies on others through the DynFlags rather than textual imports
1187 dynFlagDependencies :: DynFlags -> [ModuleName]
1188 dynFlagDependencies = pluginModNames
1189
1190 -- | Is the -fpackage-trust mode on
1191 packageTrustOn :: DynFlags -> Bool
1192 packageTrustOn = dopt Opt_PackageTrust
1193
1194 -- | Is Safe Haskell on in some way (including inference mode)
1195 safeHaskellOn :: DynFlags -> Bool
1196 safeHaskellOn dflags = safeHaskell dflags /= Sf_None
1197
1198 -- | Is the Safe Haskell safe language in use
1199 safeLanguageOn :: DynFlags -> Bool
1200 safeLanguageOn dflags = safeHaskell dflags == Sf_Safe
1201
1202 -- | Is the Safe Haskell safe inference mode active
1203 safeInferOn :: DynFlags -> Bool
1204 safeInferOn dflags = safeHaskell dflags == Sf_SafeInferred
1205
1206 -- | Test if Safe Imports are on in some form
1207 safeImportsOn :: DynFlags -> Bool
1208 safeImportsOn dflags = safeHaskell dflags == Sf_Unsafe ||
1209 safeHaskell dflags == Sf_Trustworthy ||
1210 safeHaskell dflags == Sf_Safe
1211
1212 -- | Set a 'Safe Haskell' flag
1213 setSafeHaskell :: SafeHaskellMode -> DynP ()
1214 setSafeHaskell s = updM f
1215 where f dfs = do
1216 let sf = safeHaskell dfs
1217 safeM <- combineSafeFlags sf s
1218 return $ dfs { safeHaskell = safeM }
1219
1220 -- | Are all direct imports required to be safe for this Safe Haskell mode?
1221 -- Direct imports are when the code explicitly imports a module
1222 safeDirectImpsReq :: DynFlags -> Bool
1223 safeDirectImpsReq d = safeLanguageOn d
1224
1225 -- | Are all implicit imports required to be safe for this Safe Haskell mode?
1226 -- Implicit imports are things in the prelude. e.g System.IO when print is used.
1227 safeImplicitImpsReq :: DynFlags -> Bool
1228 safeImplicitImpsReq d = safeLanguageOn d
1229
1230 -- | Combine two Safe Haskell modes correctly. Used for dealing with multiple flags.
1231 -- This makes Safe Haskell very much a monoid but for now I prefer this as I don't
1232 -- want to export this functionality from the module but do want to export the
1233 -- type constructors.
1234 combineSafeFlags :: SafeHaskellMode -> SafeHaskellMode -> DynP SafeHaskellMode
1235 combineSafeFlags a b | a == Sf_SafeInferred = return b
1236 | b == Sf_SafeInferred = return a
1237 | a == Sf_None = return b
1238 | b == Sf_None = return a
1239 | a == b = return a
1240 | otherwise = addErr errm >> return (panic errm)
1241 where errm = "Incompatible Safe Haskell flags! ("
1242 ++ show a ++ ", " ++ show b ++ ")"
1243
1244 -- | A list of unsafe flags under Safe Haskell. Tuple elements are:
1245 -- * name of the flag
1246 -- * function to get srcspan that enabled the flag
1247 -- * function to test if the flag is on
1248 -- * function to turn the flag off
1249 unsafeFlags :: [(String, DynFlags -> SrcSpan, DynFlags -> Bool, DynFlags -> DynFlags)]
1250 unsafeFlags = [("-XGeneralizedNewtypeDeriving", newDerivOnLoc,
1251 xopt Opt_GeneralizedNewtypeDeriving,
1252 flip xopt_unset Opt_GeneralizedNewtypeDeriving),
1253 ("-XTemplateHaskell", thOnLoc,
1254 xopt Opt_TemplateHaskell,
1255 flip xopt_unset Opt_TemplateHaskell)]
1256
1257 -- | Retrieve the options corresponding to a particular @opt_*@ field in the correct order
1258 getOpts :: DynFlags -- ^ 'DynFlags' to retrieve the options from
1259 -> (DynFlags -> [a]) -- ^ Relevant record accessor: one of the @opt_*@ accessors
1260 -> [a] -- ^ Correctly ordered extracted options
1261 getOpts dflags opts = reverse (opts dflags)
1262 -- We add to the options from the front, so we need to reverse the list
1263
1264 -- | Gets the verbosity flag for the current verbosity level. This is fed to
1265 -- other tools, so GHC-specific verbosity flags like @-ddump-most@ are not included
1266 getVerbFlags :: DynFlags -> [String]
1267 getVerbFlags dflags
1268 | verbosity dflags >= 4 = ["-v"]
1269 | otherwise = []
1270
1271 setObjectDir, setHiDir, setStubDir, setDumpDir, setOutputDir,
1272 setDylibInstallName,
1273 setObjectSuf, setHiSuf, setHcSuf, parseDynLibLoaderMode,
1274 setPgmP, addOptl, addOptP,
1275 addCmdlineFramework, addHaddockOpts, addGhciScript,
1276 setInteractivePrint
1277 :: String -> DynFlags -> DynFlags
1278 setOutputFile, setOutputHi, setDumpPrefixForce
1279 :: Maybe String -> DynFlags -> DynFlags
1280
1281 setObjectDir f d = d{ objectDir = Just f}
1282 setHiDir f d = d{ hiDir = Just f}
1283 setStubDir f d = d{ stubDir = Just f, includePaths = f : includePaths d }
1284 -- -stubdir D adds an implicit -I D, so that gcc can find the _stub.h file
1285 -- \#included from the .hc file when compiling via C (i.e. unregisterised
1286 -- builds).
1287 setDumpDir f d = d{ dumpDir = Just f}
1288 setOutputDir f = setObjectDir f . setHiDir f . setStubDir f . setDumpDir f
1289 setDylibInstallName f d = d{ dylibInstallName = Just f}
1290
1291 setObjectSuf f d = d{ objectSuf = f}
1292 setHiSuf f d = d{ hiSuf = f}
1293 setHcSuf f d = d{ hcSuf = f}
1294
1295 setOutputFile f d = d{ outputFile = f}
1296 setOutputHi f d = d{ outputHi = f}
1297
1298 addPluginModuleName :: String -> DynFlags -> DynFlags
1299 addPluginModuleName name d = d { pluginModNames = (mkModuleName name) : (pluginModNames d) }
1300
1301 addPluginModuleNameOption :: String -> DynFlags -> DynFlags
1302 addPluginModuleNameOption optflag d = d { pluginModNameOpts = (mkModuleName m, option) : (pluginModNameOpts d) }
1303 where (m, rest) = break (== ':') optflag
1304 option = case rest of
1305 [] -> "" -- should probably signal an error
1306 (_:plug_opt) -> plug_opt -- ignore the ':' from break
1307
1308 parseDynLibLoaderMode f d =
1309 case splitAt 8 f of
1310 ("deploy", "") -> d{ dynLibLoader = Deployable }
1311 ("sysdep", "") -> d{ dynLibLoader = SystemDependent }
1312 _ -> ghcError (CmdLineError ("Unknown dynlib loader: " ++ f))
1313
1314 setDumpPrefixForce f d = d { dumpPrefixForce = f}
1315
1316 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
1317 -- Config.hs should really use Option.
1318 setPgmP f = let (pgm:args) = words f in alterSettings (\s -> s { sPgm_P = (pgm, map Option args)})
1319 addOptl f = alterSettings (\s -> s { sOpt_l = f : sOpt_l s})
1320 addOptP f = alterSettings (\s -> s { sOpt_P = f : sOpt_P s})
1321
1322
1323 setDepMakefile :: FilePath -> DynFlags -> DynFlags
1324 setDepMakefile f d = d { depMakefile = deOptDep f }
1325
1326 setDepIncludePkgDeps :: Bool -> DynFlags -> DynFlags
1327 setDepIncludePkgDeps b d = d { depIncludePkgDeps = b }
1328
1329 addDepExcludeMod :: String -> DynFlags -> DynFlags
1330 addDepExcludeMod m d
1331 = d { depExcludeMods = mkModuleName (deOptDep m) : depExcludeMods d }
1332
1333 addDepSuffix :: FilePath -> DynFlags -> DynFlags
1334 addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d }
1335
1336 -- XXX Legacy code:
1337 -- We used to use "-optdep-flag -optdeparg", so for legacy applications
1338 -- we need to strip the "-optdep" off of the arg
1339 deOptDep :: String -> String
1340 deOptDep x = case stripPrefix "-optdep" x of
1341 Just rest -> rest
1342 Nothing -> x
1343
1344 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
1345
1346 addHaddockOpts f d = d{ haddockOptions = Just f}
1347
1348 addGhciScript f d = d{ ghciScripts = f : ghciScripts d}
1349
1350 setInteractivePrint f d = d{ interactivePrint = Just f}
1351
1352 -- -----------------------------------------------------------------------------
1353 -- Command-line options
1354
1355 -- | When invoking external tools as part of the compilation pipeline, we
1356 -- pass these a sequence of options on the command-line. Rather than
1357 -- just using a list of Strings, we use a type that allows us to distinguish
1358 -- between filepaths and 'other stuff'. The reason for this is that
1359 -- this type gives us a handle on transforming filenames, and filenames only,
1360 -- to whatever format they're expected to be on a particular platform.
1361 data Option
1362 = FileOption -- an entry that _contains_ filename(s) / filepaths.
1363 String -- a non-filepath prefix that shouldn't be
1364 -- transformed (e.g., "/out=")
1365 String -- the filepath/filename portion
1366 | Option String
1367 deriving ( Eq )
1368
1369 showOpt :: Option -> String
1370 showOpt (FileOption pre f) = pre ++ f
1371 showOpt (Option s) = s
1372
1373 -----------------------------------------------------------------------------
1374 -- Setting the optimisation level
1375
1376 updOptLevel :: Int -> DynFlags -> DynFlags
1377 -- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
1378 updOptLevel n dfs
1379 = dfs2{ optLevel = final_n }
1380 where
1381 final_n = max 0 (min 2 n) -- Clamp to 0 <= n <= 2
1382 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
1383 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
1384
1385 extra_dopts = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
1386 remove_dopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
1387
1388 -- -----------------------------------------------------------------------------
1389 -- StgToDo: abstraction of stg-to-stg passes to run.
1390
1391 data StgToDo
1392 = StgDoMassageForProfiling -- should be (next to) last
1393 -- There's also setStgVarInfo, but its absolute "lastness"
1394 -- is so critical that it is hardwired in (no flag).
1395 | D_stg_stats
1396
1397 getStgToDo :: DynFlags -> [StgToDo]
1398 getStgToDo dflags
1399 = todo2
1400 where
1401 stg_stats = dopt Opt_StgStats dflags
1402
1403 todo1 = if stg_stats then [D_stg_stats] else []
1404
1405 todo2 | WayProf `elem` wayNames dflags
1406 = StgDoMassageForProfiling : todo1
1407 | otherwise
1408 = todo1
1409
1410 {- **********************************************************************
1411 %* *
1412 DynFlags parser
1413 %* *
1414 %********************************************************************* -}
1415
1416 -- -----------------------------------------------------------------------------
1417 -- Parsing the dynamic flags.
1418
1419
1420 -- | Parse dynamic flags from a list of command line arguments. Returns the
1421 -- the parsed 'DynFlags', the left-over arguments, and a list of warnings.
1422 -- Throws a 'UsageError' if errors occurred during parsing (such as unknown
1423 -- flags or missing arguments).
1424 parseDynamicFlagsCmdLine :: Monad m => DynFlags -> [Located String]
1425 -> m (DynFlags, [Located String], [Located String])
1426 -- ^ Updated 'DynFlags', left-over arguments, and
1427 -- list of warnings.
1428 parseDynamicFlagsCmdLine = parseDynamicFlagsFull flagsAll True
1429
1430
1431 -- | Like 'parseDynamicFlagsCmdLine' but does not allow the package flags
1432 -- (-package, -hide-package, -ignore-package, -hide-all-packages, -package-db).
1433 -- Used to parse flags set in a modules pragma.
1434 parseDynamicFilePragma :: Monad m => DynFlags -> [Located String]
1435 -> m (DynFlags, [Located String], [Located String])
1436 -- ^ Updated 'DynFlags', left-over arguments, and
1437 -- list of warnings.
1438 parseDynamicFilePragma = parseDynamicFlagsFull flagsDynamic False
1439
1440
1441 -- | Parses the dynamically set flags for GHC. This is the most general form of
1442 -- the dynamic flag parser that the other methods simply wrap. It allows
1443 -- saying which flags are valid flags and indicating if we are parsing
1444 -- arguments from the command line or from a file pragma.
1445 parseDynamicFlagsFull :: Monad m
1446 => [Flag (CmdLineP DynFlags)] -- ^ valid flags to match against
1447 -> Bool -- ^ are the arguments from the command line?
1448 -> DynFlags -- ^ current dynamic flags
1449 -> [Located String] -- ^ arguments to parse
1450 -> m (DynFlags, [Located String], [Located String])
1451 parseDynamicFlagsFull activeFlags cmdline dflags0 args = do
1452 -- XXX Legacy support code
1453 -- We used to accept things like
1454 -- optdep-f -optdepdepend
1455 -- optdep-f -optdep depend
1456 -- optdep -f -optdepdepend
1457 -- optdep -f -optdep depend
1458 -- but the spaces trip up proper argument handling. So get rid of them.
1459 let f (L p "-optdep" : L _ x : xs) = (L p ("-optdep" ++ x)) : f xs
1460 f (x : xs) = x : f xs
1461 f xs = xs
1462 args' = f args
1463
1464 let ((leftover, errs, warns), dflags1)
1465 = runCmdLine (processArgs activeFlags args') dflags0
1466 when (not (null errs)) $ ghcError $ errorsToGhcException errs
1467
1468 -- check for disabled flags in safe haskell
1469 let (dflags2, sh_warns) = safeFlagCheck cmdline dflags1
1470
1471 return (dflags2, leftover, sh_warns ++ warns)
1472
1473
1474 -- | Check (and potentially disable) any extensions that aren't allowed
1475 -- in safe mode.
1476 --
1477 -- The bool is to indicate if we are parsing command line flags (false means
1478 -- file pragma). This allows us to generate better warnings.
1479 safeFlagCheck :: Bool -> DynFlags -> (DynFlags, [Located String])
1480 safeFlagCheck _ dflags | not (safeLanguageOn dflags || safeInferOn dflags)
1481 = (dflags, [])
1482
1483 -- safe or safe-infer ON
1484 safeFlagCheck cmdl dflags =
1485 case safeLanguageOn dflags of
1486 True -> (dflags', warns)
1487
1488 -- throw error if -fpackage-trust by itself with no safe haskell flag
1489 False | not cmdl && packageTrustOn dflags
1490 -> (dopt_unset dflags' Opt_PackageTrust,
1491 [L (pkgTrustOnLoc dflags') $
1492 "-fpackage-trust ignored;" ++
1493 " must be specified with a Safe Haskell flag"]
1494 )
1495
1496 False | null warns && safeInfOk
1497 -> (dflags', [])
1498
1499 | otherwise
1500 -> (dflags' { safeHaskell = Sf_None }, [])
1501 -- Have we inferred Unsafe?
1502 -- See Note [HscMain . Safe Haskell Inference]
1503 where
1504 -- TODO: Can we do better than this for inference?
1505 safeInfOk = not $ xopt Opt_OverlappingInstances dflags
1506
1507 (dflags', warns) = foldl check_method (dflags, []) unsafeFlags
1508
1509 check_method (df, warns) (str,loc,test,fix)
1510 | test df = (apFix fix df, warns ++ safeFailure (loc dflags) str)
1511 | otherwise = (df, warns)
1512
1513 apFix f = if safeInferOn dflags then id else f
1514
1515 safeFailure loc str
1516 = [L loc $ str ++ " is not allowed in Safe Haskell; ignoring " ++ str]
1517
1518 {- **********************************************************************
1519 %* *
1520 DynFlags specifications
1521 %* *
1522 %********************************************************************* -}
1523
1524 -- | All dynamic flags option strings. These are the user facing strings for
1525 -- enabling and disabling options.
1526 allFlags :: [String]
1527 allFlags = map ('-':) $
1528 [ flagName flag | flag <- dynamic_flags ++ package_flags, ok (flagOptKind flag) ] ++
1529 map ("fno-"++) fflags ++
1530 map ("f"++) fflags ++
1531 map ("X"++) supportedExtensions
1532 where ok (PrefixPred _ _) = False
1533 ok _ = True
1534 fflags = fflags0 ++ fflags1 ++ fflags2
1535 fflags0 = [ name | (name, _, _) <- fFlags ]
1536 fflags1 = [ name | (name, _, _) <- fWarningFlags ]
1537 fflags2 = [ name | (name, _, _) <- fLangFlags ]
1538
1539 {-
1540 - Below we export user facing symbols for GHC dynamic flags for use with the
1541 - GHC API.
1542 -}
1543
1544 -- All dynamic flags present in GHC.
1545 flagsAll :: [Flag (CmdLineP DynFlags)]
1546 flagsAll = package_flags ++ dynamic_flags
1547
1548 -- All dynamic flags, minus package flags, present in GHC.
1549 flagsDynamic :: [Flag (CmdLineP DynFlags)]
1550 flagsDynamic = dynamic_flags
1551
1552 -- ALl package flags present in GHC.
1553 flagsPackage :: [Flag (CmdLineP DynFlags)]
1554 flagsPackage = package_flags
1555
1556 --------------- The main flags themselves ------------------
1557 dynamic_flags :: [Flag (CmdLineP DynFlags)]
1558 dynamic_flags = [
1559 Flag "n" (NoArg (addWarn "The -n flag is deprecated and no longer has any effect"))
1560 , Flag "cpp" (NoArg (setExtensionFlag Opt_Cpp))
1561 , Flag "F" (NoArg (setDynFlag Opt_Pp))
1562 , Flag "#include"
1563 (HasArg (\s -> do addCmdlineHCInclude s
1564 addWarn "-#include and INCLUDE pragmas are deprecated: They no longer have any effect"))
1565 , Flag "v" (OptIntSuffix setVerbosity)
1566
1567 ------- Specific phases --------------------------------------------
1568 -- need to appear before -pgmL to be parsed as LLVM flags.
1569 , Flag "pgmlo" (hasArg (\f -> alterSettings (\s -> s { sPgm_lo = (f,[])})))
1570 , Flag "pgmlc" (hasArg (\f -> alterSettings (\s -> s { sPgm_lc = (f,[])})))
1571 , Flag "pgmL" (hasArg (\f -> alterSettings (\s -> s { sPgm_L = f})))
1572 , Flag "pgmP" (hasArg setPgmP)
1573 , Flag "pgmF" (hasArg (\f -> alterSettings (\s -> s { sPgm_F = f})))
1574 , Flag "pgmc" (hasArg (\f -> alterSettings (\s -> s { sPgm_c = (f,[])})))
1575 , Flag "pgmm" (HasArg (\_ -> addWarn "The -pgmm flag does nothing; it will be removed in a future GHC release"))
1576 , Flag "pgms" (hasArg (\f -> alterSettings (\s -> s { sPgm_s = (f,[])})))
1577 , Flag "pgma" (hasArg (\f -> alterSettings (\s -> s { sPgm_a = (f,[])})))
1578 , Flag "pgml" (hasArg (\f -> alterSettings (\s -> s { sPgm_l = (f,[])})))
1579 , Flag "pgmdll" (hasArg (\f -> alterSettings (\s -> s { sPgm_dll = (f,[])})))
1580 , Flag "pgmwindres" (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
1581
1582 -- need to appear before -optl/-opta to be parsed as LLVM flags.
1583 , Flag "optlo" (hasArg (\f -> alterSettings (\s -> s { sOpt_lo = f : sOpt_lo s})))
1584 , Flag "optlc" (hasArg (\f -> alterSettings (\s -> s { sOpt_lc = f : sOpt_lc s})))
1585 , Flag "optL" (hasArg (\f -> alterSettings (\s -> s { sOpt_L = f : sOpt_L s})))
1586 , Flag "optP" (hasArg addOptP)
1587 , Flag "optF" (hasArg (\f -> alterSettings (\s -> s { sOpt_F = f : sOpt_F s})))
1588 , Flag "optc" (hasArg (\f -> alterSettings (\s -> s { sOpt_c = f : sOpt_c s})))
1589 , Flag "optm" (HasArg (\_ -> addWarn "The -optm flag does nothing; it will be removed in a future GHC release"))
1590 , Flag "opta" (hasArg (\f -> alterSettings (\s -> s { sOpt_a = f : sOpt_a s})))
1591 , Flag "optl" (hasArg addOptl)
1592 , Flag "optwindres" (hasArg (\f -> alterSettings (\s -> s { sOpt_windres = f : sOpt_windres s})))
1593
1594 , Flag "split-objs"
1595 (NoArg (if can_split
1596 then setDynFlag Opt_SplitObjs
1597 else addWarn "ignoring -fsplit-objs"))
1598
1599 -------- ghc -M -----------------------------------------------------
1600 , Flag "dep-suffix" (hasArg addDepSuffix)
1601 , Flag "optdep-s" (hasArgDF addDepSuffix "Use -dep-suffix instead")
1602 , Flag "dep-makefile" (hasArg setDepMakefile)
1603 , Flag "optdep-f" (hasArgDF setDepMakefile "Use -dep-makefile instead")
1604 , Flag "optdep-w" (NoArg (deprecate "doesn't do anything"))
1605 , Flag "include-pkg-deps" (noArg (setDepIncludePkgDeps True))
1606 , Flag "optdep--include-prelude" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
1607 , Flag "optdep--include-pkg-deps" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
1608 , Flag "exclude-module" (hasArg addDepExcludeMod)
1609 , Flag "optdep--exclude-module" (hasArgDF addDepExcludeMod "Use -exclude-module instead")
1610 , Flag "optdep-x" (hasArgDF addDepExcludeMod "Use -exclude-module instead")
1611
1612 -------- Linking ----------------------------------------------------
1613 , Flag "no-link" (noArg (\d -> d{ ghcLink=NoLink }))
1614 , Flag "shared" (noArg (\d -> d{ ghcLink=LinkDynLib }))
1615 , Flag "dynload" (hasArg parseDynLibLoaderMode)
1616 , Flag "dylib-install-name" (hasArg setDylibInstallName)
1617
1618 ------- Libraries ---------------------------------------------------
1619 , Flag "L" (Prefix addLibraryPath)
1620 , Flag "l" (hasArg (addOptl . ("-l" ++)))
1621
1622 ------- Frameworks --------------------------------------------------
1623 -- -framework-path should really be -F ...
1624 , Flag "framework-path" (HasArg addFrameworkPath)
1625 , Flag "framework" (hasArg addCmdlineFramework)
1626
1627 ------- Output Redirection ------------------------------------------
1628 , Flag "odir" (hasArg setObjectDir)
1629 , Flag "o" (sepArg (setOutputFile . Just))
1630 , Flag "ohi" (hasArg (setOutputHi . Just ))
1631 , Flag "osuf" (hasArg setObjectSuf)
1632 , Flag "hcsuf" (hasArg setHcSuf)
1633 , Flag "hisuf" (hasArg setHiSuf)
1634 , Flag "hidir" (hasArg setHiDir)
1635 , Flag "tmpdir" (hasArg setTmpDir)
1636 , Flag "stubdir" (hasArg setStubDir)
1637 , Flag "dumpdir" (hasArg setDumpDir)
1638 , Flag "outputdir" (hasArg setOutputDir)
1639 , Flag "ddump-file-prefix" (hasArg (setDumpPrefixForce . Just))
1640
1641 ------- Keeping temporary files -------------------------------------
1642 -- These can be singular (think ghc -c) or plural (think ghc --make)
1643 , Flag "keep-hc-file" (NoArg (setDynFlag Opt_KeepHcFiles))
1644 , Flag "keep-hc-files" (NoArg (setDynFlag Opt_KeepHcFiles))
1645 , Flag "keep-s-file" (NoArg (setDynFlag Opt_KeepSFiles))
1646 , Flag "keep-s-files" (NoArg (setDynFlag Opt_KeepSFiles))
1647 , Flag "keep-raw-s-file" (NoArg (addWarn "The -keep-raw-s-file flag does nothing; it will be removed in a future GHC release"))
1648 , Flag "keep-raw-s-files" (NoArg (addWarn "The -keep-raw-s-files flag does nothing; it will be removed in a future GHC release"))
1649 , Flag "keep-llvm-file" (NoArg (do setObjTarget HscLlvm
1650 setDynFlag Opt_KeepLlvmFiles))
1651 , Flag "keep-llvm-files" (NoArg (do setObjTarget HscLlvm
1652 setDynFlag Opt_KeepLlvmFiles))
1653 -- This only makes sense as plural
1654 , Flag "keep-tmp-files" (NoArg (setDynFlag Opt_KeepTmpFiles))
1655
1656 ------- Miscellaneous ----------------------------------------------
1657 , Flag "no-auto-link-packages" (NoArg (unSetDynFlag Opt_AutoLinkPackages))
1658 , Flag "no-hs-main" (NoArg (setDynFlag Opt_NoHsMain))
1659 , Flag "with-rtsopts" (HasArg setRtsOpts)
1660 , Flag "rtsopts" (NoArg (setRtsOptsEnabled RtsOptsAll))
1661 , Flag "rtsopts=all" (NoArg (setRtsOptsEnabled RtsOptsAll))
1662 , Flag "rtsopts=some" (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
1663 , Flag "rtsopts=none" (NoArg (setRtsOptsEnabled RtsOptsNone))
1664 , Flag "no-rtsopts" (NoArg (setRtsOptsEnabled RtsOptsNone))
1665 , Flag "main-is" (SepArg setMainIs)
1666 , Flag "haddock" (NoArg (setDynFlag Opt_Haddock))
1667 , Flag "haddock-opts" (hasArg addHaddockOpts)
1668 , Flag "hpcdir" (SepArg setOptHpcDir)
1669 , Flag "ghci-script" (hasArg addGhciScript)
1670 , Flag "interactive-print" (hasArg setInteractivePrint)
1671 ------- recompilation checker --------------------------------------
1672 , Flag "recomp" (NoArg (do unSetDynFlag Opt_ForceRecomp
1673 deprecate "Use -fno-force-recomp instead"))
1674 , Flag "no-recomp" (NoArg (do setDynFlag Opt_ForceRecomp
1675 deprecate "Use -fforce-recomp instead"))
1676
1677 ------ HsCpp opts ---------------------------------------------------
1678 , Flag "D" (AnySuffix (upd . addOptP))
1679 , Flag "U" (AnySuffix (upd . addOptP))
1680
1681 ------- Include/Import Paths ----------------------------------------
1682 , Flag "I" (Prefix addIncludePath)
1683 , Flag "i" (OptPrefix addImportPath)
1684
1685 ------ Output style options -----------------------------------------
1686 , Flag "dppr-user-length" (intSuffix (\n d -> d{ pprUserLength = n }))
1687 , Flag "dppr-cols" (intSuffix (\n d -> d{ pprCols = n }))
1688 , Flag "dtrace-level" (intSuffix (\n d -> d{ traceLevel = n }))
1689
1690 ------ Debugging ----------------------------------------------------
1691 , Flag "dstg-stats" (NoArg (setDynFlag Opt_StgStats))
1692
1693 , Flag "ddump-cmm" (setDumpFlag Opt_D_dump_cmm)
1694 , Flag "ddump-raw-cmm" (setDumpFlag Opt_D_dump_raw_cmm)
1695 , Flag "ddump-cmmz" (setDumpFlag Opt_D_dump_cmmz)
1696 , Flag "ddump-cmmz-cfg" (setDumpFlag Opt_D_dump_cmmz_cbe)
1697 , Flag "ddump-cmmz-cbe" (setDumpFlag Opt_D_dump_cmmz_cbe)
1698 , Flag "ddump-cmmz-spills" (setDumpFlag Opt_D_dump_cmmz_spills)
1699 , Flag "ddump-cmmz-proc" (setDumpFlag Opt_D_dump_cmmz_proc)
1700 , Flag "ddump-cmmz-rewrite" (setDumpFlag Opt_D_dump_cmmz_rewrite)
1701 , Flag "ddump-cmmz-dead" (setDumpFlag Opt_D_dump_cmmz_dead)
1702 , Flag "ddump-cmmz-stub" (setDumpFlag Opt_D_dump_cmmz_stub)
1703 , Flag "ddump-cmmz-sp" (setDumpFlag Opt_D_dump_cmmz_sp)
1704 , Flag "ddump-cmmz-procmap" (setDumpFlag Opt_D_dump_cmmz_procmap)
1705 , Flag "ddump-cmmz-split" (setDumpFlag Opt_D_dump_cmmz_split)
1706 , Flag "ddump-cmmz-lower" (setDumpFlag Opt_D_dump_cmmz_lower)
1707 , Flag "ddump-cmmz-info" (setDumpFlag Opt_D_dump_cmmz_info)
1708 , Flag "ddump-cmmz-cafs" (setDumpFlag Opt_D_dump_cmmz_cafs)
1709 , Flag "ddump-core-stats" (setDumpFlag Opt_D_dump_core_stats)
1710 , Flag "ddump-cps-cmm" (setDumpFlag Opt_D_dump_cps_cmm)
1711 , Flag "ddump-cvt-cmm" (setDumpFlag Opt_D_dump_cvt_cmm)
1712 , Flag "ddump-asm" (setDumpFlag Opt_D_dump_asm)
1713 , Flag "ddump-asm-native" (setDumpFlag Opt_D_dump_asm_native)
1714 , Flag "ddump-asm-liveness" (setDumpFlag Opt_D_dump_asm_liveness)
1715 , Flag "ddump-asm-coalesce" (setDumpFlag Opt_D_dump_asm_coalesce)
1716 , Flag "ddump-asm-regalloc" (setDumpFlag Opt_D_dump_asm_regalloc)
1717 , Flag "ddump-asm-conflicts" (setDumpFlag Opt_D_dump_asm_conflicts)
1718 , Flag "ddump-asm-regalloc-stages" (setDumpFlag Opt_D_dump_asm_regalloc_stages)
1719 , Flag "ddump-asm-stats" (setDumpFlag Opt_D_dump_asm_stats)
1720 , Flag "ddump-asm-expanded" (setDumpFlag Opt_D_dump_asm_expanded)
1721 , Flag "ddump-llvm" (NoArg (do setObjTarget HscLlvm
1722 setDumpFlag' Opt_D_dump_llvm))
1723 , Flag "ddump-cpranal" (setDumpFlag Opt_D_dump_cpranal)
1724 , Flag "ddump-deriv" (setDumpFlag Opt_D_dump_deriv)
1725 , Flag "ddump-ds" (setDumpFlag Opt_D_dump_ds)
1726 , Flag "ddump-flatC" (setDumpFlag Opt_D_dump_flatC)
1727 , Flag "ddump-foreign" (setDumpFlag Opt_D_dump_foreign)
1728 , Flag "ddump-inlinings" (setDumpFlag Opt_D_dump_inlinings)
1729 , Flag "ddump-rule-firings" (setDumpFlag Opt_D_dump_rule_firings)
1730 , Flag "ddump-rule-rewrites" (setDumpFlag Opt_D_dump_rule_rewrites)
1731 , Flag "ddump-occur-anal" (setDumpFlag Opt_D_dump_occur_anal)
1732 , Flag "ddump-parsed" (setDumpFlag Opt_D_dump_parsed)
1733 , Flag "ddump-rn" (setDumpFlag Opt_D_dump_rn)
1734 , Flag "ddump-core-pipeline" (setDumpFlag Opt_D_dump_core_pipeline)
1735 , Flag "ddump-simpl" (setDumpFlag Opt_D_dump_simpl)
1736 , Flag "ddump-simpl-iterations" (setDumpFlag Opt_D_dump_simpl_iterations)
1737 , Flag "ddump-simpl-phases" (OptPrefix setDumpSimplPhases)
1738 , Flag "ddump-spec" (setDumpFlag Opt_D_dump_spec)
1739 , Flag "ddump-prep" (setDumpFlag Opt_D_dump_prep)
1740 , Flag "ddump-stg" (setDumpFlag Opt_D_dump_stg)
1741 , Flag "ddump-stranal" (setDumpFlag Opt_D_dump_stranal)
1742 , Flag "ddump-tc" (setDumpFlag Opt_D_dump_tc)
1743 , Flag "ddump-types" (setDumpFlag Opt_D_dump_types)
1744 , Flag "ddump-rules" (setDumpFlag Opt_D_dump_rules)
1745 , Flag "ddump-cse" (setDumpFlag Opt_D_dump_cse)
1746 , Flag "ddump-worker-wrapper" (setDumpFlag Opt_D_dump_worker_wrapper)
1747 , Flag "ddump-rn-trace" (setDumpFlag Opt_D_dump_rn_trace)
1748 , Flag "ddump-if-trace" (setDumpFlag Opt_D_dump_if_trace)
1749 , Flag "ddump-cs-trace" (setDumpFlag Opt_D_dump_cs_trace)
1750 , Flag "ddump-tc-trace" (setDumpFlag Opt_D_dump_tc_trace)
1751 , Flag "ddump-vt-trace" (setDumpFlag Opt_D_dump_vt_trace)
1752 , Flag "ddump-splices" (setDumpFlag Opt_D_dump_splices)
1753 , Flag "ddump-rn-stats" (setDumpFlag Opt_D_dump_rn_stats)
1754 , Flag "ddump-opt-cmm" (setDumpFlag Opt_D_dump_opt_cmm)
1755 , Flag "ddump-simpl-stats" (setDumpFlag Opt_D_dump_simpl_stats)
1756 , Flag "ddump-bcos" (setDumpFlag Opt_D_dump_BCOs)
1757 , Flag "dsource-stats" (setDumpFlag Opt_D_source_stats)
1758 , Flag "dverbose-core2core" (NoArg (do setVerbosity (Just 2)
1759 setVerboseCore2Core))
1760 , Flag "dverbose-stg2stg" (setDumpFlag Opt_D_verbose_stg2stg)
1761 , Flag "ddump-hi" (setDumpFlag Opt_D_dump_hi)
1762 , Flag "ddump-minimal-imports" (setDumpFlag Opt_D_dump_minimal_imports)
1763 , Flag "ddump-vect" (setDumpFlag Opt_D_dump_vect)
1764 , Flag "ddump-avoid-vect" (setDumpFlag Opt_D_dump_avoid_vect)
1765 , Flag "ddump-hpc" (setDumpFlag Opt_D_dump_ticked) -- back compat
1766 , Flag "ddump-ticked" (setDumpFlag Opt_D_dump_ticked)
1767 , Flag "ddump-mod-cycles" (setDumpFlag Opt_D_dump_mod_cycles)
1768 , Flag "ddump-view-pattern-commoning" (setDumpFlag Opt_D_dump_view_pattern_commoning)
1769 , Flag "ddump-to-file" (setDumpFlag Opt_DumpToFile)
1770 , Flag "ddump-hi-diffs" (setDumpFlag Opt_D_dump_hi_diffs)
1771 , Flag "ddump-rtti" (setDumpFlag Opt_D_dump_rtti)
1772 , Flag "dcore-lint" (NoArg (setDynFlag Opt_DoCoreLinting))
1773 , Flag "dstg-lint" (NoArg (setDynFlag Opt_DoStgLinting))
1774 , Flag "dcmm-lint" (NoArg (setDynFlag Opt_DoCmmLinting))
1775 , Flag "dasm-lint" (NoArg (setDynFlag Opt_DoAsmLinting))
1776 , Flag "dshow-passes" (NoArg (do forceRecompile
1777 setVerbosity $ Just 2))
1778 , Flag "dfaststring-stats" (NoArg (setDynFlag Opt_D_faststring_stats))
1779 , Flag "dno-llvm-mangler" (NoArg (setDynFlag Opt_NoLlvmMangler)) -- hidden flag
1780
1781 ------ Machine dependant (-m<blah>) stuff ---------------------------
1782
1783 , Flag "monly-2-regs" (NoArg (addWarn "The -monly-2-regs flag does nothing; it will be removed in a future GHC release"))
1784 , Flag "monly-3-regs" (NoArg (addWarn "The -monly-3-regs flag does nothing; it will be removed in a future GHC release"))
1785 , Flag "monly-4-regs" (NoArg (addWarn "The -monly-4-regs flag does nothing; it will be removed in a future GHC release"))
1786 , Flag "msse2" (NoArg (setDynFlag Opt_SSE2))
1787 , Flag "msse4.2" (NoArg (setDynFlag Opt_SSE4_2))
1788
1789 ------ Warning opts -------------------------------------------------
1790 , Flag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
1791 , Flag "Werror" (NoArg (setDynFlag Opt_WarnIsError))
1792 , Flag "Wwarn" (NoArg (unSetDynFlag Opt_WarnIsError))
1793 , Flag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
1794 , Flag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
1795 deprecate "Use -w instead"))
1796 , Flag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
1797
1798 ------ Plugin flags ------------------------------------------------
1799 , Flag "fplugin-opt" (hasArg addPluginModuleNameOption)
1800 , Flag "fplugin" (hasArg addPluginModuleName)
1801
1802 ------ Optimisation flags ------------------------------------------
1803 , Flag "O" (noArgM (setOptLevel 1))
1804 , Flag "Onot" (noArgM (\dflags -> do deprecate "Use -O0 instead"
1805 setOptLevel 0 dflags))
1806 , Flag "Odph" (noArgM setDPHOpt)
1807 , Flag "O" (optIntSuffixM (\mb_n -> setOptLevel (mb_n `orElse` 1)))
1808 -- If the number is missing, use 1
1809
1810 , Flag "fsimplifier-phases" (intSuffix (\n d -> d{ simplPhases = n }))
1811 , Flag "fmax-simplifier-iterations" (intSuffix (\n d -> d{ maxSimplIterations = n }))
1812 , Flag "fsimpl-tick-factor" (intSuffix (\n d -> d{ simplTickFactor = n }))
1813 , Flag "fspec-constr-threshold" (intSuffix (\n d -> d{ specConstrThreshold = Just n }))
1814 , Flag "fno-spec-constr-threshold" (noArg (\d -> d{ specConstrThreshold = Nothing }))
1815 , Flag "fspec-constr-count" (intSuffix (\n d -> d{ specConstrCount = Just n }))
1816 , Flag "fno-spec-constr-count" (noArg (\d -> d{ specConstrCount = Nothing }))
1817 , Flag "fliberate-case-threshold" (intSuffix (\n d -> d{ liberateCaseThreshold = Just n }))
1818 , Flag "fno-liberate-case-threshold" (noArg (\d -> d{ liberateCaseThreshold = Nothing }))
1819 , Flag "frule-check" (sepArg (\s d -> d{ ruleCheck = Just s }))
1820 , Flag "fcontext-stack" (intSuffix (\n d -> d{ ctxtStkDepth = n }))
1821 , Flag "fstrictness-before" (intSuffix (\n d -> d{ strictnessBefore = n : strictnessBefore d }))
1822 , Flag "ffloat-lam-args" (intSuffix (\n d -> d{ floatLamArgs = Just n }))
1823 , Flag "ffloat-all-lams" (noArg (\d -> d{ floatLamArgs = Nothing }))
1824
1825 ------ Profiling ----------------------------------------------------
1826
1827 -- OLD profiling flags
1828 , Flag "auto-all" (noArg (\d -> d { profAuto = ProfAutoAll } ))
1829 , Flag "no-auto-all" (noArg (\d -> d { profAuto = NoProfAuto } ))
1830 , Flag "auto" (noArg (\d -> d { profAuto = ProfAutoExports } ))
1831 , Flag "no-auto" (noArg (\d -> d { profAuto = NoProfAuto } ))
1832 , Flag "caf-all" (NoArg (setDynFlag Opt_AutoSccsOnIndividualCafs))
1833 , Flag "no-caf-all" (NoArg (unSetDynFlag Opt_AutoSccsOnIndividualCafs))
1834
1835 -- NEW profiling flags
1836 , Flag "fprof-auto" (noArg (\d -> d { profAuto = ProfAutoAll } ))
1837 , Flag "fprof-auto-top" (noArg (\d -> d { profAuto = ProfAutoTop } ))
1838 , Flag "fprof-auto-exported" (noArg (\d -> d { profAuto = ProfAutoExports } ))
1839 , Flag "fprof-auto-calls" (noArg (\d -> d { profAuto = ProfAutoCalls } ))
1840 , Flag "fno-prof-auto" (noArg (\d -> d { profAuto = NoProfAuto } ))
1841
1842 ------ Compiler flags -----------------------------------------------
1843
1844 , Flag "fasm" (NoArg (setObjTarget HscAsm))
1845 , Flag "fvia-c" (NoArg
1846 (addWarn "The -fvia-c flag does nothing; it will be removed in a future GHC release"))
1847 , Flag "fvia-C" (NoArg
1848 (addWarn "The -fvia-C flag does nothing; it will be removed in a future GHC release"))
1849 , Flag "fllvm" (NoArg (setObjTarget HscLlvm))
1850
1851 , Flag "fno-code" (NoArg (do upd $ \d -> d{ ghcLink=NoLink }
1852 setTarget HscNothing))
1853 , Flag "fbyte-code" (NoArg (setTarget HscInterpreted))
1854 , Flag "fobject-code" (NoArg (setTarget defaultHscTarget))
1855 , Flag "fglasgow-exts" (NoArg (enableGlasgowExts >> deprecate "Use individual extensions instead"))
1856 , Flag "fno-glasgow-exts" (NoArg (disableGlasgowExts >> deprecate "Use individual extensions instead"))
1857
1858 ------ Safe Haskell flags -------------------------------------------
1859 , Flag "fpackage-trust" (NoArg setPackageTrust)
1860 , Flag "fno-safe-infer" (NoArg (setSafeHaskell Sf_None))
1861 , Flag "fPIC" (NoArg setFPIC)
1862 , Flag "fno-PIC" (NoArg unSetFPIC)
1863 ]
1864 ++ map (mkFlag turnOn "" setDynFlag ) negatableFlags
1865 ++ map (mkFlag turnOff "no-" unSetDynFlag) negatableFlags
1866 ++ map (mkFlag turnOn "d" setDynFlag ) dFlags
1867 ++ map (mkFlag turnOff "dno-" unSetDynFlag) dFlags
1868 ++ map (mkFlag turnOn "f" setDynFlag ) fFlags
1869 ++ map (mkFlag turnOff "fno-" unSetDynFlag) fFlags
1870 ++ map (mkFlag turnOn "f" setWarningFlag ) fWarningFlags
1871 ++ map (mkFlag turnOff "fno-" unSetWarningFlag) fWarningFlags
1872 ++ map (mkFlag turnOn "f" setExtensionFlag ) fLangFlags
1873 ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags
1874 ++ map (mkFlag turnOn "X" setExtensionFlag ) xFlags
1875 ++ map (mkFlag turnOff "XNo" unSetExtensionFlag) xFlags
1876 ++ map (mkFlag turnOn "X" setLanguage) languageFlags
1877 ++ map (mkFlag turnOn "X" setSafeHaskell) safeHaskellFlags
1878 ++ [ Flag "XGenerics" (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support."))
1879 , Flag "XNoGenerics" (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support.")) ]
1880
1881 package_flags :: [Flag (CmdLineP DynFlags)]
1882 package_flags = [
1883 ------- Packages ----------------------------------------------------
1884 Flag "package-db" (HasArg (addPkgConfRef . PkgConfFile))
1885 , Flag "clear-package-db" (NoArg clearPkgConf)
1886 , Flag "no-global-package-db" (NoArg removeGlobalPkgConf)
1887 , Flag "no-user-package-db" (NoArg removeUserPkgConf)
1888 , Flag "global-package-db" (NoArg (addPkgConfRef GlobalPkgConf))
1889 , Flag "user-package-db" (NoArg (addPkgConfRef UserPkgConf))
1890
1891 -- backwards compat with GHC<=7.4 :
1892 , Flag "package-conf" (HasArg $ \path -> do
1893 addPkgConfRef (PkgConfFile path)
1894 deprecate "Use -package-db instead")
1895 , Flag "no-user-package-conf" (NoArg $ do
1896 removeUserPkgConf
1897 deprecate "Use -no-user-package-db instead")
1898
1899 , Flag "package-name" (hasArg setPackageName)
1900 , Flag "package-id" (HasArg exposePackageId)
1901 , Flag "package" (HasArg exposePackage)
1902 , Flag "hide-package" (HasArg hidePackage)
1903 , Flag "hide-all-packages" (NoArg (setDynFlag Opt_HideAllPackages))
1904 , Flag "ignore-package" (HasArg ignorePackage)
1905 , Flag "syslib" (HasArg (\s -> do exposePackage s
1906 deprecate "Use -package instead"))
1907 , Flag "distrust-all-packages" (NoArg (setDynFlag Opt_DistrustAllPackages))
1908 , Flag "trust" (HasArg trustPackage)
1909 , Flag "distrust" (HasArg distrustPackage)
1910 ]
1911
1912 type TurnOnFlag = Bool -- True <=> we are turning the flag on
1913 -- False <=> we are turning the flag off
1914 turnOn :: TurnOnFlag; turnOn = True
1915 turnOff :: TurnOnFlag; turnOff = False
1916
1917 type FlagSpec flag
1918 = ( String -- Flag in string form
1919 , flag -- Flag in internal form
1920 , TurnOnFlag -> DynP ()) -- Extra action to run when the flag is found
1921 -- Typically, emit a warning or error
1922
1923 mkFlag :: TurnOnFlag -- ^ True <=> it should be turned on
1924 -> String -- ^ The flag prefix
1925 -> (flag -> DynP ()) -- ^ What to do when the flag is found
1926 -> FlagSpec flag -- ^ Specification of this particular flag
1927 -> Flag (CmdLineP DynFlags)
1928 mkFlag turn_on flagPrefix f (name, flag, extra_action)
1929 = Flag (flagPrefix ++ name) (NoArg (f flag >> extra_action turn_on))
1930
1931 deprecatedForExtension :: String -> TurnOnFlag -> DynP ()
1932 deprecatedForExtension lang turn_on
1933 = deprecate ("use -X" ++ flag ++ " or pragma {-# LANGUAGE " ++ flag ++ " #-} instead")
1934 where
1935 flag | turn_on = lang
1936 | otherwise = "No"++lang
1937
1938 useInstead :: String -> TurnOnFlag -> DynP ()
1939 useInstead flag turn_on
1940 = deprecate ("Use -f" ++ no ++ flag ++ " instead")
1941 where
1942 no = if turn_on then "" else "no-"
1943
1944 nop :: TurnOnFlag -> DynP ()
1945 nop _ = return ()
1946
1947 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
1948 fWarningFlags :: [FlagSpec WarningFlag]
1949 fWarningFlags = [
1950 ( "warn-dodgy-foreign-imports", Opt_WarnDodgyForeignImports, nop ),
1951 ( "warn-dodgy-exports", Opt_WarnDodgyExports, nop ),
1952 ( "warn-dodgy-imports", Opt_WarnDodgyImports, nop ),
1953 ( "warn-duplicate-exports", Opt_WarnDuplicateExports, nop ),
1954 ( "warn-hi-shadowing", Opt_WarnHiShadows, nop ),
1955 ( "warn-implicit-prelude", Opt_WarnImplicitPrelude, nop ),
1956 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns, nop ),
1957 ( "warn-incomplete-uni-patterns", Opt_WarnIncompleteUniPatterns, nop ),
1958 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd, nop ),
1959 ( "warn-missing-fields", Opt_WarnMissingFields, nop ),
1960 ( "warn-missing-import-lists", Opt_WarnMissingImportList, nop ),
1961 ( "warn-missing-methods", Opt_WarnMissingMethods, nop ),
1962 ( "warn-missing-signatures", Opt_WarnMissingSigs, nop ),
1963 ( "warn-missing-local-sigs", Opt_WarnMissingLocalSigs, nop ),
1964 ( "warn-name-shadowing", Opt_WarnNameShadowing, nop ),
1965 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns, nop ),
1966 ( "warn-type-defaults", Opt_WarnTypeDefaults, nop ),
1967 ( "warn-monomorphism-restriction", Opt_WarnMonomorphism, nop ),
1968 ( "warn-unused-binds", Opt_WarnUnusedBinds, nop ),
1969 ( "warn-unused-imports", Opt_WarnUnusedImports, nop ),
1970 ( "warn-unused-matches", Opt_WarnUnusedMatches, nop ),
1971 ( "warn-warnings-deprecations", Opt_WarnWarningsDeprecations, nop ),
1972 ( "warn-deprecations", Opt_WarnWarningsDeprecations, nop ),
1973 ( "warn-deprecated-flags", Opt_WarnDeprecatedFlags, nop ),
1974 ( "warn-orphans", Opt_WarnOrphans, nop ),
1975 ( "warn-identities", Opt_WarnIdentities, nop ),
1976 ( "warn-auto-orphans", Opt_WarnAutoOrphans, nop ),
1977 ( "warn-tabs", Opt_WarnTabs, nop ),
1978 ( "warn-unrecognised-pragmas", Opt_WarnUnrecognisedPragmas, nop ),
1979 ( "warn-lazy-unlifted-bindings", Opt_WarnLazyUnliftedBindings, nop ),
1980 ( "warn-unused-do-bind", Opt_WarnUnusedDoBind, nop ),
1981 ( "warn-wrong-do-bind", Opt_WarnWrongDoBind, nop ),
1982 ( "warn-alternative-layout-rule-transitional", Opt_WarnAlternativeLayoutRuleTransitional, nop ),
1983 ( "warn-unsafe", Opt_WarnUnsafe, setWarnUnsafe ),
1984 ( "warn-safe", Opt_WarnSafe, setWarnSafe ),
1985 ( "warn-pointless-pragmas", Opt_WarnPointlessPragmas, nop ),
1986 ( "warn-unsupported-calling-conventions", Opt_WarnUnsupportedCallingConventions, nop ),
1987 ( "warn-inline-rule-shadowing", Opt_WarnInlineRuleShadowing, nop ) ]
1988
1989 -- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@
1990 negatableFlags :: [FlagSpec DynFlag]
1991 negatableFlags = [
1992 ( "ignore-dot-ghci", Opt_IgnoreDotGhci, nop ) ]
1993
1994 -- | These @-d\<blah\>@ flags can all be reversed with @-dno-\<blah\>@
1995 dFlags :: [FlagSpec DynFlag]
1996 dFlags = [
1997 ( "ppr-case-as-let", Opt_PprCaseAsLet, nop ) ]
1998
1999 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
2000 fFlags :: [FlagSpec DynFlag]
2001 fFlags = [
2002 ( "print-explicit-foralls", Opt_PrintExplicitForalls, nop ),
2003 ( "strictness", Opt_Strictness, nop ),
2004 ( "specialise", Opt_Specialise, nop ),
2005 ( "float-in", Opt_FloatIn, nop ),
2006 ( "static-argument-transformation", Opt_StaticArgumentTransformation, nop ),
2007 ( "full-laziness", Opt_FullLaziness, nop ),
2008 ( "liberate-case", Opt_LiberateCase, nop ),
2009 ( "spec-constr", Opt_SpecConstr, nop ),
2010 ( "cse", Opt_CSE, nop ),
2011 ( "pedantic-bottoms", Opt_PedanticBottoms, nop ),
2012 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas, nop ),
2013 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas, nop ),
2014 ( "expose-all-unfoldings", Opt_ExposeAllUnfoldings, nop ),
2015 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion, nop ),
2016 ( "ignore-asserts", Opt_IgnoreAsserts, nop ),
2017 ( "do-eta-reduction", Opt_DoEtaReduction, nop ),
2018 ( "case-merge", Opt_CaseMerge, nop ),
2019 ( "unbox-strict-fields", Opt_UnboxStrictFields, nop ),
2020 ( "dicts-cheap", Opt_DictsCheap, nop ),
2021 ( "excess-precision", Opt_ExcessPrecision, nop ),
2022 ( "eager-blackholing", Opt_EagerBlackHoling, nop ),
2023 ( "print-bind-result", Opt_PrintBindResult, nop ),
2024 ( "force-recomp", Opt_ForceRecomp, nop ),
2025 ( "hpc-no-auto", Opt_Hpc_No_Auto, nop ),
2026 ( "rewrite-rules", Opt_EnableRewriteRules, useInstead "enable-rewrite-rules" ),
2027 ( "enable-rewrite-rules", Opt_EnableRewriteRules, nop ),
2028 ( "break-on-exception", Opt_BreakOnException, nop ),
2029 ( "break-on-error", Opt_BreakOnError, nop ),
2030 ( "print-evld-with-show", Opt_PrintEvldWithShow, nop ),
2031 ( "print-bind-contents", Opt_PrintBindContents, nop ),
2032 ( "run-cps", Opt_RunCPS, nop ),
2033 ( "run-cpsz", Opt_RunCPSZ, nop ),
2034 ( "new-codegen", Opt_TryNewCodeGen, nop ),
2035 ( "vectorise", Opt_Vectorise, nop ),
2036 ( "avoid-vect", Opt_AvoidVect, nop ),
2037 ( "regs-graph", Opt_RegsGraph, nop ),
2038 ( "regs-iterative", Opt_RegsIterative, nop ),
2039 ( "llvm-tbaa", Opt_LlvmTBAA, nop), -- hidden flag
2040 ( "regs-liveness", Opt_RegLiveness, nop), -- hidden flag
2041 ( "irrefutable-tuples", Opt_IrrefutableTuples, nop ),
2042 ( "gen-manifest", Opt_GenManifest, nop ),
2043 ( "embed-manifest", Opt_EmbedManifest, nop ),
2044 ( "ext-core", Opt_EmitExternalCore, nop ),
2045 ( "shared-implib", Opt_SharedImplib, nop ),
2046 ( "ghci-sandbox", Opt_GhciSandbox, nop ),
2047 ( "ghci-history", Opt_GhciHistory, nop ),
2048 ( "helpful-errors", Opt_HelpfulErrors, nop ),
2049 ( "defer-type-errors", Opt_DeferTypeErrors, nop ),
2050 ( "parallel", Opt_Parallel, nop ),
2051 ( "scc-profiling", Opt_SccProfilingOn, nop ),
2052 ( "gransim", Opt_GranMacros, nop ),
2053 ( "building-cabal-package", Opt_BuildingCabalPackage, nop ),
2054 ( "implicit-import-qualified", Opt_ImplicitImportQualified, nop ),
2055 ( "prof-count-entries", Opt_ProfCountEntries, nop ),
2056 ( "prof-cafs", Opt_AutoSccsOnIndividualCafs, nop )
2057 ]
2058
2059 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
2060 fLangFlags :: [FlagSpec ExtensionFlag]
2061 fLangFlags = [
2062 ( "th", Opt_TemplateHaskell,
2063 deprecatedForExtension "TemplateHaskell" >> checkTemplateHaskellOk ),
2064 ( "fi", Opt_ForeignFunctionInterface,
2065 deprecatedForExtension "ForeignFunctionInterface" ),
2066 ( "ffi", Opt_ForeignFunctionInterface,
2067 deprecatedForExtension "ForeignFunctionInterface" ),
2068 ( "arrows", Opt_Arrows,
2069 deprecatedForExtension "Arrows" ),
2070 ( "implicit-prelude", Opt_ImplicitPrelude,
2071 deprecatedForExtension "ImplicitPrelude" ),
2072 ( "bang-patterns", Opt_BangPatterns,
2073 deprecatedForExtension "BangPatterns" ),
2074 ( "monomorphism-restriction", Opt_MonomorphismRestriction,
2075 deprecatedForExtension "MonomorphismRestriction" ),
2076 ( "mono-pat-binds", Opt_MonoPatBinds,
2077 deprecatedForExtension "MonoPatBinds" ),
2078 ( "extended-default-rules", Opt_ExtendedDefaultRules,
2079 deprecatedForExtension "ExtendedDefaultRules" ),
2080 ( "implicit-params", Opt_ImplicitParams,
2081 deprecatedForExtension "ImplicitParams" ),
2082 ( "scoped-type-variables", Opt_ScopedTypeVariables,
2083 deprecatedForExtension "ScopedTypeVariables" ),
2084 ( "parr", Opt_ParallelArrays,
2085 deprecatedForExtension "ParallelArrays" ),
2086 ( "PArr", Opt_ParallelArrays,
2087 deprecatedForExtension "ParallelArrays" ),
2088 ( "allow-overlapping-instances", Opt_OverlappingInstances,
2089 deprecatedForExtension "OverlappingInstances" ),
2090 ( "allow-undecidable-instances", Opt_UndecidableInstances,
2091 deprecatedForExtension "UndecidableInstances" ),
2092 ( "allow-incoherent-instances", Opt_IncoherentInstances,
2093 deprecatedForExtension "IncoherentInstances" )
2094 ]
2095
2096 supportedLanguages :: [String]
2097 supportedLanguages = [ name | (name, _, _) <- languageFlags ]
2098
2099 supportedLanguageOverlays :: [String]
2100 supportedLanguageOverlays = [ name | (name, _, _) <- safeHaskellFlags ]
2101
2102 supportedExtensions :: [String]
2103 supportedExtensions = [ name' | (name, _, _) <- xFlags, name' <- [name, "No" ++ name] ]
2104
2105 supportedLanguagesAndExtensions :: [String]
2106 supportedLanguagesAndExtensions =
2107 supportedLanguages ++ supportedLanguageOverlays ++ supportedExtensions
2108
2109 -- | These -X<blah> flags cannot be reversed with -XNo<blah>
2110 languageFlags :: [FlagSpec Language]
2111 languageFlags = [
2112 ( "Haskell98", Haskell98, nop ),
2113 ( "Haskell2010", Haskell2010, nop )
2114 ]
2115
2116 -- | These -X<blah> flags cannot be reversed with -XNo<blah>
2117 -- They are used to place hard requirements on what GHC Haskell language
2118 -- features can be used.
2119 safeHaskellFlags :: [FlagSpec SafeHaskellMode]
2120 safeHaskellFlags = [mkF Sf_Unsafe, mkF Sf_Trustworthy, mkF Sf_Safe]
2121 where mkF flag = (show flag, flag, nop)
2122
2123 -- | These -X<blah> flags can all be reversed with -XNo<blah>
2124 xFlags :: [FlagSpec ExtensionFlag]
2125 xFlags = [
2126 ( "CPP", Opt_Cpp, nop ),
2127 ( "PostfixOperators", Opt_PostfixOperators, nop ),
2128 ( "TupleSections", Opt_TupleSections, nop ),
2129 ( "PatternGuards", Opt_PatternGuards, nop ),
2130 ( "UnicodeSyntax", Opt_UnicodeSyntax, nop ),
2131 ( "MagicHash", Opt_MagicHash, nop ),
2132 ( "PolymorphicComponents", Opt_PolymorphicComponents, nop ),
2133 ( "ExistentialQuantification", Opt_ExistentialQuantification, nop ),
2134 ( "KindSignatures", Opt_KindSignatures, nop ),
2135 ( "EmptyDataDecls", Opt_EmptyDataDecls, nop ),
2136 ( "ParallelListComp", Opt_ParallelListComp, nop ),
2137 ( "TransformListComp", Opt_TransformListComp, nop ),
2138 ( "MonadComprehensions", Opt_MonadComprehensions, nop),
2139 ( "ForeignFunctionInterface", Opt_ForeignFunctionInterface, nop ),
2140 ( "UnliftedFFITypes", Opt_UnliftedFFITypes, nop ),
2141 ( "InterruptibleFFI", Opt_InterruptibleFFI, nop ),
2142 ( "CApiFFI", Opt_CApiFFI, nop ),
2143 ( "GHCForeignImportPrim", Opt_GHCForeignImportPrim, nop ),
2144 ( "LiberalTypeSynonyms", Opt_LiberalTypeSynonyms, nop ),
2145 ( "Rank2Types", Opt_Rank2Types, nop ),
2146 ( "RankNTypes", Opt_RankNTypes, nop ),
2147 ( "ImpredicativeTypes", Opt_ImpredicativeTypes, nop),
2148 ( "TypeOperators", Opt_TypeOperators, nop ),
2149 ( "ExplicitNamespaces", Opt_ExplicitNamespaces, nop ),
2150 ( "RecursiveDo", Opt_RecursiveDo, nop ), -- Enables 'mdo' and 'rec'
2151 ( "DoRec", Opt_RecursiveDo,
2152 deprecatedForExtension "RecursiveDo" ),
2153 ( "Arrows", Opt_Arrows, nop ),
2154 ( "ParallelArrays", Opt_ParallelArrays, nop ),
2155 ( "TemplateHaskell", Opt_TemplateHaskell, checkTemplateHaskellOk ),
2156 ( "QuasiQuotes", Opt_QuasiQuotes, nop ),
2157 ( "ImplicitPrelude", Opt_ImplicitPrelude, nop ),
2158 ( "RecordWildCards", Opt_RecordWildCards, nop ),
2159 ( "NamedFieldPuns", Opt_RecordPuns, nop ),
2160 ( "RecordPuns", Opt_RecordPuns,
2161 deprecatedForExtension "NamedFieldPuns" ),
2162 ( "DisambiguateRecordFields", Opt_DisambiguateRecordFields, nop ),
2163 ( "OverloadedStrings", Opt_OverloadedStrings, nop ),
2164 ( "GADTs", Opt_GADTs, nop ),
2165 ( "GADTSyntax", Opt_GADTSyntax, nop ),
2166 ( "ViewPatterns", Opt_ViewPatterns, nop ),
2167 ( "TypeFamilies", Opt_TypeFamilies, nop ),
2168 ( "BangPatterns", Opt_BangPatterns, nop ),
2169 ( "MonomorphismRestriction", Opt_MonomorphismRestriction, nop ),
2170 ( "NPlusKPatterns", Opt_NPlusKPatterns, nop ),
2171 ( "DoAndIfThenElse", Opt_DoAndIfThenElse, nop ),
2172 ( "RebindableSyntax", Opt_RebindableSyntax, nop ),
2173 ( "ConstraintKinds", Opt_ConstraintKinds, nop ),
2174 ( "PolyKinds", Opt_PolyKinds, nop ),
2175 ( "DataKinds", Opt_DataKinds, nop ),
2176 ( "InstanceSigs", Opt_InstanceSigs, nop ),
2177 ( "MonoPatBinds", Opt_MonoPatBinds,
2178 \ turn_on -> when turn_on $ deprecate "Experimental feature now removed; has no effect" ),
2179 ( "ExplicitForAll", Opt_ExplicitForAll, nop ),
2180 ( "AlternativeLayoutRule", Opt_AlternativeLayoutRule, nop ),
2181 ( "AlternativeLayoutRuleTransitional",Opt_AlternativeLayoutRuleTransitional, nop ),
2182 ( "DatatypeContexts", Opt_DatatypeContexts,
2183 \ turn_on -> when turn_on $ deprecate "It was widely considered a misfeature, and has been removed from the Haskell language." ),
2184 ( "NondecreasingIndentation", Opt_NondecreasingIndentation, nop ),
2185 ( "RelaxedLayout", Opt_RelaxedLayout, nop ),
2186 ( "TraditionalRecordSyntax", Opt_TraditionalRecordSyntax, nop ),
2187 ( "LambdaCase", Opt_LambdaCase, nop ),
2188 ( "MultiWayIf", Opt_MultiWayIf, nop ),
2189 ( "MonoLocalBinds", Opt_MonoLocalBinds, nop ),
2190 ( "RelaxedPolyRec", Opt_RelaxedPolyRec,
2191 \ turn_on -> if not turn_on
2192 then deprecate "You can't turn off RelaxedPolyRec any more"
2193 else return () ),
2194 ( "ExtendedDefaultRules", Opt_ExtendedDefaultRules, nop ),
2195 ( "ImplicitParams", Opt_ImplicitParams, nop ),
2196 ( "ScopedTypeVariables", Opt_ScopedTypeVariables, nop ),
2197
2198 ( "PatternSignatures", Opt_ScopedTypeVariables,
2199 deprecatedForExtension "ScopedTypeVariables" ),
2200
2201 ( "UnboxedTuples", Opt_UnboxedTuples, nop ),
2202 ( "StandaloneDeriving", Opt_StandaloneDeriving, nop ),
2203 ( "DeriveDataTypeable", Opt_DeriveDataTypeable, nop ),
2204 ( "DeriveFunctor", Opt_DeriveFunctor, nop ),
2205 ( "DeriveTraversable", Opt_DeriveTraversable, nop ),
2206 ( "DeriveFoldable", Opt_DeriveFoldable, nop ),
2207 ( "DeriveGeneric", Opt_DeriveGeneric, nop ),
2208 ( "DefaultSignatures", Opt_DefaultSignatures, nop ),
2209 ( "TypeSynonymInstances", Opt_TypeSynonymInstances, nop ),
2210 ( "FlexibleContexts", Opt_FlexibleContexts, nop ),
2211 ( "FlexibleInstances", Opt_FlexibleInstances, nop ),
2212 ( "ConstrainedClassMethods", Opt_ConstrainedClassMethods, nop ),
2213 ( "MultiParamTypeClasses", Opt_MultiParamTypeClasses, nop ),
2214 ( "FunctionalDependencies", Opt_FunctionalDependencies, nop ),
2215 ( "GeneralizedNewtypeDeriving", Opt_GeneralizedNewtypeDeriving, setGenDeriving ),
2216 ( "OverlappingInstances", Opt_OverlappingInstances, nop ),
2217 ( "UndecidableInstances", Opt_UndecidableInstances, nop ),
2218 ( "IncoherentInstances", Opt_IncoherentInstances, nop ),
2219 ( "PackageImports", Opt_PackageImports, nop )
2220 ]
2221
2222 defaultFlags :: Platform -> [DynFlag]
2223 defaultFlags platform
2224 = [ Opt_AutoLinkPackages,
2225
2226 Opt_SharedImplib,
2227
2228 #if GHC_DEFAULT_NEW_CODEGEN
2229 Opt_TryNewCodeGen,
2230 #endif
2231
2232 Opt_GenManifest,
2233 Opt_EmbedManifest,
2234 Opt_PrintBindContents,
2235 Opt_GhciSandbox,
2236 Opt_GhciHistory,
2237 Opt_HelpfulErrors,
2238 Opt_ProfCountEntries
2239 ]
2240
2241 ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
2242 -- The default -O0 options
2243
2244 ++ (case platformOS platform of
2245 OSDarwin ->
2246 case platformArch platform of
2247 ArchX86_64 -> [Opt_PIC]
2248 _ | not opt_Static -> [Opt_PIC]
2249 _ -> []
2250 _ -> [])
2251
2252 impliedFlags :: [(ExtensionFlag, TurnOnFlag, ExtensionFlag)]
2253 impliedFlags
2254 = [ (Opt_RankNTypes, turnOn, Opt_ExplicitForAll)
2255 , (Opt_Rank2Types, turnOn, Opt_ExplicitForAll)
2256 , (Opt_ScopedTypeVariables, turnOn, Opt_ExplicitForAll)
2257 , (Opt_LiberalTypeSynonyms, turnOn, Opt_ExplicitForAll)
2258 , (Opt_ExistentialQuantification, turnOn, Opt_ExplicitForAll)
2259 , (Opt_PolymorphicComponents, turnOn, Opt_ExplicitForAll)
2260 , (Opt_FlexibleInstances, turnOn, Opt_TypeSynonymInstances)
2261 , (Opt_FunctionalDependencies, turnOn, Opt_MultiParamTypeClasses)
2262
2263 , (Opt_RebindableSyntax, turnOff, Opt_ImplicitPrelude) -- NB: turn off!
2264
2265 , (Opt_GADTs, turnOn, Opt_GADTSyntax)
2266 , (Opt_GADTs, turnOn, Opt_MonoLocalBinds)
2267 , (Opt_TypeFamilies, turnOn, Opt_MonoLocalBinds)
2268
2269 , (Opt_TypeFamilies, turnOn, Opt_KindSignatures) -- Type families use kind signatures
2270 , (Opt_PolyKinds, turnOn, Opt_KindSignatures) -- Ditto polymorphic kinds
2271
2272 -- We turn this on so that we can export associated type
2273 -- type synonyms in subordinates (e.g. MyClass(type AssocType))
2274 , (Opt_TypeFamilies, turnOn, Opt_ExplicitNamespaces)
2275 , (Opt_TypeOperators, turnOn, Opt_ExplicitNamespaces)
2276
2277 , (Opt_ImpredicativeTypes, turnOn, Opt_RankNTypes)
2278
2279 -- Record wild-cards implies field disambiguation
2280 -- Otherwise if you write (C {..}) you may well get
2281 -- stuff like " 'a' not in scope ", which is a bit silly
2282 -- if the compiler has just filled in field 'a' of constructor 'C'
2283 , (Opt_RecordWildCards, turnOn, Opt_DisambiguateRecordFields)
2284
2285 , (Opt_ParallelArrays, turnOn, Opt_ParallelListComp)
2286
2287 -- An implicit parameter constraint, `?x::Int`, is desugared into
2288 -- `IP "x" Int`, which requires a flexible context/instance.
2289 , (Opt_ImplicitParams, turnOn, Opt_FlexibleContexts)
2290 , (Opt_ImplicitParams, turnOn, Opt_FlexibleInstances)
2291 ]
2292
2293 optLevelFlags :: [([Int], DynFlag)]
2294 optLevelFlags
2295 = [ ([0], Opt_IgnoreInterfacePragmas)
2296 , ([0], Opt_OmitInterfacePragmas)
2297
2298 , ([1,2], Opt_IgnoreAsserts)
2299 , ([1,2], Opt_EnableRewriteRules) -- Off for -O0; see Note [Scoping for Builtin rules]
2300 -- in PrelRules
2301 , ([1,2], Opt_DoEtaReduction)
2302 , ([1,2], Opt_CaseMerge)
2303 , ([1,2], Opt_Strictness)
2304 , ([1,2], Opt_CSE)
2305 , ([1,2], Opt_FullLaziness)
2306 , ([1,2], Opt_Specialise)
2307 , ([1,2], Opt_FloatIn)
2308
2309 , ([2], Opt_LiberateCase)
2310 , ([2], Opt_SpecConstr)
2311 , ([2], Opt_RegsGraph)
2312 , ([0,1,2], Opt_LlvmTBAA)
2313 , ([0,1,2], Opt_RegLiveness)
2314
2315 -- , ([2], Opt_StaticArgumentTransformation)
2316 -- Max writes: I think it's probably best not to enable SAT with -O2 for the
2317 -- 6.10 release. The version of SAT in HEAD at the moment doesn't incorporate
2318 -- several improvements to the heuristics, and I'm concerned that without
2319 -- those changes SAT will interfere with some attempts to write "high
2320 -- performance Haskell", as we saw in some posts on Haskell-Cafe earlier
2321 -- this year. In particular, the version in HEAD lacks the tail call
2322 -- criterion, so many things that look like reasonable loops will be
2323 -- turned into functions with extra (unneccesary) thunk creation.
2324
2325 , ([0,1,2], Opt_DoLambdaEtaExpansion)
2326 -- This one is important for a tiresome reason:
2327 -- we want to make sure that the bindings for data
2328 -- constructors are eta-expanded. This is probably
2329 -- a good thing anyway, but it seems fragile.
2330 ]
2331
2332 -- -----------------------------------------------------------------------------
2333 -- Standard sets of warning options
2334
2335 standardWarnings :: [WarningFlag]
2336 standardWarnings
2337 = [ Opt_WarnWarningsDeprecations,
2338 Opt_WarnDeprecatedFlags,
2339 Opt_WarnUnrecognisedPragmas,
2340 Opt_WarnOverlappingPatterns,
2341 Opt_WarnMissingFields,
2342 Opt_WarnMissingMethods,
2343 Opt_WarnDuplicateExports,
2344 Opt_WarnLazyUnliftedBindings,
2345 Opt_WarnDodgyForeignImports,
2346 Opt_WarnWrongDoBind,
2347 Opt_WarnAlternativeLayoutRuleTransitional,
2348 Opt_WarnPointlessPragmas,
2349 Opt_WarnUnsupportedCallingConventions
2350 ]
2351
2352 minusWOpts :: [WarningFlag]
2353 -- Things you get with -W
2354 minusWOpts
2355 = standardWarnings ++
2356 [ Opt_WarnUnusedBinds,
2357 Opt_WarnUnusedMatches,
2358 Opt_WarnUnusedImports,
2359 Opt_WarnIncompletePatterns,
2360 Opt_WarnDodgyExports,
2361 Opt_WarnDodgyImports
2362 ]
2363
2364 minusWallOpts :: [WarningFlag]
2365 -- Things you get with -Wall
2366 minusWallOpts
2367 = minusWOpts ++
2368 [ Opt_WarnTypeDefaults,
2369 Opt_WarnNameShadowing,
2370 Opt_WarnMissingSigs,
2371 Opt_WarnHiShadows,
2372 Opt_WarnOrphans,
2373 Opt_WarnUnusedDoBind
2374 ]
2375
2376 enableGlasgowExts :: DynP ()
2377 enableGlasgowExts = do setDynFlag Opt_PrintExplicitForalls
2378 mapM_ setExtensionFlag glasgowExtsFlags
2379
2380 disableGlasgowExts :: DynP ()
2381 disableGlasgowExts = do unSetDynFlag Opt_PrintExplicitForalls
2382 mapM_ unSetExtensionFlag glasgowExtsFlags
2383
2384 glasgowExtsFlags :: [ExtensionFlag]
2385 glasgowExtsFlags = [
2386 Opt_ForeignFunctionInterface
2387 , Opt_UnliftedFFITypes
2388 , Opt_ImplicitParams
2389 , Opt_ScopedTypeVariables
2390 , Opt_UnboxedTuples
2391 , Opt_TypeSynonymInstances
2392 , Opt_StandaloneDeriving
2393 , Opt_DeriveDataTypeable
2394 , Opt_DeriveFunctor
2395 , Opt_DeriveFoldable
2396 , Opt_DeriveTraversable
2397 , Opt_DeriveGeneric
2398 , Opt_FlexibleContexts
2399 , Opt_FlexibleInstances
2400 , Opt_ConstrainedClassMethods
2401 , Opt_MultiParamTypeClasses
2402 , Opt_FunctionalDependencies
2403 , Opt_MagicHash
2404 , Opt_PolymorphicComponents
2405 , Opt_ExistentialQuantification
2406 , Opt_UnicodeSyntax
2407 , Opt_PostfixOperators
2408 , Opt_PatternGuards
2409 , Opt_LiberalTypeSynonyms
2410 , Opt_RankNTypes
2411 , Opt_TypeOperators
2412 , Opt_ExplicitNamespaces
2413 , Opt_RecursiveDo
2414 , Opt_ParallelListComp
2415 , Opt_EmptyDataDecls
2416 , Opt_KindSignatures
2417 , Opt_GeneralizedNewtypeDeriving ]
2418
2419 #ifdef GHCI
2420 -- Consult the RTS to find whether GHC itself has been built profiled
2421 -- If so, you can't use Template Haskell
2422 foreign import ccall unsafe "rts_isProfiled" rtsIsProfiledIO :: IO CInt
2423
2424 rtsIsProfiled :: Bool
2425 rtsIsProfiled = unsafePerformIO rtsIsProfiledIO /= 0
2426 #endif
2427
2428 setWarnSafe :: Bool -> DynP ()
2429 setWarnSafe True = getCurLoc >>= \l -> upd (\d -> d { warnSafeOnLoc = l })
2430 setWarnSafe False = return ()
2431
2432 setWarnUnsafe :: Bool -> DynP ()
2433 setWarnUnsafe True = getCurLoc >>= \l -> upd (\d -> d { warnUnsafeOnLoc = l })
2434 setWarnUnsafe False = return ()
2435
2436 setPackageTrust :: DynP ()
2437 setPackageTrust = do
2438 setDynFlag Opt_PackageTrust
2439 l <- getCurLoc
2440 upd $ \d -> d { pkgTrustOnLoc = l }
2441
2442 setGenDeriving :: Bool -> DynP ()
2443 setGenDeriving True = getCurLoc >>= \l -> upd (\d -> d { newDerivOnLoc = l })
2444 setGenDeriving False = return ()
2445
2446 checkTemplateHaskellOk :: Bool -> DynP ()
2447 #ifdef GHCI
2448 checkTemplateHaskellOk turn_on
2449 | turn_on && rtsIsProfiled
2450 = addErr "You can't use Template Haskell with a profiled compiler"
2451 | otherwise
2452 = getCurLoc >>= \l -> upd (\d -> d { thOnLoc = l })
2453 #else
2454 -- In stage 1 we don't know that the RTS has rts_isProfiled,
2455 -- so we simply say "ok". It doesn't matter because TH isn't
2456 -- available in stage 1 anyway.
2457 checkTemplateHaskellOk _ = return ()
2458 #endif
2459
2460 {- **********************************************************************
2461 %* *
2462 DynFlags constructors
2463 %* *
2464 %********************************************************************* -}
2465
2466 type DynP = EwM (CmdLineP DynFlags)
2467
2468 upd :: (DynFlags -> DynFlags) -> DynP ()
2469 upd f = liftEwM (do dflags <- getCmdLineState
2470 putCmdLineState $! f dflags)
2471
2472 updM :: (DynFlags -> DynP DynFlags) -> DynP ()
2473 updM f = do dflags <- liftEwM getCmdLineState
2474 dflags' <- f dflags
2475 liftEwM $ putCmdLineState $! dflags'
2476
2477 --------------- Constructor functions for OptKind -----------------
2478 noArg :: (DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
2479 noArg fn = NoArg (upd fn)
2480
2481 noArgM :: (DynFlags -> DynP DynFlags) -> OptKind (CmdLineP DynFlags)
2482 noArgM fn = NoArg (updM fn)
2483
2484 noArgDF :: (DynFlags -> DynFlags) -> String -> OptKind (CmdLineP DynFlags)
2485 noArgDF fn deprec = NoArg (upd fn >> deprecate deprec)
2486
2487 hasArg :: (String -> DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
2488 hasArg fn = HasArg (upd . fn)
2489
2490 hasArgDF :: (String -> DynFlags -> DynFlags) -> String -> OptKind (CmdLineP DynFlags)
2491 hasArgDF fn deprec = HasArg (\s -> do upd (fn s)
2492 deprecate deprec)
2493
2494 sepArg :: (String -> DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
2495 sepArg fn = SepArg (upd . fn)
2496
2497 intSuffix :: (Int -> DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
2498 intSuffix fn = IntSuffix (\n -> upd (fn n))
2499
2500 optIntSuffixM :: (Maybe Int -> DynFlags -> DynP DynFlags)
2501 -> OptKind (CmdLineP DynFlags)
2502 optIntSuffixM fn = OptIntSuffix (\mi -> updM (fn mi))
2503
2504 setDumpFlag :: DynFlag -> OptKind (CmdLineP DynFlags)
2505 setDumpFlag dump_flag = NoArg (setDumpFlag' dump_flag)
2506
2507 --------------------------
2508 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
2509 setDynFlag f = upd (\dfs -> dopt_set dfs f)
2510 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
2511
2512 --------------------------
2513 setWarningFlag, unSetWarningFlag :: WarningFlag -> DynP ()
2514 setWarningFlag f = upd (\dfs -> wopt_set dfs f)
2515 unSetWarningFlag f = upd (\dfs -> wopt_unset dfs f)
2516
2517 --------------------------
2518 setExtensionFlag, unSetExtensionFlag :: ExtensionFlag -> DynP ()
2519 setExtensionFlag f = do upd (\dfs -> xopt_set dfs f)
2520 sequence_ deps
2521 where
2522 deps = [ if turn_on then setExtensionFlag d
2523 else unSetExtensionFlag d
2524 | (f', turn_on, d) <- impliedFlags, f' == f ]
2525 -- When you set f, set the ones it implies
2526 -- NB: use setExtensionFlag recursively, in case the implied flags
2527 -- implies further flags
2528
2529 unSetExtensionFlag f = upd (\dfs -> xopt_unset dfs f)
2530 -- When you un-set f, however, we don't un-set the things it implies
2531 -- (except for -fno-glasgow-exts, which is treated specially)
2532
2533 --------------------------
2534 alterSettings :: (Settings -> Settings) -> DynFlags -> DynFlags
2535 alterSettings f dflags = dflags { settings = f (settings dflags) }
2536
2537 --------------------------
2538 setDumpFlag' :: DynFlag -> DynP ()
2539 setDumpFlag' dump_flag
2540 = do setDynFlag dump_flag
2541 when want_recomp forceRecompile
2542 where
2543 -- Certain dumpy-things are really interested in what's going
2544 -- on during recompilation checking, so in those cases we
2545 -- don't want to turn it off.
2546 want_recomp = dump_flag `notElem` [Opt_D_dump_if_trace,
2547 Opt_D_dump_hi_diffs]
2548
2549 forceRecompile :: DynP ()
2550 -- Whenver we -ddump, force recompilation (by switching off the
2551 -- recompilation checker), else you don't see the dump! However,
2552 -- don't switch it off in --make mode, else *everything* gets
2553 -- recompiled which probably isn't what you want
2554 forceRecompile = do dfs <- liftEwM getCmdLineState
2555 when (force_recomp dfs) (setDynFlag Opt_ForceRecomp)
2556 where
2557 force_recomp dfs = isOneShot (ghcMode dfs)
2558
2559 setVerboseCore2Core :: DynP ()
2560 setVerboseCore2Core = do forceRecompile
2561 setDynFlag Opt_D_verbose_core2core
2562 upd (\dfs -> dfs { shouldDumpSimplPhase = Nothing })
2563
2564 setDumpSimplPhases :: String -> DynP ()
2565 setDumpSimplPhases s = do forceRecompile
2566 upd (\dfs -> dfs { shouldDumpSimplPhase = Just spec })
2567 where
2568 spec = case s of { ('=' : s') -> s'; _ -> s }
2569
2570 setVerbosity :: Maybe Int -> DynP ()
2571 setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
2572
2573 addCmdlineHCInclude :: String -> DynP ()
2574 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
2575
2576 data PkgConfRef
2577 = GlobalPkgConf
2578 | UserPkgConf
2579 | PkgConfFile FilePath
2580
2581 addPkgConfRef :: PkgConfRef -> DynP ()
2582 addPkgConfRef p = upd $ \s -> s { extraPkgConfs = (p:) . extraPkgConfs s }
2583
2584 removeUserPkgConf :: DynP ()
2585 removeUserPkgConf = upd $ \s -> s { extraPkgConfs = filter isNotUser . extraPkgConfs s }
2586 where
2587 isNotUser UserPkgConf = False
2588 isNotUser _ = True
2589
2590 removeGlobalPkgConf :: DynP ()
2591 removeGlobalPkgConf = upd $ \s -> s { extraPkgConfs = filter isNotGlobal . extraPkgConfs s }
2592 where
2593 isNotGlobal GlobalPkgConf = False
2594 isNotGlobal _ = True
2595
2596 clearPkgConf :: DynP ()
2597 clearPkgConf = upd $ \s -> s { extraPkgConfs = const [] }
2598
2599 exposePackage, exposePackageId, hidePackage, ignorePackage,
2600 trustPackage, distrustPackage :: String -> DynP ()
2601 exposePackage p =
2602 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
2603 exposePackageId p =
2604 upd (\s -> s{ packageFlags = ExposePackageId p : packageFlags s })
2605 hidePackage p =
2606 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
2607 ignorePackage p =
2608 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
2609 trustPackage p = exposePackage p >> -- both trust and distrust also expose a package
2610 upd (\s -> s{ packageFlags = TrustPackage p : packageFlags s })
2611 distrustPackage p = exposePackage p >>
2612 upd (\s -> s{ packageFlags = DistrustPackage p : packageFlags s })
2613
2614 setPackageName :: String -> DynFlags -> DynFlags
2615 setPackageName p s = s{ thisPackage = stringToPackageId p }
2616
2617 -- If we're linking a binary, then only targets that produce object
2618 -- code are allowed (requests for other target types are ignored).
2619 setTarget :: HscTarget -> DynP ()
2620 setTarget l = upd set
2621 where
2622 set dfs
2623 | ghcLink dfs /= LinkBinary || isObjectTarget l = dfs{ hscTarget = l }
2624 | otherwise = dfs
2625
2626 -- Changes the target only if we're compiling object code. This is
2627 -- used by -fasm and -fllvm, which switch from one to the other, but
2628 -- not from bytecode to object-code. The idea is that -fasm/-fllvm
2629 -- can be safely used in an OPTIONS_GHC pragma.
2630 setObjTarget :: HscTarget -> DynP ()
2631 setObjTarget l = updM set
2632 where
2633 set dflags
2634 | isObjectTarget (hscTarget dflags)
2635 = case l of
2636 HscC
2637 | cGhcUnregisterised /= "YES" ->
2638 do addWarn ("Compiler not unregisterised, so ignoring " ++ flag)
2639 return dflags
2640 HscAsm
2641 | cGhcWithNativeCodeGen /= "YES" ->
2642 do addWarn ("Compiler has no native codegen, so ignoring " ++
2643 flag)
2644 return dflags
2645 HscLlvm
2646 | not ((arch == ArchX86_64) && (os == OSLinux || os == OSDarwin)) &&
2647 (not opt_Static || dopt Opt_PIC dflags)
2648 ->
2649 do addWarn ("Ignoring " ++ flag ++ " as it is incompatible with -fPIC and -dynamic on this platform")
2650 return dflags
2651 _ -> return $ dflags { hscTarget = l }
2652 | otherwise = return dflags
2653 where platform = targetPlatform dflags
2654 arch = platformArch platform
2655 os = platformOS platform
2656 flag = showHscTargetFlag l
2657
2658 setFPIC :: DynP ()
2659 setFPIC = updM set
2660 where
2661 set dflags
2662 | cGhcWithNativeCodeGen == "YES" || cGhcUnregisterised == "YES"
2663 = let platform = targetPlatform dflags
2664 in case hscTarget dflags of
2665 HscLlvm
2666 | (platformArch platform == ArchX86_64) &&
2667 (platformOS platform `elem` [OSLinux, OSDarwin]) ->
2668 do addWarn "Ignoring -fPIC as it is incompatible with LLVM on this platform"
2669 return dflags
2670 _ -> return $ dopt_set dflags Opt_PIC
2671 | otherwise
2672 = ghcError $ CmdLineError "-fPIC is not supported on this platform"
2673
2674 unSetFPIC :: DynP ()
2675 unSetFPIC = updM set
2676 where
2677 set dflags
2678 = let platform = targetPlatform dflags
2679 in case platformOS platform of
2680 OSDarwin
2681 | platformArch platform == ArchX86_64 ->
2682 do addWarn "Ignoring -fno-PIC on this platform"
2683 return dflags
2684 _ | not opt_Static ->
2685 do addWarn "Ignoring -fno-PIC as -fstatic is off"
2686 return dflags
2687 _ -> return $ dopt_unset dflags Opt_PIC
2688
2689 setOptLevel :: Int -> DynFlags -> DynP DynFlags
2690 setOptLevel n dflags
2691 | hscTarget dflags == HscInterpreted && n > 0
2692 = do addWarn "-O conflicts with --interactive; -O ignored."
2693 return dflags
2694 | otherwise
2695 = return (updOptLevel n dflags)
2696
2697
2698 -- -Odph is equivalent to
2699 --
2700 -- -O2 optimise as much as possible
2701 -- -fmax-simplifier-iterations20 this is necessary sometimes
2702 -- -fsimplifier-phases=3 we use an additional simplifier phase for fusion
2703 --
2704 setDPHOpt :: DynFlags -> DynP DynFlags
2705 setDPHOpt dflags = setOptLevel 2 (dflags { maxSimplIterations = 20
2706 , simplPhases = 3
2707 })
2708
2709 setMainIs :: String -> DynP ()
2710 setMainIs arg
2711 | not (null main_fn) && isLower (head main_fn)
2712 -- The arg looked like "Foo.Bar.baz"
2713 = upd $ \d -> d{ mainFunIs = Just main_fn,
2714 mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
2715
2716 | isUpper (head arg) -- The arg looked like "Foo" or "Foo.Bar"
2717 = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName arg) }
2718
2719 | otherwise -- The arg looked like "baz"
2720 = upd $ \d -> d{ mainFunIs = Just arg }
2721 where
2722 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
2723
2724 -----------------------------------------------------------------------------
2725 -- Paths & Libraries
2726
2727 addImportPath, addLibraryPath, addIncludePath, addFrameworkPath :: FilePath -> DynP ()
2728
2729 -- -i on its own deletes the import paths
2730 addImportPath "" = upd (\s -> s{importPaths = []})
2731 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
2732
2733 addLibraryPath p =
2734 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
2735
2736 addIncludePath p =
2737 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
2738
2739 addFrameworkPath p =
2740 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
2741
2742 #ifndef mingw32_TARGET_OS
2743 split_marker :: Char
2744 split_marker = ':' -- not configurable (ToDo)
2745 #endif
2746
2747 splitPathList :: String -> [String]
2748 splitPathList s = filter notNull (splitUp s)
2749 -- empty paths are ignored: there might be a trailing
2750 -- ':' in the initial list, for example. Empty paths can
2751 -- cause confusion when they are translated into -I options
2752 -- for passing to gcc.
2753 where
2754 #ifndef mingw32_TARGET_OS
2755 splitUp xs = split split_marker xs
2756 #else
2757 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
2758 --
2759 -- That is, if "foo:bar:baz" is used, this interpreted as
2760 -- consisting of three entries, 'foo', 'bar', 'baz'.
2761 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
2762 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
2763 --
2764 -- Notice that no attempt is made to fully replace the 'standard'
2765 -- split marker ':' with the Windows / DOS one, ';'. The reason being
2766 -- that this will cause too much breakage for users & ':' will
2767 -- work fine even with DOS paths, if you're not insisting on being silly.
2768 -- So, use either.
2769 splitUp [] = []
2770 splitUp (x:':':div:xs) | div `elem` dir_markers
2771 = ((x:':':div:p): splitUp rs)
2772 where
2773 (p,rs) = findNextPath xs
2774 -- we used to check for existence of the path here, but that
2775 -- required the IO monad to be threaded through the command-line
2776 -- parser which is quite inconvenient. The
2777 splitUp xs = cons p (splitUp rs)
2778 where
2779 (p,rs) = findNextPath xs
2780
2781 cons "" xs = xs
2782 cons x xs = x:xs
2783
2784 -- will be called either when we've consumed nought or the
2785 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
2786 -- finding the next split marker.
2787 findNextPath xs =
2788 case break (`elem` split_markers) xs of
2789 (p, _:ds) -> (p, ds)
2790 (p, xs) -> (p, xs)
2791
2792 split_markers :: [Char]
2793 split_markers = [':', ';']
2794
2795 dir_markers :: [Char]
2796 dir_markers = ['/', '\\']
2797 #endif
2798
2799 -- -----------------------------------------------------------------------------
2800 -- tmpDir, where we store temporary files.
2801
2802 setTmpDir :: FilePath -> DynFlags -> DynFlags
2803 setTmpDir dir = alterSettings (\s -> s { sTmpDir = normalise dir })
2804 -- we used to fix /cygdrive/c/.. on Windows, but this doesn't
2805 -- seem necessary now --SDM 7/2/2008
2806
2807 -----------------------------------------------------------------------------
2808 -- RTS opts
2809
2810 setRtsOpts :: String -> DynP ()
2811 setRtsOpts arg = upd $ \ d -> d {rtsOpts = Just arg}
2812
2813 setRtsOptsEnabled :: RtsOptsEnabled -> DynP ()
2814 setRtsOptsEnabled arg = upd $ \ d -> d {rtsOptsEnabled = arg}
2815
2816 -----------------------------------------------------------------------------
2817 -- Hpc stuff
2818
2819 setOptHpcDir :: String -> DynP ()
2820 setOptHpcDir arg = upd $ \ d -> d{hpcDir = arg}
2821
2822 -----------------------------------------------------------------------------
2823 -- Via-C compilation stuff
2824
2825 -- There are some options that we need to pass to gcc when compiling
2826 -- Haskell code via C, but are only supported by recent versions of
2827 -- gcc. The configure script decides which of these options we need,
2828 -- and puts them in the "settings" file in $topdir. The advantage of
2829 -- having these in a separate file is that the file can be created at
2830 -- install-time depending on the available gcc version, and even
2831 -- re-generated later if gcc is upgraded.
2832 --
2833 -- The options below are not dependent on the version of gcc, only the
2834 -- platform.
2835
2836 picCCOpts :: DynFlags -> [String]
2837 picCCOpts dflags
2838 = case platformOS (targetPlatform dflags) of
2839 OSDarwin
2840 -- Apple prefers to do things the other way round.
2841 -- PIC is on by default.
2842 -- -mdynamic-no-pic:
2843 -- Turn off PIC code generation.
2844 -- -fno-common:
2845 -- Don't generate "common" symbols - these are unwanted
2846 -- in dynamic libraries.
2847
2848 | dopt Opt_PIC dflags -> ["-fno-common", "-U __PIC__", "-D__PIC__"]
2849 | otherwise -> ["-mdynamic-no-pic"]
2850 OSMinGW32 -- no -fPIC for Windows
2851 | dopt Opt_PIC dflags -> ["-U __PIC__", "-D__PIC__"]
2852 | otherwise -> []
2853 _
2854 -- we need -fPIC for C files when we are compiling with -dynamic,
2855 -- otherwise things like stub.c files don't get compiled
2856 -- correctly. They need to reference data in the Haskell
2857 -- objects, but can't without -fPIC. See
2858 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode
2859 | dopt Opt_PIC dflags || not opt_Static -> ["-fPIC", "-U __PIC__", "-D__PIC__"]
2860 | otherwise -> []
2861
2862 picPOpts :: DynFlags -> [String]
2863 picPOpts dflags
2864 | dopt Opt_PIC dflags = ["-U __PIC__", "-D__PIC__"]
2865 | otherwise = []
2866
2867 -- -----------------------------------------------------------------------------
2868 -- Splitting
2869
2870 can_split :: Bool
2871 can_split = cSupportsSplitObjs == "YES"
2872
2873 -- -----------------------------------------------------------------------------
2874 -- Compiler Info
2875
2876 compilerInfo :: DynFlags -> [(String, String)]
2877 compilerInfo dflags
2878 = -- We always make "Project name" be first to keep parsing in
2879 -- other languages simple, i.e. when looking for other fields,
2880 -- you don't have to worry whether there is a leading '[' or not
2881 ("Project name", cProjectName)
2882 -- Next come the settings, so anything else can be overridden
2883 -- in the settings file (as "lookup" uses the first match for the
2884 -- key)
2885 : rawSettings dflags
2886 ++ [("Project version", cProjectVersion),
2887 ("Booter version", cBooterVersion),
2888 ("Stage", cStage),
2889 ("Build platform", cBuildPlatformString),
2890 ("Host platform", cHostPlatformString),
2891 ("Target platform", cTargetPlatformString),
2892 ("Have interpreter", cGhcWithInterpreter),
2893 ("Object splitting supported", cSupportsSplitObjs),
2894 ("Have native code generator", cGhcWithNativeCodeGen),
2895 ("Support SMP", cGhcWithSMP),
2896 ("Unregisterised", cGhcUnregisterised),
2897 ("Tables next to code", cGhcEnableTablesNextToCode),
2898 ("RTS ways", cGhcRTSWays),
2899 ("Leading underscore", cLeadingUnderscore),
2900 ("Debug on", show debugIsOn),
2901 ("LibDir", topDir dflags),
2902 ("Global Package DB", systemPackageConfig dflags),
2903 ("Gcc Linker flags", show cGccLinkerOpts),
2904 ("Ld Linker flags", show cLdLinkerOpts)
2905 ]
2906