[Git][ghc/ghc][wip/spj-reinstallable-base2] 7 commits: fix indentation
Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC Commits: a2ef5577 by Rodrigo Mesquita at 2026-06-09T17:22:09+01:00 fix indentation - - - - - 79bcda2c by Rodrigo Mesquita at 2026-06-09T17:22:45+01:00 attempt at saving when ESSENTIALS is used - - - - - 17bc7b47 by Rodrigo Mesquita at 2026-06-09T17:22:48+01:00 Revert "attempt at saving when ESSENTIALS is used" This reverts commit 79bcda2c218c8179b663cb2ab0bfe9754021b68f. - - - - - ab9c2bc4 by Rodrigo Mesquita at 2026-06-11T11:52:46+01:00 Make sure to add a direct package dependency unless -frebindable-known-names We already add an implicit edge to the module graph. We better include an edge in the Iface information too, for consistency and recompilation checking to work properly Fixes T27013b - - - - - 12153266 by Rodrigo Mesquita at 2026-06-11T11:54:36+01:00 T27013c, where x = x makes recompilation checkng still broken - - - - - 88fe754d by Rodrigo Mesquita at 2026-06-11T16:02:05+01:00 Unconditionally add the GHC.Essentials module to the direct pkg deps, unless -frebindable-known-names; this matches the logic that always adds a module graph edge to GHC.Essentials because we'll need to look up that module unless -frebindable-known-names. To fix defaulting, just make defaulting not happen if the GHC.Essentials module is not found (meaning we'll never try to load the rebindable name bc we don't enter the branch at all) Fixes T27013{a,b,c} - - - - - 5943ac8c by Rodrigo Mesquita at 2026-06-11T16:06:53+01:00 use lookupKnownKeyModule for defaulting check too - - - - - 13 changed files: - changelog.d/refactor-known-names - compiler/GHC/HsToCore.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Iface/Make.hs - compiler/GHC/Parser/Header.hs - compiler/GHC/Tc/Module.hs - compiler/GHC/Tc/Utils/Env.hs - compiler/GHC/Unit/External.hs - compiler/GHC/Unit/Module/Deps.hs - + testsuite/tests/driver/T27013c/Makefile - + testsuite/tests/driver/T27013c/T27013c.stdout - + testsuite/tests/driver/T27013c/X.hs - + testsuite/tests/driver/T27013c/all.T Changes: ===================================== changelog.d/refactor-known-names ===================================== @@ -5,7 +5,13 @@ synopsis: Completely refactor the handling of "known entities". The goal is to itself. This is a major step along the path to making `base` into an ordinary re-installable library. - Mostly this change is only visible to authors of modules in `ghc-internal` or - `base`. + Mostly this change is only visible to authors of modules in `ghc-internal` or `base`. + + Since the known-names are no longer fully wired in to the compiler, GHCi must + be able to find `base` for all the known-names like `print` and `IO` to be + available. Therefore `ghci -hide-all-packages`, which hides `base` from ghci, + no longer works. One must use `ghci -hide-all-packages -package base` to + bring in the known-names from base. + issues: #27013 mrs: !15899 ===================================== compiler/GHC/HsToCore.hs ===================================== @@ -99,7 +99,7 @@ import Data.IORef import GHC.Iface.Make (mkRecompUsageInfo) import GHC.Runtime.Interpreter (interpreterProfiled) import GHC.Types.Unique.FM -import GHC.Iface.Load (KnownEntitySource(..), lookupKnownKeyName) +import GHC.Iface.Load (KnownEntitySource(..), lookupKnownKeyName, lookupKnownKeysModule) import GHC.HsToCore.Types (DsGblEnv(..)) {- @@ -220,11 +220,13 @@ deSugar hsc_env ; endPassHscEnvIO hsc_env name_ppr_ctx CoreDesugar ds_binds ds_rules_for_imps ; let pluginModules = map lpModule (loadedPlugins (hsc_plugins hsc_env)) - home_unit = hsc_home_unit hsc_env + home_unit = hsc_home_unit hsc_env + ; essentials_mod <- liftIO $ lookupKnownKeysModule hsc_env dflags ; let deps = mkDependencies home_unit (tcg_mod tcg_env) (tcg_imports tcg_env) (map mi_module pluginModules) + (moduleUnitId <$> essentials_mod) ; safe_mode <- finalSafeMode dflags tcg_env ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -24,7 +24,7 @@ module GHC.Iface.Load ( lookupKnownKeyThing, lookupKnownKeyName, lookupKnownOccThing, lookupKnownOccName, loadKnownKeyOccMaps, lookupKnownGRE, - lookupKnownKeysMap, + lookupKnownKeysMap, lookupKnownKeysModule, -- RnM/TcM functions loadModuleInterface, loadModuleInterfaces, @@ -283,7 +283,7 @@ loadKnownKeyOccMaps :: IfM lcl KnownKeyNameMaps loadKnownKeyOccMaps = do { eps <- getEps ; case eps_known_keys eps of { - Just kk_maps -> return kk_maps ; + Just (kk_maps, _) -> return kk_maps ; Nothing -> -- We don't have a KnownKeyOccMap yet, so create it @@ -310,7 +310,7 @@ loadKnownKeyOccMaps , nm <- availNames avail ] -- Record the KnownKeyOccMap in the EPS, so we will find it next time - ; updateEps_ (\eps -> eps { eps_known_keys = Just (kk_map, occ_map) }) + ; updateEps_ (\eps -> eps { eps_known_keys = Just ((kk_map, occ_map), mi_module iface) }) #ifdef DEBUG ; case checkKnownKeyNamesIface kk_map of @@ -355,6 +355,17 @@ checkKnownKeyNamesIface known_key_names_occ_map Just name -> getOccName name /= occ #endif +-- | Lookup the module exporting the canonical known-entities definitions (GHC.Essentials) +lookupKnownKeysModule :: HscEnv -> DynFlags {-^ Module dyn flags -} -> IO (Maybe Module) +lookupKnownKeysModule hsc_env dflags = do + found_essentials <- findImportedModule hsc_env eSSENTIALS_NAME NoPkgQual + let rebindable_kn = gopt Opt_RebindableKnownNames dflags + let essentials_uid + | rebindable_kn = Nothing + | Found _ mod <- found_essentials = Just mod + | otherwise = Nothing + return essentials_uid + {- ********************************************************************* * * * Global things ===================================== compiler/GHC/Iface/Make.hs ===================================== @@ -238,16 +238,18 @@ mkIfaceTc hsc_env safe_mode mod_details mod_summary mb_program tcg_fix_env = fix_env, tcg_warns = warns } - = do - let pluginModules = map lpModule (loadedPlugins (hsc_plugins hsc_env)) - let home_unit = hsc_home_unit hsc_env + = do let pluginModules = map lpModule (loadedPlugins (hsc_plugins hsc_env)) + let home_unit = hsc_home_unit hsc_env + let dflags = ms_hspp_opts mod_summary + essentials_mod <- liftIO $ lookupKnownKeysModule hsc_env dflags let deps = mkDependencies home_unit (tcg_mod tc_result) (tcg_imports tc_result) (map mi_module pluginModules) + (moduleUnitId <$> essentials_mod) usage <- mkRecompUsageInfo hsc_env tc_result - docs <- extractDocs (ms_hspp_opts mod_summary) tc_result + docs <- extractDocs dflags tc_result self_recomp <- traverse (mkSelfRecomp hsc_env this_mod (ms_hs_hash mod_summary)) usage let partial_iface = mkIface_ hsc_env ===================================== compiler/GHC/Parser/Header.hs ===================================== @@ -126,7 +126,7 @@ getImportEdges dflags buf filename source_filename = do mkPrelImports :: ModuleName -> Bool -> [LImportDecl GhcPs] -> [LImportDecl GhcPs] --- Construct the implicit declaration "import Prelude" (or not) +-- ^ Construct the implicit declaration "import Prelude" (or not) -- -- NB: opt_NoImplicitPrelude is slightly different to import Prelude (); -- because the former doesn't even look at Prelude.hi for instance ===================================== compiler/GHC/Tc/Module.hs ===================================== @@ -473,28 +473,28 @@ tcRnImports hsc_env import_decls ; gbl_env <- getGblEnv ; let unitId = homeUnitId $ hsc_home_unit hsc_env mnwib = GWIB (moduleName this_mod)(hscSourceToIsBoot (tcg_src gbl_env)) - ; -- We want instance declarations from all home-package - -- modules below this one, including boot modules, except - -- ourselves. The 'except ourselves' is so that we don't - -- get the instances from this module's hs-boot file. This - -- filtering also ensures that we don't see instances from - -- modules batch (@--make@) compiled before this one, but - -- which are not below this one. - ; (home_insts, home_fam_insts) <- liftIO $ - hugInstancesBelow hsc_env unitId mnwib - - -- We use 'unsafeInterleaveIO' to avoid redundant memory allocations - -- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad - -- and see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14274#note_620545 - ; completeSigsBelow <- liftIO $ unsafeInterleaveIO $ - hugCompleteSigsBelow hsc_env unitId mnwib - - -- Record boot-file info in the EPS, so that it's - -- visible to loadHiBootInterface in tcRnSrcDecls, - -- and any other incrementally-performed imports - ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do { - updateEps_ $ \eps -> eps { eps_is_boot = imp_boot_mods imports } - } + -- We want instance declarations from all home-package + -- modules below this one, including boot modules, except + -- ourselves. The 'except ourselves' is so that we don't + -- get the instances from this module's hs-boot file. This + -- filtering also ensures that we don't see instances from + -- modules batch (@--make@) compiled before this one, but + -- which are not below this one. + ; (home_insts, home_fam_insts) <- liftIO $ + hugInstancesBelow hsc_env unitId mnwib + + -- We use 'unsafeInterleaveIO' to avoid redundant memory allocations + -- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad + -- and see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14274#note_620545 + ; completeSigsBelow <- liftIO $ unsafeInterleaveIO $ + hugCompleteSigsBelow hsc_env unitId mnwib + + -- Record boot-file info in the EPS, so that it's + -- visible to loadHiBootInterface in tcRnSrcDecls, + -- and any other incrementally-performed imports + ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do { + updateEps_ $ \eps -> eps { eps_is_boot = imp_boot_mods imports } + } -- Update the gbl env ; updGblEnv ( \ gbl -> ===================================== compiler/GHC/Tc/Utils/Env.hs ===================================== @@ -217,7 +217,7 @@ lookupKnownKeyGlobal hsc_env key = do eps <- hscEPS hsc_env case eps_known_keys eps of Nothing -> pprPanic "lookupKnownKeyGlobal" (text "eps_known_keys not initialized") - Just (kk_map, _) -> case lookupKnownKeysMap kk_map key of + Just ((kk_map, _), _) -> case lookupKnownKeysMap kk_map key of Succeeded name -> lookupGlobal hsc_env name Failed err -> pprPanic "lookupKnownKeyGlobal" (pprDiagnostic err) @@ -1116,6 +1116,7 @@ tcGetDefaultTys :: TcM (DefaultEnv, -- Default classes and types Bool) -- True <=> Use extended defaulting rules tcGetDefaultTys = do { dflags <- getDynFlags + ; hsc_env <- getTopEnv ; let ovl_strings = xopt LangExt.OverloadedStrings dflags extended_defaults = xopt LangExt.ExtendedDefaultRules dflags -- See also #1974 @@ -1128,11 +1129,17 @@ tcGetDefaultTys ; user_defaults <- getDeclaredDefaultTys -- User-supplied defaults ; this_module <- tcg_mod <$> getGblEnv ; let this_unit = moduleUnit this_module - ; if this_unit == ghcInternalUnit -- if we wanted, this needn't be about ghc-internal - -- see Remark [No built-in defaults in ghc-internal] - -- in Note [Builtin class defaults] in GHC.Tc.Utils.Env - then return (user_defaults, extended_defaults) - else do + ; essentials_mod <- liftIO $ lookupKnownKeysModule hsc_env dflags + ; case essentials_mod of + Nothing -> + -- If GHC.Essentials isn't available at all (e.g. -hide-all-packages), + -- don't add the built-in defaulting, bc e.g. Num is a known-entity. + return (user_defaults, extended_defaults) + _ | this_unit == ghcInternalUnit -> + -- see Remark [No built-in defaults in ghc-internal] + -- in Note [Builtin class defaults] in GHC.Tc.Utils.Env + return (user_defaults, extended_defaults) + _ -> do -- Not one of the built-in units -- @default Num (Integer, Double)@, plus extensions { extDef <- if extended_defaults ===================================== compiler/GHC/Unit/External.hs ===================================== @@ -153,7 +153,9 @@ data ExternalPackageState -- See Note [Interface Files with Core Definitions] eps_iface_bytecode :: !(ModuleEnv (IO Linkable)), - eps_known_keys :: Maybe KnownKeyNameMaps, -- ^ See Note [Overview of known entities] + eps_known_keys :: Maybe (KnownKeyNameMaps, Module), + -- ^ See Note [Overview of known entities]. + -- Caches the 'Module' where known entities are defined. eps_inst_env :: !PackageInstEnv, -- ^ The total 'InstEnv' accumulated -- from all the external-package modules ===================================== compiler/GHC/Unit/Module/Deps.hs ===================================== @@ -174,8 +174,9 @@ instance Outputable IfaceImportLevel where -- a dependencies information for the module being compiled. -- -- The fourth argument is a list of plugin modules. -mkDependencies :: HomeUnit -> Module -> ImportAvails -> [Module] -> Dependencies -mkDependencies home_unit mod imports plugin_mods = +-- The fifth argument is the unit-id of GHC.Essentials, unless -frebindable-known-names. +mkDependencies :: HomeUnit -> Module -> ImportAvails -> [Module] -> Maybe UnitId -> Dependencies +mkDependencies home_unit mod imports plugin_mods messentials_pkg = let (home_plugins, external_plugins) = partition (isHomeUnit home_unit . moduleUnit) plugin_mods plugin_units = Set.fromList (map (toUnitId . moduleUnit) external_plugins) all_direct_mods = foldr (\(s, mn) m -> extendInstalledModuleEnv m mn (s, (GWIB (moduleName mn) NotBoot))) @@ -202,7 +203,14 @@ mkDependencies home_unit mod imports plugin_mods = -- We must also remove self-references from imp_orphs. See -- Note [Module self-dependency] - direct_pkgs = Set.map (\(lvl, uid) -> (IfaceImportLevel lvl, uid)) (imp_dep_direct_pkgs imports) + direct_pkgs = add_essentials_pkg $ + Set.map (\(lvl, uid) -> (IfaceImportLevel lvl, uid)) (imp_dep_direct_pkgs imports) + + -- Add the GHC.Essentials package to direct deps unless -frebindable-known-names is on + -- (the modgraph has edges to GHC.Essentials similarly, see `getImportEdges` in GHC.Parser.Header) + add_essentials_pkg = case messentials_pkg of + Nothing -> id + Just essentials_uid -> Set.insert (IfaceImportLevel NormalLevel, essentials_uid) -- Set the packages required to be Safe according to Safe Haskell. -- See Note [Tracking Trust Transitively] in GHC.Rename.Names ===================================== testsuite/tests/driver/T27013c/Makefile ===================================== @@ -0,0 +1,14 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# Test that compiling X.hs without implicit Prelude does not recompile X the +# second time or third time. In !15899, X.hs was recompiled because of an +# incorrect "GHC.Essentials package changed" +clean: + rm -f *.o *.hi + +T27013c: clean + '$(TEST_HC)' $(TEST_HC_OPTS) --make X.hs + '$(TEST_HC)' $(TEST_HC_OPTS) --make X.hs + '$(TEST_HC)' $(TEST_HC_OPTS) --make X.hs ===================================== testsuite/tests/driver/T27013c/T27013c.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling X ( X.hs, X.o ) ===================================== testsuite/tests/driver/T27013c/X.hs ===================================== @@ -0,0 +1,3 @@ +{-# LANGUAGE NoImplicitPrelude #-} +module X where +x = x ===================================== testsuite/tests/driver/T27013c/all.T ===================================== @@ -0,0 +1,2 @@ +test('T27013c', [extra_files(['X.hs'])], + makefile_test, []) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/48c0a754c26b319bd2df0c8d04f9e44... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/48c0a754c26b319bd2df0c8d04f9e44... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)