summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2023-04-13 15:48:22 +0100
committerGHC GitLab CI <ghc-ci@gitlab-haskell.org>2023-04-13 15:56:18 +0100
commite63a8cd4dca2c97c0aad47c33b6bfbad4ded8e74 (patch)
tree3b4c66853ec67fd2659e2930f670eca84c396bb5
parent27d2978e5412f2bef4448e208182a03137dd5ee8 (diff)
downloadhaskell-wip/unused-ghc-prim.tar.gz
Account for special GHC.Prim import in warnUnusedPackageswip/unused-ghc-prim
The GHC.Prim import is treated quite specially primarily because there isn't an interface file for GHC.Prim. Therefore we record separately in the ModSummary if it's imported or not so we don't go looking for it. This logic hasn't made it's way to `-Wunused-packages` so if you imported GHC.Prim then the warning would complain you didn't use `-package ghc-prim`. Fixes #23212
-rw-r--r--compiler/GHC/Driver/Make.hs10
-rw-r--r--testsuite/tests/warnings/should_compile/T23212.hs3
-rw-r--r--testsuite/tests/warnings/should_compile/all.T4
3 files changed, 14 insertions, 3 deletions
diff --git a/compiler/GHC/Driver/Make.hs b/compiler/GHC/Driver/Make.hs
index 0d0df0dd1b..7f60d5a8a0 100644
--- a/compiler/GHC/Driver/Make.hs
+++ b/compiler/GHC/Driver/Make.hs
@@ -514,13 +514,17 @@ warnUnusedPackages :: UnitState -> DynFlags -> ModuleGraph -> DriverMessages
warnUnusedPackages us dflags mod_graph =
let diag_opts = initDiagOpts dflags
+ home_mod_sum = filter (\ms -> homeUnitId_ dflags == ms_unitid ms) (mgModSummaries mod_graph)
+
-- Only need non-source imports here because SOURCE imports are always HPT
loadedPackages = concat $
mapMaybe (\(fs, mn) -> lookupModulePackage us (unLoc mn) fs)
- $ concatMap ms_imps (
- filter (\ms -> homeUnitId_ dflags == ms_unitid ms) (mgModSummaries mod_graph))
+ $ concatMap ms_imps home_mod_sum
+
+ any_import_ghc_prim = any ms_ghc_prim_import home_mod_sum
- used_args = Set.fromList $ map unitId loadedPackages
+ used_args = Set.fromList (map unitId loadedPackages)
+ `Set.union` Set.fromList [ primUnitId | any_import_ghc_prim ]
resolve (u,mflag) = do
-- The units which we depend on via the command line explicitly
diff --git a/testsuite/tests/warnings/should_compile/T23212.hs b/testsuite/tests/warnings/should_compile/T23212.hs
new file mode 100644
index 0000000000..892a28d4a4
--- /dev/null
+++ b/testsuite/tests/warnings/should_compile/T23212.hs
@@ -0,0 +1,3 @@
+module T23212 where
+
+import GHC.Prim
diff --git a/testsuite/tests/warnings/should_compile/all.T b/testsuite/tests/warnings/should_compile/all.T
index 9fe8b99787..0c8c2f6a5d 100644
--- a/testsuite/tests/warnings/should_compile/all.T
+++ b/testsuite/tests/warnings/should_compile/all.T
@@ -39,6 +39,10 @@ test('UnusedPackages', [normalise_version('bytestring')
], multimod_compile,
['UnusedPackages.hs', '-package=bytestring -package=base -package=process -package=ghc -Wunused-packages'])
+test('T23212', [normalise_version('ghc-prim')
+ ], multimod_compile,
+ ['T23212', '-v0 -package=ghc-prim -Werror -Wunused-packages'])
+
test('T18402', normal, compile, [''])
test('T19564a', normal, compile, [''])