diff options
author | sheaf <sam.derbyshire@gmail.com> | 2023-03-24 19:31:10 +0100 |
---|---|---|
committer | sheaf <sam.derbyshire@gmail.com> | 2023-03-29 13:57:34 +0200 |
commit | d246049c81b922f9beddc629988c4e3eda8d4115 (patch) | |
tree | 73cde56497e9ab65931e50f375a4893c78f52c60 /compiler/GHC/Types | |
parent | 4f1940f05a9c0353ed12afe12a547a01878abd15 (diff) | |
download | haskell-d246049c81b922f9beddc629988c4e3eda8d4115.tar.gz |
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
-------------------------
Diffstat (limited to 'compiler/GHC/Types')
-rw-r--r-- | compiler/GHC/Types/Name/Occurrence.hs | 11 | ||||
-rw-r--r-- | compiler/GHC/Types/Name/Reader.hs | 8 |
2 files changed, 16 insertions, 3 deletions
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 |