diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-03-01 16:13:44 +0000 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-03-04 10:41:29 +0000 |
commit | 7692da45af5f6e8f8b6bb0d55e2fe9d43779dc11 (patch) | |
tree | 59de5c255e8b65e42e07fed17ec17360fb289e40 /compiler/GHC | |
parent | c534b3dd30de8d5a59ff64628a6a0b3eb938a102 (diff) | |
download | haskell-wip/unused-package.tar.gz |
Fix behaviour of -Wunused-packages in ghciwip/unused-package
Ticket #21110 points out that -Wunused-packages behaves a bit unusually
in GHCi. Now we define the semantics for -Wunused-packages in
interactive mode as follows:
* If you use -Wunused-packages on an initial load then the warning is reported.
* If you explicitly set -Wunused-packages on the command line then the
warning is displayed (until it is disabled)
* If you then subsequently modify the set of available targets by using
:load or :cd (:cd unloads everything) then the warning is (silently)
turned off.
This means that every :r the warning is printed if it's turned on (but you did ask for it).
Fixes #21110
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/Driver/Env.hs | 25 | ||||
-rw-r--r-- | compiler/GHC/Driver/Make.hs | 25 |
2 files changed, 25 insertions, 25 deletions
diff --git a/compiler/GHC/Driver/Env.hs b/compiler/GHC/Driver/Env.hs index 8bc1f516bf..0d52ecc7cc 100644 --- a/compiler/GHC/Driver/Env.hs +++ b/compiler/GHC/Driver/Env.hs @@ -32,6 +32,7 @@ module GHC.Driver.Env , hptSomeThingsBelowUs , hptRules , prepareAnnotations + , discardIC , lookupType , lookupIfaceByModule , mainModIs @@ -421,3 +422,27 @@ hscSetActiveUnitId uid e = e hscActiveUnitId :: HscEnv -> UnitId hscActiveUnitId e = ue_currentUnit (hsc_unit_env e) + +-- | Discard the contents of the InteractiveContext, but keep the DynFlags and +-- the loaded plugins. It will also keep ic_int_print and ic_monad if their +-- names are from external packages. +discardIC :: HscEnv -> HscEnv +discardIC hsc_env + = hsc_env { hsc_IC = empty_ic { ic_int_print = new_ic_int_print + , ic_monad = new_ic_monad + , ic_plugins = old_plugins + } } + where + -- Force the new values for ic_int_print and ic_monad to avoid leaking old_ic + !new_ic_int_print = keep_external_name ic_int_print + !new_ic_monad = keep_external_name ic_monad + !old_plugins = ic_plugins old_ic + dflags = ic_dflags old_ic + old_ic = hsc_IC hsc_env + empty_ic = emptyInteractiveContext dflags + keep_external_name ic_name + | nameIsFromExternalPackage home_unit old_name = old_name + | otherwise = ic_name empty_ic + where + home_unit = hsc_home_unit hsc_env + old_name = ic_name old_ic diff --git a/compiler/GHC/Driver/Make.hs b/compiler/GHC/Driver/Make.hs index bd4b4eeb57..38df5ecf26 100644 --- a/compiler/GHC/Driver/Make.hs +++ b/compiler/GHC/Driver/Make.hs @@ -61,7 +61,6 @@ import GHC.Runtime.Interpreter import qualified GHC.Linker.Loader as Linker import GHC.Linker.Types -import GHC.Runtime.Context import GHC.Platform.Ways import GHC.Driver.Config.Finder (initFinderOpts) @@ -107,7 +106,6 @@ import GHC.Types.SourceFile import GHC.Types.SourceError import GHC.Types.SrcLoc import GHC.Types.Unique.FM -import GHC.Types.Name import GHC.Types.PkgQual import GHC.Unit @@ -706,29 +704,6 @@ loadFinish all_ok = do modifySession discardIC return all_ok --- | Discard the contents of the InteractiveContext, but keep the DynFlags and --- the loaded plugins. It will also keep ic_int_print and ic_monad if their --- names are from external packages. -discardIC :: HscEnv -> HscEnv -discardIC hsc_env - = hsc_env { hsc_IC = empty_ic { ic_int_print = new_ic_int_print - , ic_monad = new_ic_monad - , ic_plugins = old_plugins - } } - where - -- Force the new values for ic_int_print and ic_monad to avoid leaking old_ic - !new_ic_int_print = keep_external_name ic_int_print - !new_ic_monad = keep_external_name ic_monad - !old_plugins = ic_plugins old_ic - dflags = ic_dflags old_ic - old_ic = hsc_IC hsc_env - empty_ic = emptyInteractiveContext dflags - keep_external_name ic_name - | nameIsFromExternalPackage home_unit old_name = old_name - | otherwise = ic_name empty_ic - where - home_unit = hsc_home_unit hsc_env - old_name = ic_name old_ic -- | If there is no -o option, guess the name of target executable -- by using top-level source file name as a base. |