diff options
| author | Thomas Miedema <thomasmiedema@gmail.com> | 2016-01-19 11:54:36 +0100 |
|---|---|---|
| committer | Thomas Miedema <thomasmiedema@gmail.com> | 2016-01-24 20:33:30 +0100 |
| commit | edc68b2ffe833e487ae6b2b04cd9be18e40a5a5e (patch) | |
| tree | c1b2612ce0dd2a2e728b6a2005c8c5dc2b63356a | |
| parent | 98d6a29e534350efd6aa72c0bf9d9e3ac4a76107 (diff) | |
| download | haskell-edc68b2ffe833e487ae6b2b04cd9be18e40a5a5e.tar.gz | |
Remove `replaceDynFlags` from `ContainsDynFlags`
Refactoring only. It's shorter, and brings
`HasDynFlags/ContainsDynFLags` in line with `HasModule/ContainsModule`.
Introduce `updTopEnv`.
Reviewed by: bgamari
Differential Revision: https://phabricator.haskell.org/D1832
| -rw-r--r-- | compiler/main/DriverPipeline.hs | 2 | ||||
| -rw-r--r-- | compiler/main/DynFlags.hs | 1 | ||||
| -rw-r--r-- | compiler/main/HscTypes.hs | 4 | ||||
| -rw-r--r-- | compiler/typecheck/TcRnMonad.hs | 24 | ||||
| -rw-r--r-- | compiler/typecheck/TcRnTypes.hs | 2 |
5 files changed, 14 insertions, 19 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index f40efd0f84..3de94fd403 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -611,7 +611,7 @@ runPipeline stop_phase hsc_env0 (input_fn, mb_phase) -- If we are compiling a Haskell module, and doing -- -dynamic-too, but couldn't do the -dynamic-too fast -- path, then rerun the pipeline for the dyn way - let dflags = extractDynFlags hsc_env + let dflags = hsc_dflags hsc_env -- NB: Currently disabled on Windows (ref #7134, #8228, and #5987) when (not $ platformOS (targetPlatform dflags) == OSMinGW32) $ do when isHaskellishFile $ whenCannotGenerateDynamicToo dflags $ do diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 79406a71cc..c9b7a993e3 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -905,7 +905,6 @@ instance (Monad m, HasDynFlags m) => HasDynFlags (ExceptT e m) where class ContainsDynFlags t where extractDynFlags :: t -> DynFlags - replaceDynFlags :: t -> DynFlags -> t data ProfAuto = NoProfAuto -- ^ no SCC annotations added diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs index 16a1ebd98c..6d43ec0037 100644 --- a/compiler/main/HscTypes.hs +++ b/compiler/main/HscTypes.hs @@ -408,10 +408,6 @@ data HscEnv #endif } -instance ContainsDynFlags HscEnv where - extractDynFlags env = hsc_dflags env - replaceDynFlags env dflags = env {hsc_dflags = dflags} - #ifdef GHCI data IServ = IServ { iservPipe :: Pipe diff --git a/compiler/typecheck/TcRnMonad.hs b/compiler/typecheck/TcRnMonad.hs index b0b1e3dcfe..692e9f3f43 100644 --- a/compiler/typecheck/TcRnMonad.hs +++ b/compiler/typecheck/TcRnMonad.hs @@ -278,6 +278,10 @@ discardResult a = a >> return () getTopEnv :: TcRnIf gbl lcl HscEnv getTopEnv = do { env <- getEnv; return (env_top env) } +updTopEnv :: (HscEnv -> HscEnv) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a +updTopEnv upd = updEnv (\ env@(Env { env_top = top }) -> + env { env_top = upd top }) + getGblEnv :: TcRnIf gbl lcl gbl getGblEnv = do { env <- getEnv; return (env_gbl env) } @@ -319,16 +323,16 @@ woptM :: WarningFlag -> TcRnIf gbl lcl Bool woptM flag = do { dflags <- getDynFlags; return (wopt flag dflags) } setXOptM :: LangExt.Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a -setXOptM flag = updEnv (\ env@(Env { env_top = top }) -> - env { env_top = top { hsc_dflags = xopt_set (hsc_dflags top) flag}} ) +setXOptM flag = + updTopEnv (\top -> top { hsc_dflags = xopt_set (hsc_dflags top) flag}) unsetGOptM :: GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a -unsetGOptM flag = updEnv (\ env@(Env { env_top = top }) -> - env { env_top = top { hsc_dflags = gopt_unset (hsc_dflags top) flag}} ) +unsetGOptM flag = + updTopEnv (\top -> top { hsc_dflags = gopt_unset (hsc_dflags top) flag}) unsetWOptM :: WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a -unsetWOptM flag = updEnv (\ env@(Env { env_top = top }) -> - env { env_top = top { hsc_dflags = wopt_unset (hsc_dflags top) flag}} ) +unsetWOptM flag = + updTopEnv (\top -> top { hsc_dflags = wopt_unset (hsc_dflags top) flag}) -- | Do it flag is true whenDOptM :: DumpFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl () @@ -351,11 +355,9 @@ getGhcMode :: TcRnIf gbl lcl GhcMode getGhcMode = do { env <- getTopEnv; return (ghcMode (hsc_dflags env)) } withDoDynamicToo :: TcRnIf gbl lcl a -> TcRnIf gbl lcl a -withDoDynamicToo m = do env <- getEnv - let dflags = extractDynFlags env - dflags' = dynamicTooMkDynamicDynFlags dflags - env' = replaceDynFlags env dflags' - setEnv env' m +withDoDynamicToo = + updTopEnv (\top@(HscEnv { hsc_dflags = dflags }) -> + top { hsc_dflags = dynamicTooMkDynamicDynFlags dflags }) getEpsVar :: TcRnIf gbl lcl (TcRef ExternalPackageState) getEpsVar = do { env <- getTopEnv; return (hsc_EPS env) } diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs index 07037c706f..d7670f1ba1 100644 --- a/compiler/typecheck/TcRnTypes.hs +++ b/compiler/typecheck/TcRnTypes.hs @@ -237,8 +237,6 @@ data Env gbl lcl instance ContainsDynFlags (Env gbl lcl) where extractDynFlags env = hsc_dflags (env_top env) - replaceDynFlags env dflags - = env {env_top = replaceDynFlags (env_top env) dflags} instance ContainsModule gbl => ContainsModule (Env gbl lcl) where extractModule env = extractModule (env_gbl env) |
