Commit f76e3cbe authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Change key of SolverInstallPlan to be SolverId.



This is a bit more accurate and doesn't require any
fake UnitIds anymore. (But to-do: axe fake UnitIds!)
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent d350003b
......@@ -725,10 +725,7 @@ validateSolverResult platform comp indepGoals pkgs =
problems -> error (formatPkgProblems problems)
where
index = Graph.fromList (map toPlanPackage pkgs)
toPlanPackage (PreExisting pkg) = SolverInstallPlan.PreExisting pkg
toPlanPackage (Configured pkg) = SolverInstallPlan.Configured pkg
index = Graph.fromList pkgs
formatPkgProblems = formatProblemMessage . map showPlanPackageProblem
formatPlanProblems = formatProblemMessage . map SolverInstallPlan.showPlanProblem
......
......@@ -305,8 +305,12 @@ topDownResolver' platform cinfo installedPkgIndex sourcePkgIndex
$ finaliseSelectedPackages preferences selected' constraints'
toResolverPackage :: FinalSelectedPackage -> ResolverPackage UnresolvedPkgLoc
toResolverPackage (SelectedInstalled (InstalledPackage pkg _))
= PreExisting pkg
toResolverPackage (SelectedInstalled (InstalledPackage pkg pid_deps))
= PreExisting pkg deps
where deps = CD.fromLibraryDeps lib
. zipWith PreExistingId pid_deps
$ InstalledPackageInfo.depends pkg
lib = display (packageName pkg)
toResolverPackage (SelectedSource pkg) = Configured pkg
addTopLevelTargets :: [PackageName]
......
......@@ -41,7 +41,7 @@ import Distribution.Solver.Types.PkgConfigDb
import Distribution.Solver.Types.SolverId
import Distribution.Package
( Package, packageId, packageName, packageVersion, installedUnitId )
( Package, packageId, packageName, packageVersion )
import Distribution.Simple.Compiler
( Compiler, compilerInfo, PackageDBStack )
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
......@@ -227,7 +227,7 @@ pruneInstallPlan :: SolverInstallPlan
-> [SolverPlanPackage]
pruneInstallPlan installPlan pkgSpecifiers =
removeSelf pkgIds $
SolverInstallPlan.dependencyClosure installPlan (map installedUnitId pkgIds)
SolverInstallPlan.dependencyClosure installPlan pkgIds
where
pkgIds = [ PlannedId (packageId pkg)
| SpecificSourcePackage pkg <- pkgSpecifiers ]
......
......@@ -595,7 +595,7 @@ configureInstallPlan :: SolverInstallPlan -> InstallPlan
configureInstallPlan solverPlan =
flip fromSolverInstallPlan solverPlan $ \mapDep planpkg ->
case planpkg of
SolverInstallPlan.PreExisting pkg ->
SolverInstallPlan.PreExisting pkg _ ->
PreExisting pkg
SolverInstallPlan.Configured pkg ->
......
......@@ -1020,7 +1020,7 @@ elaborateInstallPlan platform compiler compilerprogdb
elaboratedInstallPlan =
flip InstallPlan.fromSolverInstallPlan solverPlan $ \mapDep planpkg ->
case planpkg of
SolverInstallPlan.PreExisting pkg ->
SolverInstallPlan.PreExisting pkg _ ->
InstallPlan.PreExisting pkg
SolverInstallPlan.Configured pkg ->
......@@ -1258,7 +1258,7 @@ elaborateInstallPlan platform compiler compilerprogdb
$ map installedPackageId
$ SolverInstallPlan.reverseDependencyClosure
solverPlan
[ installedPackageId (PlannedId (packageId pkg))
[ PlannedId (packageId pkg)
| pkg <- localPackages ]
isLocalToProject :: Package pkg => pkg -> Bool
......@@ -1306,7 +1306,7 @@ elaborateInstallPlan platform compiler compilerprogdb
$ map packageId
$ SolverInstallPlan.dependencyClosure
solverPlan
[ installedPackageId pkg
[ Graph.nodeKey pkg
| pkg <- SolverInstallPlan.toList solverPlan
, property pkg ] -- just the packages that satisfy the propety
--TODO: [nice to have] this does not check the config consistency,
......
......@@ -51,7 +51,7 @@ module Distribution.Client.SolverInstallPlan(
import Distribution.Package
( PackageIdentifier(..), Package(..), PackageName(..)
, HasUnitId(..), UnitId(..), PackageId, packageVersion, packageName )
, HasUnitId(..), PackageId, packageVersion, packageName )
import qualified Distribution.Solver.Types.ComponentDeps as CD
import Distribution.Text
( display )
......@@ -64,6 +64,7 @@ import Distribution.Version
import Distribution.Solver.Types.PackageFixedDeps
import Distribution.Solver.Types.Settings
import Distribution.Solver.Types.ResolverPackage
import Distribution.Solver.Types.SolverId
import Data.List
( intercalate )
......@@ -129,7 +130,7 @@ showInstallPlan :: SolverInstallPlan -> String
showInstallPlan = showPlanIndex . planIndex
showPlanPackageTag :: SolverPlanPackage -> String
showPlanPackageTag (PreExisting _) = "PreExisting"
showPlanPackageTag (PreExisting _ _) = "PreExisting"
showPlanPackageTag (Configured _) = "Configured"
-- | Build an installation plan from a valid set of resolved packages.
......@@ -209,7 +210,7 @@ showPlanProblem (PackageStateInvalid pkg pkg') =
++ " which is in the " ++ showPlanState pkg'
++ " state"
where
showPlanState (PreExisting _) = "pre-existing"
showPlanState (PreExisting _ _) = "pre-existing"
showPlanState (Configured _) = "configured"
-- | For an invalid plan, produce a detailed list of problems as human readable
......@@ -238,7 +239,7 @@ problems indepGoals index =
++ [ PackageStateInvalid pkg pkg'
| pkg <- Graph.toList index
, Just pkg' <- map (flip Graph.lookup index)
(CD.flatDeps (depends pkg))
(nodeNeighbors pkg)
, not (stateDependencyRelation pkg pkg') ]
......@@ -266,7 +267,7 @@ dependencyInconsistencies indepGoals index =
-- This is the set of all top-level library roots (taken together normally, or
-- as singletons sets if we are considering them as independent goals), along
-- with all setup dependencies of all packages.
rootSets :: IndependentGoals -> SolverPlanIndex -> [[UnitId]]
rootSets :: IndependentGoals -> SolverPlanIndex -> [[SolverId]]
rootSets (IndependentGoals indepGoals) index =
if indepGoals then map (:[]) libRoots else [libRoots]
++ setupRoots index
......@@ -277,7 +278,7 @@ rootSets (IndependentGoals indepGoals) index =
--
-- The library roots are the set of packages with no reverse dependencies
-- (no reverse library dependencies but also no reverse setup dependencies).
libraryRoots :: SolverPlanIndex -> [UnitId]
libraryRoots :: SolverPlanIndex -> [SolverId]
libraryRoots index =
map (nodeKey . toPkgId) roots
where
......@@ -287,9 +288,9 @@ libraryRoots index =
isRoot v = indegree ! v == 0
-- | The setup dependencies of each package in the plan
setupRoots :: SolverPlanIndex -> [[UnitId]]
setupRoots :: SolverPlanIndex -> [[SolverId]]
setupRoots = filter (not . null)
. map (CD.setupDeps . depends)
. map (CD.setupDeps . resolverPackageDeps)
. Graph.toList
-- | Given a package index where we assume we want to use all the packages
......@@ -315,15 +316,15 @@ dependencyInconsistencies' index =
-- and each installed ID of that that package
-- the associated package instance
-- and a list of reverse dependencies (as source IDs)
inverseIndex :: Map PackageName (Map UnitId (SolverPlanPackage, [PackageId]))
inverseIndex :: Map PackageName (Map SolverId (SolverPlanPackage, [PackageId]))
inverseIndex = Map.fromListWith (Map.unionWith (\(a,b) (_,b') -> (a,b++b')))
[ (packageName dep, Map.fromList [(ipid,(dep,[packageId pkg]))])
[ (packageName dep, Map.fromList [(sid,(dep,[packageId pkg]))])
| -- For each package @pkg@
pkg <- Graph.toList index
-- Find out which @ipid@ @pkg@ depends on
, ipid <- CD.nonSetupDeps (depends pkg)
-- And look up those @ipid@ (i.e., @ipid@ is the ID of @dep@)
, Just dep <- [Graph.lookup ipid index]
-- Find out which @sid@ @pkg@ depends on
, sid <- CD.nonSetupDeps (resolverPackageDeps pkg)
-- And look up those @sid@ (i.e., @sid@ is the ID of @dep@)
, Just dep <- [Graph.lookup sid index]
]
-- If, in a single install plan, we depend on more than one version of a
......@@ -386,9 +387,9 @@ consistent = null . dependencyInconsistencies (IndependentGoals False)
stateDependencyRelation :: SolverPlanPackage
-> SolverPlanPackage
-> Bool
stateDependencyRelation (PreExisting _) (PreExisting _) = True
stateDependencyRelation PreExisting{} PreExisting{} = True
stateDependencyRelation (Configured _) (PreExisting _) = True
stateDependencyRelation (Configured _) PreExisting{} = True
stateDependencyRelation (Configured _) (Configured _) = True
stateDependencyRelation _ _ = False
......@@ -397,13 +398,13 @@ stateDependencyRelation _ _ = False
-- | Compute the dependency closure of a package in a install plan
--
dependencyClosure :: SolverInstallPlan
-> [UnitId]
-> [SolverId]
-> [SolverPlanPackage]
dependencyClosure plan = fromMaybe [] . Graph.closure (planIndex plan)
reverseDependencyClosure :: SolverInstallPlan
-> [UnitId]
-> [SolverId]
-> [SolverPlanPackage]
reverseDependencyClosure plan = fromMaybe [] . Graph.revClosure (planIndex plan)
......
......@@ -29,7 +29,7 @@ convCP :: SI.InstalledPackageIndex ->
convCP iidx sidx (CP qpi fa es ds) =
case convPI qpi of
Left pi -> PreExisting
(fromJust $ SI.lookupUnitId iidx pi)
(fromJust $ SI.lookupUnitId iidx pi) ds'
Right pi -> Configured $ SolverPackage
srcpkg
fa
......
......@@ -2,8 +2,10 @@
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Solver.Types.ResolverPackage
( ResolverPackage(..)
, resolverPackageDeps
) where
import Distribution.Solver.Types.SolverId
import Distribution.Solver.Types.SolverPackage
import Distribution.Solver.Types.PackageFixedDeps
import qualified Distribution.Solver.Types.ComponentDeps as CD
......@@ -11,7 +13,7 @@ import qualified Distribution.Solver.Types.ComponentDeps as CD
import Distribution.Compat.Binary (Binary(..))
import Distribution.Compat.Graph (IsNode(..))
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import Distribution.Package (UnitId, Package(..), HasUnitId(..))
import Distribution.Package (Package(..), HasUnitId(..))
import GHC.Generics (Generic)
-- | The dependency resolver picks either pre-existing installed packages
......@@ -19,26 +21,31 @@ import GHC.Generics (Generic)
--
-- This is like the 'InstallPlan.PlanPackage' but with fewer cases.
--
data ResolverPackage loc = PreExisting InstalledPackageInfo
data ResolverPackage loc = PreExisting InstalledPackageInfo (CD.ComponentDeps [SolverId])
| Configured (SolverPackage loc)
deriving (Eq, Show, Generic)
instance Binary loc => Binary (ResolverPackage loc)
instance Package (ResolverPackage loc) where
packageId (PreExisting ipkg) = packageId ipkg
packageId (PreExisting ipkg _) = packageId ipkg
packageId (Configured spkg) = packageId spkg
instance PackageFixedDeps (ResolverPackage loc) where
depends (PreExisting pkg) = depends pkg
depends (PreExisting pkg _) = depends pkg
depends (Configured pkg) = depends pkg
instance HasUnitId (ResolverPackage loc) where
installedUnitId (PreExisting ipkg ) = installedUnitId ipkg
installedUnitId (PreExisting ipkg _) = installedUnitId ipkg
installedUnitId (Configured spkg) = installedUnitId spkg
resolverPackageDeps :: ResolverPackage loc -> CD.ComponentDeps [SolverId]
resolverPackageDeps (PreExisting _ deps) = deps
resolverPackageDeps (Configured spkg) = solverPkgDeps spkg
instance IsNode (ResolverPackage loc) where
type Key (ResolverPackage loc) = UnitId -- TODO: change me
nodeKey = installedUnitId
type Key (ResolverPackage loc) = SolverId
nodeKey (PreExisting ipkg _) = PreExistingId (packageId ipkg) (installedUnitId ipkg)
nodeKey (Configured spkg) = PlannedId (packageId spkg)
-- Use dependencies for ALL components
nodeNeighbors = CD.flatDeps . depends
nodeNeighbors pkg = CD.flatDeps (resolverPackageDeps pkg)
......@@ -17,7 +17,7 @@ import GHC.Generics (Generic)
--
data SolverId = PreExistingId { solverSrcId :: PackageId, solverInstId :: UnitId }
| PlannedId { solverSrcId :: PackageId }
deriving (Eq, Generic)
deriving (Eq, Ord, Generic)
instance Binary SolverId
......
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