Skip to content

Commit

Permalink
Deduplicate build targets by storing them in a set.
Browse files Browse the repository at this point in the history
The solver can handle duplicate targets by linking them together, but the log
is more complex, and the result is the same as if the targets were deduplicated
beforehand.

Duplicate targets can occur in a sandbox (issue haskell#3203).
  • Loading branch information
grayjay committed Sep 5, 2016
1 parent a5e9544 commit f7533c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
22 changes: 10 additions & 12 deletions cabal-install/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import Control.Exception
-- implemented in terms of adjustments to the parameters.
--
data DepResolverParams = DepResolverParams {
depResolverTargets :: [PackageName],
depResolverTargets :: Set PackageName,
depResolverConstraints :: [LabeledPackageConstraint],
depResolverPreferences :: [PackagePreference],
depResolverPreferenceDefault :: PackagesPreferenceDefault,
Expand All @@ -165,7 +165,7 @@ data DepResolverParams = DepResolverParams {

showDepResolverParams :: DepResolverParams -> String
showDepResolverParams p =
"targets: " ++ intercalate ", " (map display (depResolverTargets p))
"targets: " ++ intercalate ", " (map display $ Set.toList (depResolverTargets p))
++ "\nconstraints: "
++ concatMap (("\n " ++) . showLabeledConstraint)
(depResolverConstraints p)
Expand Down Expand Up @@ -221,7 +221,7 @@ basicDepResolverParams :: InstalledPackageIndex
-> DepResolverParams
basicDepResolverParams installedPkgIndex sourcePkgIndex =
DepResolverParams {
depResolverTargets = [],
depResolverTargets = Set.empty,
depResolverConstraints = [],
depResolverPreferences = [],
depResolverPreferenceDefault = PreferLatestForSelected,
Expand All @@ -242,7 +242,7 @@ addTargets :: [PackageName]
-> DepResolverParams -> DepResolverParams
addTargets extraTargets params =
params {
depResolverTargets = extraTargets ++ depResolverTargets params
depResolverTargets = Set.fromList extraTargets `Set.union` depResolverTargets params
}

addConstraints :: [LabeledPackageConstraint]
Expand Down Expand Up @@ -334,7 +334,7 @@ dontUpgradeNonUpgradeablePackages params =
[ LabeledPackageConstraint
(PackageConstraintInstalled pkgname)
ConstraintSourceNonUpgradeablePackage
| notElem (PackageName "base") (depResolverTargets params)
| Set.notMember (PackageName "base") (depResolverTargets params)
, pkgname <- map PackageName [ "base", "ghc-prim", "integer-gmp"
, "integer-simple" ]
, isInstalled pkgname ]
Expand Down Expand Up @@ -454,7 +454,7 @@ upgradeDependencies = setPreferenceDefault PreferAllLatest

reinstallTargets :: DepResolverParams -> DepResolverParams
reinstallTargets params =
hideInstalledPackagesAllVersions (depResolverTargets params) params
hideInstalledPackagesAllVersions (Set.toList $ depResolverTargets params) params


-- | A basic solver policy on which all others are built.
Expand Down Expand Up @@ -598,7 +598,7 @@ resolveDependencies :: Platform

--TODO: is this needed here? see dontUpgradeNonUpgradeablePackages
resolveDependencies platform comp _pkgConfigDB _solver params
| null (depResolverTargets params)
| Set.null (depResolverTargets params)
= return (validateSolverResult platform comp indGoals [])
where
indGoals = depResolverIndependentGoals params
Expand Down Expand Up @@ -629,8 +629,7 @@ resolveDependencies platform comp pkgConfigDB solver params =
enableBj
order) = dontUpgradeNonUpgradeablePackages params

preferences = interpretPackagesPreference
(Set.fromList targets) defpref prefs
preferences = interpretPackagesPreference targets defpref prefs


-- | Give an interpretation to the global 'PackagesPreference' as
Expand Down Expand Up @@ -854,7 +853,7 @@ resolveWithoutDependencies (DepResolverParams targets constraints
prefs defpref installedPkgIndex sourcePkgIndex
_reorderGoals _countConflicts _indGoals _avoidReinstalls
_shadowing _strFlags _maxBjumps _enableBj _order) =
collectEithers (map selectPackage targets)
collectEithers $ map selectPackage (Set.toList targets)
where
selectPackage :: PackageName -> Either ResolveNoDepsError UnresolvedSourcePackage
selectPackage pkgname
Expand Down Expand Up @@ -892,8 +891,7 @@ resolveWithoutDependencies (DepResolverParams targets constraints
| PackageConstraintVersion name range <- pcs ]

packagePreferences :: PackageName -> PackagePreferences
packagePreferences = interpretPackagesPreference
(Set.fromList targets) defpref prefs
packagePreferences = interpretPackagesPreference targets defpref prefs


collectEithers :: [Either a b] -> Either [a] [b]
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/Distribution/Solver/Modular/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Distribution.Solver.Modular.Solver

import Data.Map as M
import Data.List as L
import Data.Set as S
import Data.Version

import Distribution.Compiler (CompilerInfo)
Expand Down Expand Up @@ -93,7 +94,7 @@ solve :: SolverConfig -- ^ solver parameters
-> PkgConfigDb -- ^ available pkg-config pkgs
-> (PN -> PackagePreferences) -- ^ preferences
-> Map PN [LabeledPackageConstraint] -- ^ global constraints
-> [PN] -- ^ global goals
-> Set PN -- ^ global goals
-> Log Message (Assignment, RevDepMap)
solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
explorePhase $
Expand Down Expand Up @@ -134,7 +135,7 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
])
buildPhase = traceTree "build.json" id
$ addLinking
$ buildTree idx (independentGoals sc) userGoals
$ buildTree idx (independentGoals sc) (S.toList userGoals)

-- Counting conflicts and reordering goals interferes, as both are strategies to
-- change the order of goals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Distribution.Solver.Types.DependencyResolver
( DependencyResolver
) where

import Data.Set (Set)

import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.PkgConfigDb ( PkgConfigDb )
import Distribution.Solver.Types.PackagePreferences
Expand Down Expand Up @@ -30,5 +32,5 @@ type DependencyResolver loc = Platform
-> PkgConfigDb
-> (PackageName -> PackagePreferences)
-> [LabeledPackageConstraint]
-> [PackageName]
-> Set PackageName
-> Progress String String [ResolverPackage loc]

0 comments on commit f7533c3

Please sign in to comment.