summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGergo ERDI <gergo@erdi.hu>2021-11-16 11:41:56 +0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-12-09 22:14:24 -0500
commitb6f7d145872573baa632a3bbee1c52f0596ec482 (patch)
treea2fdc62630c48e68868db48d8c7c9f02b1f7ac7c
parent6d0319220ebc63a29b941483a6c40ed4f972dc24 (diff)
downloadhaskell-b6f7d145872573baa632a3bbee1c52f0596ec482.tar.gz
Remove `optLevel` from `DynFlags` (closes #20500)
-rw-r--r--compiler/GHC/Driver/Session.hs45
-rw-r--r--testsuite/tests/ghc-api/T10052/T10052.stderr2
-rw-r--r--testsuite/tests/ghci.debugger/scripts/print007.stderr2
-rw-r--r--testsuite/tests/ghci/should_fail/T10549.stderr4
-rw-r--r--testsuite/tests/ghci/should_fail/T10549a.stderr2
-rw-r--r--testsuite/tests/regalloc/regalloc_unit_tests.hs2
-rw-r--r--testsuite/tests/safeHaskell/ghci/p14.stderr3
-rw-r--r--testsuite/tests/th/T8333.stderr3
8 files changed, 40 insertions, 23 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index def183b62b..232740dfe4 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -449,7 +449,6 @@ data DynFlags = DynFlags {
-- configuration lazily. See Note [LLVM Configuration] in "GHC.SysTools".
llvmOptLevel :: Int, -- ^ LLVM optimisation level
verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
- optLevel :: Int, -- ^ Optimisation level
debugLevel :: Int, -- ^ How much debug information to produce
simplPhases :: Int, -- ^ Number of simplifier phases
maxSimplIterations :: Int, -- ^ Max simplifier iterations
@@ -1093,7 +1092,6 @@ defaultDynFlags mySettings llvmConfig =
ghcLink = LinkBinary,
backend = platformDefaultBackend (sTargetPlatform mySettings),
verbosity = 0,
- optLevel = 0,
debugLevel = 0,
simplPhases = 2,
maxSimplIterations = 4,
@@ -1779,18 +1777,35 @@ setInteractivePrint f d = d { interactivePrint = Just f}
-----------------------------------------------------------------------------
-- Setting the optimisation level
-updOptLevel :: Int -> DynFlags -> DynFlags
--- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
-updOptLevel n dfs
- = dfs2{ optLevel = final_n, llvmOptLevel = final_n }
+updOptLevelChanged :: Int -> DynFlags -> (DynFlags, Bool)
+-- ^ Sets the 'DynFlags' to be appropriate to the optimisation level and signals if any changes took place
+updOptLevelChanged n dfs
+ = (dfs3, changed1 || changed2 || changed3)
where
final_n = max 0 (min 2 n) -- Clamp to 0 <= n <= 2
- dfs1 = foldr (flip gopt_unset) dfs remove_gopts
- dfs2 = foldr (flip gopt_set) dfs1 extra_gopts
+ (dfs1, changed1) = foldr unset (dfs , False) remove_gopts
+ (dfs2, changed2) = foldr set (dfs1, False) extra_gopts
+ (dfs3, changed3) = setLlvmOptLevel dfs2
extra_gopts = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
remove_gopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
+ set f (dfs, changed)
+ | gopt f dfs = (dfs, changed)
+ | otherwise = (gopt_set dfs f, True)
+
+ unset f (dfs, changed)
+ | not (gopt f dfs) = (dfs, changed)
+ | otherwise = (gopt_unset dfs f, True)
+
+ setLlvmOptLevel dfs
+ | llvmOptLevel dfs /= final_n = (dfs{ llvmOptLevel = final_n }, True)
+ | otherwise = (dfs, False)
+
+updOptLevel :: Int -> DynFlags -> DynFlags
+-- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
+updOptLevel n = fst . updOptLevelChanged n
+
{- **********************************************************************
%* *
DynFlags parser
@@ -4263,13 +4278,6 @@ setObjBackend l = updM set
setOptLevel :: Int -> DynFlags -> DynP DynFlags
setOptLevel n dflags = return (updOptLevel n dflags)
-checkOptLevel :: Int -> DynFlags -> Either String DynFlags
-checkOptLevel n dflags
- | backend dflags == Interpreter && n > 0
- = Left "-O conflicts with --interactive; -O ignored."
- | otherwise
- = Right dflags
-
setCallerCcFilters :: String -> DynP ()
setCallerCcFilters arg =
case parseCallerCcFilter arg of
@@ -4643,8 +4651,11 @@ makeDynFlagsConsistent dflags
not (gopt Opt_PIC dflags)
= loop (gopt_set dflags Opt_PIC)
"Enabling -fPIC as it is always on for this platform"
- | Left err <- checkOptLevel (optLevel dflags) dflags
- = loop (updOptLevel 0 dflags) err
+
+ | backend dflags == Interpreter
+ , let (dflags', changed) = updOptLevelChanged 0 dflags
+ , changed
+ = loop dflags' "Optimization flags conflict with --interactive; optimization flags ignored."
| LinkInMemory <- ghcLink dflags
, not (gopt Opt_ExternalInterpreter dflags)
diff --git a/testsuite/tests/ghc-api/T10052/T10052.stderr b/testsuite/tests/ghc-api/T10052/T10052.stderr
index 62f0b6d152..50db4fe9f2 100644
--- a/testsuite/tests/ghc-api/T10052/T10052.stderr
+++ b/testsuite/tests/ghc-api/T10052/T10052.stderr
@@ -1,3 +1,3 @@
when making flags consistent: warning:
- -O conflicts with --interactive; -O ignored.
+ Optimization flags conflict with --interactive; optimization flags ignored.
diff --git a/testsuite/tests/ghci.debugger/scripts/print007.stderr b/testsuite/tests/ghci.debugger/scripts/print007.stderr
index 62f0b6d152..50db4fe9f2 100644
--- a/testsuite/tests/ghci.debugger/scripts/print007.stderr
+++ b/testsuite/tests/ghci.debugger/scripts/print007.stderr
@@ -1,3 +1,3 @@
when making flags consistent: warning:
- -O conflicts with --interactive; -O ignored.
+ Optimization flags conflict with --interactive; optimization flags ignored.
diff --git a/testsuite/tests/ghci/should_fail/T10549.stderr b/testsuite/tests/ghci/should_fail/T10549.stderr
index 1f49f8e6c9..50db4fe9f2 100644
--- a/testsuite/tests/ghci/should_fail/T10549.stderr
+++ b/testsuite/tests/ghci/should_fail/T10549.stderr
@@ -1,3 +1,3 @@
-when making flags consistent: Warning:
- -O conflicts with --interactive; -O ignored.
+when making flags consistent: warning:
+ Optimization flags conflict with --interactive; optimization flags ignored.
diff --git a/testsuite/tests/ghci/should_fail/T10549a.stderr b/testsuite/tests/ghci/should_fail/T10549a.stderr
index 62f0b6d152..50db4fe9f2 100644
--- a/testsuite/tests/ghci/should_fail/T10549a.stderr
+++ b/testsuite/tests/ghci/should_fail/T10549a.stderr
@@ -1,3 +1,3 @@
when making flags consistent: warning:
- -O conflicts with --interactive; -O ignored.
+ Optimization flags conflict with --interactive; optimization flags ignored.
diff --git a/testsuite/tests/regalloc/regalloc_unit_tests.hs b/testsuite/tests/regalloc/regalloc_unit_tests.hs
index 7726c79b1f..b005982d2d 100644
--- a/testsuite/tests/regalloc/regalloc_unit_tests.hs
+++ b/testsuite/tests/regalloc/regalloc_unit_tests.hs
@@ -212,7 +212,7 @@ testGraphNoSpills logger dflags' path us = do
let acc n = maybe n (++ n) in
foldr (\(as, bs) (xs, ys) -> (acc xs as, acc ys bs)) ([], [])
- dflags = dflags' { optLevel = 2 }
+ dflags = updOptLevel 2 dflags'
-- discard irrelevant stats
extractSRMs x = case x of
diff --git a/testsuite/tests/safeHaskell/ghci/p14.stderr b/testsuite/tests/safeHaskell/ghci/p14.stderr
index 3e0ac0ae46..66ac9c0074 100644
--- a/testsuite/tests/safeHaskell/ghci/p14.stderr
+++ b/testsuite/tests/safeHaskell/ghci/p14.stderr
@@ -1,4 +1,7 @@
+when making flags consistent: warning:
+ Optimization flags conflict with --interactive; optimization flags ignored.
+
<interactive>:10:25: error:
• No instance for (Num a) arising from a use of ‘f’
Possible fix: add (Num a) to the context of the RULE "id/Int"
diff --git a/testsuite/tests/th/T8333.stderr b/testsuite/tests/th/T8333.stderr
new file mode 100644
index 0000000000..50db4fe9f2
--- /dev/null
+++ b/testsuite/tests/th/T8333.stderr
@@ -0,0 +1,3 @@
+
+when making flags consistent: warning:
+ Optimization flags conflict with --interactive; optimization flags ignored.