Skip to content

Commit 5cb0408

Browse files
sebrightezyang
authored andcommitted
Solver: Only print conflict counts at higher verbosity (fixes haskell#4150).
1 parent 85e92fa commit 5cb0408

File tree

13 files changed

+79
-34
lines changed

13 files changed

+79
-34
lines changed

cabal-install/Distribution/Client/Configure.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ planLocalPackage verbosity comp platform configFlags configExFlags
362362
-- installed package index
363363
. setSolveExecutables (SolveExecutables False)
364364

365+
. setSolverVerbosity verbosity
366+
365367
$ standardInstallPolicy
366368
installedPkgIndex
367369
-- NB: We pass in an *empty* source package database,

cabal-install/Distribution/Client/Dependency.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module Distribution.Client.Dependency (
5656
setEnableBackjumping,
5757
setSolveExecutables,
5858
setGoalOrder,
59+
setSolverVerbosity,
5960
removeLowerBounds,
6061
removeUpperBounds,
6162
addDefaultSetupDependencies,
@@ -106,7 +107,7 @@ import Distribution.Simple.Setup
106107
import Distribution.Text
107108
( display )
108109
import Distribution.Verbosity
109-
( Verbosity )
110+
( normal, Verbosity )
110111
import qualified Distribution.Compat.Graph as Graph
111112

112113
import Distribution.Solver.Types.ComponentDeps (ComponentDeps)
@@ -174,7 +175,8 @@ data DepResolverParams = DepResolverParams {
174175
depResolverSolveExecutables :: SolveExecutables,
175176

176177
-- | Function to override the solver's goal-ordering heuristics.
177-
depResolverGoalOrder :: Maybe (Variable QPN -> Variable QPN -> Ordering)
178+
depResolverGoalOrder :: Maybe (Variable QPN -> Variable QPN -> Ordering),
179+
depResolverVerbosity :: Verbosity
178180
}
179181

180182
showDepResolverParams :: DepResolverParams -> String
@@ -252,7 +254,8 @@ basicDepResolverParams installedPkgIndex sourcePkgIndex =
252254
depResolverMaxBackjumps = Nothing,
253255
depResolverEnableBackjumping = EnableBackjumping True,
254256
depResolverSolveExecutables = SolveExecutables True,
255-
depResolverGoalOrder = Nothing
257+
depResolverGoalOrder = Nothing,
258+
depResolverVerbosity = normal
256259
}
257260

258261
addTargets :: [PackageName]
@@ -353,6 +356,12 @@ setGoalOrder order params =
353356
depResolverGoalOrder = order
354357
}
355358

359+
setSolverVerbosity :: Verbosity -> DepResolverParams -> DepResolverParams
360+
setSolverVerbosity verbosity params =
361+
params {
362+
depResolverVerbosity = verbosity
363+
}
364+
356365
-- | Some packages are specific to a given compiler version and should never be
357366
-- upgraded.
358367
dontUpgradeNonUpgradeablePackages :: DepResolverParams -> DepResolverParams
@@ -663,7 +672,7 @@ resolveDependencies platform comp pkgConfigDB solver params =
663672
$ runSolver solver (SolverConfig reordGoals cntConflicts
664673
indGoals noReinstalls
665674
shadowing strFlags allowBootLibs maxBkjumps enableBj
666-
solveExes order)
675+
solveExes order verbosity)
667676
platform comp installedPkgIndex sourcePkgIndex
668677
pkgConfigDB preferences constraints targets
669678
where
@@ -683,9 +692,11 @@ resolveDependencies platform comp pkgConfigDB solver params =
683692
maxBkjumps
684693
enableBj
685694
solveExes
686-
order) = if asBool (depResolverAllowBootLibInstalls params)
687-
then params
688-
else dontUpgradeNonUpgradeablePackages params
695+
order
696+
verbosity) =
697+
if asBool (depResolverAllowBootLibInstalls params)
698+
then params
699+
else dontUpgradeNonUpgradeablePackages params
689700

690701
preferences = interpretPackagesPreference targets defpref prefs
691702

@@ -911,7 +922,7 @@ resolveWithoutDependencies (DepResolverParams targets constraints
911922
prefs defpref installedPkgIndex sourcePkgIndex
912923
_reorderGoals _countConflicts _indGoals _avoidReinstalls
913924
_shadowing _strFlags _maxBjumps _enableBj
914-
_solveExes _allowBootLibInstalls _order) =
925+
_solveExes _allowBootLibInstalls _order _verbosity) =
915926
collectEithers $ map selectPackage (Set.toList targets)
916927
where
917928
selectPackage :: PackageName -> Either ResolveNoDepsError UnresolvedSourcePackage

cabal-install/Distribution/Client/Fetch.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ planPackages verbosity comp platform fetchFlags
166166

