[Git][ghc/ghc][master] ghci: Use loadInterfaceForModule rather than loadSrcInterface in mkTopLevEnv

Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 91564daf by Matthew Pickering at 2025-04-24T00:29:02-04:00 ghci: Use loadInterfaceForModule rather than loadSrcInterface in mkTopLevEnv loadSrcInterface takes a user given `ModuleName` and resolves it to the module which needs to be loaded (taking into account module renaming/visibility etc). loadInterfaceForModule takes a specific module and loads it. The modules in `ImpDeclSpec` have already been resolved to the actual module to get the information from during renaming. Therefore we just need to fetch the precise interface from disk (and not attempt to rename it again). Fixes #25951 - - - - - 5 changed files: - compiler/GHC/Runtime/Eval.hs - + testsuite/tests/ghci/scripts/GhciPackageRename.hs - + testsuite/tests/ghci/scripts/GhciPackageRename.script - + testsuite/tests/ghci/scripts/GhciPackageRename.stdout - testsuite/tests/ghci/scripts/all.T Changes: ===================================== compiler/GHC/Runtime/Eval.hs ===================================== @@ -78,7 +78,7 @@ import GHC.Core.Type hiding( typeKind ) import qualified GHC.Core.Type as Type import GHC.Iface.Env ( newInteractiveBinder ) -import GHC.Iface.Load ( loadSrcInterface ) +import GHC.Iface.Load ( loadInterfaceForModule ) import GHC.Tc.Utils.TcType import GHC.Tc.Types.Constraint import GHC.Tc.Types.Origin @@ -843,7 +843,7 @@ mkTopLevEnv hsc_env modl $ fmap (foldr plusGlobalRdrEnv emptyGlobalRdrEnv) $ forM imports $ \iface_import -> do let ImpUserSpec spec details = tcIfaceImport iface_import - iface <- loadSrcInterface (text "imported by GHCi") (moduleName $ is_mod spec) (is_isboot spec) (is_pkg_qual spec) + iface <- loadInterfaceForModule (text "imported by GHCi") (is_mod spec) pure $ case details of ImpUserAll -> importsFromIface hsc_env iface spec Nothing ImpUserEverythingBut ns -> importsFromIface hsc_env iface spec (Just ns) ===================================== testsuite/tests/ghci/scripts/GhciPackageRename.hs ===================================== @@ -0,0 +1,4 @@ +module GhciPackageRename where + +foo :: Map k v +foo = empty \ No newline at end of file ===================================== testsuite/tests/ghci/scripts/GhciPackageRename.script ===================================== @@ -0,0 +1,6 @@ +:l GhciPackageRename.hs +-- Test that Data.Map is available as Prelude +:t fromList + +-- Test using a Map function +fromList [(1,"a"), (2,"b")] \ No newline at end of file ===================================== testsuite/tests/ghci/scripts/GhciPackageRename.stdout ===================================== @@ -0,0 +1,3 @@ +fromList + :: ghc-internal:GHC.Internal.Classes.Ord k => [(k, a)] -> Map k a +fromList [(1,"a"),(2,"b")] ===================================== testsuite/tests/ghci/scripts/all.T ===================================== @@ -386,3 +386,9 @@ test('T13869', extra_files(['T13869a.hs', 'T13869b.hs']), ghci_script, ['T13869. test('ListTuplePunsPpr', normal, ghci_script, ['ListTuplePunsPpr.script']) test('ListTuplePunsPprNoAbbrevTuple', [expect_broken(23135), limit_stdout_lines(13)], ghci_script, ['ListTuplePunsPprNoAbbrevTuple.script']) test('T24459', normal, ghci_script, ['T24459.script']) + +# Test package renaming in GHCi session +test('GhciPackageRename', + [extra_hc_opts("-hide-all-packages -package 'containers (Data.Map as Prelude)'")], + ghci_script, + ['GhciPackageRename.script']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/91564dafd60445f03025c3fee4f9802e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/91564dafd60445f03025c3fee4f9802e... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)