[Git][ghc/ghc][master] Package Imports: Get candidate packages also from re-exported modules
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Thu Dec 15 08:54:59 UTC 2022
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
2eb0fb87 by Matthew Pickering at 2022-12-15T03:54:39-05:00
Package Imports: Get candidate packages also from re-exported modules
Previously we were just looking at the direct imports to try and work
out what a package qualifier could apply to but #22333 pointed out we
also needed to look for reexported modules.
Fixes #22333
- - - - -
16 changed files:
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/State.hs
- + testsuite/tests/cabal/t22333/Makefile
- + testsuite/tests/cabal/t22333/Setup.hs
- + testsuite/tests/cabal/t22333/all.T
- + testsuite/tests/cabal/t22333/my-exe/CHANGELOG.md
- + testsuite/tests/cabal/t22333/my-exe/app/Main.hs
- + testsuite/tests/cabal/t22333/my-exe/my-exe.cabal
- + testsuite/tests/cabal/t22333/my-package-a/CHANGELOG.md
- + testsuite/tests/cabal/t22333/my-package-a/Setup.hs
- + testsuite/tests/cabal/t22333/my-package-a/my-package-a.cabal
- + testsuite/tests/cabal/t22333/my-package-a/src/MyLib.hs
- + testsuite/tests/cabal/t22333/my-package-b/CHANGELOG.md
- + testsuite/tests/cabal/t22333/my-package-b/Setup.hs
- + testsuite/tests/cabal/t22333/my-package-b/my-package-b.cabal
- + testsuite/tests/cabal/t22333/my-package-b/src/LibB.hs
Changes:
=====================================
compiler/GHC/Unit/Finder.hs
=====================================
@@ -136,13 +136,13 @@ lookupFileCache (FinderCache _ ref) key = do
-- that package is searched for the module.
findImportedModule :: HscEnv -> ModuleName -> PkgQual -> IO FindResult
-findImportedModule hsc_env mod fs =
+findImportedModule hsc_env mod pkg_qual =
let fc = hsc_FC hsc_env
mhome_unit = hsc_home_unit_maybe hsc_env
dflags = hsc_dflags hsc_env
fopts = initFinderOpts dflags
in do
- findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod fs
+ findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) mhome_unit mod pkg_qual
findImportedModuleNoHsc
:: FinderCache
=====================================
compiler/GHC/Unit/State.hs
=====================================
@@ -571,13 +571,25 @@ resolvePackageImport unit_st mn pn = do
-- 1. Find all modules providing the ModuleName (this accounts for visibility/thinning etc)
providers <- Map.filter originVisible <$> Map.lookup mn (moduleNameProvidersMap unit_st)
-- 2. Get the UnitIds of the candidates
- let candidates_uid = map (toUnitId . moduleUnit) $ Map.keys providers
+ let candidates_uid = concatMap to_uid $ Map.assocs providers
-- 3. Get the package names of the candidates
let candidates_units = map (\ui -> ((unitPackageName ui), unitId ui))
$ mapMaybe (\uid -> Map.lookup uid (unitInfoMap unit_st)) candidates_uid
-- 4. Check to see if the PackageName helps us disambiguate any candidates.
lookup pn candidates_units
+ where
+
+ -- Get the UnitId from which a visible identifier is from
+ to_uid :: (Module, ModuleOrigin) -> [UnitId]
+ to_uid (mod, ModOrigin mo re_exps _ _) =
+ case mo of
+ -- Available directly, but also potentially from re-exports
+ Just True -> (toUnitId (moduleUnit mod)) : map unitId re_exps
+ -- Just available from these re-exports
+ _ -> map unitId re_exps
+ to_uid _ = []
+
-- | Create a Map UnitId UnitInfo
--
-- For each instantiated unit, we add two map keys:
=====================================
testsuite/tests/cabal/t22333/Makefile
=====================================
@@ -0,0 +1,32 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+SETUP=../Setup -v0
+CONFIGURE=$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp.d --prefix='$(PWD)/../dist'
+
+T22333: clean
+ $(MAKE) -s --no-print-directory clean
+ '$(GHC_PKG)' init tmp.d
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
+ # build b
+ cd my-package-b; $(CONFIGURE) --cid "my-package-b-0.1" my-package-b
+ cd my-package-b; $(SETUP) build
+ cd my-package-b; $(SETUP) copy
+ cd my-package-b; $(SETUP) register
+ # build a
+ cd my-package-a; $(CONFIGURE) --cid "my-package-a-0.1" my-package-a
+ cd my-package-a; $(SETUP) build
+ cd my-package-a; $(SETUP) copy
+ cd my-package-a; $(SETUP) register
+ # build my-exe
+ cd my-exe; $(CONFIGURE) --cid "my-exe-0.1" my-exe
+ cd my-exe; $(SETUP) build
+ cd my-exe; $(SETUP) copy
+ cd my-exe; $(SETUP) register
+ifneq "$(CLEANUP)" ""
+ $(MAKE) -s --no-print-directory clean
+endif
+
+clean :
+ $(RM) -r tmp.d dist Setup$(exeext)
=====================================
testsuite/tests/cabal/t22333/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/cabal/t22333/all.T
=====================================
@@ -0,0 +1,4 @@
+test('T22333',
+ [extra_files(['Setup.hs', 'my-exe', 'my-package-a', 'my-package-b' ])],
+ makefile_test,
+ [])
=====================================
testsuite/tests/cabal/t22333/my-exe/CHANGELOG.md
=====================================
@@ -0,0 +1,5 @@
+# Revision history for my-exe
+
+## 0.1.0.0 -- YYYY-mm-dd
+
+* First version. Released on an unsuspecting world.
=====================================
testsuite/tests/cabal/t22333/my-exe/app/Main.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE PackageImports #-}
+
+module Main (main) where
+
+import "my-package-a" LibB (someFuncB)
+--import LibB (someFuncB)
+
+main :: IO ()
+main = print someFuncB
=====================================
testsuite/tests/cabal/t22333/my-exe/my-exe.cabal
=====================================
@@ -0,0 +1,20 @@
+cabal-version: 3.8
+name: my-exe
+version: 0.1.0.0
+license: NONE
+author: a.pelenitsyn at gmail.com
+maintainer: Artem Pelenitsyn
+build-type: Simple
+extra-doc-files: CHANGELOG.md
+
+common warnings
+ ghc-options: -Wall
+
+executable my-exe
+ import: warnings
+ main-is: Main.hs
+ build-depends: base
+ , my-package-a
+ , my-package-b
+ hs-source-dirs: app
+ default-language: Haskell2010
=====================================
testsuite/tests/cabal/t22333/my-package-a/CHANGELOG.md
=====================================
@@ -0,0 +1,5 @@
+# Revision history for my-package-a
+
+## 0.1.0.0 -- YYYY-mm-dd
+
+* First version. Released on an unsuspecting world.
=====================================
testsuite/tests/cabal/t22333/my-package-a/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/cabal/t22333/my-package-a/my-package-a.cabal
=====================================
@@ -0,0 +1,20 @@
+cabal-version: 3.8
+name: my-package-a
+version: 0.1.0.0
+license: NONE
+author: a.pelenitsyn at gmail.com
+maintainer: Artem Pelenitsyn
+build-type: Simple
+extra-doc-files: CHANGELOG.md
+
+common warnings
+ ghc-options: -Wall
+
+library
+ import: warnings
+ exposed-modules: MyLib
+ build-depends: base
+ , my-package-b
+ reexported-modules: LibB
+ hs-source-dirs: src
+ default-language: Haskell2010
=====================================
testsuite/tests/cabal/t22333/my-package-a/src/MyLib.hs
=====================================
@@ -0,0 +1,4 @@
+module MyLib (someFunc) where
+
+someFunc :: IO ()
+someFunc = putStrLn "someFunc"
=====================================
testsuite/tests/cabal/t22333/my-package-b/CHANGELOG.md
=====================================
@@ -0,0 +1,5 @@
+# Revision history for my-package-b
+
+## 0.1.0.0 -- YYYY-mm-dd
+
+* First version. Released on an unsuspecting world.
=====================================
testsuite/tests/cabal/t22333/my-package-b/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/cabal/t22333/my-package-b/my-package-b.cabal
=====================================
@@ -0,0 +1,18 @@
+cabal-version: 3.8
+name: my-package-b
+version: 0.1.0.0
+license: NONE
+author: a.pelenitsyn at gmail.com
+maintainer: Artem Pelenitsyn
+build-type: Simple
+extra-doc-files: CHANGELOG.md
+
+common warnings
+ ghc-options: -Wall
+
+library
+ import: warnings
+ exposed-modules: LibB
+ build-depends: base
+ hs-source-dirs: src
+ default-language: Haskell2010
=====================================
testsuite/tests/cabal/t22333/my-package-b/src/LibB.hs
=====================================
@@ -0,0 +1,4 @@
+module LibB (someFuncB) where
+
+someFuncB :: Int
+someFuncB = 42
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2eb0fb87b921efc8f107eb39a3d34dae08082a3c
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2eb0fb87b921efc8f107eb39a3d34dae08082a3c
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221215/0505799b/attachment-0001.html>
More information about the ghc-commits
mailing list