HscLang(..),
DynFlag(..), -- needed non-abstractly by DriverFlags
DynFlags(..),
+ PackageFlag(..),
v_Static_hsc_opts,
dopt_HscLang, -- DynFlags -> HscLang
dopt_OutName, -- DynFlags -> String
getOpts, -- (DynFlags -> [a]) -> IO [a]
- setLang,
getVerbFlag,
- setOptLevel,
-
- -- Manipulating the DynFlags state
- getDynFlags, -- IO DynFlags
- setDynFlags, -- DynFlags -> IO ()
- updDynFlags, -- (DynFlags -> DynFlags) -> IO ()
- dynFlag, -- (DynFlags -> a) -> IO a
- setDynFlag, unSetDynFlag, -- DynFlag -> IO ()
- saveDynFlags, -- IO ()
- restoreDynFlags, -- IO DynFlags
+ updOptLevel,
-- sets of warning opts
minusWOpts,
opt_Flatten,
-- optimisation opts
- opt_NoMethodSharing,
+ opt_NoMethodSharing,
+ opt_NoStateHack,
opt_LiberateCaseThreshold,
opt_CprOff,
opt_RulesOff,
opt_UF_DearOp,
-- misc opts
- opt_InPackage,
+ opt_ErrorSpans,
opt_EmitCExternDecls,
opt_EnsureSplittableC,
opt_GranMacros,
opt_OmitBlackHoling,
opt_Static,
opt_Unregisterised,
- opt_EmitExternalCore
+ opt_EmitExternalCore,
+ opt_PIC
) where
#include "HsVersions.h"
+import {-# SOURCE #-} Packages (PackageState)
import Constants -- Default values for some flags
import Util
import FastString ( FastString, mkFastString )
import Config
import Maybes ( firstJust )
+import Panic ( ghcError, GhcException(UsageError) )
import GLAEXTS
-import DATA_IOREF ( IORef, readIORef, writeIORef )
+import DATA_IOREF ( IORef, readIORef )
import UNSAFE_IO ( unsafePerformIO )
\end{code}
data DynFlag
-- debugging flags
- = Opt_D_dump_absC
+ = Opt_D_dump_cmm
| Opt_D_dump_asm
| Opt_D_dump_cpranal
| Opt_D_dump_deriv
| Opt_D_dump_inlinings
| Opt_D_dump_occur_anal
| Opt_D_dump_parsed
- | Opt_D_dump_realC
| Opt_D_dump_rn
| Opt_D_dump_simpl
| Opt_D_dump_simpl_iterations
| Opt_D_dump_worker_wrapper
| Opt_D_dump_rn_trace
| Opt_D_dump_rn_stats
- | Opt_D_dump_stix
+ | Opt_D_dump_opt_cmm
| Opt_D_dump_simpl_stats
| Opt_D_dump_tc_trace
| Opt_D_dump_if_trace
| Opt_D_dump_minimal_imports
| Opt_DoCoreLinting
| Opt_DoStgLinting
+ | Opt_DoCmmLinting
| Opt_WarnIsError -- -Werror; makes warnings fatal
| Opt_WarnDuplicateExports
| Opt_WarnHiShadows
| Opt_WarnIncompletePatterns
+ | Opt_WarnIncompletePatternsRecUpd
| Opt_WarnMissingFields
| Opt_WarnMissingMethods
| Opt_WarnMissingSigs
| Opt_WarnUnusedImports
| Opt_WarnUnusedMatches
| Opt_WarnDeprecations
- | Opt_WarnMisc
+ | Opt_WarnDodgyImports
-- language opts
| Opt_AllowOverlappingInstances
| Opt_AllowUndecidableInstances
| Opt_AllowIncoherentInstances
- | Opt_NoMonomorphismRestriction
+ | Opt_MonomorphismRestriction
| Opt_GlasgowExts
| Opt_FFI
| Opt_PArr -- syntactic support for parallel arrays
| Opt_TH
| Opt_ImplicitParams
| Opt_Generics
- | Opt_NoImplicitPrelude
+ | Opt_ImplicitPrelude
-- optimisation opts
| Opt_Strictness
+ | Opt_FullLaziness
| Opt_CSE
| Opt_IgnoreInterfacePragmas
| Opt_OmitInterfacePragmas
ppFlag :: Bool, -- preprocess with a Haskell Pp?
stolen_x86_regs :: Int,
cmdlineHcIncludes :: [String], -- -#includes
+ importPaths :: [FilePath],
-- options for particular phases
opt_L :: [String],
opt_i :: [String],
#endif
+ -- ** Package flags
+ extraPkgConfs :: [FilePath],
+ -- The -package-conf flags given on the command line, in the order
+ -- they appeared.
+
+ readUserPkgConf :: Bool,
+ -- Whether or not to read the user package database
+ -- (-no-user-package-conf).
+
+ packageFlags :: [PackageFlag],
+ -- The -package and -hide-package flags from the command-line
+
+ -- ** Package state
+ pkgState :: PackageState,
+
-- hsc dynamic flags
flags :: [DynFlag]
}
+data PackageFlag
+ = ExposePackage String
+ | HidePackage String
+ | IgnorePackage String
+
data HscLang
= HscC
| HscAsm
ppFlag = False,
stolen_x86_regs = 4,
cmdlineHcIncludes = [],
+ importPaths = ["."],
opt_L = [],
opt_P = [],
opt_F = [],
opt_I = [],
opt_i = [],
#endif
+
+ extraPkgConfs = [],
+ readUserPkgConf = True,
+ packageFlags = [],
+ pkgState = error "pkgState",
+
flags = [
+ Opt_ImplicitPrelude,
+ Opt_MonomorphismRestriction,
Opt_Generics,
-- Generating the helper-functions for
-- generics is now on by default
Opt_Strictness,
-- strictness is on by default, but this only
-- applies to -O.
- Opt_CSE,
- -- similarly for CSE.
+ Opt_CSE, -- similarly for CSE.
+ Opt_FullLaziness, -- ...and for full laziness
+
Opt_DoLambdaEtaExpansion,
-- This one is important for a tiresome reason:
-- we want to make sure that the bindings for data
Opt_IgnoreInterfacePragmas,
Opt_OmitInterfacePragmas
- ] ++ standardWarnings,
+ ] ++ standardWarnings
}
{-
dopt_unset :: DynFlags -> DynFlag -> DynFlags
dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
-getOpts :: (DynFlags -> [a]) -> IO [a]
+getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
-- We add to the options from the front, so we need to reverse the list
-getOpts opts = dynFlag opts >>= return . reverse
-
--- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
--- (-fvia-C, -fasm, -filx respectively).
-setLang l = updDynFlags (\ dfs -> case hscLang dfs of
- HscC -> dfs{ hscLang = l }
- HscAsm -> dfs{ hscLang = l }
- HscILX -> dfs{ hscLang = l }
- _ -> dfs)
+getOpts dflags opts = reverse (opts dflags)
-getVerbFlag = do
- verb <- dynFlag verbosity
- if verb >= 3 then return "-v" else return ""
+getVerbFlag dflags
+ | verbosity dflags >= 3 = "-v"
+ | otherwise = ""
-----------------------------------------------------------------------------
-- Setting the optimisation level
-setOptLevel :: Int -> IO ()
-setOptLevel n
- = do dflags <- getDynFlags
- if hscLang dflags == HscInterpreted && n > 0
- then putStr "warning: -O conflicts with --interactive; -O ignored.\n"
- else updDynFlags (setOptLevel' n)
-
-setOptLevel' n dfs
+updOptLevel n dfs
= if (n >= 1)
then dfs2{ hscLang = HscC, optLevel = n } -- turn on -fvia-C with -O
else dfs2{ optLevel = n }
buildCoreToDo :: DynFlags -> [CoreToDo]
buildCoreToDo dflags = core_todo
where
- opt_level = optLevel dflags
- max_iter = maxSimplIterations dflags
- strictness = dopt Opt_Strictness dflags
- cse = dopt Opt_CSE dflags
- rule_check = ruleCheck dflags
+ opt_level = optLevel dflags
+ max_iter = maxSimplIterations dflags
+ strictness = dopt Opt_Strictness dflags
+ full_laziness = dopt Opt_FullLaziness dflags
+ cse = dopt Opt_CSE dflags
+ rule_check = ruleCheck dflags
core_todo =
if opt_level == 0 then
-- so that overloaded functions have all their dictionary lambdas manifest
CoreDoSpecialising,
- CoreDoFloatOutwards (FloatOutSw False False),
+ if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
+ else CoreDoNothing,
+
CoreDoFloatInwards,
CoreDoSimplify (SimplPhase 2) [
MaxSimplifierIterations max_iter
],
- CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
- True), -- Float constants
+ if full_laziness then
+ CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
+ True) -- Float constants
+ else CoreDoNothing,
-- 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
MaxSimplifierIterations max_iter
]
]
-
--- --------------------------------------------------------------------------
--- Mess about with the mutable variables holding the dynamic arguments
-
--- v_InitDynFlags
--- is the "baseline" dynamic flags, initialised from
--- the defaults and command line options, and updated by the
--- ':s' command in GHCi.
---
--- v_DynFlags
--- is the dynamic flags for the current compilation. It is reset
--- to the value of v_InitDynFlags before each compilation, then
--- updated by reading any OPTIONS pragma in the current module.
-
-GLOBAL_VAR(v_InitDynFlags, defaultDynFlags, DynFlags)
-GLOBAL_VAR(v_DynFlags, defaultDynFlags, DynFlags)
-
-setDynFlags :: DynFlags -> IO ()
-setDynFlags dfs = writeIORef v_DynFlags dfs
-
-saveDynFlags :: IO ()
-saveDynFlags = do dfs <- readIORef v_DynFlags
- writeIORef v_InitDynFlags dfs
-
-restoreDynFlags :: IO DynFlags
-restoreDynFlags = do dfs <- readIORef v_InitDynFlags
- writeIORef v_DynFlags dfs
- return dfs
-
-getDynFlags :: IO DynFlags
-getDynFlags = readIORef v_DynFlags
-
-updDynFlags :: (DynFlags -> DynFlags) -> IO ()
-updDynFlags f = do dfs <- readIORef v_DynFlags
- writeIORef v_DynFlags (f dfs)
-
-dynFlag :: (DynFlags -> a) -> IO a
-dynFlag f = do dflags <- readIORef v_DynFlags; return (f dflags)
-
-setDynFlag, unSetDynFlag :: DynFlag -> IO ()
-setDynFlag f = updDynFlags (\dfs -> dopt_set dfs f)
-unSetDynFlag f = updDynFlags (\dfs -> dopt_unset dfs f)
\end{code}
-
%************************************************************************
%* *
\subsection{Warnings}
Opt_WarnUnusedMatches,
Opt_WarnUnusedImports,
Opt_WarnIncompletePatterns,
- Opt_WarnMisc
+ Opt_WarnDodgyImports
]
minusWallOpts
GLOBAL_VAR(v_Static_hsc_opts, [], [String])
lookUp :: FastString -> Bool
-lookup_int :: String -> Maybe Int
lookup_def_int :: String -> Int -> Int
lookup_def_float :: String -> Float -> Float
lookup_str :: String -> Maybe String
lookUp sw = sw `elem` packed_static_opts
-lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
-
-lookup_int sw = case (lookup_str sw) of
- Nothing -> Nothing
- Just xx -> Just (read xx)
+-- (lookup_str "foo") looks for the flag -foo=X or -fooX,
+-- and returns the string X
+lookup_str sw
+ = case firstJust (map (startsWith sw) unpacked_static_opts) of
+ Just ('=' : str) -> Just str
+ Just str -> Just str
+ Nothing -> Nothing
lookup_def_int sw def = case (lookup_str sw) of
Nothing -> def -- Use default
- Just xx -> read xx
+ Just xx -> try_read sw xx
lookup_def_float sw def = case (lookup_str sw) of
Nothing -> def -- Use default
- Just xx -> read xx
+ Just xx -> try_read sw xx
+
+
+try_read :: Read a => String -> String -> a
+-- (try_read sw str) tries to read s; if it fails, it
+-- bleats about flag sw
+try_read sw str
+ = case reads str of
+ ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
+ [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
+ -- ToDo: hack alert. We should really parse the arugments
+ -- and announce errors in a more civilised way.
{-
opt_Flatten = lookUp FSLIT("-fflatten")
-- optimisation opts
+opt_NoStateHack = lookUp FSLIT("-fno-state-hack")
opt_NoMethodSharing = lookUp FSLIT("-fno-method-sharing")
opt_CprOff = lookUp FSLIT("-fcpr-off")
opt_RulesOff = lookUp FSLIT("-frules-off")
opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" (10::Int)
opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
-{-
- The optional '-inpackage=P' flag tells what package
- we are compiling this module for.
- The Prelude, for example is compiled with '-inpackage std'
--}
-opt_InPackage = case lookup_str "-inpackage=" of
- Just p -> mkFastString p
- Nothing -> FSLIT("Main") -- The package name if none is specified
-
opt_EmitCExternDecls = lookUp FSLIT("-femit-extern-decls")
opt_EnsureSplittableC = lookUp FSLIT("-fglobalise-toplev-names")
opt_GranMacros = lookUp FSLIT("-fgransim")
opt_Static = lookUp FSLIT("-static")
opt_Unregisterised = lookUp FSLIT("-funregisterised")
opt_EmitExternalCore = lookUp FSLIT("-fext-core")
+
+-- Include full span info in error messages, instead of just the start position.
+opt_ErrorSpans = lookUp FSLIT("-ferror-spans")
+
+opt_PIC = lookUp FSLIT("-fPIC")
\end{code}
%************************************************************************
"fno-hi-version-check",
"dno-black-holing",
"fno-method-sharing",
+ "fno-state-hack",
"fruntime-types",
"fno-pre-inlining",
"fexcess-precision",
"funfolding-update-in-place",
- "fno-prune-decls",
"static",
"funregisterised",
"fext-core",
"frule-check",
"frules-off",
- "fcpr-off"
+ "fcpr-off",
+ "ferror-spans",
+ "fPIC"
]
|| any (flip prefixMatch f) [
"fcontext-stack",