[Git][ghc/ghc][master] Extend the `TrustOverlay` for wired-in units
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 54381079 by Hannes Siebenhandl at 2026-10-02T17:39:01-04:00 Extend the `TrustOverlay` for wired-in units The TrustOverlay only contained the `UnitId` of all on-disk units. However, wired-in units are referred to by their wired-in unit id, which is not the same as the on-disk unit id. Thus, trust checks for wired-in units failed because the lookup was using the wired-in unit, which wasn't present in the `TrustOverlay`. We fix #27834, by copying the trust info for wired-in unit ids. - - - - - 7 changed files: - changelog.d/unit-index - compiler/GHC/Unit/External/Wired.hs - compiler/GHC/Unit/State.hs - + testsuite/tests/ghci/scripts/T27834.hs - + testsuite/tests/ghci/scripts/T27834.script - + testsuite/tests/ghci/scripts/T27834.stdout - testsuite/tests/ghci/scripts/all.T Changes: ===================================== changelog.d/unit-index ===================================== @@ -1,7 +1,7 @@ section: compiler synopsis: Use global ``UnitIndex`` to deduplicate ``UnitInfo``s over multiple home units -issues: #27500 #26423 #27748 -mrs: !16115 !16598 +issues: #27500 #26423 #27748 #27834 +mrs: !16115 !16598 !16743 description: { The ``UnitState`` used to be duplicated for all ``HomeUnitEnv``, not sharing any of the ``UnitInfo``s. ===================================== compiler/GHC/Unit/External/Wired.hs ===================================== @@ -5,6 +5,7 @@ module GHC.Unit.External.Wired ( isWireMapEmpty, lookupWireMap, listWireMap, + nonDetFoldWireMap, -- * 'UnwireMap' UnwireMap, emptyUnwireMap, @@ -48,6 +49,9 @@ lookupWireMap uid (WireMap wmap) = lookupUniqMap wmap uid listWireMap :: WireMap -> [(UnitId, UnitId)] listWireMap (WireMap wmap) = nonDetUniqMapToList wmap +nonDetFoldWireMap :: ((UnitId, UnitId) -> b -> b) -> b -> WireMap -> b +nonDetFoldWireMap go z (WireMap uniq) = nonDetFoldUniqMap go z uniq + -- | The reverse of 'WireMap'. -- Records the mapping from the wired-in 'UnitId' to the on-disk 'UnitId'. newtype UnwireMap = ===================================== compiler/GHC/Unit/State.hs ===================================== @@ -286,6 +286,21 @@ trustUnits elements (TrustOverlay to) = TrustOverlay $ foldl' (\ acc uid -> addT emptyTrustOverlay :: TrustOverlay emptyTrustOverlay = TrustOverlay emptyUniqMap +-- | For all values in the 'WireMap', copy the recorded trust/distrust +-- for the wired-in unit id. +-- +extendForWireMap :: TrustOverlay -> WireMap -> TrustOverlay +extendForWireMap to wmap = + nonDetFoldWireMap go to wmap + where + go (onDiskUid, wiredInUid) overlay = + case lookupTrustOverlay overlay onDiskUid of + Nothing -> overlay + Just Trusted -> + trustUnits [wiredInUid] overlay + Just Distrusted -> + distrustUnits [wiredInUid] overlay + {- Note [Sharing 'UnitInfo's across the 'UnitEnv'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -957,7 +972,7 @@ mkUnitState logger unit_index cfg = do , explicitUnits = explicit_pkgs , homeUnitDepends = home_unit_deps , unitInfoMap = pkg_db - , trustedUnits = trustUnitsOverlay + , trustedUnits = trustUnitsOverlay `extendForWireMap` wired_map , moduleNameProvidersMap = mod_map , pluginModuleNameProvidersMap = mkModuleNameProvidersMap logger (unitConfigAllowVirtual cfg) pkg_db plugin_vis_map , packageNameMap = pkgname_map ===================================== testsuite/tests/ghci/scripts/T27834.hs ===================================== @@ -0,0 +1,9 @@ +{-# LANGUAGE Haskell2010 #-} +{-# LANGUAGE Safe #-} +module Main where + +-- Importing a wired-in in module should honour trustworthiness +import GHC.Internal.Char (chr) + +main :: IO () +main = print (chr 120) ===================================== testsuite/tests/ghci/scripts/T27834.script ===================================== @@ -0,0 +1,2 @@ +:load T27834 +putStrLn "Can import trusted module from ghc-internal" ===================================== testsuite/tests/ghci/scripts/T27834.stdout ===================================== @@ -0,0 +1 @@ +Can import trusted module from ghc-internal ===================================== testsuite/tests/ghci/scripts/all.T ===================================== @@ -403,3 +403,4 @@ test('GhciPackageRename', ['GhciPackageRename.script']) test('T26233', normal, ghci_script, ['T26233.script']) test('T27641', normal, ghci_script, ['T27641.script']) +test('T27834', [extra_hc_opts("-fpackage-trust -trust base -trust ghc-internal -package ghc-internal")], ghci_script, ['T27834.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/54381079e5a0808f798d1a74e5b94d9f... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/54381079e5a0808f798d1a74e5b94d9f... 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
participants (1)
-
Marge Bot (@marge-bot)