2 {-# OPTIONS -fno-warn-missing-fields #-}
4 -- The above warning supression flag is a temporary kludge.
5 -- While working on this module you are encouraged to remove it and fix
6 -- any warnings in the module. See
7 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
10 -----------------------------------------------------------------------------
14 -- Most flags are dynamic flags, which means they can change from
15 -- compilation to compilation using OPTIONS_GHC pragmas, and in a
16 -- multi-session GHC each session can be using different dynamic
17 -- flags. Dynamic flags can also be set at the prompt in GHCi.
19 -- (c) The University of Glasgow 2005
21 -----------------------------------------------------------------------------
27 HscTarget(..), isObjectTarget, defaultObjectTarget,
28 GhcMode(..), isOneShot,
29 GhcLink(..), isNoLink,
33 -- Configuration of the core-to-core and stg-to-stg phases
37 SimplifierMode(..), FloatOutSwitches(..),
38 getCoreToDo, getStgToDo,
40 -- Manipulating DynFlags
41 defaultDynFlags, -- DynFlags
42 initDynFlags, -- DynFlags -> IO DynFlags
44 dopt, -- DynFlag -> DynFlags -> Bool
45 dopt_set, dopt_unset, -- DynFlags -> DynFlag -> DynFlags
46 getOpts, -- (DynFlags -> [a]) -> IO [a]
57 machdepCCOpts, picCCOpts,
62 #include "HsVersions.h"
66 import PrelNames ( mAIN )
67 #ifdef i386_TARGET_ARCH
68 import StaticFlags ( opt_Static )
70 import StaticFlags ( opt_PIC, WayName(..), v_Ways, v_Build_tag,
72 import {-# SOURCE #-} Packages (PackageState)
73 import DriverPhases ( Phase(..), phaseInputExt )
76 import Constants ( mAX_CONTEXT_REDUCTION_DEPTH )
77 import Panic ( panic, GhcException(..) )
78 import UniqFM ( UniqFM )
80 import Maybes ( orElse, fromJust )
81 import SrcLoc ( SrcSpan )
83 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
85 import Data.IORef ( readIORef )
86 import Control.Exception ( throwDyn )
87 import Control.Monad ( when )
88 #ifdef mingw32_TARGET_OS
89 import Data.List ( isPrefixOf )
95 import System.IO ( hPutStrLn, stderr )
97 -- -----------------------------------------------------------------------------
105 | Opt_D_dump_cmmz_pretty
109 | Opt_D_dump_asm_native
110 | Opt_D_dump_asm_liveness
111 | Opt_D_dump_asm_coalesce
112 | Opt_D_dump_asm_regalloc
113 | Opt_D_dump_asm_regalloc_stages
114 | Opt_D_dump_asm_conflicts
115 | Opt_D_dump_asm_stats
121 | Opt_D_dump_inlinings
122 | Opt_D_dump_rule_firings
123 | Opt_D_dump_occur_anal
127 | Opt_D_dump_simpl_iterations
136 | Opt_D_dump_worker_wrapper
137 | Opt_D_dump_rn_trace
138 | Opt_D_dump_rn_stats
140 | Opt_D_dump_simpl_stats
141 | Opt_D_dump_tc_trace
142 | Opt_D_dump_if_trace
148 | Opt_D_verbose_core2core
149 | Opt_D_verbose_stg2stg
151 | Opt_D_dump_hi_diffs
152 | Opt_D_dump_minimal_imports
153 | Opt_D_dump_mod_cycles
154 | Opt_D_dump_view_pattern_commoning
155 | Opt_D_faststring_stats
156 | Opt_DumpToFile -- ^ Append dump output to files instead of stdout.
162 | Opt_WarnIsError -- -Werror; makes warnings fatal
163 | Opt_WarnDuplicateExports
165 | Opt_WarnImplicitPrelude
166 | Opt_WarnIncompletePatterns
167 | Opt_WarnIncompletePatternsRecUpd
168 | Opt_WarnMissingFields
169 | Opt_WarnMissingMethods
170 | Opt_WarnMissingSigs
171 | Opt_WarnNameShadowing
172 | Opt_WarnOverlappingPatterns
173 | Opt_WarnSimplePatterns
174 | Opt_WarnTypeDefaults
175 | Opt_WarnMonomorphism
176 | Opt_WarnUnusedBinds
177 | Opt_WarnUnusedImports
178 | Opt_WarnUnusedMatches
179 | Opt_WarnDeprecations
180 | Opt_WarnDodgyImports
185 | Opt_OverlappingInstances
186 | Opt_UndecidableInstances
187 | Opt_IncoherentInstances
188 | Opt_MonomorphismRestriction
190 | Opt_ExtendedDefaultRules -- Use GHC's extended rules for defaulting
191 | Opt_ForeignFunctionInterface
192 | Opt_UnliftedFFITypes
193 | Opt_PArr -- Syntactic support for parallel arrays
194 | Opt_Arrows -- Arrow-notation syntax
195 | Opt_TemplateHaskell
198 | Opt_ImplicitPrelude
199 | Opt_ScopedTypeVariables
203 | Opt_OverloadedStrings
204 | Opt_DisambiguateRecordFields
205 | Opt_RecordWildCards
210 | Opt_StandaloneDeriving
211 | Opt_DeriveDataTypeable
212 | Opt_TypeSynonymInstances
213 | Opt_FlexibleContexts
214 | Opt_FlexibleInstances
215 | Opt_ConstrainedClassMethods
216 | Opt_MultiParamTypeClasses
217 | Opt_FunctionalDependencies
219 | Opt_PolymorphicComponents
220 | Opt_ExistentialQuantification
224 | Opt_PatternSignatures
225 | Opt_ParallelListComp
226 | Opt_GeneralizedNewtypeDeriving
229 | Opt_LiberalTypeSynonyms
234 | Opt_PrintExplicitForalls
242 | Opt_IgnoreInterfacePragmas
243 | Opt_OmitInterfacePragmas
244 | Opt_DoLambdaEtaExpansion
246 | Opt_IgnoreBreakpoints
249 | Opt_UnboxStrictFields
253 | Opt_RegsGraph -- do graph coloring register allocation
254 | Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
262 | Opt_ExcessPrecision
263 | Opt_ReadUserPackageConf
267 | Opt_HideAllPackages
268 | Opt_PrintBindResult
272 | Opt_BreakOnException
274 | Opt_PrintEvldWithShow
278 | Opt_ConvertToZipCfgAndBack
289 data DynFlags = DynFlags {
292 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
293 stgToDo :: Maybe [StgToDo], -- similarly
294 hscTarget :: HscTarget,
295 hscOutName :: String, -- name of the output file
296 extCoreName :: String, -- name of the .core output file
297 verbosity :: Int, -- verbosity level
298 optLevel :: Int, -- optimisation level
299 maxSimplIterations :: Int, -- max simplifier iterations
300 ruleCheck :: Maybe String,
302 specThreshold :: Int, -- Threshold for function specialisation
304 stolen_x86_regs :: Int,
305 cmdlineHcIncludes :: [String], -- -#includes
306 importPaths :: [FilePath],
308 mainFunIs :: Maybe String,
309 ctxtStkDepth :: Int, -- Typechecker context stack depth
311 thisPackage :: PackageId,
314 wayNames :: [WayName], -- way flags from the cmd line
315 buildTag :: String, -- the global "way" (eg. "p" for prof)
316 rtsBuildTag :: String, -- the RTS "way"
319 objectDir :: Maybe String,
320 hiDir :: Maybe String,
321 stubDir :: Maybe String,
327 outputFile :: Maybe String,
328 outputHi :: Maybe String,
330 -- | This is set by DriverPipeline.runPipeline based on where
331 -- its output is going.
332 dumpPrefix :: Maybe FilePath,
334 -- | Override the dumpPrefix set by runPipeline.
335 -- Set by -ddump-file-prefix
336 dumpPrefixForce :: Maybe FilePath,
338 includePaths :: [String],
339 libraryPaths :: [String],
340 frameworkPaths :: [String], -- used on darwin only
341 cmdlineFrameworks :: [String], -- ditto
342 tmpDir :: String, -- no trailing '/'
344 ghcUsagePath :: FilePath, -- Filled in by SysTools
345 ghciUsagePath :: FilePath, -- ditto
347 hpcDir :: String, -- ^ path to store the .mix files
349 -- options for particular phases
358 opt_windres :: [String],
360 -- commands for particular phases
362 pgm_P :: (String,[Option]),
364 pgm_c :: (String,[Option]),
365 pgm_m :: (String,[Option]),
366 pgm_s :: (String,[Option]),
367 pgm_a :: (String,[Option]),
368 pgm_l :: (String,[Option]),
369 pgm_dll :: (String,[Option]),
371 pgm_sysman :: String,
372 pgm_windres :: String,
375 extraPkgConfs :: [FilePath],
376 topDir :: FilePath, -- filled in by SysTools
377 systemPackageConfig :: FilePath, -- ditto
378 -- The -package-conf flags given on the command line, in the order
381 packageFlags :: [PackageFlag],
382 -- The -package and -hide-package flags from the command-line
385 -- NB. do not modify this field, it is calculated by
386 -- Packages.initPackages and Packages.updatePackages.
387 pkgDatabase :: Maybe (UniqFM PackageConfig),
388 pkgState :: PackageState,
394 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO (),
396 haddockOptions :: Maybe String
407 -- | will this target result in an object file on the disk?
408 isObjectTarget :: HscTarget -> Bool
409 isObjectTarget HscC = True
410 isObjectTarget HscAsm = True
411 isObjectTarget _ = False
413 -- | The 'GhcMode' tells us whether we're doing multi-module
414 -- compilation (controlled via the "GHC" API) or one-shot
415 -- (single-module) compilation. This makes a difference primarily to
416 -- the "Finder": in one-shot mode we look for interface files for
417 -- imported modules, but in multi-module mode we look for source files
418 -- in order to check whether they need to be recompiled.
420 = CompManager -- ^ --make, GHCi, etc.
421 | OneShot -- ^ ghc -c Foo.hs
422 | MkDepend -- ^ ghc -M, see Finder for why we need this
425 isOneShot :: GhcMode -> Bool
426 isOneShot OneShot = True
427 isOneShot _other = False
429 -- | What kind of linking to do.
430 data GhcLink -- What to do in the link step, if there is one
431 = NoLink -- Don't link at all
432 | LinkBinary -- Link object code into a binary
433 | LinkInMemory -- Use the in-memory dynamic linker
434 | LinkDynLib -- Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
437 isNoLink :: GhcLink -> Bool
438 isNoLink NoLink = True
439 isNoLink other = False
442 = ExposePackage String
444 | IgnorePackage String
447 defaultHscTarget = defaultObjectTarget
449 -- | the 'HscTarget' value corresponding to the default way to create
450 -- object files on the current platform.
452 | cGhcWithNativeCodeGen == "YES" = HscAsm
455 initDynFlags dflags = do
456 -- someday these will be dynamic flags
457 ways <- readIORef v_Ways
458 build_tag <- readIORef v_Build_tag
459 rts_build_tag <- readIORef v_RTS_Build_tag
462 buildTag = build_tag,
463 rtsBuildTag = rts_build_tag
468 ghcMode = CompManager,
469 ghcLink = LinkBinary,
472 hscTarget = defaultHscTarget,
477 maxSimplIterations = 4,
481 cmdlineHcIncludes = [],
485 ctxtStkDepth = mAX_CONTEXT_REDUCTION_DEPTH,
487 thisPackage = mainPackageId,
493 objectSuf = phaseInputExt StopLn,
494 hcSuf = phaseInputExt HCc,
497 outputFile = Nothing,
499 dumpPrefix = Nothing,
500 dumpPrefixForce = Nothing,
504 cmdlineFrameworks = [],
505 tmpDir = cDEFAULT_TMPDIR,
523 pkgDatabase = Nothing,
524 pkgState = panic "no package state yet: call GHC.setSessionDynFlags",
525 haddockOptions = Nothing,
527 Opt_ReadUserPackageConf,
529 Opt_MonoPatBinds, -- Experimentally, I'm making this non-standard
530 -- behaviour the default, to see if anyone notices
534 Opt_MonomorphismRestriction,
542 Opt_PrintBindResult ]
543 ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
544 -- The default -O0 options
547 log_action = \severity srcSpan style msg ->
549 SevInfo -> hPutStrLn stderr (show (msg style))
550 SevFatal -> hPutStrLn stderr (show (msg style))
551 _ -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
557 0 | print errors & warnings only
558 1 | minimal verbosity: print "compiling M ... done." for each module.
559 2 | equivalent to -dshow-passes
560 3 | equivalent to existing "ghc -v"
561 4 | "ghc -v -ddump-most"
562 5 | "ghc -v -ddump-all"
565 dopt :: DynFlag -> DynFlags -> Bool
566 dopt f dflags = f `elem` (flags dflags)
568 dopt_set :: DynFlags -> DynFlag -> DynFlags
569 dopt_set dfs f = dfs{ flags = f : flags dfs }
571 dopt_unset :: DynFlags -> DynFlag -> DynFlags
572 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
574 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
575 getOpts dflags opts = reverse (opts dflags)
576 -- We add to the options from the front, so we need to reverse the list
578 getVerbFlag :: DynFlags -> String
580 | verbosity dflags >= 3 = "-v"
583 setObjectDir f d = d{ objectDir = Just f}
584 setHiDir f d = d{ hiDir = Just f}
585 setStubDir f d = d{ stubDir = Just f, includePaths = f : includePaths d }
586 -- -stubdir D adds an implicit -I D, so that gcc can find the _stub.h file
587 -- #included from the .hc file when compiling with -fvia-C.
589 setObjectSuf f d = d{ objectSuf = f}
590 setHiSuf f d = d{ hiSuf = f}
591 setHcSuf f d = d{ hcSuf = f}
593 setOutputFile f d = d{ outputFile = f}
594 setOutputHi f d = d{ outputHi = f}
596 setDumpPrefixForce f d = d { dumpPrefixForce = f}
598 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
599 -- Config.hs should really use Option.
600 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
602 setPgmL f d = d{ pgm_L = f}
603 setPgmF f d = d{ pgm_F = f}
604 setPgmc f d = d{ pgm_c = (f,[])}
605 setPgmm f d = d{ pgm_m = (f,[])}
606 setPgms f d = d{ pgm_s = (f,[])}
607 setPgma f d = d{ pgm_a = (f,[])}
608 setPgml f d = d{ pgm_l = (f,[])}
609 setPgmdll f d = d{ pgm_dll = (f,[])}
610 setPgmwindres f d = d{ pgm_windres = f}
612 addOptL f d = d{ opt_L = f : opt_L d}
613 addOptP f d = d{ opt_P = f : opt_P d}
614 addOptF f d = d{ opt_F = f : opt_F d}
615 addOptc f d = d{ opt_c = f : opt_c d}
616 addOptm f d = d{ opt_m = f : opt_m d}
617 addOpta f d = d{ opt_a = f : opt_a d}
618 addOptl f d = d{ opt_l = f : opt_l d}
619 addOptdep f d = d{ opt_dep = f : opt_dep d}
620 addOptwindres f d = d{ opt_windres = f : opt_windres d}
622 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
624 addHaddockOpts f d = d{ haddockOptions = Just f}
626 -- -----------------------------------------------------------------------------
627 -- Command-line options
629 -- When invoking external tools as part of the compilation pipeline, we
630 -- pass these a sequence of options on the command-line. Rather than
631 -- just using a list of Strings, we use a type that allows us to distinguish
632 -- between filepaths and 'other stuff'. [The reason being, of course, that
633 -- this type gives us a handle on transforming filenames, and filenames only,
634 -- to whatever format they're expected to be on a particular platform.]
637 = FileOption -- an entry that _contains_ filename(s) / filepaths.
638 String -- a non-filepath prefix that shouldn't be
639 -- transformed (e.g., "/out=")
640 String -- the filepath/filename portion
643 -----------------------------------------------------------------------------
644 -- Setting the optimisation level
646 updOptLevel :: Int -> DynFlags -> DynFlags
647 -- Set dynflags appropriate to the optimisation level
649 = dfs2{ optLevel = final_n }
651 final_n = max 0 (min 2 n) -- Clamp to 0 <= n <= 2
652 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
653 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
655 extra_dopts = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
656 remove_dopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
658 optLevelFlags :: [([Int], DynFlag)]
660 = [ ([0], Opt_IgnoreInterfacePragmas)
661 , ([0], Opt_OmitInterfacePragmas)
663 , ([1,2], Opt_IgnoreAsserts)
664 , ([1,2], Opt_RewriteRules) -- Off for -O0; see Note [Scoping for Builtin rules]
666 , ([1,2], Opt_DoEtaReduction)
667 , ([1,2], Opt_CaseMerge)
668 , ([1,2], Opt_Strictness)
670 , ([1,2], Opt_FullLaziness)
672 , ([2], Opt_LiberateCase)
673 , ([2], Opt_SpecConstr)
675 , ([0,1,2], Opt_DoLambdaEtaExpansion)
676 -- This one is important for a tiresome reason:
677 -- we want to make sure that the bindings for data
678 -- constructors are eta-expanded. This is probably
679 -- a good thing anyway, but it seems fragile.
682 -- -----------------------------------------------------------------------------
683 -- Standard sets of warning options
686 = [ Opt_WarnDeprecations,
687 Opt_WarnOverlappingPatterns,
688 Opt_WarnMissingFields,
689 Opt_WarnMissingMethods,
690 Opt_WarnDuplicateExports
694 = standardWarnings ++
695 [ Opt_WarnUnusedBinds,
696 Opt_WarnUnusedMatches,
697 Opt_WarnUnusedImports,
698 Opt_WarnIncompletePatterns,
704 [ Opt_WarnTypeDefaults,
705 Opt_WarnNameShadowing,
711 -- minuswRemovesOpts should be every warning option
714 [Opt_WarnImplicitPrelude,
715 Opt_WarnIncompletePatternsRecUpd,
716 Opt_WarnSimplePatterns,
717 Opt_WarnMonomorphism,
721 -- -----------------------------------------------------------------------------
722 -- CoreToDo: abstraction of core-to-core passes to run.
724 data CoreToDo -- These are diff core-to-core passes,
725 -- which may be invoked in any order,
726 -- as many times as you like.
728 = CoreDoSimplify -- The core-to-core simplifier.
731 -- Each run of the simplifier can take a different
732 -- set of simplifier-specific flags.
734 | CoreDoFloatOutwards FloatOutSwitches
739 | CoreDoWorkerWrapper
742 | CoreDoOldStrictness
745 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
746 -- matching this string
747 | CoreDoVectorisation
748 | CoreDoNothing -- Useful when building up
749 | CoreDoPasses [CoreToDo] -- lists of these things
751 data SimplifierMode -- See comments in SimplMonad
755 data SimplifierSwitch
756 = MaxSimplifierIterations Int
759 data FloatOutSwitches
760 = FloatOutSw Bool -- True <=> float lambdas to top level
761 Bool -- True <=> float constants to top level,
762 -- even if they do not escape a lambda
765 -- The core-to-core pass ordering is derived from the DynFlags:
766 runWhen :: Bool -> CoreToDo -> CoreToDo
767 runWhen True do_this = do_this
768 runWhen False do_this = CoreDoNothing
770 getCoreToDo :: DynFlags -> [CoreToDo]
772 | Just todo <- coreToDo dflags = todo -- set explicitly by user
773 | otherwise = core_todo
775 opt_level = optLevel dflags
776 max_iter = maxSimplIterations dflags
777 strictness = dopt Opt_Strictness dflags
778 full_laziness = dopt Opt_FullLaziness dflags
779 cse = dopt Opt_CSE dflags
780 spec_constr = dopt Opt_SpecConstr dflags
781 liberate_case = dopt Opt_LiberateCase dflags
782 rule_check = ruleCheck dflags
783 vectorisation = dopt Opt_Vectorise dflags
786 if opt_level == 0 then
788 CoreDoSimplify (SimplPhase 0) [
789 MaxSimplifierIterations max_iter
792 else {- opt_level >= 1 -} [
794 -- initial simplify: mk specialiser happy: minimum effort please
795 CoreDoSimplify SimplGently [
797 -- Don't inline anything till full laziness has bitten
798 -- In particular, inlining wrappers inhibits floating
799 -- e.g. ...(case f x of ...)...
800 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
801 -- ==> ...(case x of I# x# -> case fw x# of ...)...
802 -- and now the redex (f x) isn't floatable any more
803 -- Similarly, don't apply any rules until after full
804 -- laziness. Notably, list fusion can prevent floating.
806 NoCaseOfCase, -- Don't do case-of-case transformations.
807 -- This makes full laziness work better
808 MaxSimplifierIterations max_iter
812 -- We run vectorisation here for now, but we might also try to run
814 runWhen vectorisation (CoreDoPasses [
816 CoreDoSimplify SimplGently
818 MaxSimplifierIterations max_iter]]),
820 -- Specialisation is best done before full laziness
821 -- so that overloaded functions have all their dictionary lambdas manifest
824 runWhen full_laziness (CoreDoFloatOutwards (FloatOutSw False False)),
828 CoreDoSimplify (SimplPhase 2) [
829 -- Want to run with inline phase 2 after the specialiser to give
830 -- maximum chance for fusion to work before we inline build/augment
831 -- in phase 1. This made a difference in 'ansi' where an
832 -- overloaded function wasn't inlined till too late.
833 MaxSimplifierIterations max_iter
835 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
837 CoreDoSimplify (SimplPhase 1) [
838 -- Need inline-phase2 here so that build/augment get
839 -- inlined. I found that spectral/hartel/genfft lost some useful
840 -- strictness in the function sumcode' if augment is not inlined
841 -- before strictness analysis runs
842 MaxSimplifierIterations max_iter
844 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
846 CoreDoSimplify (SimplPhase 0) [
847 -- Phase 0: allow all Ids to be inlined now
848 -- This gets foldr inlined before strictness analysis
850 MaxSimplifierIterations 3
851 -- At least 3 iterations because otherwise we land up with
852 -- huge dead expressions because of an infelicity in the
854 -- let k = BIG in foldr k z xs
855 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
856 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
860 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
862 #ifdef OLD_STRICTNESS
865 runWhen strictness (CoreDoPasses [
869 CoreDoSimplify (SimplPhase 0) [
870 MaxSimplifierIterations max_iter
873 runWhen full_laziness
874 (CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
875 True)), -- Float constants
876 -- nofib/spectral/hartel/wang doubles in speed if you
877 -- do full laziness late in the day. It only happens
878 -- after fusion and other stuff, so the early pass doesn't
879 -- catch it. For the record, the redex is
880 -- f_el22 (f_el21 r_midblock)
884 -- We want CSE to follow the final full-laziness pass, because it may
885 -- succeed in commoning up things floated out by full laziness.
886 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
890 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
892 -- Case-liberation for -O2. This should be after
893 -- strictness analysis and the simplification which follows it.
894 runWhen liberate_case (CoreDoPasses [
896 CoreDoSimplify (SimplPhase 0) [
897 MaxSimplifierIterations max_iter
898 ] ]), -- Run the simplifier after LiberateCase to vastly
899 -- reduce the possiblility of shadowing
900 -- Reason: see Note [Shadowing] in SpecConstr.lhs
902 runWhen spec_constr CoreDoSpecConstr,
904 -- Final clean-up simplification:
905 CoreDoSimplify (SimplPhase 0) [
906 MaxSimplifierIterations max_iter
910 -- -----------------------------------------------------------------------------
911 -- StgToDo: abstraction of stg-to-stg passes to run.
914 = StgDoMassageForProfiling -- should be (next to) last
915 -- There's also setStgVarInfo, but its absolute "lastness"
916 -- is so critical that it is hardwired in (no flag).
919 getStgToDo :: DynFlags -> [StgToDo]
921 | Just todo <- stgToDo dflags = todo -- set explicitly by user
924 stg_stats = dopt Opt_StgStats dflags
926 todo1 = if stg_stats then [D_stg_stats] else []
928 todo2 | WayProf `elem` wayNames dflags
929 = StgDoMassageForProfiling : todo1
933 -- -----------------------------------------------------------------------------
937 allFlags = map ('-':) $
938 [ name | (name, optkind) <- dynamic_flags, ok optkind ] ++
939 map ("fno-"++) flags ++
941 where ok (PrefixPred _ _) = False
943 flags = map fst fFlags
945 dynamic_flags :: [(String, OptKind DynP)]
947 ( "n" , NoArg (setDynFlag Opt_DryRun) )
948 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
949 , ( "F" , NoArg (setDynFlag Opt_Pp))
950 , ( "#include" , HasArg (addCmdlineHCInclude) )
951 , ( "v" , OptIntSuffix setVerbosity )
953 ------- Specific phases --------------------------------------------
954 , ( "pgmL" , HasArg (upd . setPgmL) )
955 , ( "pgmP" , HasArg (upd . setPgmP) )
956 , ( "pgmF" , HasArg (upd . setPgmF) )
957 , ( "pgmc" , HasArg (upd . setPgmc) )
958 , ( "pgmm" , HasArg (upd . setPgmm) )
959 , ( "pgms" , HasArg (upd . setPgms) )
960 , ( "pgma" , HasArg (upd . setPgma) )
961 , ( "pgml" , HasArg (upd . setPgml) )
962 , ( "pgmdll" , HasArg (upd . setPgmdll) )
963 , ( "pgmwindres" , HasArg (upd . setPgmwindres) )
965 , ( "optL" , HasArg (upd . addOptL) )
966 , ( "optP" , HasArg (upd . addOptP) )
967 , ( "optF" , HasArg (upd . addOptF) )
968 , ( "optc" , HasArg (upd . addOptc) )
969 , ( "optm" , HasArg (upd . addOptm) )
970 , ( "opta" , HasArg (upd . addOpta) )
971 , ( "optl" , HasArg (upd . addOptl) )
972 , ( "optdep" , HasArg (upd . addOptdep) )
973 , ( "optwindres" , HasArg (upd . addOptwindres) )
975 , ( "split-objs" , NoArg (if can_split
976 then setDynFlag Opt_SplitObjs
979 -------- Linking ----------------------------------------------------
980 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
981 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
982 , ( "shared" , NoArg (upd $ \d -> d{ ghcLink=LinkDynLib } ))
984 ------- Libraries ---------------------------------------------------
985 , ( "L" , Prefix addLibraryPath )
986 , ( "l" , AnySuffix (\s -> do upd (addOptl s)))
988 ------- Frameworks --------------------------------------------------
989 -- -framework-path should really be -F ...
990 , ( "framework-path" , HasArg addFrameworkPath )
991 , ( "framework" , HasArg (upd . addCmdlineFramework) )
993 ------- Output Redirection ------------------------------------------
994 , ( "odir" , HasArg (upd . setObjectDir))
995 , ( "o" , SepArg (upd . setOutputFile . Just))
996 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
997 , ( "osuf" , HasArg (upd . setObjectSuf))
998 , ( "hcsuf" , HasArg (upd . setHcSuf))
999 , ( "hisuf" , HasArg (upd . setHiSuf))
1000 , ( "hidir" , HasArg (upd . setHiDir))
1001 , ( "tmpdir" , HasArg (upd . setTmpDir))
1002 , ( "stubdir" , HasArg (upd . setStubDir))
1003 , ( "ddump-file-prefix", HasArg (upd . setDumpPrefixForce . Just))
1005 ------- Keeping temporary files -------------------------------------
1006 -- These can be singular (think ghc -c) or plural (think ghc --make)
1007 , ( "keep-hc-file" , NoArg (setDynFlag Opt_KeepHcFiles))
1008 , ( "keep-hc-files" , NoArg (setDynFlag Opt_KeepHcFiles))
1009 , ( "keep-s-file" , NoArg (setDynFlag Opt_KeepSFiles))
1010 , ( "keep-s-files" , NoArg (setDynFlag Opt_KeepSFiles))
1011 , ( "keep-raw-s-file" , NoArg (setDynFlag Opt_KeepRawSFiles))
1012 , ( "keep-raw-s-files", NoArg (setDynFlag Opt_KeepRawSFiles))
1013 -- This only makes sense as plural
1014 , ( "keep-tmp-files" , NoArg (setDynFlag Opt_KeepTmpFiles))
1016 ------- Miscellaneous ----------------------------------------------
1017 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
1018 , ( "main-is" , SepArg setMainIs )
1019 , ( "haddock" , NoArg (setDynFlag Opt_Haddock) )
1020 , ( "haddock-opts" , HasArg (upd . addHaddockOpts))
1021 , ( "hpcdir" , SepArg setOptHpcDir )
1023 ------- recompilation checker (DEPRECATED, use -fforce-recomp) -----
1024 , ( "recomp" , NoArg (unSetDynFlag Opt_ForceRecomp) )
1025 , ( "no-recomp" , NoArg (setDynFlag Opt_ForceRecomp) )
1027 ------- Packages ----------------------------------------------------
1028 , ( "package-conf" , HasArg extraPkgConf_ )
1029 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
1030 , ( "package-name" , HasArg (upd . setPackageName) )
1031 , ( "package" , HasArg exposePackage )
1032 , ( "hide-package" , HasArg hidePackage )
1033 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
1034 , ( "ignore-package" , HasArg ignorePackage )
1035 , ( "syslib" , HasArg exposePackage ) -- for compatibility
1037 ------ HsCpp opts ---------------------------------------------------
1038 , ( "D", AnySuffix (upd . addOptP) )
1039 , ( "U", AnySuffix (upd . addOptP) )
1041 ------- Include/Import Paths ----------------------------------------
1042 , ( "I" , Prefix addIncludePath)
1043 , ( "i" , OptPrefix addImportPath )
1045 ------ Debugging ----------------------------------------------------
1046 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
1048 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
1049 , ( "ddump-cmmz", setDumpFlag Opt_D_dump_cmmz)
1050 , ( "ddump-cmmz-pretty", setDumpFlag Opt_D_dump_cmmz_pretty)
1051 , ( "ddump-cps-cmm", setDumpFlag Opt_D_dump_cps_cmm)
1052 , ( "ddump-cvt-cmm", setDumpFlag Opt_D_dump_cvt_cmm)
1053 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
1054 , ( "ddump-asm-native", setDumpFlag Opt_D_dump_asm_native)
1055 , ( "ddump-asm-liveness", setDumpFlag Opt_D_dump_asm_liveness)
1056 , ( "ddump-asm-coalesce", setDumpFlag Opt_D_dump_asm_coalesce)
1057 , ( "ddump-asm-regalloc", setDumpFlag Opt_D_dump_asm_regalloc)
1058 , ( "ddump-asm-conflicts", setDumpFlag Opt_D_dump_asm_conflicts)
1059 , ( "ddump-asm-regalloc-stages",
1060 setDumpFlag Opt_D_dump_asm_regalloc_stages)
1061 , ( "ddump-asm-stats", setDumpFlag Opt_D_dump_asm_stats)
1062 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
1063 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
1064 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
1065 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
1066 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
1067 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
1068 , ( "ddump-rule-firings", setDumpFlag Opt_D_dump_rule_firings)
1069 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
1070 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
1071 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
1072 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
1073 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
1074 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
1075 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
1076 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
1077 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
1078 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
1079 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
1080 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
1081 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
1082 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
1083 , ( "ddump-rn-trace", setDumpFlag Opt_D_dump_rn_trace)
1084 , ( "ddump-if-trace", setDumpFlag Opt_D_dump_if_trace)
1085 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
1086 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
1087 , ( "ddump-rn-stats", setDumpFlag Opt_D_dump_rn_stats)
1088 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
1089 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
1090 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
1091 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
1092 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
1093 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
1094 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
1095 , ( "ddump-minimal-imports", setDumpFlag Opt_D_dump_minimal_imports)
1096 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
1097 , ( "ddump-hpc", setDumpFlag Opt_D_dump_hpc)
1098 , ( "ddump-mod-cycles", setDumpFlag Opt_D_dump_mod_cycles)
1099 , ( "ddump-view-pattern-commoning", setDumpFlag Opt_D_dump_view_pattern_commoning)
1100 , ( "ddump-to-file", setDumpFlag Opt_DumpToFile)
1101 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs))
1102 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
1103 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
1104 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
1105 , ( "dasm-lint", NoArg (setDynFlag Opt_DoAsmLinting))
1106 , ( "dshow-passes", NoArg (do setDynFlag Opt_ForceRecomp
1107 setVerbosity (Just 2)) )
1108 , ( "dfaststring-stats", NoArg (setDynFlag Opt_D_faststring_stats))
1110 ------ Machine dependant (-m<blah>) stuff ---------------------------
1112 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
1113 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
1114 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
1116 ------ Warning opts -------------------------------------------------
1117 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
1118 , ( "Werror", NoArg (setDynFlag Opt_WarnIsError) )
1119 , ( "Wwarn" , NoArg (unSetDynFlag Opt_WarnIsError) )
1120 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
1121 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) -- DEPRECATED
1122 , ( "w" , NoArg (mapM_ unSetDynFlag minuswRemovesOpts) )
1124 ------ Optimisation flags ------------------------------------------
1125 , ( "O" , NoArg (upd (setOptLevel 1)))
1126 , ( "Onot" , NoArg (upd (setOptLevel 0))) -- deprecated
1127 , ( "O" , OptIntSuffix (\mb_n -> upd (setOptLevel (mb_n `orElse` 1))))
1128 -- If the number is missing, use 1
1130 , ( "fmax-simplifier-iterations", IntSuffix (\n ->
1131 upd (\dfs -> dfs{ maxSimplIterations = n })) )
1133 -- liberate-case-threshold is an old flag for '-fspec-threshold'
1134 , ( "fspec-threshold", IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1135 , ( "fliberate-case-threshold", IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1137 , ( "frule-check", SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
1138 , ( "fcontext-stack" , IntSuffix $ \n -> upd $ \dfs -> dfs{ ctxtStkDepth = n })
1140 ------ Compiler flags -----------------------------------------------
1142 , ( "fasm", NoArg (setObjTarget HscAsm) )
1143 , ( "fvia-c", NoArg (setObjTarget HscC) )
1144 , ( "fvia-C", NoArg (setObjTarget HscC) )
1146 , ( "fno-code", NoArg (setTarget HscNothing))
1147 , ( "fbyte-code", NoArg (setTarget HscInterpreted) )
1148 , ( "fobject-code", NoArg (setTarget defaultHscTarget) )
1150 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
1151 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
1153 -- the rest of the -f* and -fno-* flags
1154 , ( "f", PrefixPred (isFlag fFlags)
1155 (\f -> setDynFlag (getFlag fFlags f)) )
1156 , ( "f", PrefixPred (isPrefFlag "no-" fFlags)
1157 (\f -> unSetDynFlag (getPrefFlag "no-" fFlags f)) )
1159 -- the -X* and -XNo* flags
1160 , ( "X", PrefixPred (isFlag xFlags)
1161 (\f -> setDynFlag (getFlag xFlags f)) )
1162 , ( "X", PrefixPred (isPrefFlag "No" xFlags)
1163 (\f -> unSetDynFlag (getPrefFlag "No" xFlags f)) )
1166 -- these -f<blah> flags can all be reversed with -fno-<blah>
1169 ( "warn-dodgy-imports", Opt_WarnDodgyImports ),
1170 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
1171 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
1172 ( "warn-implicit-prelude", Opt_WarnImplicitPrelude ),
1173 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
1174 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
1175 ( "warn-missing-fields", Opt_WarnMissingFields ),
1176 ( "warn-missing-methods", Opt_WarnMissingMethods ),
1177 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
1178 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
1179 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
1180 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
1181 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
1182 ( "warn-monomorphism-restriction", Opt_WarnMonomorphism ),
1183 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
1184 ( "warn-unused-imports", Opt_WarnUnusedImports ),
1185 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
1186 ( "warn-deprecations", Opt_WarnDeprecations ),
1187 ( "warn-orphans", Opt_WarnOrphans ),
1188 ( "warn-tabs", Opt_WarnTabs ),
1189 ( "print-explicit-foralls", Opt_PrintExplicitForalls ),
1190 ( "strictness", Opt_Strictness ),
1191 ( "full-laziness", Opt_FullLaziness ),
1192 ( "liberate-case", Opt_LiberateCase ),
1193 ( "spec-constr", Opt_SpecConstr ),
1195 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
1196 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
1197 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
1198 ( "ignore-asserts", Opt_IgnoreAsserts ),
1199 ( "ignore-breakpoints", Opt_IgnoreBreakpoints),
1200 ( "do-eta-reduction", Opt_DoEtaReduction ),
1201 ( "case-merge", Opt_CaseMerge ),
1202 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
1203 ( "dicts-cheap", Opt_DictsCheap ),
1204 ( "excess-precision", Opt_ExcessPrecision ),
1205 ( "asm-mangling", Opt_DoAsmMangling ),
1206 ( "print-bind-result", Opt_PrintBindResult ),
1207 ( "force-recomp", Opt_ForceRecomp ),
1208 ( "hpc-no-auto", Opt_Hpc_No_Auto ),
1209 ( "rewrite-rules", Opt_RewriteRules ),
1210 ( "break-on-exception", Opt_BreakOnException ),
1211 ( "break-on-error", Opt_BreakOnError ),
1212 ( "print-evld-with-show", Opt_PrintEvldWithShow ),
1213 ( "run-cps", Opt_RunCPSZ ),
1214 ( "convert-to-zipper-and-back", Opt_ConvertToZipCfgAndBack),
1215 ( "vectorise", Opt_Vectorise ),
1216 ( "regs-graph", Opt_RegsGraph),
1217 ( "regs-iterative", Opt_RegsIterative),
1218 -- Deprecated in favour of -XTemplateHaskell:
1219 ( "th", Opt_TemplateHaskell ),
1220 -- Deprecated in favour of -XForeignFunctionInterface:
1221 ( "fi", Opt_ForeignFunctionInterface ),
1222 -- Deprecated in favour of -XForeignFunctionInterface:
1223 ( "ffi", Opt_ForeignFunctionInterface ),
1224 -- Deprecated in favour of -XArrows:
1225 ( "arrows", Opt_Arrows ),
1226 -- Deprecated in favour of -XGenerics:
1227 ( "generics", Opt_Generics ),
1228 -- Deprecated in favour of -XImplicitPrelude:
1229 ( "implicit-prelude", Opt_ImplicitPrelude ),
1230 -- Deprecated in favour of -XBangPatterns:
1231 ( "bang-patterns", Opt_BangPatterns ),
1232 -- Deprecated in favour of -XMonomorphismRestriction:
1233 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
1234 -- Deprecated in favour of -XMonoPatBinds:
1235 ( "mono-pat-binds", Opt_MonoPatBinds ),
1236 -- Deprecated in favour of -XExtendedDefaultRules:
1237 ( "extended-default-rules", Opt_ExtendedDefaultRules ),
1238 -- Deprecated in favour of -XImplicitParams:
1239 ( "implicit-params", Opt_ImplicitParams ),
1240 -- Deprecated in favour of -XScopedTypeVariables:
1241 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
1242 -- Deprecated in favour of -XPArr:
1243 ( "parr", Opt_PArr ),
1244 -- Deprecated in favour of -XOverlappingInstances:
1245 ( "allow-overlapping-instances", Opt_OverlappingInstances ),
1246 -- Deprecated in favour of -XUndecidableInstances:
1247 ( "allow-undecidable-instances", Opt_UndecidableInstances ),
1248 -- Deprecated in favour of -XIncoherentInstances:
1249 ( "allow-incoherent-instances", Opt_IncoherentInstances ),
1250 ( "gen-manifest", Opt_GenManifest ),
1251 ( "embed-manifest", Opt_EmbedManifest )
1254 supportedLanguages :: [String]
1255 supportedLanguages = map fst xFlags
1257 -- These -X<blah> flags can all be reversed with -XNo<blah>
1258 xFlags :: [(String, DynFlag)]
1261 ( "PatternGuards", Opt_PatternGuards ),
1262 ( "UnicodeSyntax", Opt_UnicodeSyntax ),
1263 ( "MagicHash", Opt_MagicHash ),
1264 ( "PolymorphicComponents", Opt_PolymorphicComponents ),
1265 ( "ExistentialQuantification", Opt_ExistentialQuantification ),
1266 ( "KindSignatures", Opt_KindSignatures ),
1267 ( "PatternSignatures", Opt_PatternSignatures ),
1268 ( "EmptyDataDecls", Opt_EmptyDataDecls ),
1269 ( "ParallelListComp", Opt_ParallelListComp ),
1270 ( "ForeignFunctionInterface", Opt_ForeignFunctionInterface ),
1271 ( "UnliftedFFITypes", Opt_UnliftedFFITypes ),
1272 ( "LiberalTypeSynonyms", Opt_LiberalTypeSynonyms ),
1273 ( "Rank2Types", Opt_Rank2Types ),
1274 ( "RankNTypes", Opt_RankNTypes ),
1275 ( "TypeOperators", Opt_TypeOperators ),
1276 ( "RecursiveDo", Opt_RecursiveDo ),
1277 ( "Arrows", Opt_Arrows ),
1278 ( "PArr", Opt_PArr ),
1279 ( "TemplateHaskell", Opt_TemplateHaskell ),
1280 ( "Generics", Opt_Generics ),
1282 ( "ImplicitPrelude", Opt_ImplicitPrelude ),
1283 ( "RecordWildCards", Opt_RecordWildCards ),
1284 ( "RecordPuns", Opt_RecordPuns ),
1285 ( "DisambiguateRecordFields", Opt_DisambiguateRecordFields ),
1286 ( "OverloadedStrings", Opt_OverloadedStrings ),
1287 ( "GADTs", Opt_GADTs ),
1288 ( "ViewPatterns", Opt_ViewPatterns),
1289 ( "TypeFamilies", Opt_TypeFamilies ),
1290 ( "BangPatterns", Opt_BangPatterns ),
1292 ( "MonomorphismRestriction", Opt_MonomorphismRestriction ),
1293 -- On by default (which is not strictly H98):
1294 ( "MonoPatBinds", Opt_MonoPatBinds ),
1295 ( "RelaxedPolyRec", Opt_RelaxedPolyRec),
1296 ( "ExtendedDefaultRules", Opt_ExtendedDefaultRules ),
1297 ( "ImplicitParams", Opt_ImplicitParams ),
1298 ( "ScopedTypeVariables", Opt_ScopedTypeVariables ),
1299 ( "UnboxedTuples", Opt_UnboxedTuples ),
1300 ( "StandaloneDeriving", Opt_StandaloneDeriving ),
1301 ( "DeriveDataTypeable", Opt_DeriveDataTypeable ),
1302 ( "TypeSynonymInstances", Opt_TypeSynonymInstances ),
1303 ( "FlexibleContexts", Opt_FlexibleContexts ),
1304 ( "FlexibleInstances", Opt_FlexibleInstances ),
1305 ( "ConstrainedClassMethods", Opt_ConstrainedClassMethods ),
1306 ( "MultiParamTypeClasses", Opt_MultiParamTypeClasses ),
1307 ( "FunctionalDependencies", Opt_FunctionalDependencies ),
1308 ( "GeneralizedNewtypeDeriving", Opt_GeneralizedNewtypeDeriving ),
1309 ( "OverlappingInstances", Opt_OverlappingInstances ),
1310 ( "UndecidableInstances", Opt_UndecidableInstances ),
1311 ( "IncoherentInstances", Opt_IncoherentInstances )
1314 impliedFlags :: [(DynFlag, [DynFlag])]
1316 ( Opt_GADTs, [Opt_RelaxedPolyRec] ) -- We want type-sig variables to be completely rigid for GADTs
1319 glasgowExtsFlags = [
1320 Opt_PrintExplicitForalls
1321 , Opt_ForeignFunctionInterface
1322 , Opt_UnliftedFFITypes
1324 , Opt_ImplicitParams
1325 , Opt_ScopedTypeVariables
1327 , Opt_TypeSynonymInstances
1328 , Opt_StandaloneDeriving
1329 , Opt_DeriveDataTypeable
1330 , Opt_FlexibleContexts
1331 , Opt_FlexibleInstances
1332 , Opt_ConstrainedClassMethods
1333 , Opt_MultiParamTypeClasses
1334 , Opt_FunctionalDependencies
1336 , Opt_PolymorphicComponents
1337 , Opt_ExistentialQuantification
1340 , Opt_LiberalTypeSynonyms
1344 , Opt_ParallelListComp
1345 , Opt_EmptyDataDecls
1346 , Opt_KindSignatures
1347 , Opt_PatternSignatures
1348 , Opt_GeneralizedNewtypeDeriving
1349 , Opt_TypeFamilies ]
1352 isFlag :: [(String,a)] -> String -> Bool
1353 isFlag flags f = any (\(ff,_) -> ff == f) flags
1355 isPrefFlag :: String -> [(String,a)] -> String -> Bool
1356 isPrefFlag pref flags no_f
1357 | Just f <- maybePrefixMatch pref no_f = isFlag flags f
1361 getFlag :: [(String,a)] -> String -> a
1362 getFlag flags f = case [ opt | (ff, opt) <- flags, ff == f] of
1364 [] -> panic ("get_flag " ++ f)
1366 getPrefFlag :: String -> [(String,a)] -> String -> a
1367 getPrefFlag pref flags f = getFlag flags (fromJust (maybePrefixMatch pref f))
1368 -- We should only be passed flags which match the prefix
1370 -- -----------------------------------------------------------------------------
1371 -- Parsing the dynamic flags.
1373 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
1374 parseDynamicFlags dflags args = do
1375 let ((leftover,errs),dflags')
1376 = runCmdLine (processArgs dynamic_flags args) dflags
1377 when (not (null errs)) $ do
1378 throwDyn (UsageError (unlines errs))
1379 return (dflags', leftover)
1382 type DynP = CmdLineP DynFlags
1384 upd :: (DynFlags -> DynFlags) -> DynP ()
1386 dfs <- getCmdLineState
1387 putCmdLineState $! (f dfs)
1389 --------------------------
1390 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1391 setDynFlag f = upd (\dfs -> foldl dopt_set (dopt_set dfs f) deps)
1393 deps = [ d | (f', ds) <- impliedFlags, f' == f, d <- ds ]
1394 -- When you set f, set the ones it implies
1395 -- When you un-set f, however, we don't un-set the things it implies
1396 -- (except for -fno-glasgow-exts, which is treated specially)
1398 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1400 --------------------------
1401 setDumpFlag :: DynFlag -> OptKind DynP
1402 setDumpFlag dump_flag
1403 = NoArg (setDynFlag Opt_ForceRecomp >> setDynFlag dump_flag)
1404 -- Whenver we -ddump, switch off the recompilation checker,
1405 -- else you don't see the dump!
1407 setVerbosity :: Maybe Int -> DynP ()
1408 setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
1410 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1412 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1415 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1417 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1419 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1422 | Nothing <- unpackPackageId pid
1423 = throwDyn (CmdLineError ("cannot parse \'" ++ p ++ "\' as a package identifier"))
1425 = \s -> s{ thisPackage = pid }
1427 pid = stringToPackageId p
1429 -- If we're linking a binary, then only targets that produce object
1430 -- code are allowed (requests for other target types are ignored).
1431 setTarget l = upd set
1434 | ghcLink dfs /= LinkBinary || isObjectTarget l = dfs{ hscTarget = l }
1437 -- Changes the target only if we're compiling object code. This is
1438 -- used by -fasm and -fvia-C, which switch from one to the other, but
1439 -- not from bytecode to object-code. The idea is that -fasm/-fvia-C
1440 -- can be safely used in an OPTIONS_GHC pragma.
1441 setObjTarget l = upd set
1444 | isObjectTarget (hscTarget dfs) = dfs { hscTarget = l }
1447 setOptLevel :: Int -> DynFlags -> DynFlags
1448 setOptLevel n dflags
1449 | hscTarget dflags == HscInterpreted && n > 0
1451 -- not in IO any more, oh well:
1452 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1454 = updOptLevel n dflags
1457 setMainIs :: String -> DynP ()
1459 | not (null main_fn) && isLower (head main_fn)
1460 -- The arg looked like "Foo.Bar.baz"
1461 = upd $ \d -> d{ mainFunIs = Just main_fn,
1462 mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
1464 | isUpper (head arg) -- The arg looked like "Foo" or "Foo.Bar"
1465 = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName arg) }
1467 | otherwise -- The arg looked like "baz"
1468 = upd $ \d -> d{ mainFunIs = Just arg }
1470 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1472 -----------------------------------------------------------------------------
1473 -- Paths & Libraries
1475 -- -i on its own deletes the import paths
1476 addImportPath "" = upd (\s -> s{importPaths = []})
1477 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1481 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1484 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1486 addFrameworkPath p =
1487 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1489 split_marker = ':' -- not configurable (ToDo)
1491 splitPathList :: String -> [String]
1492 splitPathList s = filter notNull (splitUp s)
1493 -- empty paths are ignored: there might be a trailing
1494 -- ':' in the initial list, for example. Empty paths can
1495 -- cause confusion when they are translated into -I options
1496 -- for passing to gcc.
1498 #ifndef mingw32_TARGET_OS
1499 splitUp xs = split split_marker xs
1501 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1503 -- That is, if "foo:bar:baz" is used, this interpreted as
1504 -- consisting of three entries, 'foo', 'bar', 'baz'.
1505 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1506 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1508 -- Notice that no attempt is made to fully replace the 'standard'
1509 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1510 -- that this will cause too much breakage for users & ':' will
1511 -- work fine even with DOS paths, if you're not insisting on being silly.
1514 splitUp (x:':':div:xs) | div `elem` dir_markers
1515 = ((x:':':div:p): splitUp rs)
1517 (p,rs) = findNextPath xs
1518 -- we used to check for existence of the path here, but that
1519 -- required the IO monad to be threaded through the command-line
1520 -- parser which is quite inconvenient. The
1521 splitUp xs = cons p (splitUp rs)
1523 (p,rs) = findNextPath xs
1528 -- will be called either when we've consumed nought or the
1529 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1530 -- finding the next split marker.
1532 case break (`elem` split_markers) xs of
1533 (p, d:ds) -> (p, ds)
1536 split_markers :: [Char]
1537 split_markers = [':', ';']
1539 dir_markers :: [Char]
1540 dir_markers = ['/', '\\']
1543 -- -----------------------------------------------------------------------------
1544 -- tmpDir, where we store temporary files.
1546 setTmpDir :: FilePath -> DynFlags -> DynFlags
1547 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1549 #if !defined(mingw32_HOST_OS)
1550 canonicalise p = normalisePath p
1552 -- Canonicalisation of temp path under win32 is a bit more
1553 -- involved: (a) strip trailing slash,
1554 -- (b) normalise slashes
1555 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1557 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1559 -- if we're operating under cygwin, and TMP/TEMP is of
1560 -- the form "/cygdrive/drive/path", translate this to
1561 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1562 -- understand /cygdrive paths.)
1564 | "/cygdrive/" `isPrefixOf` path =
1565 case drop (length "/cygdrive/") path of
1566 drive:xs@('/':_) -> drive:':':xs
1570 -- strip the trailing backslash (awful, but we only do this once).
1571 removeTrailingSlash path =
1578 -----------------------------------------------------------------------------
1581 setOptHpcDir :: String -> DynP ()
1582 setOptHpcDir arg = upd $ \ d -> d{hpcDir = arg}
1584 -----------------------------------------------------------------------------
1585 -- Via-C compilation stuff
1587 -- There are some options that we need to pass to gcc when compiling
1588 -- Haskell code via C, but are only supported by recent versions of
1589 -- gcc. The configure script decides which of these options we need,
1590 -- and puts them in the file "extra-gcc-opts" in $topdir, which is
1591 -- read before each via-C compilation. The advantage of having these
1592 -- in a separate file is that the file can be created at install-time
1593 -- depending on the available gcc version, and even re-generated later
1594 -- if gcc is upgraded.
1596 -- The options below are not dependent on the version of gcc, only the
1599 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1600 [String]) -- for registerised HC compilations
1601 machdepCCOpts dflags
1602 #if alpha_TARGET_ARCH
1604 #ifdef HAVE_THREADED_RTS_SUPPORT
1608 -- For now, to suppress the gcc warning "call-clobbered
1609 -- register used for global register variable", we simply
1610 -- disable all warnings altogether using the -w flag. Oh well.
1612 #elif hppa_TARGET_ARCH
1613 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1614 -- (very nice, but too bad the HP /usr/include files don't agree.)
1615 = ( ["-D_HPUX_SOURCE"], [] )
1617 #elif m68k_TARGET_ARCH
1618 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1619 -- popping of args to routines to be explicit; if we let things
1620 -- be deferred 'til after an STGJUMP, imminent death is certain!
1622 -- -fomit-frame-pointer : *don't*
1623 -- It's better to have a6 completely tied up being a frame pointer
1624 -- rather than let GCC pick random things to do with it.
1625 -- (If we want to steal a6, then we would try to do things
1626 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1627 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1629 #elif i386_TARGET_ARCH
1630 -- -fno-defer-pop : basically the same game as for m68k
1632 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1633 -- the fp (%ebp) for our register maps.
1634 = let n_regs = stolen_x86_regs dflags
1637 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1638 -- , if "mingw32" `isSuffixOf` cTARGETPLATFORM then "-mno-cygwin" else ""
1641 "-fomit-frame-pointer",
1642 -- we want -fno-builtin, because when gcc inlines
1643 -- built-in functions like memcpy() it tends to
1644 -- run out of registers, requiring -monly-n-regs
1646 "-DSTOLEN_X86_REGS="++show n_regs ]
1649 #elif ia64_TARGET_ARCH
1650 = ( [], ["-fomit-frame-pointer", "-G0"] )
1652 #elif x86_64_TARGET_ARCH
1653 = ( [], ["-fomit-frame-pointer",
1654 "-fno-asynchronous-unwind-tables",
1655 -- the unwind tables are unnecessary for HC code,
1656 -- and get in the way of -split-objs. Another option
1657 -- would be to throw them away in the mangler, but this
1660 -- calling builtins like strlen() using the FFI can
1661 -- cause gcc to run out of regs, so use the external
1665 #elif sparc_TARGET_ARCH
1667 -- For now, to suppress the gcc warning "call-clobbered
1668 -- register used for global register variable", we simply
1669 -- disable all warnings altogether using the -w flag. Oh well.
1671 #elif powerpc_apple_darwin_TARGET
1673 -- Disable Apple's precompiling preprocessor. It's a great thing
1674 -- for "normal" programs, but it doesn't support register variable
1676 = ( [], ["-no-cpp-precomp"] )
1681 picCCOpts :: DynFlags -> [String]
1683 #if darwin_TARGET_OS
1684 -- Apple prefers to do things the other way round.
1685 -- PIC is on by default.
1686 -- -mdynamic-no-pic:
1687 -- Turn off PIC code generation.
1689 -- Don't generate "common" symbols - these are unwanted
1690 -- in dynamic libraries.
1693 = ["-fno-common", "-D__PIC__"]
1695 = ["-mdynamic-no-pic"]
1696 #elif mingw32_TARGET_OS
1697 -- no -fPIC for Windows
1704 = ["-fPIC", "-D__PIC__"]
1709 -- -----------------------------------------------------------------------------
1713 can_split = cSplitObjs == "YES"
1715 -- -----------------------------------------------------------------------------
1718 compilerInfo :: [(String, String)]
1719 compilerInfo = [("Project name", cProjectName),
1720 ("Project version", cProjectVersion),
1721 ("Booter version", cBooterVersion),
1723 ("Interface file version", cHscIfaceFileVersion),
1724 ("Have interpreter", cGhcWithInterpreter),
1725 ("Object splitting", cSplitObjs),
1726 ("Have native code generator", cGhcWithNativeCodeGen),
1727 ("Support SMP", cGhcWithSMP),
1728 ("Unregisterised", cGhcUnregisterised),
1729 ("Tables next to code", cGhcEnableTablesNextToCode),
1730 ("Win32 DLLs", cEnableWin32DLLs),
1731 ("RTS ways", cGhcRTSWays),
1732 ("Leading underscore", cLeadingUnderscore)]