diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs index d25ef846356..ed5adfbf8b2 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs @@ -127,11 +127,18 @@ preferPackagePreferences pcs = -- | Traversal that tries to establish package stanza enable\/disable -- preferences. Works by reordering the branches of stanza choices. +-- Note that this works on packages lower in the path as well as at the top level. +-- This is because stanza preferences apply to local packages only +-- and for local packages, a single version is fixed, which means +-- (for now) that all stanza preferences must be uniform at all levels. +-- Further, even when we can have multiple versions of the same package, +-- the build plan will be more efficient if we can attempt to keep +-- stanza preferences aligned at all levels. preferPackageStanzaPreferences :: (PN -> PackagePreferences) -> Tree d c -> Tree d c preferPackageStanzaPreferences pcs = trav go where - go (SChoiceF qsn@(SN (Q pp pn) s) rdm gr _tr ts) - | primaryPP pp && enableStanzaPref pn s = + go (SChoiceF qsn@(SN (Q _pp pn) s) rdm gr _tr ts) + | enableStanzaPref pn s = -- move True case first to try enabling the stanza let ts' = W.mapWeightsWithKey (\k w -> weight k : w) ts weight k = if k then 0 else 1 diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 077c6422be4..fc6d9a17383 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -1024,13 +1024,14 @@ planPackages verbosity comp platform solver SolverSettings{..} | (pc, src) <- solverSettingConstraints ] . addPreferences - -- enable stanza preference where the user did not specify + -- enable stanza preference unilaterally, regardless if the user asked + -- accordingly or expressed no preference, to help hint the solver [ PackageStanzasPreference pkgname stanzas | pkg <- localPackages , let pkgname = pkgSpecifierTarget pkg stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable stanzas = [ stanza | stanza <- [minBound..maxBound] - , Map.lookup stanza stanzaM == Nothing ] + , Map.lookup stanza stanzaM /= Just False ] , not (null stanzas) ] @@ -2592,7 +2593,7 @@ nubComponentTargets = -> [(ComponentTarget, NonEmpty a)] wholeComponentOverrides ts = case [ ta | ta@(ComponentTarget _ WholeComponent, _) <- ts ] of - ((t, x):_) -> + ((t, x):_) -> let -- Delete tuple (t, x) from original list to avoid duplicates. -- Use 'deleteBy', to avoid additional Class constraint on 'nubComponentTargets'.