diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-12-26 16:04:31 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-01-24 05:37:52 -0500 |
commit | 06cc0a9529f2fe0dfa40d9966a52a982653bfcb9 (patch) | |
tree | 7d1094ca532f0a8e537ddf5d7e2d2584133b7448 | |
parent | 6469fea7c78408db679898168a8e9c50c8c7c5ce (diff) | |
download | haskell-06cc0a9529f2fe0dfa40d9966a52a982653bfcb9.tar.gz |
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
14 files changed, 61 insertions, 49 deletions
diff --git a/compiler/GHC/Driver/Errors/Ppr.hs b/compiler/GHC/Driver/Errors/Ppr.hs index 9ba53902bc..9e3822e460 100644 --- a/compiler/GHC/Driver/Errors/Ppr.hs +++ b/compiler/GHC/Driver/Errors/Ppr.hs @@ -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 diff --git a/compiler/GHC/Driver/Errors/Types.hs b/compiler/GHC/Driver/Errors/Types.hs index cb7625ca09..10127a8d6c 100644 --- a/compiler/GHC/Driver/Errors/Types.hs +++ b/compiler/GHC/Driver/Errors/Types.hs @@ -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. diff --git a/compiler/GHC/Driver/Make.hs b/compiler/GHC/Driver/Make.hs index 5f48beeb40..eee37601f1 100644 --- a/compiler/GHC/Driver/Make.hs +++ b/compiler/GHC/Driver/Make.hs @@ -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 diff --git a/testsuite/tests/driver/multipleHomeUnits/all.T b/testsuite/tests/driver/multipleHomeUnits/all.T index a21459d74f..ebee7b9f5d 100644 --- a/testsuite/tests/driver/multipleHomeUnits/all.T +++ b/testsuite/tests/driver/multipleHomeUnits/all.T @@ -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']) diff --git a/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_warnings.stderr b/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_warnings.stderr new file mode 100644 index 0000000000..64d1f6da40 --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/multipleHomeUnits_warnings.stderr @@ -0,0 +1,8 @@ + +<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 diff --git a/testsuite/tests/driver/multipleHomeUnits/unitWarnings b/testsuite/tests/driver/multipleHomeUnits/unitWarnings new file mode 100644 index 0000000000..c2fff2cb2c --- /dev/null +++ b/testsuite/tests/driver/multipleHomeUnits/unitWarnings @@ -0,0 +1 @@ +-i -i. A -reexported-module B -hidden-module C -this-unit-id unit-warnings diff --git a/testsuite/tests/warnings/should_compile/MissingMod.stderr b/testsuite/tests/warnings/should_compile/MissingMod.stderr index 92ada51d60..b36fe1437f 100644 --- a/testsuite/tests/warnings/should_compile/MissingMod.stderr +++ b/testsuite/tests/warnings/should_compile/MissingMod.stderr @@ -1,6 +1,6 @@ <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 ) diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr index d34450454a..8df11b7d80 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr @@ -1,7 +1,7 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr index d34450454a..8df11b7d80 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr @@ -1,7 +1,7 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr index 165cd8100b..a7811c3c00 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr @@ -1,8 +1,8 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr index 165cd8100b..a7811c3c00 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr @@ -1,8 +1,8 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr index 3cbbcc1b9f..1ba4d56f24 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr @@ -1,8 +1,8 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr index 3cbbcc1b9f..1ba4d56f24 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr @@ -1,8 +1,8 @@ <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 diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr index bf4f360054..a7f7dc7c5c 100644 --- a/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr +++ b/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr @@ -1,8 +1,8 @@ <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 |