Commit 06cc0a95 authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot
Browse files

Improve driver diagnostic messages by including UnitId in message

Currently the driver diagnostics don't give any indication about which unit they correspond to.

For example `-Wmissing-home-modules` can fire multiple times for each different home unit and gives no indication about which unit it's actually reporting about.

Perhaps a longer term fix is to generalise the providence information away from a SrcSpan so that these kind of whole project errors can be reported with an accurate provenance. For now we can just include the `UnitId` in the error message.

Fixes #22678
parent 6469fea7
......@@ -92,28 +92,29 @@ instance Diagnostic DriverMessage where
-> diagnosticMessage (defaultDiagnosticOpts @e) m
DriverPsHeaderMessage m
-> diagnosticMessage (psDiagnosticOpts opts) m
DriverMissingHomeModules missing buildingCabalPackage
DriverMissingHomeModules uid missing buildingCabalPackage
-> let msg | buildingCabalPackage == YesBuildingCabalPackage
= hang
(text "These modules are needed for compilation but not listed in your .cabal file's other-modules: ")
(text "These modules are needed for compilation but not listed in your .cabal file's other-modules for" <+> quotes (ppr uid) <+> text ":")
4
(sep (map ppr missing))
| otherwise
=
hang
(text "Modules are not listed in command line but needed for compilation: ")
(text "Modules are not listed in options for"
<+> quotes (ppr uid) <+> text "but needed for compilation:")
4
(sep (map ppr missing))
in mkSimpleDecorated msg
DriverUnknownHiddenModules missing
DriverUnknownHiddenModules uid missing
-> let msg = hang
(text "Modules are listened as hidden but not part of the unit: ")
(text "Modules are listed as hidden in options for" <+> quotes (ppr uid) <+> text "but not part of the unit:")
4
(sep (map ppr missing))
in mkSimpleDecorated msg
DriverUnknownReexportedModules missing
DriverUnknownReexportedModules uid missing
-> let msg = hang
(text "Modules are listened as reexported but can't be found in any dependency: ")
(text "Modules are listed as reexported in options for" <+> quotes (ppr uid) <+> text "but can't be found in any dependency:")
4
(sep (map ppr missing))
in mkSimpleDecorated msg
......
......@@ -143,17 +143,17 @@ data DriverMessage where
Test case: warnings/should_compile/MissingMod
-}
DriverMissingHomeModules :: [ModuleName] -> !BuildingCabalPackage -> DriverMessage
DriverMissingHomeModules :: UnitId -> [ModuleName] -> !BuildingCabalPackage -> DriverMessage
{-| DriverUnknown is a warning that arises when a user tries to
reexport a module which isn't part of that unit.
-}
DriverUnknownReexportedModules :: [ModuleName] -> DriverMessage
DriverUnknownReexportedModules :: UnitId -> [ModuleName] -> DriverMessage
{-| DriverUnknownHiddenModules is a warning that arises when a user tries to
hide a module which isn't part of that unit.
-}
DriverUnknownHiddenModules :: [ModuleName] -> DriverMessage
DriverUnknownHiddenModules :: UnitId -> [ModuleName] -> DriverMessage
{-| DriverUnusedPackages occurs when when package is requested on command line,
but was never needed during compilation. Activated by -Wunused-packages.
......
......@@ -365,7 +365,7 @@ warnMissingHomeModules dflags targets mod_graph =
(mgModSummaries mod_graph))
warn = singleMessage $ mkPlainMsgEnvelope diag_opts noSrcSpan
$ DriverMissingHomeModules missing (checkBuildingCabalPackage dflags)
$ DriverMissingHomeModules (homeUnitId_ dflags) missing (checkBuildingCabalPackage dflags)
-- Check that any modules we want to reexport or hide are actually in the package.
warnUnknownModules :: HscEnv -> DynFlags -> ModuleGraph -> IO DriverMessages
......@@ -393,14 +393,14 @@ warnUnknownModules hsc_env dflags mod_graph = do
_ -> return True
warn flag mod = singleMessage $ mkPlainMsgEnvelope diag_opts noSrcSpan
$ flag mod
warn diagnostic = singleMessage $ mkPlainMsgEnvelope diag_opts noSrcSpan
$ diagnostic
final_msgs hidden_warns reexported_warns
=
unionManyMessages $
[warn DriverUnknownHiddenModules (Set.toList hidden_warns) | not (Set.null hidden_warns)]
++ [warn DriverUnknownReexportedModules reexported_warns | not (null reexported_warns)]
[warn (DriverUnknownHiddenModules (homeUnitId_ dflags) (Set.toList hidden_warns)) | not (Set.null hidden_warns)]
++ [warn (DriverUnknownReexportedModules (homeUnitId_ dflags) reexported_warns) | not (null reexported_warns)]
-- | Describes which modules of the module graph need to be loaded.
data LoadHowMuch
......
......@@ -7,6 +7,8 @@ test('multipleHomeUnits_cpp', [extra_files([ 'cpp-includes/', 'unitCPPIncludes']
test('multipleHomeUnits_cfile', [extra_files([ 'c-file/', 'unitCFile'])], multiunit_compile, [['unitCFile'], '-fhide-source-paths'])
test('multipleHomeUnits_callstack', [extra_files([ 'callstack/', 'unitCallstack'])], makefile_test, [])
test('multipleHomeUnits_warnings', [extra_files([ 'unitWarnings', 'A.hs'])], multiunit_compile_fail, [['unitWarnings'], '-fhide-source-paths'])
test('multipleHomeUnits_cpp2', [extra_files([ 'cpp-includes/', 'cpp-import/', 'unitCPPImport', 'unitCPPIncludes'])], multiunit_compile, [['unitCPPImport', 'unitCPPIncludes'], '-fhide-source-paths'])
test('multiGHCi', [extra_files(['a/', 'b/', 'unitA', 'unitB', 'multiGHCi.script'])
......
<no location info>: error: [GHC-38189]
Modules are listed as hidden in options for ‘unit-warnings’ but not part of the unit:
C
<no location info>: error: [GHC-68286]
Modules are listed as reexported in options for ‘unit-warnings’ but can't be found in any dependency:
B
-i -i. A -reexported-module B -hidden-module C -this-unit-id unit-warnings
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
MissingMod1
[1 of 2] Compiling MissingMod1 ( MissingMod1.hs, MissingMod1.o )
[2 of 2] Compiling MissingMod ( MissingMod.hs, MissingMod.o )
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1
[1 of 3] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 3] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 3] Linking src-exe\Main.exe
[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 3] Linking src-exe/Main
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1
[1 of 3] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 3] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 3] Linking src-exe\Main.exe
[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 3] Linking src-exe/Main
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1 Main
[1 of 4] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 4] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 4] Compiling AltMain ( src-exe\AltMain.hs, src-exe\AltMain.o )
[4 of 4] Linking src-exe\AltMain.exe
[1 of 4] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 4] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 4] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o )
[4 of 4] Linking src-exe/AltMain
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1 Main
[1 of 4] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 4] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 4] Compiling AltMain ( src-exe\AltMain.hs, src-exe\AltMain.o )
[4 of 4] Linking src-exe\AltMain.exe
[1 of 4] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 4] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 4] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o )
[4 of 4] Linking src-exe/AltMain
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1
[1 of 4] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 4] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 4] Compiling AltMain ( src-exe\AltMain.hs, src-exe\AltMain.o )
[4 of 4] Linking src-exe\AltMain.exe
[1 of 4] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 4] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 4] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o )
[4 of 4] Linking src-exe/AltMain
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
M1
[1 of 4] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 4] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 4] Compiling AltMain ( src-exe\AltMain.hs, src-exe\AltMain.o )
[4 of 4] Linking src-exe\AltMain.exe
[1 of 4] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 4] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 4] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o )
[4 of 4] Linking src-exe/AltMain
<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
Modules are not listed in command line but needed for compilation:
Modules are not listed in options for ‘main but needed for compilation:
Main
[1 of 4] Compiling M1 ( src-lib\M1.hs, src-lib\M1.o )
[2 of 4] Compiling Main ( src-exe\Main.hs, src-exe\Main.o )
[3 of 4] Compiling AltMain ( src-exe\AltMain.hs, src-exe\AltMain.o )
[4 of 4] Linking src-exe\AltMain.exe
[1 of 4] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o )
[2 of 4] Compiling Main ( src-exe/Main.hs, src-exe/Main.o )
[3 of 4] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o )
[4 of 4] Linking src-exe/AltMain
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment