Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
a805b2a2
by Simon Hengel at 2026-06-24T15:55:20-04:00
11 changed files:
- + changelog.d/reexported-module-errors
- compiler/GHC/Iface/Errors.hs
- compiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Unit/State.hs
- ghc/GHCi/UI/Exception.hs
- + testsuite/tests/package/ImportReexport.hs
- + testsuite/tests/package/ImportReexport.stderr
- testsuite/tests/package/all.T
Changes:
| 1 | +section: compiler
|
|
| 2 | +synopsis: Reference the correct package in error messages when trying to import a reexported module from a hidden package.
|
|
| 3 | +issues: #27417
|
|
| 4 | +mrs: !16229 |
| ... | ... | @@ -128,7 +128,7 @@ cantFindErr unit_env profile mod_name find_result |
| 128 | 128 | |
| 129 | 129 | | otherwise
|
| 130 | 130 | -> GenericMissing
|
| 131 | - (map ((\uid -> (uid, lookupUnit (ue_homeUnitState unit_env) uid))) pkg_hiddens)
|
|
| 131 | + pkg_hiddens
|
|
| 132 | 132 | mod_hiddens unusables files
|
| 133 | 133 | _ -> panic "cantFindErr"
|
| 134 | 134 |
| ... | ... | @@ -261,13 +261,13 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst |
| 261 | 261 | .ppr.mkUnit) res ++
|
| 262 | 262 | if f then [text "a package flag"] else []
|
| 263 | 263 | )
|
| 264 | - pkg_hidden :: (Unit, Maybe UnitInfo) -> SDoc
|
|
| 265 | - pkg_hidden (uid, uif) =
|
|
| 264 | + pkg_hidden :: UnitInfo -> SDoc
|
|
| 265 | + pkg_hidden unit =
|
|
| 266 | 266 | text "It is a member of the hidden package"
|
| 267 | - <+> quotes (ppr uid)
|
|
| 267 | + <+> quotes (ppr $ unitId unit)
|
|
| 268 | 268 | --FIXME: we don't really want to show the unit id here we should
|
| 269 | 269 | -- show the source package id or installed package id if it's ambiguous
|
| 270 | - <> dot $$ maybe empty pkg_hidden_hint uif
|
|
| 270 | + <> dot $$ pkg_hidden_hint unit
|
|
| 271 | 271 | |
| 272 | 272 | |
| 273 | 273 | mod_hidden pkg =
|
| ... | ... | @@ -73,7 +73,7 @@ data CantFindInstalledReason |
| 73 | 73 | | NotAModule
|
| 74 | 74 | | CouldntFindInFiles [FilePath]
|
| 75 | 75 | | GenericMissing
|
| 76 | - [(Unit, Maybe UnitInfo)] [Unit]
|
|
| 76 | + [UnitInfo] [Unit]
|
|
| 77 | 77 | [UnusableUnit] [FilePath]
|
| 78 | 78 | | MultiplePackages [(Module, ModuleOrigin)]
|
| 79 | 79 | deriving Generic
|
| ... | ... | @@ -510,9 +510,9 @@ findLookupResult fc fopts r = case r of |
| 510 | 510 | , fr_suggestions = []})
|
| 511 | 511 | LookupMultiple rs ->
|
| 512 | 512 | return (FoundMultiple rs)
|
| 513 | - LookupHidden pkg_hiddens mod_hiddens ->
|
|
| 513 | + LookupHidden fr_pkgs_hidden mod_hiddens ->
|
|
| 514 | 514 | return (NotFound{ fr_paths = [], fr_pkg = Nothing
|
| 515 | - , fr_pkgs_hidden = map (moduleUnit.fst) pkg_hiddens
|
|
| 515 | + , fr_pkgs_hidden
|
|
| 516 | 516 | , fr_mods_hidden = map (moduleUnit.fst) mod_hiddens
|
| 517 | 517 | , fr_unusables = []
|
| 518 | 518 | , fr_suggestions = [] })
|
| ... | ... | @@ -70,7 +70,7 @@ data FindResult |
| 70 | 70 | , fr_mods_hidden :: [Unit] -- ^ Module is in these units,
|
| 71 | 71 | -- but the *module* is hidden
|
| 72 | 72 | |
| 73 | - , fr_pkgs_hidden :: [Unit] -- ^ Module is in these units,
|
|
| 73 | + , fr_pkgs_hidden :: [UnitInfo] -- ^ Module is in these units,
|
|
| 74 | 74 | -- but the *unit* is hidden
|
| 75 | 75 | |
| 76 | 76 | -- | Module is in these units, but it is unusable
|
| ... | ... | @@ -1905,7 +1905,7 @@ data LookupResult = |
| 1905 | 1905 | -- | No modules found, but there were some hidden ones with
|
| 1906 | 1906 | -- an exact name match. First is due to package hidden, second
|
| 1907 | 1907 | -- is due to module being hidden
|
| 1908 | - | LookupHidden [(Module, ModuleOrigin)] [(Module, ModuleOrigin)]
|
|
| 1908 | + | LookupHidden [UnitInfo] [(Module, ModuleOrigin)]
|
|
| 1909 | 1909 | -- | No modules found, but there were some unusable ones with
|
| 1910 | 1910 | -- an exact name match
|
| 1911 | 1911 | | LookupUnusable [(Module, ModuleOrigin)]
|
| ... | ... | @@ -1954,8 +1954,8 @@ lookupModuleWithSuggestions' :: UnitState |
| 1954 | 1954 | -> ModuleName
|
| 1955 | 1955 | -> PkgQual
|
| 1956 | 1956 | -> LookupResult
|
| 1957 | -lookupModuleWithSuggestions' pkgs mod_map m mb_pn
|
|
| 1958 | - = case lookupUniqMap mod_map m of
|
|
| 1957 | +lookupModuleWithSuggestions' pkgs mod_map name mb_pn
|
|
| 1958 | + = case lookupUniqMap mod_map name of
|
|
| 1959 | 1959 | Nothing -> LookupNotFound suggestions
|
| 1960 | 1960 | Just xs ->
|
| 1961 | 1961 | case foldl' classify ([],[],[], []) (sortOn fst $ nonDetUniqMapToList xs) of
|
| ... | ... | @@ -1974,14 +1974,21 @@ lookupModuleWithSuggestions' pkgs mod_map m mb_pn |
| 1974 | 1974 | -> (hidden_pkg, x:hidden_mod, unusable, exposed)
|
| 1975 | 1975 | ModUnusable _
|
| 1976 | 1976 | -> (hidden_pkg, hidden_mod, x:unusable, exposed)
|
| 1977 | - _ | originEmpty origin
|
|
| 1977 | + ModOrigin { fromOrigUnit = origAvailableUnderSameName, fromHiddenReexport }
|
|
| 1978 | + | originEmpty origin
|
|
| 1978 | 1979 | -> (hidden_pkg, hidden_mod, unusable, exposed)
|
| 1979 | 1980 | | originVisible origin
|
| 1980 | 1981 | -> (hidden_pkg, hidden_mod, unusable, x:exposed)
|
| 1981 | 1982 | | otherwise
|
| 1982 | - -> (x:hidden_pkg, hidden_mod, unusable, exposed)
|
|
| 1983 | + -> (reexports ++ maybe id (:) origUnit hidden_pkg, hidden_mod, unusable, exposed)
|
|
| 1984 | + where
|
|
| 1985 | + reexports :: [UnitInfo]
|
|
| 1986 | + reexports = sortOn unitId fromHiddenReexport
|
|
| 1983 | 1987 | |
| 1984 | - unit_lookup p = lookupUnit pkgs p `orElse` pprPanic "lookupModuleWithSuggestions" (ppr p <+> ppr m)
|
|
| 1988 | + origUnit :: Maybe UnitInfo
|
|
| 1989 | + origUnit = origAvailableUnderSameName >> lookupUnit pkgs (moduleUnit m)
|
|
| 1990 | + |
|
| 1991 | + unit_lookup p = lookupUnit pkgs p `orElse` pprPanic "lookupModuleWithSuggestions" (ppr p <+> ppr name)
|
|
| 1985 | 1992 | mod_unit = unit_lookup . moduleUnit
|
| 1986 | 1993 | |
| 1987 | 1994 | -- Filters out origins which are not associated with the given package
|
| ... | ... | @@ -2011,7 +2018,7 @@ lookupModuleWithSuggestions' pkgs mod_map m mb_pn |
| 2011 | 2018 | , fromPackageFlag = False -- always excluded
|
| 2012 | 2019 | }
|
| 2013 | 2020 | |
| 2014 | - suggestions = fuzzyLookup (moduleNameString m) all_mods
|
|
| 2021 | + suggestions = fuzzyLookup (moduleNameString name) all_mods
|
|
| 2015 | 2022 | |
| 2016 | 2023 | all_mods :: [(String, ModuleSuggestion)] -- All modules
|
| 2017 | 2024 | all_mods = sortBy (comparing fst) $
|
| ... | ... | @@ -186,11 +186,13 @@ ghciDiagnosticMessage ghc_opts msg = |
| 186 | 186 | Just (pprWithUnitState us $ cantFindErrorX pkg_hidden_hint may_show_locations module_or_interface cfi)
|
| 187 | 187 | _ -> Nothing
|
| 188 | 188 | where
|
| 189 | - |
|
| 189 | + may_show_locations :: [String] -> SDoc
|
|
| 190 | 190 | may_show_locations = mayShowLocations ":set -v" (ifaceShowTriedFiles opts)
|
| 191 | 191 | |
| 192 | + pkg_hidden_hint :: UnitInfo -> SDoc
|
|
| 192 | 193 | pkg_hidden_hint = pkgHiddenHint hidden_msg (ifaceBuildingCabalPackage opts)
|
| 193 | 194 | where
|
| 195 | + hidden_msg :: UnitInfo -> SDoc
|
|
| 194 | 196 | hidden_msg pkg =
|
| 195 | 197 | text "You can run" <+>
|
| 196 | 198 | quotes (text ":set -package " <> ppr (unitPackageName pkg)) <+>
|
| 1 | +module ImportReexport where
|
|
| 2 | +import GHC.Types -- reexported and renamed by ghc-prim from ghc-internal
|
|
| 3 | +import GHC.Platform.ArchOS -- reexported by by ghc and ghc-boot + provided by ghc-platform |
| 1 | +ImportReexport.hs:2:1: error: [GHC-87110]
|
|
| 2 | + Could not load module ‘GHC.Types’.
|
|
| 3 | + It is a member of the hidden package ‘ghc-prim-0.14.0’.
|
|
| 4 | + Use -v to see a list of the files searched for.
|
|
| 5 | + |
|
| 6 | +ImportReexport.hs:3:1: error: [GHC-87110]
|
|
| 7 | + Could not load module ‘GHC.Platform.ArchOS’.
|
|
| 8 | + It is a member of the hidden package ‘ghc-10.1’.
|
|
| 9 | + It is a member of the hidden package ‘ghc-boot-10.1’.
|
|
| 10 | + It is a member of the hidden package ‘ghc-platform-0.1.0.0’.
|
|
| 11 | + Use -v to see a list of the files searched for.
|
|
| 12 | + |
| ... | ... | @@ -13,6 +13,7 @@ test('package04', normal, compile, [incr_containers]) |
| 13 | 13 | test('package05', normal, compile, [incr_ghc + inc_ghc])
|
| 14 | 14 | test('package06', normal, compile, [incr_ghc])
|
| 15 | 15 | test('package06e', normalise_version('ghc'), compile_fail, [incr_ghc])
|
| 16 | +test('ImportReexport', normalise_version('ghc'), compile_fail, ['-hide-all-packages -XNoImplicitPrelude'])
|
|
| 16 | 17 | test('package07e', normalise_version('ghc'), compile_fail, [incr_ghc + inc_ghc + hide_ghc])
|
| 17 | 18 | test('package08e', normalise_version('ghc'), compile_fail, [incr_ghc + hide_ghc])
|
| 18 | 19 | test('package09e', normal, compile_fail, ['-package "containers (Data.Map as M, Data.Set as M)"'])
|