diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-10-26 11:58:13 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-15 03:54:39 -0500 |
commit | 2eb0fb87b921efc8f107eb39a3d34dae08082a3c (patch) | |
tree | e9ea102c18ae826d28a1b0751d9af175fc9cea0a /compiler | |
parent | 9372329008143104b0ae5e8e792e957090dfa743 (diff) | |
download | haskell-2eb0fb87b921efc8f107eb39a3d34dae08082a3c.tar.gz |
Package Imports: Get candidate packages also from re-exported modules
Previously we were just looking at the direct imports to try and work
out what a package qualifier could apply to but #22333 pointed out we
also needed to look for reexported modules.
Fixes #22333
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Unit/Finder.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Unit/State.hs | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/compiler/GHC/Unit/Finder.hs b/compiler/GHC/Unit/Finder.hs index 45057d13e2..e722e432af 100644 --- a/compiler/GHC/Unit/Finder.hs +++ b/compiler/GHC/Unit/Finder.hs @@ -136,13 +136,13 @@ lookupFileCache (FinderCache _ ref) key = do -- that package is searched for the module. findImportedModule :: HscEnv -> ModuleName -> PkgQual -> IO FindResult -findImportedModule hsc_env mod fs = +findImportedModule hsc_env mod pkg_qual = let fc = hsc_FC hsc_env mhome_unit = hsc_home_unit_maybe hsc_env dflags = hsc_dflags hsc_env fopts = initFinderOpts dflags in do - findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod fs + findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod pkg_qual findImportedModuleNoHsc :: FinderCache diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs index ca361d69d2..8123bbaab6 100644 --- a/compiler/GHC/Unit/State.hs +++ b/compiler/GHC/Unit/State.hs @@ -571,13 +571,25 @@ resolvePackageImport unit_st mn pn = do -- 1. Find all modules providing the ModuleName (this accounts for visibility/thinning etc) providers <- Map.filter originVisible <$> Map.lookup mn (moduleNameProvidersMap unit_st) -- 2. Get the UnitIds of the candidates - let candidates_uid = map (toUnitId . moduleUnit) $ Map.keys providers + let candidates_uid = concatMap to_uid $ Map.assocs providers -- 3. Get the package names of the candidates let candidates_units = map (\ui -> ((unitPackageName ui), unitId ui)) $ mapMaybe (\uid -> Map.lookup uid (unitInfoMap unit_st)) candidates_uid -- 4. Check to see if the PackageName helps us disambiguate any candidates. lookup pn candidates_units + where + + -- Get the UnitId from which a visible identifier is from + to_uid :: (Module, ModuleOrigin) -> [UnitId] + to_uid (mod, ModOrigin mo re_exps _ _) = + case mo of + -- Available directly, but also potentially from re-exports + Just True -> (toUnitId (moduleUnit mod)) : map unitId re_exps + -- Just available from these re-exports + _ -> map unitId re_exps + to_uid _ = [] + -- | Create a Map UnitId UnitInfo -- -- For each instantiated unit, we add two map keys: |