sheaf pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC
Commits:
-
e986375e
by sheaf at 2026-07-27T16:32:29+02:00
12 changed files:
- compiler/GHC/Builtin.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/State.hs
- libraries/base/base.cabal.in
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- utils/dump-decls/Main.hs
Changes:
| ... | ... | @@ -225,8 +225,7 @@ How known-occ entities work |
| 225 | 225 | This is a big reason for (KnownOccNameInvariant): an export list cannot have two
|
| 226 | 226 | entities with the same OccName.
|
| 227 | 227 | |
| 228 | - When GHC wants to find GHC.Essentials, it just looks for it in the same
|
|
| 229 | - way as any other import.
|
|
| 228 | + See Note [Finding GHC.Essentials] for how GHC finds the GHC.Essentials module.
|
|
| 230 | 229 | |
| 231 | 230 | * There are three flags that control the treatment of known entities:
|
| 232 | 231 | -frebindable-known-names
|
| ... | ... | @@ -412,10 +411,9 @@ To make `wombat` into a known-key name, do the following. |
| 412 | 411 | * Just like for known-occ names above, in any module in `base` or `ghc-internal` (which
|
| 413 | 412 | are compiled with -frebindable-known-names), ensure that `wombat` is
|
| 414 | 413 | in scope by saying `import M( wombat )`.
|
| 415 | --}
|
|
| 416 | 414 | |
| 417 | -{- Note [Known entities and reinstallable base]
|
|
| 418 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 415 | +Note [Known entities and reinstallable base]
|
|
| 416 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 419 | 417 | The design of known-entities in GHC, described in Note [Overview of known entities],
|
| 420 | 418 | is carefully crafted to support a single version of GHC to compile different
|
| 421 | 419 | versions of base, even though GHC itself is compiled against a fixed version of
|
| ... | ... | @@ -453,6 +451,23 @@ Let's compare two examples: `coerce` and `enumFromTo`. |
| 453 | 451 | `enumFromTo` (see `GHC.Iface.Load.lookupKnownOccName`). This means GHC never
|
| 454 | 452 | needs to know where precisely `enumFromTo` is defined, allowing it to be
|
| 455 | 453 | defined anywhere (wherever in `base`, or in a module imported by `base`).
|
| 454 | + |
|
| 455 | +Note [Finding GHC.Essentials]
|
|
| 456 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 457 | +As GHC.Essentials is an implementation detail for GHC, we would really rather
|
|
| 458 | +not expose this module from base.
|
|
| 459 | + |
|
| 460 | +Achieving this requires a little bit of care:
|
|
| 461 | + |
|
| 462 | + (FindEssentials1)
|
|
| 463 | + When looking up GHC.Essentials in GHC.Iface.Load.findEssentialsModule,
|
|
| 464 | + allow the module to be hidden (as long as the unit isn't hidden) by calling
|
|
| 465 | + 'findImportedModuleAllowHidden'.
|
|
| 466 | + |
|
| 467 | + (FindEssentials2)
|
|
| 468 | + To ensure the implicit module graph edge added in GHC.Parser.Header.getImportEdges
|
|
| 469 | + is properly resolved during downsweep, we use 'findImportedModuleAllowHidden'
|
|
| 470 | + in GHC.Driver.Downsweep.
|
|
| 456 | 471 | -}
|
| 457 | 472 | |
| 458 | 473 | {-
|
| ... | ... | @@ -78,7 +78,7 @@ import GHC.Types.Unique.Map |
| 78 | 78 | import GHC.Types.PkgQual
|
| 79 | 79 | import GHC.Types.Basic
|
| 80 | 80 | |
| 81 | - |
|
| 81 | +import GHC.Builtin.Modules( eSSENTIALS_NAME )
|
|
| 82 | 82 | import GHC.Unit
|
| 83 | 83 | import GHC.Unit.Env
|
| 84 | 84 | import GHC.Unit.Finder
|
| ... | ... | @@ -1373,10 +1373,20 @@ summariseModuleDispatch k hsc_env' home_unit is_boot (L _ wanted_mod) mb_pkg exc |
| 1373 | 1373 | -- happen relative to it
|
| 1374 | 1374 | hsc_env = hscSetActiveHomeUnit home_unit hsc_env'
|
| 1375 | 1375 | |
| 1376 | - find_it :: IO SummariseResult
|
|
| 1376 | + find_module :: IO FindResult
|
|
| 1377 | + find_module
|
|
| 1378 | + | wanted_mod == eSSENTIALS_NAME
|
|
| 1379 | + -- The implicit edge to GHC.Essentials added by 'getImportEdges' must be
|
|
| 1380 | + -- resolved even when GHC.Essential is a hidden module.
|
|
| 1381 | + --
|
|
| 1382 | + -- See (FindEssentials2) in Note [Finding GHC.Essentials] in GHC.Builtin.
|
|
| 1383 | + = findImportedModuleAllowHidden hsc_env wanted_mod mb_pkg
|
|
| 1384 | + | otherwise
|
|
| 1385 | + = findImportedModuleWithIsBoot hsc_env wanted_mod is_boot mb_pkg
|
|
| 1377 | 1386 | |
| 1387 | + find_it :: IO SummariseResult
|
|
| 1378 | 1388 | find_it = do
|
| 1379 | - found <- findImportedModuleWithIsBoot hsc_env wanted_mod is_boot mb_pkg
|
|
| 1389 | + found <- find_module
|
|
| 1380 | 1390 | case found of
|
| 1381 | 1391 | Found location mod
|
| 1382 | 1392 | | moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env ->
|
| ... | ... | @@ -210,7 +210,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst |
| 210 | 210 | -- package flags when making suggestions. ToDo: if the original package
|
| 211 | 211 | -- also has a reexport, prefer that one
|
| 212 | 212 | pp_sugg (SuggestVisible m mod o) = ppr m <+> provenance o
|
| 213 | - where provenance ModHidden = empty
|
|
| 213 | + where provenance (ModHidden {}) = empty
|
|
| 214 | 214 | provenance (ModUnusable _) = empty
|
| 215 | 215 | provenance (ModOrigin{ fromOrigUnit = e,
|
| 216 | 216 | fromExposedReexport = res,
|
| ... | ... | @@ -227,7 +227,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst |
| 227 | 227 | <+> ppr mod)
|
| 228 | 228 | | otherwise = empty
|
| 229 | 229 | pp_sugg (SuggestHidden m mod o) = ppr m <+> provenance o
|
| 230 | - where provenance ModHidden = empty
|
|
| 230 | + where provenance (ModHidden {}) = empty
|
|
| 231 | 231 | provenance (ModUnusable _) = empty
|
| 232 | 232 | provenance (ModOrigin{ fromOrigUnit = e,
|
| 233 | 233 | fromHiddenReexport = rhs })
|
| ... | ... | @@ -261,7 +261,7 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst |
| 261 | 261 | where
|
| 262 | 262 | pprMod (m, o) = text "it is bound as" <+> ppr m <+>
|
| 263 | 263 | text "by" <+> pprOrigin m o
|
| 264 | - pprOrigin _ ModHidden = panic "cantFindErr: bound by mod hidden"
|
|
| 264 | + pprOrigin _ (ModHidden {}) = panic "cantFindErr: bound by mod hidden"
|
|
| 265 | 265 | pprOrigin _ (ModUnusable _) = panic "cantFindErr: bound by mod unusable"
|
| 266 | 266 | pprOrigin m (ModOrigin e res _ f) = sep $ punctuate comma (
|
| 267 | 267 | if e == Just True
|
| ... | ... | @@ -302,13 +302,14 @@ loadKnownKeyOccMaps |
| 302 | 302 | -- We don't have a KnownKeyOccMap yet, so create it
|
| 303 | 303 | -- from the interface file for KnownKeyName
|
| 304 | 304 | do { hsc_env <- getTopEnv
|
| 305 | - ; mb_res <- liftIO $ findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual
|
|
| 306 | - ; case mb_res of
|
|
| 307 | - Found _ mod -> Succeeded <$> build_maps mod
|
|
| 308 | - fr -> return (Failed (CantFindEssentials
|
|
| 309 | - (cannotFindModule hsc_env eSSENTIALS_NAME fr)
|
|
| 310 | - UnknownLoadEssentialsReason))
|
|
| 311 | - } } }
|
|
| 305 | + ; res <- liftIO $ findEssentialsModule hsc_env
|
|
| 306 | + ; case res of
|
|
| 307 | + Succeeded mod -> Succeeded <$> build_maps mod
|
|
| 308 | + Failed err ->
|
|
| 309 | + return $ Failed $
|
|
| 310 | + CantFindEssentials err UnknownLoadEssentialsReason
|
|
| 311 | + }}}
|
|
| 312 | + |
|
| 312 | 313 | where
|
| 313 | 314 | doc = text "Need interface for KnownKeyNames"
|
| 314 | 315 | |
| ... | ... | @@ -374,21 +375,33 @@ checkKnownKeyNamesIface known_key_names_occ_map |
| 374 | 375 | |
| 375 | 376 | -- | Lookup the module exporting the canonical known-entities definitions (GHC.Essentials)
|
| 376 | 377 | lookupKnownKeysModule :: HscEnv -> DynFlags {-^ Module dyn flags -} -> IO (Maybe Module)
|
| 377 | -lookupKnownKeysModule hsc_env dflags = do
|
|
| 378 | - eps <- hscEPS hsc_env
|
|
| 379 | - case eps_known_keys eps of
|
|
| 380 | - Just (_, kk_mod) -> return (Just kk_mod)
|
|
| 381 | - Nothing -> do
|
|
| 382 | - found_essentials <- findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual
|
|
| 383 | - let rebindable_kn = gopt Opt_RebindableKnownNames dflags
|
|
| 384 | - let essentials_uid
|
|
| 385 | - | rebindable_kn = return Nothing
|
|
| 386 | - | Found _ mod <- found_essentials = return (Just mod)
|
|
| 387 | - | fr <- found_essentials = do
|
|
| 388 | - throwOneError (initSourceErrorContext dflags) $
|
|
| 389 | - mkPlainErrorMsgEnvelope noSrcSpan $ GhcDriverMessage $ DriverInterfaceError $
|
|
| 390 | - CantFindEssentials (cannotFindModule hsc_env eSSENTIALS_NAME fr) LookingForEssentialsModule
|
|
| 391 | - essentials_uid
|
|
| 378 | +lookupKnownKeysModule hsc_env dflags
|
|
| 379 | + | gopt Opt_RebindableKnownNames dflags
|
|
| 380 | + = return Nothing
|
|
| 381 | + | otherwise
|
|
| 382 | + = do { eps <- hscEPS hsc_env
|
|
| 383 | + ; case eps_known_keys eps of
|
|
| 384 | + { Just (_, kk_mod) -> return (Just kk_mod)
|
|
| 385 | + ; Nothing ->
|
|
| 386 | + do { mb_mod <- findEssentialsModule hsc_env
|
|
| 387 | + ; case mb_mod of
|
|
| 388 | + { Succeeded mod -> return (Just mod)
|
|
| 389 | + ; Failed err ->
|
|
| 390 | + throwOneError (initSourceErrorContext dflags) $
|
|
| 391 | + mkPlainErrorMsgEnvelope noSrcSpan $
|
|
| 392 | + GhcDriverMessage $ DriverInterfaceError $
|
|
| 393 | + CantFindEssentials err LookingForEssentialsModule
|
|
| 394 | + }}}}
|
|
| 395 | + |
|
| 396 | +-- | Find the GHC.Essentials module.
|
|
| 397 | +--
|
|
| 398 | +-- See Note [Finding GHC.Essentials] in GHC.Builtin.
|
|
| 399 | +findEssentialsModule :: HscEnv -> IO (MaybeErr MissingInterfaceError Module)
|
|
| 400 | +findEssentialsModule hsc_env = do
|
|
| 401 | + fr <- findImportedModuleAllowHidden hsc_env eSSENTIALS_NAME NoPkgQual
|
|
| 402 | + return $ case fr of
|
|
| 403 | + Found _ mod -> Succeeded mod
|
|
| 404 | + _ -> Failed $ cannotFindModule hsc_env eSSENTIALS_NAME fr
|
|
| 392 | 405 | |
| 393 | 406 | {- *********************************************************************
|
| 394 | 407 | * *
|
| ... | ... | @@ -114,7 +114,8 @@ getImportEdges dflags buf filename source_filename = do |
| 114 | 114 | convImport (L _ (i :: ImportDecl GhcPs)) = (convImportLevel (ideclLevelSpec i), ideclPkgQual i, reLoc $ ideclName i)
|
| 115 | 115 | convImport_src (L _ (i :: ImportDecl GhcPs)) = (reLoc $ ideclName i)
|
| 116 | 116 | |
| 117 | - known_key_name_edges -- Add an edge to GHC.Essentials, unless -frebindable-known-names is on
|
|
| 117 | + -- Add an edge to GHC.Essentials, unless -frebindable-known-names is on
|
|
| 118 | + known_key_name_edges
|
|
| 118 | 119 | | rebindable_kn = []
|
| 119 | 120 | | otherwise = [(NormalLevel, NoRawPkgQual, noLoc eSSENTIALS_NAME)]
|
| 120 | 121 | in
|
| ... | ... | @@ -14,6 +14,7 @@ module GHC.Unit.Finder ( |
| 14 | 14 | FinderCache(..),
|
| 15 | 15 | initFinderCache,
|
| 16 | 16 | findImportedModule,
|
| 17 | + findImportedModuleAllowHidden,
|
|
| 17 | 18 | findImportedModuleWithIsBoot,
|
| 18 | 19 | findPluginModule,
|
| 19 | 20 | findExactModule,
|
| ... | ... | @@ -172,24 +173,42 @@ getDirHash dir = do |
| 172 | 173 | return hash
|
| 173 | 174 | |
| 174 | 175 | -- -----------------------------------------------------------------------------
|
| 175 | --- The three external entry points
|
|
| 176 | - |
|
| 176 | +-- External entry points
|
|
| 177 | + |
|
| 178 | +-- | Should a module which is not in its unit's @exposed-modules@ still be
|
|
| 179 | +-- found, provided the unit itself is visible?
|
|
| 180 | +data HiddenModulePolicy
|
|
| 181 | + -- | Normal behaviour (e.g. user-written imports): don't find hidden modules.
|
|
| 182 | + = RejectHiddenModules
|
|
| 183 | + -- | Allow hidden modules (from non-hidden units) to be found.
|
|
| 184 | + --
|
|
| 185 | + -- See Note [Finding GHC.Essentials] in GHC.Builtin.
|
|
| 186 | + | AcceptHiddenModules
|
|
| 177 | 187 | |
| 178 | 188 | -- | Locate a module that was imported by the user. We have the
|
| 179 | 189 | -- module's name, and possibly a package name. Without a package
|
| 180 | 190 | -- name, this function will use the search path and the known exposed
|
| 181 | 191 | -- packages to find the module, if a package is specified then only
|
| 182 | 192 | -- that package is searched for the module.
|
| 183 | - |
|
| 184 | 193 | findImportedModule :: HscEnv -> ModuleName -> PkgQual -> IO FindResult
|
| 185 | -findImportedModule hsc_env mod pkg_qual =
|
|
| 194 | +findImportedModule = findImportedModule_policy RejectHiddenModules
|
|
| 195 | + |
|
| 196 | +-- | Like 'findImportedModule', but also finds hidden modules (from non-hidden units).
|
|
| 197 | +--
|
|
| 198 | +-- See (FindEssentials1) in Note [Finding GHC.Essentials] in GHC.Builtin.
|
|
| 199 | +findImportedModuleAllowHidden :: HscEnv -> ModuleName -> PkgQual -> IO FindResult
|
|
| 200 | +findImportedModuleAllowHidden = findImportedModule_policy AcceptHiddenModules
|
|
| 201 | + |
|
| 202 | +-- | Internal helper for 'findImportedModule' and 'findImportedModuleAllowHidden'.
|
|
| 203 | +findImportedModule_policy :: HiddenModulePolicy -> HscEnv -> ModuleName -> PkgQual -> IO FindResult
|
|
| 204 | +findImportedModule_policy policy hsc_env mod pkg_qual =
|
|
| 186 | 205 | let fc = hsc_FC hsc_env
|
| 187 | 206 | mb_home_unit = hsc_home_unit_maybe hsc_env
|
| 188 | 207 | dflags = hsc_dflags hsc_env
|
| 189 | 208 | fopts = initFinderOpts dflags
|
| 190 | 209 | in do
|
| 191 | 210 | let home_module_name_providers_map = mgHomeModuleNameProvidersMap (hsc_mod_graph hsc_env)
|
| 192 | - findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) home_module_name_providers_map mb_home_unit mod pkg_qual
|
|
| 211 | + findImportedModuleNoHsc policy fc fopts (hsc_unit_env hsc_env) home_module_name_providers_map mb_home_unit mod pkg_qual
|
|
| 193 | 212 | |
| 194 | 213 | findImportedModuleWithIsBoot :: HscEnv -> ModuleName -> IsBootInterface -> PkgQual -> IO FindResult
|
| 195 | 214 | findImportedModuleWithIsBoot hsc_env mod is_boot pkg_qual = do
|
| ... | ... | @@ -199,7 +218,8 @@ findImportedModuleWithIsBoot hsc_env mod is_boot pkg_qual = do |
| 199 | 218 | _ -> return res
|
| 200 | 219 | |
| 201 | 220 | findImportedModuleNoHsc
|
| 202 | - :: FinderCache
|
|
| 221 | + :: HiddenModulePolicy
|
|
| 222 | + -> FinderCache
|
|
| 203 | 223 | -> FinderOpts
|
| 204 | 224 | -> UnitEnv
|
| 205 | 225 | -> HomeModuleNameProvidersMap
|
| ... | ... | @@ -207,7 +227,7 @@ findImportedModuleNoHsc |
| 207 | 227 | -> ModuleName
|
| 208 | 228 | -> PkgQual
|
| 209 | 229 | -> IO FindResult
|
| 210 | -findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit mod_name mb_pkg =
|
|
| 230 | +findImportedModuleNoHsc policy fc fopts ue home_module_name_providers_map mb_home_unit mod_name mb_pkg =
|
|
| 211 | 231 | case mb_pkg of
|
| 212 | 232 | NoPkgQual -> unqual_import
|
| 213 | 233 | ThisPkg uid | (homeUnitId <$> mb_home_unit) == Just uid -> home_import
|
| ... | ... | @@ -231,13 +251,13 @@ findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit |
| 231 | 251 | NoPackage (panic "findImportedModule: no home-unit")
|
| 232 | 252 | |
| 233 | 253 | home_pkg_import :: (UnitId, FinderOpts) -> IO FindResult
|
| 234 | - home_pkg_import = findHomeUnitDepModule fc ue home_module_name_providers_map mod_name
|
|
| 254 | + home_pkg_import = findHomeUnitDepModule policy fc ue home_module_name_providers_map mod_name
|
|
| 235 | 255 | |
| 236 | 256 | pkg_import :: IO FindResult
|
| 237 | - pkg_import = findExposedPackageModule fc fopts unit_state mod_name mb_pkg
|
|
| 257 | + pkg_import = findExposedPackageModule_policy policy fc fopts unit_state mod_name mb_pkg
|
|
| 238 | 258 | |
| 239 | 259 | unqual_import :: IO FindResult
|
| 240 | - unqual_import = findHomeOrRegularPackageModule fc fopts ue
|
|
| 260 | + unqual_import = findHomeOrRegularPackageModule policy fc fopts ue
|
|
| 241 | 261 | home_module_name_providers_map mb_home_unit mod_name
|
| 242 | 262 | |
| 243 | 263 | unit_state :: UnitState
|
| ... | ... | @@ -263,7 +283,7 @@ findPluginModuleNoHsc |
| 263 | 283 | -> ModuleName
|
| 264 | 284 | -> IO FindResult
|
| 265 | 285 | findPluginModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit@(Just home_unit) mod_name =
|
| 266 | - findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map
|
|
| 286 | + findHomeModuleAmongDeps RejectHiddenModules fc fopts ue home_module_name_providers_map
|
|
| 267 | 287 | mb_home_unit mod_name
|
| 268 | 288 | `orIfNotFound`
|
| 269 | 289 | findExposedPluginPackageModule fc fopts unit_state mod_name
|
| ... | ... | @@ -339,21 +359,23 @@ homeUnitDepsFinderOpts ue home_module_name_providers_map unit_state mod_name = |
| 339 | 359 | |
| 340 | 360 | -- | Search for @mod_name@ in the given home unit.
|
| 341 | 361 | findHomeUnitDepModule
|
| 342 | - :: FinderCache
|
|
| 362 | + :: HiddenModulePolicy
|
|
| 363 | + -> FinderCache
|
|
| 343 | 364 | -> UnitEnv
|
| 344 | 365 | -> HomeModuleNameProvidersMap
|
| 345 | 366 | -> ModuleName
|
| 346 | 367 | -> (UnitId, FinderOpts)
|
| 347 | 368 | -> IO FindResult
|
| 348 | -findHomeUnitDepModule fc ue home_module_name_providers_map mod_name (uid, opts)
|
|
| 369 | +findHomeUnitDepModule policy fc ue home_module_name_providers_map mod_name (uid, opts)
|
|
| 349 | 370 | -- If the module is reexported, then look for it as if it was from the
|
| 350 | 371 | -- perspective of the package which reexports it.
|
| 351 | 372 | | Just real_mod_name
|
| 352 | 373 | <- lookupUniqMap (finder_reexportedModules opts) mod_name
|
| 353 | - = findHomeOrRegularPackageModule fc opts ue home_module_name_providers_map
|
|
| 374 | + = findHomeOrRegularPackageModule policy fc opts ue home_module_name_providers_map
|
|
| 354 | 375 | (Just $ DefiniteHomeUnit uid Nothing)
|
| 355 | 376 | real_mod_name
|
| 356 | - | elementOfUniqSet mod_name (finder_hiddenModules opts)
|
|
| 377 | + | RejectHiddenModules <- policy
|
|
| 378 | + , elementOfUniqSet mod_name (finder_hiddenModules opts)
|
|
| 357 | 379 | = return (mkHomeHidden uid)
|
| 358 | 380 | | otherwise
|
| 359 | 381 | = findHomePackageModule fc opts uid mod_name
|
| ... | ... | @@ -363,14 +385,15 @@ findHomeUnitDepModule fc ue home_module_name_providers_map mod_name (uid, opts) |
| 363 | 385 | -- reexports along the way (see 'findHomeUnitDepModule'). Yields the first
|
| 364 | 386 | -- successful result.
|
| 365 | 387 | findHomeModuleAmongDeps
|
| 366 | - :: FinderCache
|
|
| 388 | + :: HiddenModulePolicy
|
|
| 389 | + -> FinderCache
|
|
| 367 | 390 | -> FinderOpts
|
| 368 | 391 | -> UnitEnv
|
| 369 | 392 | -> HomeModuleNameProvidersMap
|
| 370 | 393 | -> Maybe HomeUnit
|
| 371 | 394 | -> ModuleName
|
| 372 | 395 | -> IO FindResult
|
| 373 | -findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map mb_home_unit mod_name =
|
|
| 396 | +findHomeModuleAmongDeps policy fc fopts ue home_module_name_providers_map mb_home_unit mod_name =
|
|
| 374 | 397 | foldr1 orIfNotFound (home_import :| map home_pkg_import other_fopts)
|
| 375 | 398 | -- Do not try to be smart and change this to `foldr orIfNotFound home_import
|
| 376 | 399 | -- (map home_pkg_import other_fopts)`, as that would not be the same.
|
| ... | ... | @@ -381,7 +404,7 @@ findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map mb_home_unit |
| 381 | 404 | Just home_unit -> findHomeModule fc fopts home_unit mod_name
|
| 382 | 405 | Nothing -> pure $
|
| 383 | 406 | NoPackage (panic "findHomeModuleAmongDeps: no home-unit")
|
| 384 | - home_pkg_import = findHomeUnitDepModule fc ue home_module_name_providers_map mod_name
|
|
| 407 | + home_pkg_import = findHomeUnitDepModule policy fc ue home_module_name_providers_map mod_name
|
|
| 385 | 408 | |
| 386 | 409 | unit_state = case homeUnitId <$> mb_home_unit of
|
| 387 | 410 | Nothing -> ue_homeUnitState ue
|
| ... | ... | @@ -393,18 +416,19 @@ findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map mb_home_unit |
| 393 | 416 | -- | Search the home-unit graph and otherwise the regular exposed package
|
| 394 | 417 | -- database.
|
| 395 | 418 | findHomeOrRegularPackageModule
|
| 396 | - :: FinderCache
|
|
| 419 | + :: HiddenModulePolicy
|
|
| 420 | + -> FinderCache
|
|
| 397 | 421 | -> FinderOpts
|
| 398 | 422 | -> UnitEnv
|
| 399 | 423 | -> HomeModuleNameProvidersMap
|
| 400 | 424 | -> Maybe HomeUnit
|
| 401 | 425 | -> ModuleName
|
| 402 | 426 | -> IO FindResult
|
| 403 | -findHomeOrRegularPackageModule fc fopts ue home_module_name_providers_map mb_home_unit mod_name =
|
|
| 404 | - findHomeModuleAmongDeps fc fopts ue home_module_name_providers_map
|
|
| 427 | +findHomeOrRegularPackageModule policy fc fopts ue home_module_name_providers_map mb_home_unit mod_name =
|
|
| 428 | + findHomeModuleAmongDeps policy fc fopts ue home_module_name_providers_map
|
|
| 405 | 429 | mb_home_unit mod_name
|
| 406 | 430 | `orIfNotFound`
|
| 407 | - findExposedPackageModule fc fopts unit_state mod_name NoPkgQual
|
|
| 431 | + findExposedPackageModule_policy policy fc fopts unit_state mod_name NoPkgQual
|
|
| 408 | 432 | where
|
| 409 | 433 | unit_state = case homeUnitId <$> mb_home_unit of
|
| 410 | 434 | Nothing -> ue_homeUnitState ue
|
| ... | ... | @@ -482,36 +506,29 @@ homeSearchCache fc home_unit mod_name do_this = do |
| 482 | 506 | modLocationCache fc mod do_this
|
| 483 | 507 | |
| 484 | 508 | findExposedPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> PkgQual -> IO FindResult
|
| 485 | -findExposedPackageModule fc fopts units mod_name mb_pkg =
|
|
| 486 | - findLookupResult fc fopts
|
|
| 509 | +findExposedPackageModule = findExposedPackageModule_policy RejectHiddenModules
|
|
| 510 | + |
|
| 511 | +findExposedPackageModule_policy :: HiddenModulePolicy -> FinderCache -> FinderOpts -> UnitState -> ModuleName -> PkgQual -> IO FindResult
|
|
| 512 | +findExposedPackageModule_policy policy fc fopts units mod_name mb_pkg =
|
|
| 513 | + findLookupResult policy fc fopts units
|
|
| 487 | 514 | $ lookupModuleWithSuggestions units mod_name mb_pkg
|
| 488 | 515 | |
| 489 | 516 | findExposedPluginPackageModule :: FinderCache -> FinderOpts -> UnitState -> ModuleName -> IO FindResult
|
| 490 | 517 | findExposedPluginPackageModule fc fopts units mod_name =
|
| 491 | - findLookupResult fc fopts
|
|
| 518 | + findLookupResult RejectHiddenModules fc fopts units
|
|
| 492 | 519 | $ lookupPluginModuleWithSuggestions units mod_name NoPkgQual
|
| 493 | 520 | |
| 494 | -findLookupResult :: FinderCache -> FinderOpts -> LookupResult -> IO FindResult
|
|
| 495 | -findLookupResult fc fopts r = case r of
|
|
| 496 | - LookupFound m pkg_conf -> do
|
|
| 497 | - let im = fst (getModuleInstantiation m)
|
|
| 498 | - r' <- findPackageModule_ fc fopts im (fst pkg_conf)
|
|
| 499 | - case r' of
|
|
| 500 | - -- TODO: ghc -M is unlikely to do the right thing
|
|
| 501 | - -- with just the location of the thing that was
|
|
| 502 | - -- instantiated; you probably also need all of the
|
|
| 503 | - -- implicit locations from the instances
|
|
| 504 | - InstalledFound loc -> return (Found loc m)
|
|
| 505 | - InstalledNoPackage _ -> return (NoPackage (moduleUnit m))
|
|
| 506 | - InstalledNotFound fp _ -> return (NotFound{ fr_paths = fmap unsafeDecodeUtf fp, fr_pkg = Just (moduleUnit m)
|
|
| 507 | - , fr_pkgs_hidden = []
|
|
| 508 | - , fr_mods_hidden = []
|
|
| 509 | - , fr_unusables = []
|
|
| 510 | - , fr_suggestions = []})
|
|
| 521 | +findLookupResult :: HiddenModulePolicy -> FinderCache -> FinderOpts -> UnitState -> LookupResult -> IO FindResult
|
|
| 522 | +findLookupResult policy fc fopts units r = case r of
|
|
| 523 | + LookupFound m pkg_conf -> found_module m (findPackageModule_ fc fopts (instantiated m) (fst pkg_conf))
|
|
| 511 | 524 | LookupMultiple rs ->
|
| 512 | 525 | return (FoundMultiple rs)
|
| 513 | - LookupHidden fr_pkgs_hidden mod_hiddens ->
|
|
| 514 | - return (NotFound{ fr_paths = [], fr_pkg = Nothing
|
|
| 526 | + LookupHidden fr_pkgs_hidden mod_hiddens
|
|
| 527 | + | AcceptHiddenModules <- policy
|
|
| 528 | + , [m] <- [ m | (m, ModHidden HiddenModInVisibleUnit) <- mod_hiddens ]
|
|
| 529 | + -> found_module m (findPackageModule fc units fopts (instantiated m))
|
|
| 530 | + | otherwise
|
|
| 531 | + -> return (NotFound{ fr_paths = [], fr_pkg = Nothing
|
|
| 515 | 532 | , fr_pkgs_hidden
|
| 516 | 533 | , fr_mods_hidden = map (moduleUnit.fst) mod_hiddens
|
| 517 | 534 | , fr_unusables = []
|
| ... | ... | @@ -535,6 +552,29 @@ findLookupResult fc fopts r = case r of |
| 535 | 552 | , fr_mods_hidden = []
|
| 536 | 553 | , fr_unusables = []
|
| 537 | 554 | , fr_suggestions = suggest' })
|
| 555 | + where
|
|
| 556 | + instantiated m = fst (getModuleInstantiation m)
|
|
| 557 | + |
|
| 558 | + -- TODO: ghc -M is unlikely to do the right thing
|
|
| 559 | + -- with just the location of the thing that was
|
|
| 560 | + -- instantiated; you probably also need all of the
|
|
| 561 | + -- implicit locations from the instances
|
|
| 562 | + found_module :: Module -> IO InstalledFindResult -> IO FindResult
|
|
| 563 | + found_module m find = do
|
|
| 564 | + r' <- find
|
|
| 565 | + return $
|
|
| 566 | + case r' of
|
|
| 567 | + InstalledFound loc -> Found loc m
|
|
| 568 | + InstalledNoPackage {} -> NoPackage (moduleUnit m)
|
|
| 569 | + InstalledNotFound fp _ ->
|
|
| 570 | + NotFound
|
|
| 571 | + { fr_paths = fmap unsafeDecodeUtf fp
|
|
| 572 | + , fr_pkg = Just (moduleUnit m)
|
|
| 573 | + , fr_pkgs_hidden = []
|
|
| 574 | + , fr_mods_hidden = []
|
|
| 575 | + , fr_unusables = []
|
|
| 576 | + , fr_suggestions = []
|
|
| 577 | + }
|
|
| 538 | 578 | |
| 539 | 579 | modLocationCache :: FinderCache -> InstalledModule -> IO InstalledFindResult -> IO InstalledFindResult
|
| 540 | 580 | modLocationCache fc mod do_this = do
|
| ... | ... | @@ -38,6 +38,7 @@ module GHC.Unit.State ( |
| 38 | 38 | LookupResult(..),
|
| 39 | 39 | ModuleSuggestion(..),
|
| 40 | 40 | ModuleOrigin(..),
|
| 41 | + HiddenModuleUnit(..),
|
|
| 41 | 42 | UnusableUnit(..),
|
| 42 | 43 | UnusableUnitReason(..),
|
| 43 | 44 | pprReason,
|
| ... | ... | @@ -168,10 +169,8 @@ import Control.Applicative |
| 168 | 169 | -- it could have come into scope. Warning: don't use the record functions,
|
| 169 | 170 | -- they're partial!
|
| 170 | 171 | data ModuleOrigin =
|
| 171 | - -- | Module is hidden, and thus never will be available for import.
|
|
| 172 | - -- (But maybe the user didn't realize), so we'll still keep track
|
|
| 173 | - -- of these modules.)
|
|
| 174 | - ModHidden
|
|
| 172 | + -- | The module is hidden (thus not available for a user-written import).
|
|
| 173 | + ModHidden !HiddenModuleUnit
|
|
| 175 | 174 | |
| 176 | 175 | -- | Module is unavailable because the unit is unusable.
|
| 177 | 176 | | ModUnusable !UnusableUnit
|
| ... | ... | @@ -193,6 +192,11 @@ data ModuleOrigin = |
| 193 | 192 | , fromPackageFlag :: Bool
|
| 194 | 193 | }
|
| 195 | 194 | |
| 195 | +-- | Is the unit providing a hidden module itself visible in this compilation?
|
|
| 196 | +data HiddenModuleUnit
|
|
| 197 | + = HiddenModInVisibleUnit
|
|
| 198 | + | HiddenModInHiddenUnit
|
|
| 199 | + |
|
| 196 | 200 | -- | A unusable unit module origin
|
| 197 | 201 | data UnusableUnit = UnusableUnit
|
| 198 | 202 | { uuUnit :: !Unit -- ^ Unusable unit
|
| ... | ... | @@ -201,7 +205,7 @@ data UnusableUnit = UnusableUnit |
| 201 | 205 | }
|
| 202 | 206 | |
| 203 | 207 | instance Outputable ModuleOrigin where
|
| 204 | - ppr ModHidden = text "hidden module"
|
|
| 208 | + ppr (ModHidden {}) = text "hidden module"
|
|
| 205 | 209 | ppr (ModUnusable _) = text "unusable module"
|
| 206 | 210 | ppr (ModOrigin e res rhs f) = sep (punctuate comma (
|
| 207 | 211 | (case e of
|
| ... | ... | @@ -255,7 +259,7 @@ instance Monoid ModuleOrigin where |
| 255 | 259 | -- | Is the name from the import actually visible? (i.e. does it cause
|
| 256 | 260 | -- ambiguity, or is it only relevant when we're making suggestions?)
|
| 257 | 261 | originVisible :: ModuleOrigin -> Bool
|
| 258 | -originVisible ModHidden = False
|
|
| 262 | +originVisible (ModHidden {}) = False
|
|
| 259 | 263 | originVisible (ModUnusable _) = False
|
| 260 | 264 | originVisible (ModOrigin b res _ f) = b == Just True || not (null res) || f
|
| 261 | 265 | |
| ... | ... | @@ -1819,7 +1823,11 @@ mkModuleNameProvidersMap logger cfg pkg_map vis_map = |
| 1819 | 1823 | esmap = listToUFM (es False) -- parameter here doesn't matter, orig will
|
| 1820 | 1824 | -- be overwritten
|
| 1821 | 1825 | |
| 1822 | - hiddens = [(m, mkModMap pk m ModHidden) | m <- hidden_mods]
|
|
| 1826 | + hiddens = [(m, mkModMap pk m (ModHidden hidden_mod_unit)) | m <- hidden_mods]
|
|
| 1827 | + |
|
| 1828 | + hidden_mod_unit
|
|
| 1829 | + | b || not (null rns) = HiddenModInVisibleUnit
|
|
| 1830 | + | otherwise = HiddenModInHiddenUnit
|
|
| 1823 | 1831 | |
| 1824 | 1832 | pk = mkUnit pkg
|
| 1825 | 1833 | unit_lookup uid = lookupUnit' (unitConfigAllowVirtual cfg) pkg_map uid
|
| ... | ... | @@ -1970,7 +1978,7 @@ lookupModuleWithSuggestions' pkgs mod_map name mb_pn |
| 1970 | 1978 | let origin = filterOrigin mb_pn (mod_unit m) origin0
|
| 1971 | 1979 | x = (m, origin)
|
| 1972 | 1980 | in case origin of
|
| 1973 | - ModHidden
|
|
| 1981 | + ModHidden {}
|
|
| 1974 | 1982 | -> (hidden_pkg, x:hidden_mod, unusable, exposed)
|
| 1975 | 1983 | ModUnusable _
|
| 1976 | 1984 | -> (hidden_pkg, hidden_mod, x:unusable, exposed)
|
| ... | ... | @@ -2003,8 +2011,8 @@ lookupModuleWithSuggestions' pkgs mod_map name mb_pn |
| 2003 | 2011 | filterOrigin (OtherPkg u) pkg o =
|
| 2004 | 2012 | let match_pkg p = u == unitId p
|
| 2005 | 2013 | in case o of
|
| 2006 | - ModHidden
|
|
| 2007 | - | match_pkg pkg -> ModHidden
|
|
| 2014 | + ModHidden {}
|
|
| 2015 | + | match_pkg pkg -> o
|
|
| 2008 | 2016 | | otherwise -> mempty
|
| 2009 | 2017 | ModUnusable _
|
| 2010 | 2018 | | match_pkg pkg -> o
|
| ... | ... | @@ -219,7 +219,6 @@ Library |
| 219 | 219 | , GHC.Integer.Logarithms
|
| 220 | 220 | , GHC.IsList
|
| 221 | 221 | , GHC.Ix
|
| 222 | - , GHC.Essentials
|
|
| 223 | 222 | , GHC.List
|
| 224 | 223 | , GHC.Maybe
|
| 225 | 224 | , GHC.MVar
|
| ... | ... | @@ -307,6 +306,7 @@ Library |
| 307 | 306 | |
| 308 | 307 | other-modules:
|
| 309 | 308 | Data.List.NubOrdSet
|
| 309 | + GHC.Essentials
|
|
| 310 | 310 | System.CPUTime.Unsupported
|
| 311 | 311 | System.CPUTime.Utils
|
| 312 | 312 | if os(windows)
|
| ... | ... | @@ -68,7 +68,6 @@ ignoredModules = |
| 68 | 68 | map mkModuleName $ concat
|
| 69 | 69 | [ unstableModules
|
| 70 | 70 | , platformDependentModules
|
| 71 | - , internalModules
|
|
| 72 | 71 | ]
|
| 73 | 72 | where
|
| 74 | 73 | unstableModules =
|
| ... | ... | @@ -81,8 +80,6 @@ ignoredModules = |
| 81 | 80 | , "GHC.Num.Backend"
|
| 82 | 81 | , "GHC.Num.Backend.Selected"
|
| 83 | 82 | ]
|
| 84 | - internalModules =
|
|
| 85 | - [ "GHC.Essentials" ]
|
|
| 86 | 83 | |
| 87 | 84 | ignoredOccNames :: [OccName]
|
| 88 | 85 | ignoredOccNames =
|