updOptLevel,
setTmpDir,
setPackageName,
+ doingTickyProfiling,
-- ** Parsing DynFlags
parseDynamicFlags,
#include "HsVersions.h"
+import Platform
import Module
import PackageConfig
import PrelNames ( mAIN, main_RDR_Unqual )
import Maybes ( orElse )
import SrcLoc
import FastString
+import FiniteMap
import Outputable
import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
-import Data.IORef ( readIORef )
+import Data.IORef
import Control.Monad ( when )
import Data.Char
+import Data.List ( intersperse )
import System.FilePath
import System.IO ( stderr, hPutChar )
| Opt_RelaxedPolyRec
| Opt_StandaloneDeriving
| Opt_DeriveDataTypeable
+ | Opt_DeriveFunctor
| Opt_TypeSynonymInstances
| Opt_FlexibleContexts
| Opt_FlexibleInstances
| Opt_RegsGraph -- do graph coloring register allocation
| Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
+ -- profiling opts
+ | Opt_AutoSccsOnAllToplevs
+ | Opt_AutoSccsOnExportedToplevs
+ | Opt_AutoSccsOnIndividualCafs
+
-- misc opts
| Opt_Cpp
| Opt_Pp
| Opt_DryRun
| Opt_DoAsmMangling
| Opt_ExcessPrecision
+ | Opt_EagerBlackHoling
| Opt_ReadUserPackageConf
| Opt_NoHsMain
| Opt_SplitObjs
| Opt_PrintBindContents
| Opt_GenManifest
| Opt_EmbedManifest
+
+ -- temporary flags
+ | Opt_RunCPS
| Opt_RunCPSZ
| Opt_ConvertToZipCfgAndBack
| Opt_AutoLinkPackages
| Opt_ImplicitImportQualified
+ | Opt_TryNewCodeGen
-- keeping stuff
| Opt_KeepHiDiffs
specConstrCount :: Maybe Int, -- ^ Max number of specialisations for any one function
liberateCaseThreshold :: Maybe Int, -- ^ Threshold for LiberateCase
+ targetPlatform :: Platform, -- ^ The platform we're compiling for. Used by the NCG.
stolen_x86_regs :: Int,
cmdlineHcIncludes :: [String], -- ^ @\-\#includes@
importPaths :: [FilePath],
buildTag :: String, -- ^ The global \"way\" (e.g. \"p\" for prof)
rtsBuildTag :: String, -- ^ The RTS \"way\"
+ -- For object splitting
+ splitInfo :: Maybe (String,Int),
+
-- paths etc.
objectDir :: Maybe String,
hiDir :: Maybe String,
depIncludePkgDeps :: Bool,
depExcludeMods :: [ModuleName],
depSuffixes :: [String],
- depWarnings :: Bool,
-- Package flags
extraPkgConfs :: [FilePath],
pkgDatabase :: Maybe (UniqFM PackageConfig),
pkgState :: PackageState,
+ -- Temporary files
+ -- These have to be IORefs, because the defaultCleanupHandler needs to
+ -- know what to clean when an exception happens
+ filesToClean :: IORef [FilePath],
+ dirsToClean :: IORef (FiniteMap FilePath FilePath),
+
-- hsc dynamic flags
flags :: [DynFlag],
haddockOptions :: Maybe String
}
+-- | The target code type of the compilation (if any).
+--
+-- Whenever you change the target, also make sure to set 'ghcLink' to
+-- something sensible.
+--
+-- 'HscNothing' can be used to avoid generating any output, however, note
+-- that:
+--
+-- * This will not run the desugaring step, thus no warnings generated in
+-- this step will be output. In particular, this includes warnings related
+-- to pattern matching. You can run the desugarer manually using
+-- 'GHC.desugarModule'.
+--
+-- * If a program uses Template Haskell the typechecker may try to run code
+-- from an imported module. This will fail if no code has been generated
+-- for this module. You can use 'GHC.needsTemplateHaskell' to detect
+-- whether this might be the case and choose to either switch to a
+-- different target or avoid typechecking such modules. (The latter may
+-- preferable for security reasons.)
+--
data HscTarget
- = HscC
- | HscAsm
- | HscJava
- | HscInterpreted
- | HscNothing
+ = HscC -- ^ Generate C code.
+ | HscAsm -- ^ Generate assembly using the native code generator.
+ | HscJava -- ^ Generate Java bytecode.
+ | HscInterpreted -- ^ Generate bytecode. (Requires 'LinkInMemory')
+ | HscNothing -- ^ Don't generate any code. See notes above.
deriving (Eq, Show)
-- | Will this target result in an object file on the disk?
data GhcLink
= NoLink -- ^ Don't link at all
| LinkBinary -- ^ Link object code into a binary
- | LinkInMemory -- ^ Use the in-memory dynamic linker
+ | LinkInMemory -- ^ Use the in-memory dynamic linker (works for both
+ -- bytecode and object code).
| LinkDynLib -- ^ Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
deriving (Eq, Show)
isNoLink NoLink = True
isNoLink _ = False
+-- Is it worth evaluating this Bool and caching it in the DynFlags value
+-- during initDynFlags?
+doingTickyProfiling :: DynFlags -> Bool
+doingTickyProfiling dflags = WayTicky `elem` wayNames dflags
+
data PackageFlag
= ExposePackage String
| HidePackage String
ways <- readIORef v_Ways
build_tag <- readIORef v_Build_tag
rts_build_tag <- readIORef v_RTS_Build_tag
+ refFilesToClean <- newIORef []
+ refDirsToClean <- newIORef emptyFM
return dflags{
wayNames = ways,
buildTag = build_tag,
- rtsBuildTag = rts_build_tag
+ rtsBuildTag = rts_build_tag,
+ filesToClean = refFilesToClean,
+ dirsToClean = refDirsToClean
}
-- | The normal 'DynFlags'. Note that they is not suitable for use in this form
specConstrThreshold = Just 200,
specConstrCount = Just 3,
liberateCaseThreshold = Just 200,
+ targetPlatform = defaultTargetPlatform,
stolen_x86_regs = 4,
cmdlineHcIncludes = [],
importPaths = ["."],
opt_L = [],
opt_P = (if opt_PIC
- then ["-D__PIC__"]
+ then ["-D__PIC__", "-U __PIC__"] -- this list is reversed
else []),
opt_F = [],
opt_c = [],
wayNames = panic "defaultDynFlags: No wayNames",
buildTag = panic "defaultDynFlags: No buildTag",
rtsBuildTag = panic "defaultDynFlags: No rtsBuildTag",
+ splitInfo = Nothing,
-- initSysTools fills all these in
ghcUsagePath = panic "defaultDynFlags: No ghciUsagePath",
ghciUsagePath = panic "defaultDynFlags: No ghciUsagePath",
depIncludePkgDeps = False,
depExcludeMods = [],
depSuffixes = [],
- depWarnings = True,
-- end of ghc -M values
+ filesToClean = panic "defaultDynFlags: No filesToClean",
+ dirsToClean = panic "defaultDynFlags: No dirsToClean",
haddockOptions = Nothing,
flags = [
Opt_AutoLinkPackages,
addDepSuffix :: FilePath -> DynFlags -> DynFlags
addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d }
-setDepWarnings :: Bool -> DynFlags -> DynFlags
-setDepWarnings b d = d { depWarnings = b }
-
-- XXX Legacy code:
-- We used to use "-optdep-flag -optdeparg", so for legacy applications
-- we need to strip the "-optdep" off of the arg
| CoreDoNothing -- Useful when building up
| CoreDoPasses [CoreToDo] -- lists of these things
+
data SimplifierMode -- See comments in SimplMonad
= SimplGently
| SimplPhase Int [String]
+instance Outputable SimplifierMode where
+ ppr SimplGently = ptext (sLit "gentle")
+ ppr (SimplPhase n ss) = int n <+> brackets (text (concat $ intersperse "," ss))
+
+
data SimplifierSwitch
= MaxSimplifierIterations Int
| NoCaseOfCase
-data FloatOutSwitches
- = FloatOutSw Bool -- True <=> float lambdas to top level
- Bool -- True <=> float constants to top level,
- -- even if they do not escape a lambda
+
+data FloatOutSwitches = FloatOutSwitches {
+ floatOutLambdas :: Bool, -- ^ True <=> float lambdas to top level
+ floatOutConstants :: Bool -- ^ True <=> float constants to top level,
+ -- even if they do not escape a lambda
+ }
+
+instance Outputable FloatOutSwitches where
+ ppr = pprFloatOutSwitches
+
+pprFloatOutSwitches :: FloatOutSwitches -> SDoc
+pprFloatOutSwitches sw = pp_not (floatOutLambdas sw) <+> text "lambdas" <> comma
+ <+> pp_not (floatOutConstants sw) <+> text "constants"
+ where
+ pp_not True = empty
+ pp_not False = text "not"
+
+-- | Switches that specify the minimum amount of floating out
+gentleFloatOutSwitches :: FloatOutSwitches
+gentleFloatOutSwitches = FloatOutSwitches False False
+
+-- | Switches that do not specify floating out of lambdas, just of constants
+constantsOnlyFloatOutSwitches :: FloatOutSwitches
+constantsOnlyFloatOutSwitches = FloatOutSwitches False True
-- The core-to-core pass ordering is derived from the DynFlags:
-- so that overloaded functions have all their dictionary lambdas manifest
CoreDoSpecialising,
- runWhen full_laziness (CoreDoFloatOutwards (FloatOutSw False False)),
+ runWhen full_laziness (CoreDoFloatOutwards gentleFloatOutSwitches),
CoreDoFloatInwards,
]),
runWhen full_laziness
- (CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
- True)), -- Float constants
+ (CoreDoFloatOutwards constantsOnlyFloatOutSwitches),
-- nofib/spectral/hartel/wang doubles in speed if you
-- do full laziness late in the day. It only happens
-- after fusion and other stuff, so the early pass doesn't
, Flag "dep-makefile" (HasArg (upd . setDepMakefile)) Supported
, Flag "optdep-f" (HasArg (upd . setDepMakefile))
(Deprecated "Use -dep-makefile instead")
- , Flag "optdep-w" (NoArg (upd (setDepWarnings False)))
+ , Flag "optdep-w" (NoArg (return ()))
(Deprecated "-optdep-w doesn't do anything")
, Flag "include-pkg-deps" (NoArg (upd (setDepIncludePkgDeps True))) Supported
, Flag "optdep--include-prelude" (NoArg (upd (setDepIncludePkgDeps True)))
(IntSuffix $ \n -> upd $ \dfs -> dfs{ ctxtStkDepth = n })
Supported
+ ------ Profiling ----------------------------------------------------
+
+ -- XXX Should the -f* flags be deprecated?
+ -- They don't seem to be documented
+ , Flag "fauto-sccs-on-all-toplevs"
+ (NoArg (setDynFlag Opt_AutoSccsOnAllToplevs))
+ Supported
+ , Flag "auto-all"
+ (NoArg (setDynFlag Opt_AutoSccsOnAllToplevs))
+ Supported
+ , Flag "no-auto-all"
+ (NoArg (unSetDynFlag Opt_AutoSccsOnAllToplevs))
+ Supported
+ , Flag "fauto-sccs-on-exported-toplevs"
+ (NoArg (setDynFlag Opt_AutoSccsOnExportedToplevs))
+ Supported
+ , Flag "auto"
+ (NoArg (setDynFlag Opt_AutoSccsOnExportedToplevs))
+ Supported
+ , Flag "no-auto"
+ (NoArg (unSetDynFlag Opt_AutoSccsOnExportedToplevs))
+ Supported
+ , Flag "fauto-sccs-on-individual-cafs"
+ (NoArg (setDynFlag Opt_AutoSccsOnIndividualCafs))
+ Supported
+ , Flag "caf-all"
+ (NoArg (setDynFlag Opt_AutoSccsOnIndividualCafs))
+ Supported
+ , Flag "no-caf-all"
+ (NoArg (unSetDynFlag Opt_AutoSccsOnIndividualCafs))
+ Supported
+
------ DPH flags ----------------------------------------------------
, Flag "fdph-seq"
( "dicts-cheap", Opt_DictsCheap, const Supported ),
( "inline-if-enough-args", Opt_InlineIfEnoughArgs, const Supported ),
( "excess-precision", Opt_ExcessPrecision, const Supported ),
+ ( "eager-blackholing", Opt_EagerBlackHoling, const Supported ),
( "asm-mangling", Opt_DoAsmMangling, const Supported ),
( "print-bind-result", Opt_PrintBindResult, const Supported ),
( "force-recomp", Opt_ForceRecomp, const Supported ),
( "break-on-error", Opt_BreakOnError, const Supported ),
( "print-evld-with-show", Opt_PrintEvldWithShow, const Supported ),
( "print-bind-contents", Opt_PrintBindContents, const Supported ),
- ( "run-cps", Opt_RunCPSZ, const Supported ),
+ ( "run-cps", Opt_RunCPS, const Supported ),
+ ( "run-cpsz", Opt_RunCPSZ, const Supported ),
+ ( "new-codegen", Opt_TryNewCodeGen, const Supported ),
( "convert-to-zipper-and-back", Opt_ConvertToZipCfgAndBack, const Supported ),
( "vectorise", Opt_Vectorise, const Supported ),
( "regs-graph", Opt_RegsGraph, const Supported ),
( "UnboxedTuples", Opt_UnboxedTuples, const Supported ),
( "StandaloneDeriving", Opt_StandaloneDeriving, const Supported ),
( "DeriveDataTypeable", Opt_DeriveDataTypeable, const Supported ),
+ ( "DeriveFunctor", Opt_DeriveFunctor, const Supported ),
( "TypeSynonymInstances", Opt_TypeSynonymInstances, const Supported ),
( "FlexibleContexts", Opt_FlexibleContexts, const Supported ),
( "FlexibleInstances", Opt_FlexibleInstances, const Supported ),
= [ (Opt_GADTs, Opt_RelaxedPolyRec) -- We want type-sig variables to
-- be completely rigid for GADTs
+ , (Opt_TypeFamilies, Opt_RelaxedPolyRec) -- Trac #2944 gives a nice example
+
, (Opt_ScopedTypeVariables, Opt_RelaxedPolyRec) -- Ditto for scoped type variables; see
-- Note [Scoped tyvars] in TcBinds
+ , (Opt_ImpredicativeTypes, Opt_RankNTypes)
]
glasgowExtsFlags :: [DynFlag]
, Opt_TypeSynonymInstances
, Opt_StandaloneDeriving
, Opt_DeriveDataTypeable
+ , Opt_DeriveFunctor
, Opt_FlexibleContexts
, Opt_FlexibleInstances
, Opt_ConstrainedClassMethods
, Opt_PatternGuards
, Opt_LiberalTypeSynonyms
, Opt_RankNTypes
- , Opt_ImpredicativeTypes
, Opt_TypeOperators
, Opt_RecursiveDo
, Opt_ParallelListComp
-- in dynamic libraries.
| opt_PIC
- = ["-fno-common", "-D__PIC__"]
+ = ["-fno-common", "-U __PIC__","-D__PIC__"]
| otherwise
= ["-mdynamic-no-pic"]
#elif mingw32_TARGET_OS
-- no -fPIC for Windows
| opt_PIC
- = ["-D__PIC__"]
+ = ["-U __PIC__","-D__PIC__"]
| otherwise
= []
#else
| opt_PIC
- = ["-fPIC", "-D__PIC__"]
+ = ["-fPIC", "-U __PIC__", "-D__PIC__"]
| otherwise
= []
#endif