[Git][ghc/ghc][master] Account for special GHC.Prim import in warnUnusedPackages

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Mon Apr 17 12:09:05 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
51479ceb by Matthew Pickering at 2023-04-17T08:08:48-04:00
Account for special GHC.Prim import in warnUnusedPackages

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

- - - - -


3 changed files:

- compiler/GHC/Driver/Make.hs
- + testsuite/tests/warnings/should_compile/T23212.hs
- testsuite/tests/warnings/should_compile/all.T


Changes:

=====================================
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


=====================================
testsuite/tests/warnings/should_compile/T23212.hs
=====================================
@@ -0,0 +1,3 @@
+module T23212 where
+
+import GHC.Prim


=====================================
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, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51479ceb31b8bfef15b966de7cfd64d1fdb22257

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/51479ceb31b8bfef15b966de7cfd64d1fdb22257
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/20230417/bed56af9/attachment-0001.html>


More information about the ghc-commits mailing list