From d246049c81b922f9beddc629988c4e3eda8d4115 Mon Sep 17 00:00:00 2001 From: sheaf Date: Fri, 24 Mar 2023 19:31:10 +0100 Subject: igre_prompt_env: discard "only-qualified" names We were unnecessarily carrying around names only available qualified in igre_prompt_env, violating the icReaderEnv invariant. We now get rid of these, as they aren't needed for the shadowing computation that igre_prompt_env exists for. Fixes #23177 ------------------------- Metric Decrease: T14052 T14052Type ------------------------- --- compiler/GHC/Types/Name/Occurrence.hs | 11 +++++++++++ compiler/GHC/Types/Name/Reader.hs | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'compiler/GHC/Types') diff --git a/compiler/GHC/Types/Name/Occurrence.hs b/compiler/GHC/Types/Name/Occurrence.hs index b7d95543b0..8aecadf71e 100644 --- a/compiler/GHC/Types/Name/Occurrence.hs +++ b/compiler/GHC/Types/Name/Occurrence.hs @@ -88,6 +88,7 @@ module GHC.Types.Name.Occurrence ( -- * The 'OccEnv' type OccEnv, emptyOccEnv, unitOccEnv, extendOccEnv, mapOccEnv, strictMapOccEnv, + mapMaybeOccEnv, lookupOccEnv, lookupOccEnv_WithFields, lookupFieldsOccEnv, mkOccEnv, mkOccEnv_C, extendOccEnvList, elemOccEnv, nonDetOccEnvElts, nonDetFoldOccEnv, @@ -685,6 +686,16 @@ plusOccEnv_C f (MkOccEnv env1) (MkOccEnv env2) mapOccEnv :: (a->b) -> OccEnv a -> OccEnv b mapOccEnv = fmap +-- | 'mapMaybe' for b 'OccEnv'. +mapMaybeOccEnv :: (a -> Maybe b) -> OccEnv a -> OccEnv b +mapMaybeOccEnv f (MkOccEnv env) + = MkOccEnv $ mapMaybeUFM g env + where + g as = + case mapMaybeUFM f as of + m' | isNullUFM m' -> Nothing + | otherwise -> Just m' + -- | Add a single element to an 'OccEnv', using a different function whether -- the 'OccName' already exists or not. extendOccEnv_Acc :: forall a b diff --git a/compiler/GHC/Types/Name/Reader.hs b/compiler/GHC/Types/Name/Reader.hs index dd7a612d22..928bac9c0c 100644 --- a/compiler/GHC/Types/Name/Reader.hs +++ b/compiler/GHC/Types/Name/Reader.hs @@ -1412,10 +1412,11 @@ Wrinkle [Shadowing namespaces] -} -shadowNames :: GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv +shadowNames :: Bool -- ^ discard names that are only available qualified? + -> GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv -- Remove certain old GREs that share the same OccName as this new Name. -- See Note [GlobalRdrEnv shadowing] for details -shadowNames env new_gres = minusOccEnv_C_Ns do_shadowing env new_gres +shadowNames drop_only_qualified env new_gres = minusOccEnv_C_Ns do_shadowing env new_gres where do_shadowing :: UniqFM NameSpace [GlobalRdrElt] @@ -1455,7 +1456,8 @@ shadowNames env new_gres = minusOccEnv_C_Ns do_shadowing env new_gres case greDefinitionModule old_gre of Nothing -> Just old_gre -- Old name is Internal; do not shadow Just old_mod - | null iss' -- Nothing remains + | null iss' -- Nothing remains + || drop_only_qualified -> Nothing | otherwise -- cgit v1.2.1