-
Notifications
You must be signed in to change notification settings - Fork 725
Perf: Speed up solver #11566
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
base: master
Are you sure you want to change the base?
Perf: Speed up solver #11566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| {-# LANGUAGE PatternSynonyms #-} | ||
| -- | Conflict sets | ||
| -- | ||
| -- Intended for double import | ||
|
|
@@ -8,7 +9,7 @@ module Distribution.Solver.Modular.ConflictSet ( | |
| ConflictSet -- opaque | ||
| , Conflict(..) | ||
| , ConflictMap | ||
| , OrderedVersionRange(..) | ||
| , OrderedVersionRange(OrderedVersionRange) | ||
| , showConflictSet | ||
| , showCSSortedByFrequency | ||
| , showCSWithFrequency | ||
|
|
@@ -40,6 +41,8 @@ import qualified Data.Set as S | |
| import Distribution.Solver.Modular.Var | ||
| import Distribution.Solver.Modular.Version | ||
| import Distribution.Solver.Types.PackagePath | ||
| import Distribution.Utils.ShortText (ShortText) | ||
| import qualified Distribution.Utils.ShortText as ShortText | ||
|
|
||
| -- | The set of variables involved in a solver conflict, each paired with | ||
| -- details about the conflict. | ||
|
|
@@ -78,13 +81,24 @@ data Conflict = | |
| | OtherConflict | ||
| deriving (Eq, Ord, Show) | ||
|
|
||
| -- | Version range with an 'Ord' instance. | ||
| newtype OrderedVersionRange = OrderedVersionRange VR | ||
| deriving (Eq, Show) | ||
| -- | Version range with an 'Ord' instance. The show string is cached to avoid | ||
| -- recomputing it on every comparison. | ||
| data OrderedVersionRange = OVR !ShortText !VR | ||
|
Comment on lines
-81
to
+86
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like #8269 added an
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be surprised if it is a significant difference either way - |
||
|
|
||
| pattern OrderedVersionRange :: VR -> OrderedVersionRange | ||
| pattern OrderedVersionRange vr <- OVR _ vr | ||
| where OrderedVersionRange vr = OVR (ShortText.toShortText (show vr)) vr | ||
| {-# COMPLETE OrderedVersionRange #-} | ||
|
|
||
| instance Eq OrderedVersionRange where | ||
| OVR _ a == OVR _ b = a == b | ||
|
|
||
| -- TODO: Avoid converting the version ranges to strings. | ||
| instance Ord OrderedVersionRange where | ||
| compare = compare `on` show | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. funny - because we'd be doing
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be, but a |
||
| compare (OVR sa _) (OVR sb _) = compare sa sb | ||
|
|
||
| instance Show OrderedVersionRange where | ||
| showsPrec d (OVR _ vr) = showParen (d > 10) $ | ||
| showString "OrderedVersionRange " . showsPrec 11 vr | ||
|
|
||
| showConflictSet :: ConflictSet -> String | ||
| showConflictSet = intercalate ", " . map showVar . toList | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,8 @@ exploreLog mbj enableBj fineGrainedConflicts (CountConflicts countConflicts) idx | |
| , esBackjumps = 0 | ||
| } | ||
|
|
||
| qo = defaultQualifyOptions idx | ||
|
|
||
| -- Is it possible for this package instance (QPN and POption) to resolve any | ||
| -- of the conflicts that were caused by the previous instance? The default | ||
| -- is true, because it is always safe to explore a package instance. | ||
|
|
@@ -270,21 +272,30 @@ exploreLog mbj enableBj fineGrainedConflicts (CountConflicts countConflicts) idx | |
| couldResolveConflicts :: QPN -> POption -> S.Set CS.Conflict -> Maybe ConflictSet | ||
| couldResolveConflicts currentQPN@(Q _ pn) (POption i@(I v _) _) conflicts = | ||
| let (PInfo deps _ _ _) = idx M.! pn M.! i | ||
| qdeps = qualifyDeps (defaultQualifyOptions idx) currentQPN deps | ||
| qdeps = qualifyDeps qo currentQPN deps | ||
|
|
||
| -- Pre-index: map from QPN to intersected version range (Constrained only) | ||
| depVRs :: M.Map QPN VR | ||
| depVRs = M.fromListWith (.&&.) | ||
| [ (qpn, case ci of Constrained vr -> vr; _ -> anyVersion) | ||
| | Simple (LDep _ (Dep (PkgComponent qpn _) ci)) _ <- qdeps | ||
| ] | ||
|
Comment on lines
+277
to
+282
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This index should only contain dependencies that are |
||
|
|
||
| depsWithVRs :: S.Set QPN | ||
| depsWithVRs = M.keysSet depVRs | ||
|
Comment on lines
+284
to
+285
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable can just be called |
||
|
|
||
| couldBeResolved :: CS.Conflict -> Maybe ConflictSet | ||
| couldBeResolved CS.OtherConflict = Nothing | ||
| couldBeResolved (CS.GoalConflict conflictingDep) = | ||
| -- Check whether this package instance also has 'conflictingDep' | ||
| -- as a dependency (ignoring flag and stanza choices). | ||
| if null [() | Simple (LDep _ (Dep (PkgComponent qpn _) _)) _ <- qdeps, qpn == conflictingDep] | ||
| then Nothing | ||
| else Just CS.empty | ||
| if S.member conflictingDep depsWithVRs | ||
| then Just CS.empty | ||
| else Nothing | ||
| couldBeResolved (CS.VersionConstraintConflict dep excludedVersion) = | ||
| -- Check whether this package instance also excludes version | ||
| -- 'excludedVersion' of 'dep' (ignoring flag and stanza choices). | ||
| let vrs = [vr | Simple (LDep _ (Dep (PkgComponent qpn _) (Constrained vr))) _ <- qdeps, qpn == dep ] | ||
| vrIntersection = L.foldl' (.&&.) anyVersion vrs | ||
| let vrIntersection = M.findWithDefault anyVersion dep depVRs | ||
| in if checkVR vrIntersection excludedVersion | ||
| then Nothing | ||
| else -- If we skip this package instance, we need to update the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,7 +301,7 @@ checkComponentsInNewPackage :: ComponentDependencyReasons | |
| -> Map ExposedComponent ComponentInfo | ||
| -> Either Conflict () | ||
| checkComponentsInNewPackage required qpn providedComps = | ||
| case M.toList $ deleteKeys (M.keys providedComps) required of | ||
| case M.toList $ M.difference required providedComps of | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be algorithmically better here
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| (missingComp, dr) : _ -> | ||
| Left $ mkConflict missingComp dr NewPackageIsMissingRequiredComponent | ||
| [] -> | ||
|
|
@@ -325,9 +325,6 @@ checkComponentsInNewPackage required qpn providedComps = | |
| mkConflict comp dr mkFailure = | ||
| (CS.insert (P qpn) (dependencyReasonToConflictSet dr), mkFailure comp dr) | ||
|
|
||
| deleteKeys :: Ord k => [k] -> Map k v -> Map k v | ||
| deleteKeys ks m = L.foldr M.delete m ks | ||
|
|
||
| -- | We try to extract as many concrete dependencies from the given flagged | ||
| -- dependencies as possible. We make use of all the flag knowledge we have | ||
| -- already acquired. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.