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