Commit befd9373 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

DynFlags: Introduce -show-mods-loaded flag

This flag reintroduces the verbose module name output produced by GHCi's
:load command behind a new flag, -show-mods-loaded. This was originally
removed in D3651 but apparently some tools (e.g. haskell-mode) rely on
this output.

Addresses #14427.

Test Plan: Validate

Reviewers: svenpanne

Reviewed By: svenpanne

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D4164

(cherry picked from commit 8613e61d)
parent a05d71a7
......@@ -536,6 +536,7 @@ data GeneralFlag
| Opt_PprCaseAsLet
| Opt_PprShowTicks
| Opt_ShowHoleConstraints
| Opt_ShowLoadedModules
-- Suppress all coercions, them replacing with '...'
| Opt_SuppressCoercions
......@@ -3762,6 +3763,7 @@ fFlagsDeps = [
flagSpec "show-warning-groups" Opt_ShowWarnGroups,
flagSpec "hide-source-paths" Opt_HideSourcePaths,
flagSpec "show-hole-constraints" Opt_ShowHoleConstraints,
flagSpec "show-loaded-modules" Opt_ShowLoadedModules,
flagSpec "whole-archive-hs-libs" Opt_WholeArchiveHsLibs
]
......
......@@ -138,6 +138,19 @@ them all in dependency order.
Windows, then the current directory is probably something like
``C:\Documents and Settings\user name``.
.. ghc-flag:: -fshow-loaded-modules
:shortdesc: Show the names of modules that GHCi loaded after a
:ghci-cmd:`:load` command.
:type: dynamic
:default: off
:since: 8.2.2
Typically GHCi will show only the number of modules that it loaded after a
:ghci-cmd:`:load` command. With this flag, GHC will also list the loaded
modules' names. This was the default behavior prior to GHC 8.2.1 and can be
useful for some tooling users.
.. _ghci-modules-filenames:
......
......@@ -51,7 +51,7 @@ import GHC ( LoadHowMuch(..), Target(..), TargetId(..), InteractiveImport(..),
import HsImpExp
import HsSyn
import HscTypes ( tyThingParent_maybe, handleFlagWarnings, getSafeMode, hsc_IC,
setInteractivePrintName, hsc_dflags )
setInteractivePrintName, hsc_dflags, msObjFilePath )
import Module
import Name
import Packages ( trusted, getPackageDetails, getInstalledPackageDetails,
......@@ -1721,7 +1721,7 @@ afterLoad ok retain_context = do
lift revertCAFs -- always revert CAFs on load.
lift discardTickArrays
loaded_mods <- getLoadedModules
modulesLoadedMsg ok (length loaded_mods)
modulesLoadedMsg ok loaded_mods
lift $ setContextAfterLoad retain_context loaded_mods
setContextAfterLoad :: Bool -> [GHC.ModSummary] -> GHCi ()
......@@ -1796,22 +1796,36 @@ keepPackageImports = filterM is_pkg_import
mod_name = unLoc (ideclName d)
modulesLoadedMsg :: SuccessFlag -> Int -> InputT GHCi ()
modulesLoadedMsg ok num_mods = do
modulesLoadedMsg :: SuccessFlag -> [GHC.ModSummary] -> InputT GHCi ()
modulesLoadedMsg ok mods = do
dflags <- getDynFlags
unqual <- GHC.getPrintUnqual
let status = case ok of
Failed -> text "Failed"
Succeeded -> text "Ok"
num_mods_pp = if num_mods == 1
then "1 module"
else int num_mods <+> "modules"
msg = status <> text "," <+> num_mods_pp <+> "loaded."
msg <- if gopt Opt_ShowLoadedModules dflags
then do
mod_names <- mapM mod_name mods
let mod_commas
| null mods = text "none."
| otherwise = hsep (punctuate comma mod_names) <> text "."
return $ status <> text ", modules loaded:" <+> mod_commas
else do
return $ status <> text ","
<+> speakNOf (length mods) (text "module") <+> "loaded."
when (verbosity dflags > 0) $
liftIO $ putStrLn $ showSDocForUser dflags unqual msg
where
status = case ok of
Failed -> text "Failed"
Succeeded -> text "Ok"
mod_name mod = do
is_interpreted <- GHC.moduleIsBootOrNotObjectLinkable mod
return $ if is_interpreted
then ppr (GHC.ms_mod mod)
else ppr (GHC.ms_mod mod)
<+> parens (text $ normalise $ msObjFilePath mod)
-- Fix #9887
-- | Run an 'ExceptT' wrapped 'GhcMonad' while handling source errors
-- and printing 'throwE' strings to 'stderr'
......
[1 of 1] Compiling A ( A.hs, interpreted )
Ok, 1 module loaded.
Ok, one module loaded.
True
[1 of 1] Compiling A ( A.hs, interpreted )
Ok, 1 module loaded.
Ok, one module loaded.
False
[1 of 2] Compiling T1914B ( T1914B.hs, interpreted )
[2 of 2] Compiling T1914A ( T1914A.hs, interpreted )
Ok, 2 modules loaded.
Ok, two modules loaded.
[2 of 2] Compiling T1914A ( T1914A.hs, interpreted )
Failed, 1 module loaded.
Failed, one module loaded.
[2 of 2] Compiling T1914A ( T1914A.hs, interpreted )
Ok, 2 modules loaded.
Ok, two modules loaded.
[1 of 1] Compiling T6105 ( T6105.hs, interpreted )
Ok, 1 module loaded.
Ok, one module loaded.
[1 of 1] Compiling T6105 ( T6105.hs, interpreted )
Ok, 1 module loaded.
Ok, one module loaded.
Ok, 1 module loaded.
Ok, one module loaded.
'a'
Ok, 1 module loaded.
Ok, one module loaded.
'b'
Markdown is supported
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