[Git][ghc/ghc][wip/sol/interactive-package-error-hints] error messages: Respect `-fno-interactive-error-hints` for missing packages
Simon Hengel pushed to branch wip/sol/interactive-package-error-hints at Glasgow Haskell Compiler / GHC Commits: 26d9f72d by Simon Hengel at 2026-06-25T16:00:46+07:00 error messages: Respect `-fno-interactive-error-hints` for missing packages (see #27409) - - - - - 7 changed files: - compiler/GHC/Iface/Errors/Ppr.hs - ghc/GHCi/UI/Exception.hs - + testsuite/tests/package/ImportReexport_cabal.hs - + testsuite/tests/package/ImportReexport_cabal.stderr - + testsuite/tests/package/ImportReexport_ghci.hs - + testsuite/tests/package/ImportReexport_ghci.stderr - testsuite/tests/package/all.T Changes: ===================================== compiler/GHC/Iface/Errors/Ppr.hs ===================================== @@ -13,11 +13,6 @@ module GHC.Iface.Errors.Ppr , missingInterfaceErrorReason , missingInterfaceErrorDiagnostic , readInterfaceErrorDiagnostic - - , lookingForHerald - , cantFindErrorX - , mayShowLocations - , pkgHiddenHint ) where @@ -124,38 +119,14 @@ data FindOrLoad = Find | Load data AmbiguousOrMissing = AoM_Ambiguous | AoM_Missing -cantFindError :: IfaceMessageOpts - -> FindingModuleOrInterface - -> CantFindInstalled - -> SDoc -cantFindError opts = - cantFindErrorX - (pkgHiddenHint (const empty) (ifaceBuildingCabalPackage opts)) - (mayShowLocations "-v" (ifaceShowTriedFiles opts)) - - -pkgHiddenHint :: (UnitInfo -> SDoc) -> BuildingCabalPackage - -> UnitInfo -> SDoc -pkgHiddenHint _hint YesBuildingCabalPackage pkg - = text "Perhaps you need to add" <+> - quotes (ppr (unitPackageName pkg)) <+> - text "to the build-depends in your .cabal file." -pkgHiddenHint hint _not_cabal pkg - = hint pkg - -mayShowLocations :: String -> Bool -> [FilePath] -> SDoc -mayShowLocations option verbose files - | null files = empty - | not verbose = - text "Use" <+> text option <+> - text "to see a list of the files searched for." - | otherwise = - hang (text "Locations searched:") 2 $ vcat (map text files) +data ErrorMode = NormalMode | InteractiveMode | BuildingCabalPackage + +cantFindError :: IfaceMessageOpts -> FindingModuleOrInterface -> CantFindInstalled -> SDoc +cantFindError opts mod_or_interface cantFindInstalled = + sdocOption sdocInteractiveErrorHints $ cantFindErrorWith opts mod_or_interface cantFindInstalled --- | General version of cantFindError which has some holes which allow GHC/GHCi to display slightly different --- error messages. -cantFindErrorX :: (UnitInfo -> SDoc) -> ([FilePath] -> SDoc) -> FindingModuleOrInterface -> CantFindInstalled -> SDoc -cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInstalled mod_name cfir) = +cantFindErrorWith :: IfaceMessageOpts -> FindingModuleOrInterface -> CantFindInstalled -> Bool -> SDoc +cantFindErrorWith opts mod_or_interface (CantFindInstalled mod_name cfir) interactiveErrorHints = let ambig = isAmbiguousInstalledReason cfir find_or_load = isLoadOrFindReason cfir ppr_what = prettyCantFindWhat find_or_load mod_or_interface ambig @@ -279,6 +250,40 @@ cantFindErrorX pkg_hidden_hint may_show_locations mod_or_interface (CantFindInst <+> quotes (ppr unit) $$ pprReason (text "which is") reason + mode :: ErrorMode + mode + | interactiveErrorHints = InteractiveMode + | otherwise = case ifaceBuildingCabalPackage opts of + NoBuildingCabalPackage -> NormalMode + YesBuildingCabalPackage -> BuildingCabalPackage + + pkg_hidden_hint :: UnitInfo -> SDoc + pkg_hidden_hint pkg = case mode of + NormalMode -> + empty + InteractiveMode -> + text "You can run" <+> + quotes (text ":set -package " <> ppr (unitPackageName pkg)) <+> + text "to expose it." $$ + text "(Note: this unloads all the modules in the current scope.)" + BuildingCabalPackage -> + text "Perhaps you need to add" <+> + quotes (ppr (unitPackageName pkg)) <+> + text "to the build-depends in your .cabal file." + + may_show_locations :: [FilePath] -> SDoc + may_show_locations files + | null files = + empty + | ifaceShowTriedFiles opts = + hang (text "Locations searched:") 2 $ vcat (map text files) + | otherwise = + text "Use" <+> text option <+> text "to see a list of the files searched for." + where + option :: String + option = case mode of + InteractiveMode -> ":set -v" + _ -> "-v" interfaceErrorDiagnostic :: IfaceMessageOpts -> IfaceMessage -> SDoc interfaceErrorDiagnostic opts = \ case ===================================== ghc/GHCi/UI/Exception.hs ===================================== @@ -20,9 +20,6 @@ import GHC.Prelude import GHC.Driver.Errors.Types -import GHC.Iface.Errors.Ppr -import GHC.Iface.Errors.Types - import GHC.Tc.Errors.Ppr import GHC.Tc.Errors.Types @@ -30,8 +27,6 @@ import GHC.Types.Error.Codes import GHC.Types.SrcLoc (interactiveSrcSpan) import GHC.TypeLits -import GHC.Unit.State - import GHC.Utils.Outputable import GHC.Utils.Error @@ -152,18 +147,11 @@ ghciDiagnosticMessage ghc_opts msg = case tcRnMessage (tcMessageOpts ghc_opts) tc_msg of Nothing -> diagnosticMessage ghc_opts msg Just sdoc -> sdoc - GhcDriverMessage (DriverInterfaceError err) -> - case ghciInterfaceError err of - Just sdoc -> mkSimpleDecorated sdoc - Nothing -> diagnosticMessage ghc_opts msg - GhcDriverMessage {} -> diagnosticMessage ghc_opts msg - GhcPsMessage {} -> diagnosticMessage ghc_opts msg - GhcDsMessage {} -> diagnosticMessage ghc_opts msg - GhcUnknownMessage {} -> diagnosticMessage ghc_opts msg + _ -> diagnosticMessage ghc_opts msg where + tcRnMessage :: TcRnMessageOpts -> TcRnMessage -> Maybe DecoratedSDoc tcRnMessage tc_opts tc_msg = case tc_msg of - TcRnInterfaceError err -> mkSimpleDecorated <$> (ghciInterfaceError err) TcRnMessageWithInfo unit_state msg_with_info -> case msg_with_info of TcRnMessageDetailed err_info wrapped_msg @@ -174,32 +162,6 @@ ghciDiagnosticMessage ghc_opts msg = messageWithHsDocContext tc_opts ctxt <$> tcRnMessage tc_opts wrapped_msg _ -> Nothing - opts = tcOptsIfaceOpts (tcMessageOpts ghc_opts) - - ghciInterfaceError (Can'tFindInterface err looking_for) = - hangNotEmpty (lookingForHerald looking_for) 2 <$> ghciMissingInterfaceErrorDiagnostic err - ghciInterfaceError _ = Nothing - - ghciMissingInterfaceErrorDiagnostic reason = - case reason of - CantFindErr us module_or_interface cfi -> - Just (pprWithUnitState us $ cantFindErrorX pkg_hidden_hint may_show_locations module_or_interface cfi) - _ -> Nothing - where - may_show_locations :: [String] -> SDoc - may_show_locations = mayShowLocations ":set -v" (ifaceShowTriedFiles opts) - - pkg_hidden_hint :: UnitInfo -> SDoc - pkg_hidden_hint = pkgHiddenHint hidden_msg (ifaceBuildingCabalPackage opts) - where - hidden_msg :: UnitInfo -> SDoc - hidden_msg pkg = - text "You can run" <+> - quotes (text ":set -package " <> ppr (unitPackageName pkg)) <+> - text "to expose it." $$ - text "(Note: this unloads all the modules in the current scope.)" - - data InvalidMacroStart = Colon | ExclamationMark instance Outputable InvalidMacroStart where ===================================== testsuite/tests/package/ImportReexport_cabal.hs ===================================== @@ -0,0 +1,3 @@ +module ImportReexport where +import GHC.Types -- reexported and renamed by ghc-prim from ghc-internal +import GHC.Platform.ArchOS -- reexported by by ghc and ghc-boot + provided by ghc-platform ===================================== testsuite/tests/package/ImportReexport_cabal.stderr ===================================== @@ -0,0 +1,16 @@ +ImportReexport_cabal.hs:2:1: error: [GHC-87110] + Could not load module ‘GHC.Types’. + It is a member of the hidden package ‘ghc-prim-0.14.0’. + Perhaps you need to add ‘ghc-prim’ to the build-depends in your .cabal file. + Use -v to see a list of the files searched for. + +ImportReexport_cabal.hs:3:1: error: [GHC-87110] + Could not load module ‘GHC.Platform.ArchOS’. + It is a member of the hidden package ‘ghc-10.1’. + Perhaps you need to add ‘ghc’ to the build-depends in your .cabal file. + It is a member of the hidden package ‘ghc-boot-10.1’. + Perhaps you need to add ‘ghc-boot’ to the build-depends in your .cabal file. + It is a member of the hidden package ‘ghc-platform-0.1.0.0’. + Perhaps you need to add ‘ghc-platform’ to the build-depends in your .cabal file. + Use -v to see a list of the files searched for. + ===================================== testsuite/tests/package/ImportReexport_ghci.hs ===================================== @@ -0,0 +1,3 @@ +module ImportReexport where +import GHC.Types -- reexported and renamed by ghc-prim from ghc-internal +import GHC.Platform.ArchOS -- reexported by by ghc and ghc-boot + provided by ghc-platform ===================================== testsuite/tests/package/ImportReexport_ghci.stderr ===================================== @@ -0,0 +1,20 @@ +ImportReexport_ghci.hs:2:1: error: [GHC-87110] + Could not load module ‘GHC.Types’. + It is a member of the hidden package ‘ghc-prim-0.14.0’. + You can run ‘:set -package ghc-prim’ to expose it. + (Note: this unloads all the modules in the current scope.) + Use :set -v to see a list of the files searched for. + +ImportReexport_ghci.hs:3:1: error: [GHC-87110] + Could not load module ‘GHC.Platform.ArchOS’. + It is a member of the hidden package ‘ghc-10.1’. + You can run ‘:set -package ghc’ to expose it. + (Note: this unloads all the modules in the current scope.) + It is a member of the hidden package ‘ghc-boot-10.1’. + You can run ‘:set -package ghc-boot’ to expose it. + (Note: this unloads all the modules in the current scope.) + It is a member of the hidden package ‘ghc-platform-0.1.0.0’. + You can run ‘:set -package ghc-platform’ to expose it. + (Note: this unloads all the modules in the current scope.) + Use :set -v to see a list of the files searched for. + ===================================== testsuite/tests/package/all.T ===================================== @@ -13,12 +13,16 @@ test('package04', normal, compile, [incr_containers]) test('package05', normal, compile, [incr_ghc + inc_ghc]) test('package06', normal, compile, [incr_ghc]) test('package06e', normalise_version('ghc'), compile_fail, [incr_ghc]) -test('ImportReexport', normalise_version('ghc'), compile_fail, ['-hide-all-packages -XNoImplicitPrelude']) test('package07e', normalise_version('ghc'), compile_fail, [incr_ghc + inc_ghc + hide_ghc]) test('package08e', normalise_version('ghc'), compile_fail, [incr_ghc + hide_ghc]) test('package09e', normal, compile_fail, ['-package "containers (Data.Map as M, Data.Set as M)"']) test('package10', normal, compile, ['-hide-all-packages -package "ghc (GHC.Types.Unique.FM as Prelude)" ']) +import_reexport_args = '-hide-all-packages -XNoImplicitPrelude ' +test('ImportReexport', normal, compile_fail, [import_reexport_args]) +test('ImportReexport_cabal', normal, compile_fail, [import_reexport_args + '-fbuilding-cabal-package']) +test('ImportReexport_ghci', normal, compile_fail, [import_reexport_args + '-finteractive-error-hints']) + test('T4806', normalise_version('containers'), compile_fail, ['-ignore-package containers']) test('T4806a', normalise_version('deepseq', 'containers', 'template-haskell'), compile_fail, ['-ignore-package deepseq']) test('T22884', normalise_version('text'), compile_fail, ['-hide-package text']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/26d9f72d342922650fac946061840f14... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/26d9f72d342922650fac946061840f14... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Hengel (@sol)