summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-12-22 16:59:53 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-12-22 17:20:12 +0000
commitb8e4102bd19d86d6a60ee78fba81c9a3b5be2aed (patch)
treee588149d0c7b2ae9070c88206402199e6f9e7dcb
parent09b6cb45505c2c32ddaffcdb930fb3f7873b2cfc (diff)
downloadhaskell-b8e4102bd19d86d6a60ee78fba81c9a3b5be2aed.tar.gz
Properly filter for module visibility in resolvePackageImportwip/resolve-package-import
This completes the fix for #20779 / !7123. Beforehand, the program worked by accident because the two versions of the library happened to be ordered properly (due to how the hashes were computed). In the real world I observed them being the other way around which meant the final lookup failed because we weren't filtering for visibility. I modified the test so that it failed (and it's fixed by this patch).
-rw-r--r--compiler/GHC/Unit/State.hs2
-rw-r--r--testsuite/tests/driver/package-imports-t20779/Makefile7
-rw-r--r--testsuite/tests/driver/package-imports-t20779/all.T2
-rw-r--r--testsuite/tests/driver/package-imports-t20779/p/p.cabal2
-rw-r--r--testsuite/tests/driver/package-imports-t20779/q-3/LICENSE1
-rw-r--r--testsuite/tests/driver/package-imports-t20779/q-3/QLib.hs3
-rw-r--r--testsuite/tests/driver/package-imports-t20779/q-3/q.cabal25
7 files changed, 39 insertions, 3 deletions
diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs
index e178bafea6..859b99f1a1 100644
--- a/compiler/GHC/Unit/State.hs
+++ b/compiler/GHC/Unit/State.hs
@@ -551,7 +551,7 @@ searchPackageId pkgstate pid = filter ((pid ==) . unitPackageId)
resolvePackageImport :: UnitState -> ModuleName -> PackageName -> Maybe UnitId
resolvePackageImport unit_st mn pn = do
-- 1. Find all modules providing the ModuleName (this accounts for visibility/thinning etc)
- providers <- Map.lookup mn (moduleNameProvidersMap unit_st)
+ 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
-- 3. Get the package names of the candidates
diff --git a/testsuite/tests/driver/package-imports-t20779/Makefile b/testsuite/tests/driver/package-imports-t20779/Makefile
index 451a1a8739..fc75a47d09 100644
--- a/testsuite/tests/driver/package-imports-t20779/Makefile
+++ b/testsuite/tests/driver/package-imports-t20779/Makefile
@@ -22,6 +22,13 @@ package-imports-20779:
(cd q-2; $(SETUP) copy)
(cd q-2; $(SETUP) register)
+ # build q3
+ rm -rf q-3/dist
+ (cd q-3; $(CONFIGURE) --ipid "q-3")
+ (cd q-3; $(SETUP) build)
+ (cd q-3; $(SETUP) copy)
+ (cd q-3; $(SETUP) register)
+
# build p
rm -rf p/dist
(cd p; $(CONFIGURE) --ipid "p-1")
diff --git a/testsuite/tests/driver/package-imports-t20779/all.T b/testsuite/tests/driver/package-imports-t20779/all.T
index 2d7fb3f8ea..c6fc03d5f1 100644
--- a/testsuite/tests/driver/package-imports-t20779/all.T
+++ b/testsuite/tests/driver/package-imports-t20779/all.T
@@ -1,4 +1,4 @@
-test('package-imports-20779', [extra_files(['q-1', 'q-2', 'p', 'Setup.hs']),
+test('package-imports-20779', [extra_files(['q-1', 'q-2', 'q-3', 'p', 'Setup.hs']),
when(fast(), skip)],
makefile_test,
[])
diff --git a/testsuite/tests/driver/package-imports-t20779/p/p.cabal b/testsuite/tests/driver/package-imports-t20779/p/p.cabal
index b9d25f155c..2fdee5beaa 100644
--- a/testsuite/tests/driver/package-imports-t20779/p/p.cabal
+++ b/testsuite/tests/driver/package-imports-t20779/p/p.cabal
@@ -20,6 +20,6 @@ library
exposed-modules: PLib
-- other-modules:
-- other-extensions:
- build-depends: base >=4 && <5, q == 1
+ build-depends: base >=4 && <5, q == 2
-- hs-source-dirs:
default-language: Haskell2010
diff --git a/testsuite/tests/driver/package-imports-t20779/q-3/LICENSE b/testsuite/tests/driver/package-imports-t20779/q-3/LICENSE
new file mode 100644
index 0000000000..bca70f3531
--- /dev/null
+++ b/testsuite/tests/driver/package-imports-t20779/q-3/LICENSE
@@ -0,0 +1 @@
+q
diff --git a/testsuite/tests/driver/package-imports-t20779/q-3/QLib.hs b/testsuite/tests/driver/package-imports-t20779/q-3/QLib.hs
new file mode 100644
index 0000000000..b98aa33300
--- /dev/null
+++ b/testsuite/tests/driver/package-imports-t20779/q-3/QLib.hs
@@ -0,0 +1,3 @@
+module QLib where
+
+q = 'q'
diff --git a/testsuite/tests/driver/package-imports-t20779/q-3/q.cabal b/testsuite/tests/driver/package-imports-t20779/q-3/q.cabal
new file mode 100644
index 0000000000..70c24cf45f
--- /dev/null
+++ b/testsuite/tests/driver/package-imports-t20779/q-3/q.cabal
@@ -0,0 +1,25 @@
+cabal-version: >=1.10
+-- Initial package description 'q.cabal' generated by 'cabal init'. For
+-- further documentation, see http://haskell.org/cabal/users-guide/
+
+name: q
+version: 3
+-- synopsis:
+-- description:
+-- bug-reports:
+-- license:
+license-file: LICENSE
+author: Matthew Pickering
+maintainer: matthewtpickering@gmail.com
+-- copyright:
+-- category:
+build-type: Simple
+extra-source-files: CHANGELOG.md
+
+library
+ exposed-modules: QLib
+ -- other-modules:
+ -- other-extensions:
+ build-depends: base >=4 && <5
+ -- hs-source-dirs:
+ default-language: Haskell2010