167167
. setAllowBootLibInstalls allowBootLibInstalls
168168

169+
. setSolverVerbosity verbosity
170+
169171
-- Reinstall the targets given on the command line so that the dep
170172
-- resolver will decide that they need fetching, even if they're
171173
-- already installed. Since we want to get the source packages of

cabal-install/Distribution/Client/Freeze.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ planPackages verbosity comp platform mSandboxPkgInfo freezeFlags
181181

182182
. setAllowBootLibInstalls allowBootLibInstalls
183183

184+
. setSolverVerbosity verbosity
185+
184186
. addConstraints
185187
[ let pkg = pkgSpecifierTarget pkgSpecifier
186188
pc = PackageConstraint (scopeToplevel pkg)

cabal-install/Distribution/Client/Install.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ makeInstallPlan verbosity
320320
solver <- chooseSolver verbosity (fromFlag (configSolver configExFlags))
321321
(compilerInfo comp)
322322
notice verbosity "Resolving dependencies..."
323-
return $ planPackages comp platform mSandboxPkgInfo solver
323+
return $ planPackages verbosity comp platform mSandboxPkgInfo solver
324324
configFlags configExFlags installFlags
325325
installedPkgIndex sourcePkgDb pkgConfigDb pkgSpecifiers
326326

@@ -349,7 +349,8 @@ processInstallPlan verbosity
349349
-- * Installation planning
350350
-- ------------------------------------------------------------
351351

352-
planPackages :: Compiler
352+
planPackages :: Verbosity
353+
-> Compiler
353354
-> Platform
354355
-> Maybe SandboxPackageInfo
355356
-> Solver
@@ -361,7 +362,7 @@ planPackages :: Compiler
361362
-> PkgConfigDb
362363
-> [PackageSpecifier UnresolvedSourcePackage]
363364
-> Progress String String SolverInstallPlan
364-
planPackages comp platform mSandboxPkgInfo solver
365+
planPackages verbosity comp platform mSandboxPkgInfo solver
365366
configFlags configExFlags installFlags
366367
installedPkgIndex sourcePkgDb pkgConfigDb pkgSpecifiers =
367368

@@ -392,6 +393,8 @@ planPackages comp platform mSandboxPkgInfo solver
392393

393394
. setAllowBootLibInstalls allowBootLibInstalls
394395

396+
. setSolverVerbosity verbosity
397+
395398
. setPreferenceDefault (if upgradeDeps then PreferAllLatest
396399
else PreferLatestForSelected)
397400

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ rebuildInstallPlan verbosity
517517

518518
notice verbosity "Resolving dependencies..."
519519
plan <- foldProgress logMsg die return $
520-
planPackages compiler platform solver solverSettings
520+
planPackages verbosity compiler platform solver solverSettings
521521
installedPkgIndex sourcePkgDb pkgConfigDB
522522
localPackages localPackagesEnabledStanzas
523523
return (plan, pkgConfigDB)
@@ -894,7 +894,8 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
894894
-- * Installation planning
895895
-- ------------------------------------------------------------
896896

897-
planPackages :: Compiler
897+
planPackages :: Verbosity
898+
-> Compiler
898899
-> Platform
899900
-> Solver -> SolverSettings
900901
-> InstalledPackageIndex
@@ -903,7 +904,7 @@ planPackages :: Compiler
903904
-> [UnresolvedSourcePackage]
904905
-> Map PackageName (Map OptionalStanza Bool)
905906
-> Progress String String SolverInstallPlan
906-
planPackages comp platform solver SolverSettings{..}
907+
planPackages verbosity comp platform solver SolverSettings{..}
907908
installedPkgIndex sourcePkgDb pkgConfigDB
908909
localPackages pkgStanzasEnable =
909910

@@ -937,6 +938,8 @@ planPackages comp platform solver SolverSettings{..}
937938

938939
. setAllowBootLibInstalls solverSettingAllowBootLibInstalls
939940

941+
. setSolverVerbosity verbosity
942+
940943
--TODO: [required eventually] decide if we need to prefer installed for
941944
-- global packages, or prefer latest even for global packages. Perhaps
942945
-- should be configurable but with a different name than "upgrade-dependencies".

cabal-install/Distribution/Solver/Modular.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import Distribution.System
3939
-- solver. Performs the necessary translations before and after.
4040
modularResolver :: SolverConfig -> DependencyResolver loc
4141
modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns =
42-
fmap (uncurry postprocess) $ -- convert install plan
43-
logToProgress (maxBackjumps sc) $ -- convert log format into progress format
42+
fmap (uncurry postprocess) $ -- convert install plan
43+
logToProgress (solverVerbosity sc) (maxBackjumps sc) $ -- convert log format into progress format
4444
solve sc cinfo idx pkgConfigDB pprefs gcs pns
4545
where
4646
-- Indices have to be converted into solver-specific uniform index.

cabal-install/Distribution/Solver/Modular/ConflictSet.hs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module Distribution.Solver.Modular.ConflictSet (
1414
#ifdef DEBUG_CONFLICT_SETS
1515
, conflictSetOrigin
1616
#endif
17-
, showCS
17+
, showConflictSet
18+
, showCSSortedByFrequency
1819
, showCSWithFrequency
1920
-- Set-like operations
2021
, toList
@@ -74,16 +75,24 @@ instance Eq ConflictSet where
7475
instance Ord ConflictSet where
7576
compare = compare `on` conflictSetToSet
7677

77-
showCS :: ConflictSet -> String
78-
showCS = intercalate ", " . map showVar . toList
78+
showConflictSet :: ConflictSet -> String
79+
showConflictSet = intercalate ", " . map showVar . toList
80+
81+
showCSSortedByFrequency :: ConflictMap -> ConflictSet -> String
82+
showCSSortedByFrequency = showCS False
7983

8084
showCSWithFrequency :: ConflictMap -> ConflictSet -> String
81-
showCSWithFrequency cm = intercalate ", " . map showWithFrequency . indexByFrequency
85+
showCSWithFrequency = showCS True
86+
87+
showCS :: Bool -> ConflictMap -> ConflictSet -> String
88+
showCS showCount cm =
89+
intercalate ", " . map showWithFrequency . indexByFrequency
8290
where
8391
indexByFrequency = sortBy (flip compare `on` snd) . map (\c -> (c, M.lookup c cm)) . toList
8492
showWithFrequency (conflict, maybeFrequency) = case maybeFrequency of
85-
Just frequency -> showVar conflict ++ " (" ++ show frequency ++ ")"
86-
Nothing -> showVar conflict
93+
Just frequency
94+
| showCount -> showVar conflict ++ " (" ++ show frequency ++ ")"
95+
_ -> showVar conflict
8796

8897
{-------------------------------------------------------------------------------
8998
Set-like operations

cabal-install/Distribution/Solver/Modular/Dependency.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Distribution.Solver.Modular.Dependency (
1313
-- * Conflict sets
1414
, ConflictSet
1515
, ConflictMap
16-
, CS.showCS
16+
, CS.showConflictSet
1717
-- * Constrained instances
1818
, CI(..)
1919
, merge

cabal-install/Distribution/Solver/Modular/Log.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Distribution.Solver.Modular.Dependency
1414
import Distribution.Solver.Modular.Message
1515
import Distribution.Solver.Modular.Tree (FailReason(..))
1616
import qualified Distribution.Solver.Modular.ConflictSet as CS
17+
import Distribution.Verbosity
1718

1819
-- | The 'Log' datatype.
1920
--
@@ -30,12 +31,12 @@ data Exhaustiveness = Exhaustive | BackjumpLimitReached
3031
-- | Postprocesses a log file. Takes as an argument a limit on allowed backjumps.
3132
-- If the limit is 'Nothing', then infinitely many backjumps are allowed. If the
3233
-- limit is 'Just 0', backtracking is completely disabled.
33-
logToProgress :: Maybe Int -> Log Message a -> Progress String String a
34-
logToProgress mbj l = let
35-
es = proc (Just 0) l -- catch first error (always)
36-
ms = proc mbj l
37-
in go es es -- trace for first error
38-
(showMessages (const True) True ms) -- run with backjump limit applied
34+
logToProgress :: Verbosity -> Maybe Int -> Log Message a -> Progress String String a
35+
logToProgress verbosity mbj l =
36+
let es = proc (Just 0) l -- catch first error (always)
37+
ms = proc mbj l
38+
in go es es -- trace for first error
39+
(showMessages (const True) True ms) -- run with backjump limit applied
3940
where
4041
-- Proc takes the allowed number of backjumps and a 'Progress' and explores the
4142
-- messages until the maximum number of backjumps has been reached. It filters out
@@ -73,7 +74,11 @@ logToProgress mbj l = let
7374
Exhaustive ->
7475
"After searching the rest of the dependency tree exhaustively, "
7576
++ "these were the goals I've had most trouble fulfilling: "
76-
++ CS.showCSWithFrequency cm cs
77+
++ showCS cm cs
78+
where
79+
showCS = if verbosity > normal
80+
then CS.showCSWithFrequency
81+
else CS.showCSSortedByFrequency
7782
BackjumpLimitReached ->
7883
"Backjump limit reached (" ++ currlimit mbj ++
7984
"change with --max-backjumps or try to run with --reorder-goals).\n"

0 commit comments

Comments
 (0)