[Git][ghc/ghc][wip/t25122] driver: Fix -Wmissing-home-modules when multiple units have the same module name
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Tue Jul 30 12:31:21 UTC 2024
Matthew Pickering pushed to branch wip/t25122 at Glasgow Haskell Compiler / GHC
Commits:
d95d0356 by Matthew Pickering at 2024-07-30T13:30:43+01:00
driver: Fix -Wmissing-home-modules when multiple units have the same module name
It was assumed that module names were unique but that isn't true with
multiple units.
The fix is quite simple, maintain a set of `(ModuleName, UnitId)` and
query that to see whether the module has been specified.
Fixes #25122
- - - - -
5 changed files:
- compiler/GHC/Driver/Make.hs
- + testsuite/tests/driver/multipleHomeUnits/T25122/T25122.hs
- testsuite/tests/driver/multipleHomeUnits/all.T
- + testsuite/tests/driver/multipleHomeUnits/unitSame1
- + testsuite/tests/driver/multipleHomeUnits/unitSame2
Changes:
=====================================
compiler/GHC/Driver/Make.hs
=====================================
@@ -329,10 +329,12 @@ warnMissingHomeModules dflags targets mod_graph =
-- Note also that we can't always infer the associated module name
-- directly from the filename argument. See #13727.
is_known_module mod =
- (Map.lookup (moduleName (ms_mod mod)) mod_targets == Just (ms_unitid mod))
+ is_module_target mod
||
maybe False is_file_target (ml_hs_file (ms_location mod))
+ is_module_target mod = (moduleName (ms_mod mod), ms_unitid mod) `Set.member` mod_targets
+
is_file_target file = Set.member (withoutExt file) file_targets
file_targets = Set.fromList (mapMaybe file_target targets)
@@ -343,7 +345,7 @@ warnMissingHomeModules dflags targets mod_graph =
TargetFile file _ ->
Just (withoutExt (augmentByWorkingDirectory dflags file))
- mod_targets = Map.fromList (mod_target <$> targets)
+ mod_targets = Set.fromList (mod_target <$> targets)
mod_target Target {targetUnitId, targetId} =
case targetId of
=====================================
testsuite/tests/driver/multipleHomeUnits/T25122/T25122.hs
=====================================
@@ -0,0 +1 @@
+module T25122 where
=====================================
testsuite/tests/driver/multipleHomeUnits/all.T
=====================================
@@ -71,6 +71,11 @@ test('multipleHomeUnits_shared', [extra_files([ 'A.hs', 'unitShared1', 'unitShar
test('multipleHomeUnits_shared_ghci', [extra_files([ 'shared.script', 'A.hs', 'unitShared1', 'unitShared2']), extra_run_opts('-unit @unitShared1 -unit @unitShared2')], ghci_script, ['shared.script'])
+test('T25122',
+ [ extra_files(
+ [ 'T25122', 'unitSame1', 'unitSame2'])
+ ], multiunit_compile, [['unitSame1', 'unitSame2'], '-v0 -fhide-source-paths -Werror -Wmissing-home-modules'])
+
=====================================
testsuite/tests/driver/multipleHomeUnits/unitSame1
=====================================
@@ -0,0 +1,3 @@
+T25122
+-iT25122
+-this-unit-id=s1
=====================================
testsuite/tests/driver/multipleHomeUnits/unitSame2
=====================================
@@ -0,0 +1,3 @@
+T25122
+-iT25122
+-this-unit-id=u2
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d95d03561ca861d23b8f4df620e4c69fefa0b6b7
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d95d03561ca861d23b8f4df620e4c69fefa0b6b7
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/20240730/0a84e86d/attachment-0001.html>
More information about the ghc-commits
mailing list