diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-11-12 10:36:58 +0100 |
---|---|---|
committer | Sylvain Henry <sylvain@haskus.fr> | 2020-12-14 19:45:13 +0100 |
commit | d0e8c10d587e4b9984526d0dfcfcb258b75733b8 (patch) | |
tree | e0993719d76f87a0f4f8eccef089526217bf5bb4 /compiler/GHC/Driver/Env.hs | |
parent | 92377c27e1a48d0d3776f65c7074dfeb122b46db (diff) | |
download | haskell-d0e8c10d587e4b9984526d0dfcfcb258b75733b8.tar.gz |
Move Unit related fields from DynFlags to HscEnv
The unit database cache, the home unit and the unit state were stored in
DynFlags while they ought to be stored in the compiler session state
(HscEnv). This patch fixes this.
It introduces a new UnitEnv type that should be used in the future to
handle separate unit environments (especially host vs target units).
Related to #17957
Bump haddock submodule
Diffstat (limited to 'compiler/GHC/Driver/Env.hs')
-rw-r--r-- | compiler/GHC/Driver/Env.hs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/compiler/GHC/Driver/Env.hs b/compiler/GHC/Driver/Env.hs index 6bf83c576e..596ea936ca 100644 --- a/compiler/GHC/Driver/Env.hs +++ b/compiler/GHC/Driver/Env.hs @@ -4,6 +4,8 @@ module GHC.Driver.Env ( Hsc(..) , HscEnv (..) + , hsc_home_unit + , hsc_units , runHsc , mkInteractiveHscEnv , runInteractiveHsc @@ -17,6 +19,7 @@ module GHC.Driver.Env , prepareAnnotations , lookupType , lookupIfaceByModule + , mainModIs ) where @@ -38,6 +41,7 @@ import GHC.Unit.Module.ModIface import GHC.Unit.Module.ModDetails import GHC.Unit.Module.Deps import GHC.Unit.Home.ModInfo +import GHC.Unit.Env import GHC.Unit.External import GHC.Unit.Finder.Types @@ -179,9 +183,6 @@ data HscEnv , hsc_loader :: Loader -- ^ Loader (dynamic linker) - , hsc_home_unit :: !HomeUnit - -- ^ Home-unit - , hsc_plugins :: ![LoadedPlugin] -- ^ plugins dynamically loaded after processing arguments. What -- will be loaded here is directed by DynFlags.pluginModNames. @@ -197,8 +198,31 @@ data HscEnv -- -- To add dynamically loaded plugins through the GHC API see -- 'addPluginModuleName' instead. + + , hsc_unit_dbs :: !(Maybe [UnitDatabase UnitId]) + -- ^ Stack of unit databases for the target platform. + -- + -- This field is populated with the result of `initUnits`. + -- + -- 'Nothing' means the databases have never been read from disk. + -- + -- Usually we don't reload the databases from disk if they are + -- cached, even if the database flags changed! + + , hsc_unit_env :: UnitEnv + -- ^ Unit environment (unit state, home unit, etc.). + -- + -- Initialized from the databases cached in 'hsc_unit_dbs' and + -- from the DynFlags. } + +hsc_home_unit :: HscEnv -> HomeUnit +hsc_home_unit = ue_home_unit . hsc_unit_env + +hsc_units :: HscEnv -> UnitState +hsc_units = ue_units . hsc_unit_env + {- Note [Target code interpreter] @@ -392,3 +416,6 @@ lookupIfaceByModule hpt pit mod -- We could eliminate (b) if we wanted, by making GHC.Prim belong to a package -- of its own, but it doesn't seem worth the bother. +mainModIs :: HscEnv -> Module +mainModIs hsc_env = mkHomeModule (hsc_home_unit hsc_env) (mainModuleNameIs (hsc_dflags hsc_env)) + |