Commit 55b4263e authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot

Remove ClosureUnitInfoMap

parent 202728e5
......@@ -194,7 +194,8 @@ withBkpSession cid insts deps session_type do_this = do
importPaths = [],
-- Synthesized the flags
packageFlags = packageFlags dflags ++ map (\(uid0, rn) ->
let uid = unwireUnit dflags (improveUnit (unitInfoMap (unitState dflags)) $ renameHoleUnit (unitState dflags) (listToUFM insts) uid0)
let state = unitState dflags
uid = unwireUnit dflags (improveUnit state $ renameHoleUnit state (listToUFM insts) uid0)
in ExposePackage
(showSDoc dflags
(text "-unit-id" <+> ppr uid <+> ppr rn))
......@@ -275,7 +276,7 @@ buildUnit session cid insts lunit = do
dflags <- getDynFlags
-- IMPROVE IT
let deps = map (improveUnit (unitInfoMap (unitState dflags))) deps0
let deps = map (improveUnit (unitState dflags)) deps0
mb_old_eps <- case session of
TcSession -> fmap Just getEpsGhc
......
......@@ -9,7 +9,6 @@ module GHC.Unit
, module GHC.Unit.Info
, module GHC.Unit.Parser
, module GHC.Unit.State
, module GHC.Unit.Subst
, module GHC.Unit.Module
)
where
......@@ -18,7 +17,6 @@ import GHC.Unit.Types
import GHC.Unit.Info
import GHC.Unit.Parser
import GHC.Unit.State
import GHC.Unit.Subst
import GHC.Unit.Module
{-
......
......@@ -43,7 +43,6 @@ module GHC.Unit.Module
, moduleIsDefinite
, HasModule(..)
, ContainsModule(..)
, instModuleToModule
, unitIdEq
, installedModuleEq
) where
......@@ -57,9 +56,6 @@ import GHC.Unit.Module.Location
import GHC.Unit.Module.Env
import GHC.Utils.Misc
import {-# SOURCE #-} GHC.Unit.State (PackageState)
-- | A 'Module' is definite if it has no free holes.
moduleIsDefinite :: Module -> Bool
moduleIsDefinite = isEmptyUniqDSet . moduleFreeHoles
......@@ -87,12 +83,6 @@ class HasModule m where
getModule :: m Module
-- | Injects an 'InstantiatedModule' to 'Module' (see also
-- 'instUnitToUnit'.
instModuleToModule :: PackageState -> InstantiatedModule -> Module
instModuleToModule pkgstate (Module iuid mod_name) =
mkModule (instUnitToUnit pkgstate iuid) mod_name
-- | Test if a 'Module' corresponds to a given 'InstalledModule',
-- modulo instantiation.
installedModuleEq :: InstalledModule -> Module -> Bool
......
This diff is collapsed.
module GHC.Unit.State where
import GHC.Prelude
import GHC.Data.FastString
import {-# SOURCE #-} GHC.Unit.Types (IndefUnitId, Unit, UnitId)
import {-# SOURCE #-} GHC.Unit.Types (IndefUnitId, UnitId)
data PackageState
data ClosureUnitInfoMap
data UnitDatabase unit
emptyPackageState :: PackageState
mkIndefUnitId :: PackageState -> FastString -> IndefUnitId
displayUnitId :: PackageState -> UnitId -> Maybe String
improveUnit :: ClosureUnitInfoMap -> Unit -> Unit
unitInfoMap :: PackageState -> ClosureUnitInfoMap
updateIndefUnitId :: PackageState -> IndefUnitId -> IndefUnitId
-- | Module hole substitutions
module GHC.Unit.Subst
( ShHoleSubst
, renameHoleUnit
, renameHoleModule
, renameHoleUnit'
, renameHoleModule'
)
where
import GHC.Prelude
import {-# SOURCE #-} GHC.Unit.State
import GHC.Unit.Types
import GHC.Unit.Module.Env
import GHC.Unit.Module
import GHC.Types.Unique.FM
import GHC.Types.Unique.DFM
import GHC.Types.Unique.DSet
-- | Substitution on module variables, mapping module names to module
-- identifiers.
type ShHoleSubst = ModuleNameEnv Module
-- | Substitutes holes in a 'Module'. NOT suitable for being called
-- directly on a 'nameModule', see Note [Representation of module/name variable].
-- @p[A=<A>]:B@ maps to @p[A=q():A]:B@ with @A=q():A@;
-- similarly, @<A>@ maps to @q():A@.
renameHoleModule :: PackageState -> ShHoleSubst -> Module -> Module
renameHoleModule state = renameHoleModule' (unitInfoMap state)
-- | Substitutes holes in a 'Unit', suitable for renaming when
-- an include occurs; see Note [Representation of module/name variable].
--
-- @p[A=<A>]@ maps to @p[A=<B>]@ with @A=<B>@.
renameHoleUnit :: PackageState -> ShHoleSubst -> Unit -> Unit
renameHoleUnit state = renameHoleUnit' (unitInfoMap state)
-- | Like 'renameHoleModule', but requires only 'ClosureUnitInfoMap'
-- so it can be used by "Packages".
renameHoleModule' :: ClosureUnitInfoMap -> ShHoleSubst -> Module -> Module
renameHoleModule' pkg_map env m
| not (isHoleModule m) =
let uid = renameHoleUnit' pkg_map env (moduleUnit m)
in mkModule uid (moduleName m)
| Just m' <- lookupUFM env (moduleName m) = m'
-- NB m = <Blah>, that's what's in scope.
| otherwise = m
-- | Like 'renameHoleUnit, but requires only 'ClosureUnitInfoMap'
-- so it can be used by "Packages".
renameHoleUnit' :: ClosureUnitInfoMap -> ShHoleSubst -> Unit -> Unit
renameHoleUnit' pkg_map env uid =
case uid of
(VirtUnit
InstantiatedUnit{ instUnitInstanceOf = cid
, instUnitInsts = insts
, instUnitHoles = fh })
-> if isNullUFM (intersectUFM_C const (udfmToUfm (getUniqDSet fh)) env)
then uid
-- Functorially apply the substitution to the instantiation,
-- then check the 'ClosureUnitInfoMap' to see if there is
-- a compiled version of this 'InstantiatedUnit' we can improve to.
-- See Note [VirtUnit to RealUnit improvement]
else improveUnit pkg_map $
mkVirtUnit cid
(map (\(k,v) -> (k, renameHoleModule' pkg_map env v)) insts)
_ -> uid
......@@ -39,7 +39,6 @@ module GHC.Unit.Types
, fsToUnit
, unitFS
, unitString
, instUnitToUnit
, toUnitId
, virtualUnitId
, stringToUnit
......@@ -104,7 +103,7 @@ import Data.Bifunctor
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS.Char8
import {-# SOURCE #-} GHC.Unit.State (improveUnit, PackageState, unitInfoMap, displayUnitId)
import {-# SOURCE #-} GHC.Unit.State (displayUnitId)
import {-# SOURCE #-} GHC.Driver.Session (unitState)
---------------------------------------------------------------------
......@@ -457,24 +456,6 @@ mapGenUnit f gunitFS = go
(fmap (second (fmap go)) (instUnitInsts i))
-- | Check the database to see if we already have an installed unit that
-- corresponds to the given 'InstantiatedUnit'.
--
-- Return a `UnitId` which either wraps the `InstantiatedUnit` unchanged or
-- references a matching installed unit.
--
-- See Note [VirtUnit to RealUnit improvement]
instUnitToUnit :: PackageState -> InstantiatedUnit -> Unit
instUnitToUnit pkgstate iuid =
-- NB: suppose that we want to compare the indefinite
-- unit id p[H=impl:H] against p+abcd (where p+abcd
-- happens to be the existing, installed version of
-- p[H=impl:H]. If we *only* wrap in p[H=impl:H]
-- VirtUnit, they won't compare equal; only
-- after improvement will the equality hold.
improveUnit (unitInfoMap pkgstate) $
VirtUnit iuid
-- | Return the UnitId of the Unit. For on-the-fly instantiated units, return
-- the UnitId of the indefinite unit this unit is an instance of.
toUnitId :: Unit -> UnitId
......
......@@ -226,7 +226,6 @@ Library
GHC.Unit
GHC.Unit.Parser
GHC.Unit.Ppr
GHC.Unit.Subst
GHC.Unit.Types
GHC.Unit.Module
GHC.Unit.Module.Name
......
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