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