-
Notifications
You must be signed in to change notification settings - Fork 711
Move solver types to Distribution.Solver.* namespace #3406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
23Skidoo
merged 7 commits into
haskell:master
from
BardurArantsson:reorg-solver-modules-3
May 6, 2016
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
baef5a5
Move PackageConstraint to Distribution.Solver.* namespace
BardurArantsson a1f7a6d
Move LabeledPackageConstraint to Distribution.Solver.* namespace
BardurArantsson 20b3c99
Move InstalledPreference to Distribution.Solver.* namespace
BardurArantsson efeffaa
Move PackagePreferences to Distribution.Solver.* namespace
BardurArantsson 1bc9290
Move DependencyResolver to Distribution.Solver.* namespace
BardurArantsson fd8bad0
Remove redundant "import Prelude hiding ..."
BardurArantsson 1ddb0a4
Remove obsolete module header
BardurArantsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,25 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Distribution.Client.Dependency.Types | ||
-- Copyright : (c) Duncan Coutts 2008 | ||
-- License : BSD-like | ||
-- | ||
-- Maintainer : [email protected] | ||
-- Stability : provisional | ||
-- Portability : portable | ||
-- | ||
-- Common types for dependency resolution. | ||
----------------------------------------------------------------------------- | ||
module Distribution.Client.Dependency.Types ( | ||
PreSolver(..), | ||
Solver(..), | ||
|
||
DependencyResolver, | ||
|
||
PackageConstraint(..), | ||
showPackageConstraint, | ||
PackagePreferences(..), | ||
InstalledPreference(..), | ||
PackagesPreferenceDefault(..), | ||
|
||
LabeledPackageConstraint(..), | ||
unlabelPackageConstraint | ||
|
||
) where | ||
|
||
import Data.Char | ||
( isAlpha, toLower ) | ||
|
||
import Distribution.Solver.Types.ConstraintSource | ||
import Distribution.Solver.Types.OptionalStanza | ||
import Distribution.Solver.Types.PkgConfigDb ( PkgConfigDb ) | ||
import Distribution.Solver.Types.PackageIndex ( PackageIndex ) | ||
import Distribution.Solver.Types.Progress | ||
import Distribution.Solver.Types.ResolverPackage | ||
import Distribution.Solver.Types.SourcePackage | ||
|
||
import qualified Distribution.Compat.ReadP as Parse | ||
( pfail, munch1 ) | ||
import Distribution.PackageDescription | ||
( FlagAssignment, FlagName(..) ) | ||
import Distribution.Simple.PackageIndex ( InstalledPackageIndex ) | ||
import Distribution.Package | ||
( PackageName ) | ||
import Distribution.Version | ||
( VersionRange, simplifyVersionRange ) | ||
import Distribution.Compiler | ||
( CompilerInfo ) | ||
import Distribution.System | ||
( Platform ) | ||
import Distribution.Text | ||
( Text(..), display ) | ||
( Text(..) ) | ||
|
||
import Text.PrettyPrint | ||
( text ) | ||
import GHC.Generics (Generic) | ||
import Distribution.Compat.Binary (Binary(..)) | ||
|
||
import Prelude hiding (fail) | ||
|
||
|
||
-- | All the solvers that can be selected. | ||
data PreSolver = AlwaysTopDown | AlwaysModular | Choose | ||
|
@@ -86,81 +44,6 @@ instance Text PreSolver where | |
"choose" -> return Choose | ||
_ -> Parse.pfail | ||
|
||
-- | A dependency resolver is a function that works out an installation plan | ||
-- given the set of installed and available packages and a set of deps to | ||
-- solve for. | ||
-- | ||
-- The reason for this interface is because there are dozens of approaches to | ||
-- solving the package dependency problem and we want to make it easy to swap | ||
-- in alternatives. | ||
-- | ||
type DependencyResolver loc = Platform | ||
-> CompilerInfo | ||
-> InstalledPackageIndex | ||
-> PackageIndex (SourcePackage loc) | ||
-> PkgConfigDb | ||
-> (PackageName -> PackagePreferences) | ||
-> [LabeledPackageConstraint] | ||
-> [PackageName] | ||
-> Progress String String [ResolverPackage loc] | ||
|
||
-- | Per-package constraints. Package constraints must be respected by the | ||
-- solver. Multiple constraints for each package can be given, though obviously | ||
-- it is possible to construct conflicting constraints (eg impossible version | ||
-- range or inconsistent flag assignment). | ||
-- | ||
data PackageConstraint | ||
= PackageConstraintVersion PackageName VersionRange | ||
| PackageConstraintInstalled PackageName | ||
| PackageConstraintSource PackageName | ||
| PackageConstraintFlags PackageName FlagAssignment | ||
| PackageConstraintStanzas PackageName [OptionalStanza] | ||
deriving (Eq,Show,Generic) | ||
|
||
instance Binary PackageConstraint | ||
|
||
-- | Provide a textual representation of a package constraint | ||
-- for debugging purposes. | ||
-- | ||
showPackageConstraint :: PackageConstraint -> String | ||
showPackageConstraint (PackageConstraintVersion pn vr) = | ||
display pn ++ " " ++ display (simplifyVersionRange vr) | ||
showPackageConstraint (PackageConstraintInstalled pn) = | ||
display pn ++ " installed" | ||
showPackageConstraint (PackageConstraintSource pn) = | ||
display pn ++ " source" | ||
showPackageConstraint (PackageConstraintFlags pn fs) = | ||
"flags " ++ display pn ++ " " ++ unwords (map (uncurry showFlag) fs) | ||
where | ||
showFlag (FlagName f) True = "+" ++ f | ||
showFlag (FlagName f) False = "-" ++ f | ||
showPackageConstraint (PackageConstraintStanzas pn ss) = | ||
"stanzas " ++ display pn ++ " " ++ unwords (map showStanza ss) | ||
where | ||
showStanza TestStanzas = "test" | ||
showStanza BenchStanzas = "bench" | ||
|
||
-- | Per-package preferences on the version. It is a soft constraint that the | ||
-- 'DependencyResolver' should try to respect where possible. It consists of | ||
-- an 'InstalledPreference' which says if we prefer versions of packages | ||
-- that are already installed. It also has (possibly multiple) | ||
-- 'PackageVersionPreference's which are suggested constraints on the version | ||
-- number. The resolver should try to use package versions that satisfy | ||
-- the maximum number of the suggested version constraints. | ||
-- | ||
-- It is not specified if preferences on some packages are more important than | ||
-- others. | ||
-- | ||
data PackagePreferences = PackagePreferences [VersionRange] | ||
InstalledPreference | ||
[OptionalStanza] | ||
|
||
-- | Whether we prefer an installed version of a package or simply the latest | ||
-- version. | ||
-- | ||
data InstalledPreference = PreferInstalled | PreferLatest | ||
deriving Show | ||
|
||
-- | Global policy for all packages to say if we prefer package versions that | ||
-- are already installed locally or if we just prefer the latest available. | ||
-- | ||
|
@@ -185,10 +68,3 @@ data PackagesPreferenceDefault = | |
-- | ||
| PreferLatestForSelected | ||
deriving Show | ||
|
||
-- | 'PackageConstraint' labeled with its source. | ||
data LabeledPackageConstraint | ||
= LabeledPackageConstraint PackageConstraint ConstraintSource | ||
|
||
unlabelPackageConstraint :: LabeledPackageConstraint -> PackageConstraint | ||
unlabelPackageConstraint (LabeledPackageConstraint pc _) = pc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
cabal-install/Distribution/Solver/Types/DependencyResolver.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Distribution.Solver.Types.DependencyResolver | ||
( DependencyResolver | ||
) where | ||
|
||
import Distribution.Solver.Types.LabeledPackageConstraint | ||
import Distribution.Solver.Types.PkgConfigDb ( PkgConfigDb ) | ||
import Distribution.Solver.Types.PackagePreferences | ||
import Distribution.Solver.Types.PackageIndex ( PackageIndex ) | ||
import Distribution.Solver.Types.Progress | ||
import Distribution.Solver.Types.ResolverPackage | ||
import Distribution.Solver.Types.SourcePackage | ||
|
||
import Distribution.Simple.PackageIndex ( InstalledPackageIndex ) | ||
import Distribution.Package ( PackageName ) | ||
import Distribution.Compiler ( CompilerInfo ) | ||
import Distribution.System ( Platform ) | ||
|
||
-- | A dependency resolver is a function that works out an installation plan | ||
-- given the set of installed and available packages and a set of deps to | ||
-- solve for. | ||
-- | ||
-- The reason for this interface is because there are dozens of approaches to | ||
-- solving the package dependency problem and we want to make it easy to swap | ||
-- in alternatives. | ||
-- | ||
type DependencyResolver loc = Platform | ||
-> CompilerInfo | ||
-> InstalledPackageIndex | ||
-> PackageIndex (SourcePackage loc) | ||
-> PkgConfigDb | ||
-> (PackageName -> PackagePreferences) | ||
-> [LabeledPackageConstraint] | ||
-> [PackageName] | ||
-> Progress String String [ResolverPackage loc] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with removing the header, but it'd be nice to preserve the top comment about the purpose of the module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually removed it because the "purpose" isn't very clear any longer. The module is now a sort of weird mish-mash.
(I think this module should perhaps also be split, but I'm kind of waiting to see where migrating the Tests takes me... The module may become entirely redundant.)