Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC Commits: 4a84e770 by fendor at 2026-11-30T14:38:38+01:00 Fix hugSomeThingsBelowUs check - - - - - 3 changed files: - compiler/GHC/Core/Opt/Pipeline.hs - compiler/GHC/Driver/Env.hs - compiler/GHC/Tc/Module.hs Changes: ===================================== compiler/GHC/Core/Opt/Pipeline.hs ===================================== @@ -102,7 +102,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod logger = hsc_logger hsc_env unit_env = hsc_unit_env hsc_env extra_vars = interactiveInScope (hsc_IC hsc_env) - home_pkg_rules = hugRulesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) (moduleUnitId mod) + home_pkg_rules = hugRulesBelow (hsc_unit_env hsc_env) (moduleUnitId mod) (GWIB { gwib_mod = moduleName mod, gwib_isBoot = NotBoot }) name_ppr_ctx = mkNamePprCtx ptc unit_env rdr_env ptc = initPromotionTickContext dflags ===================================== compiler/GHC/Driver/Env.hs ===================================== @@ -260,26 +260,26 @@ hscUIC hsc_env = ue_uic (hsc_unit_env hsc_env) -- | Find all rules in modules that are in the transitive closure of the given -- module. -hugRulesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase -hugRulesBelow mg hug uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$> - hugSomeThingsBelowUs (md_rules . hm_details) False mg hug uid mn +hugRulesBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase +hugRulesBelow unit_env uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$> + hugSomeThingsBelowUs (md_rules . hm_details) False unit_env uid mn -- | Get annotations from all modules "below" this one (in the dependency -- sense) within the home units. If the module is @Nothing@, returns /all/ -- annotations in the home units. -hugAnnsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv -hugAnnsBelow mg hug uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$> - hugSomeThingsBelowUs (md_anns . hm_details) False mg hug uid mn +hugAnnsBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv +hugAnnsBelow unit_env uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$> + hugSomeThingsBelowUs (md_anns . hm_details) False unit_env uid mn -- | Find all COMPLETE pragmas in modules that are in the transitive closure of the -- given module. -hugCompleteSigsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches -hugCompleteSigsBelow mg hug uid mn = foldr (++) [] <$> - hugSomeThingsBelowUs (md_complete_matches . hm_details) False mg hug uid mn +hugCompleteSigsBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches +hugCompleteSigsBelow unit_env uid mn = foldr (++) [] <$> + hugSomeThingsBelowUs (md_complete_matches . hm_details) False unit_env uid mn -- | Find instances visible from the given set of imports -hugInstancesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst]) -hugInstancesBelow mg hug uid mnwib = do +hugInstancesBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst]) +hugInstancesBelow unit_env uid mnwib = do let mn = mkModule uid (gwib_mod mnwib) (insts, famInsts) <- unzip . concat <$> @@ -290,8 +290,7 @@ hugInstancesBelow mg hug uid mnwib = do then [] else [(md_insts details, md_fam_insts details)]) True -- Include -hi-boot - mg - hug + unit_env uid mnwib return (foldl' unionInstEnv emptyInstEnv insts, concat famInsts) @@ -299,18 +298,19 @@ hugInstancesBelow mg hug uid mnwib = do -- | Get things from modules in the transitive closure of the given module. -- -- Note: Don't expose this function. This is a footgun if exposed! -hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO [[a]] +hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]] -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk --- These things are currently stored in the EPS for home packages. (See #25795 for +-- These things are currently stored in the HPT's loader state for home packages. (See #25795 for -- progress in removing these kind of checks; and making these functions of -- `UnitEnv` rather than `HscEnv`) -- See Note [The ModuleGraph] -hugSomeThingsBelowUs extract include_hi_boot mg hug uid mn = - -- If the first hpt is a one-shot table, we don't recurse into it. - -- TODO @fendor: I guess that's nonsense to a certain degree - if HPT.isOneShotMode $ homeUnitEnv_hpt $ unitEnv_lookup uid hug - then pure [] - else +hugSomeThingsBelowUs extract include_hi_boot unit_env uid mn + | HPT.isOneShotMode (ue_hpt unit_env) + = pure [] + | otherwise + = let hug = ue_home_unit_graph unit_env + mg = ue_module_graph unit_env + in sequence [ things -- "Finding each non-hi-boot module below me" maybe could be cached (well, @@ -350,7 +350,7 @@ prepareAnnotations hsc_env mb_guts = do -- entries regardless of dependency ordering. get_mod mg = (moduleUnitId (mg_module mg), GWIB (moduleName (mg_module mg)) NotBoot) home_pkg_anns <- fromMaybe (hugAllAnns (hsc_unit_env hsc_env)) - $ uncurry (hugAnnsBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env)) + $ uncurry (hugAnnsBelow (hsc_unit_env hsc_env)) . get_mod <$> mb_guts more_home_pkg_anns <- HomePackageTable.hptLoadedAnnEnv $ hsc_HPT hsc_env let ===================================== compiler/GHC/Tc/Module.hs ===================================== @@ -501,13 +501,13 @@ tcRnImports hsc_env import_decls -- modules batch (@--make@) compiled before this one, but -- which are not below this one. ; (home_insts, home_fam_insts) <- liftIO $ - hugInstancesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib + hugInstancesBelow (hsc_unit_env 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_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib + hugCompleteSigsBelow (hsc_unit_env hsc_env) unitId mnwib -- Record boot-file info in the HPT, so that it's -- visible to loadHiBootInterface in tcRnSrcDecls, View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a84e770e44280d52e65eddaff453e09... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a84e770e44280d52e65eddaff453e09... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help