@@ -27,34 +27,51 @@ import Distribution.Solver.Modular.ConfiguredConversion
27
27
( convCP )
28
28
import qualified Distribution.Solver.Modular.ConflictSet as CS
29
29
import Distribution.Solver.Modular.Dependency
30
- import Distribution.Solver.Modular.Flag
31
- import Distribution.Solver.Modular.Index
30
+ ( Var (.. ),
31
+ showVar ,
32
+ ConflictMap ,
33
+ ConflictSet ,
34
+ showConflictSet ,
35
+ RevDepMap )
36
+ import Distribution.Solver.Modular.Flag ( SN (SN ), FN (FN ) )
37
+ import Distribution.Solver.Modular.Index ( Index )
32
38
import Distribution.Solver.Modular.IndexConversion
33
39
( convPIs )
34
40
import Distribution.Solver.Modular.Log
35
41
( SolverFailure (.. ), displayLogMessages )
36
42
import Distribution.Solver.Modular.Package
37
43
( PN )
38
44
import Distribution.Solver.Modular.RetryLog
45
+ ( RetryLog ,
46
+ toProgress ,
47
+ fromProgress ,
48
+ retry ,
49
+ failWith ,
50
+ continueWith )
39
51
import Distribution.Solver.Modular.Solver
40
52
( SolverConfig (.. ), PruneAfterFirstSuccess (.. ), solve )
41
53
import Distribution.Solver.Types.DependencyResolver
54
+ ( DependencyResolver )
42
55
import Distribution.Solver.Types.LabeledPackageConstraint
56
+ ( LabeledPackageConstraint , unlabelPackageConstraint )
43
57
import Distribution.Solver.Types.PackageConstraint
44
- import Distribution.Solver.Types.PackagePath
58
+ ( PackageConstraint (.. ), scopeToPackageName )
59
+ import Distribution.Solver.Types.PackagePath ( QPN )
45
60
import Distribution.Solver.Types.PackagePreferences
61
+ ( PackagePreferences )
46
62
import Distribution.Solver.Types.PkgConfigDb
47
63
( PkgConfigDb )
48
64
import Distribution.Solver.Types.Progress
49
- import Distribution.Solver.Types.Variable
65
+ ( Progress (.. ), foldProgress , SummarizedMessage (ErrorMsg ) )
66
+ import Distribution.Solver.Types.Variable ( Variable (.. ) )
50
67
import Distribution.System
51
68
( Platform (.. ) )
52
69
import Distribution.Simple.Setup
53
70
( BooleanFlag (.. ) )
54
71
import Distribution.Simple.Utils
55
- ( ordNubBy )
56
- import Distribution.Verbosity
57
-
72
+ ( ordNubBy )
73
+ import Distribution.Verbosity ( normal , verbose )
74
+ import Distribution.Solver.Modular.Message ( renderSummarizedMessage )
58
75
59
76
-- | Ties the two worlds together: classic cabal-install vs. the modular
60
77
-- solver. Performs the necessary translations before and after.
@@ -120,21 +137,21 @@ solve' :: SolverConfig
120
137
-> (PN -> PackagePreferences )
121
138
-> Map PN [LabeledPackageConstraint ]
122
139
-> Set PN
123
- -> Progress String String (Assignment , RevDepMap )
140
+ -> Progress SummarizedMessage String (Assignment , RevDepMap )
124
141
solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
125
142
toProgress $ retry (runSolver printFullLog sc) createErrorMsg
126
143
where
127
144
runSolver :: Bool -> SolverConfig
128
- -> RetryLog String SolverFailure (Assignment , RevDepMap )
145
+ -> RetryLog SummarizedMessage SolverFailure (Assignment , RevDepMap )
129
146
runSolver keepLog sc' =
130
147
displayLogMessages keepLog $
131
148
solve sc' cinfo idx pkgConfigDB pprefs gcs pns
132
149
133
150
createErrorMsg :: SolverFailure
134
- -> RetryLog String String (Assignment , RevDepMap )
151
+ -> RetryLog SummarizedMessage String (Assignment , RevDepMap )
135
152
createErrorMsg failure@ (ExhaustiveSearch cs cm) =
136
153
if asBool $ minimizeConflictSet sc
137
- then continueWith (" Found no solution after exhaustively searching the "
154
+ then continueWith (mkErrorMsg $ " Found no solution after exhaustively searching the "
138
155
++ " dependency tree. Rerunning the dependency solver "
139
156
++ " to minimize the conflict set ({"
140
157
++ showConflictSet cs ++ " })." ) $
@@ -155,7 +172,7 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
155
172
rerunSolverForErrorMsg cs ++ finalErrorMsg sc failure
156
173
createErrorMsg failure@ BackjumpLimitReached =
157
174
continueWith
158
- (" Backjump limit reached. Rerunning dependency solver to generate "
175
+ (mkErrorMsg $ " Backjump limit reached. Rerunning dependency solver to generate "
159
176
++ " a final conflict set for the search tree containing the "
160
177
++ " first backjump." ) $
161
178
retry (runSolver printFullLog sc { pruneAfterFirstSuccess = PruneAfterFirstSuccess True }) $
@@ -181,13 +198,16 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
181
198
-- original goal order.
182
199
goalOrder' = preferGoalsFromConflictSet cs <> fromMaybe mempty (goalOrder sc)
183
200
184
- in unlines (" Could not resolve dependencies:" : messages (toProgress (runSolver True sc')))
201
+ in unlines (" Could not resolve dependencies:" : map renderSummarizedMessage ( messages (toProgress (runSolver True sc') )))
185
202
186
203
printFullLog = solverVerbosity sc >= verbose
187
204
188
205
messages :: Progress step fail done -> [step ]
189
206
messages = foldProgress (:) (const [] ) (const [] )
190
207
208
+ mkErrorMsg :: String -> SummarizedMessage
209
+ mkErrorMsg msg = ErrorMsg msg
210
+
191
211
-- | Try to remove variables from the given conflict set to create a minimal
192
212
-- conflict set.
193
213
--
@@ -219,11 +239,11 @@ solve' sc cinfo idx pkgConfigDB pprefs gcs pns =
219
239
-- solver to add new unnecessary variables to the conflict set. This function
220
240
-- discards the result from any run that adds new variables to the conflict
221
241
-- set, but the end result may not be completely minimized.
222
- tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog String SolverFailure a )
242
+ tryToMinimizeConflictSet :: forall a . (SolverConfig -> RetryLog SummarizedMessage SolverFailure a )
223
243
-> SolverConfig
224
244
-> ConflictSet
225
245
-> ConflictMap
226
- -> RetryLog String SolverFailure a
246
+ -> RetryLog SummarizedMessage SolverFailure a
227
247
tryToMinimizeConflictSet runSolver sc cs cm =
228
248
foldl (\ r v -> retryNoSolution r $ tryToRemoveOneVar v)
229
249
(fromProgress $ Fail $ ExhaustiveSearch cs cm)
@@ -249,14 +269,14 @@ tryToMinimizeConflictSet runSolver sc cs cm =
249
269
tryToRemoveOneVar :: Var QPN
250
270
-> ConflictSet
251
271
-> ConflictMap
252
- -> RetryLog String SolverFailure a
272
+ -> RetryLog SummarizedMessage SolverFailure a
253
273
tryToRemoveOneVar v smallestKnownCS smallestKnownCM
254
274
-- Check whether v is still present, because it may have already been
255
275
-- removed in a previous solver rerun.
256
276
| not (v `CS.member` smallestKnownCS) =
257
277
fromProgress $ Fail $ ExhaustiveSearch smallestKnownCS smallestKnownCM
258
278
| otherwise =
259
- continueWith (" Trying to remove variable " ++ varStr ++ " from the "
279
+ continueWith (mkErrorMsg $ " Trying to remove variable " ++ varStr ++ " from the "
260
280
++ " conflict set." ) $
261
281
retry (runSolver sc') $ \ case
262
282
err@ (ExhaustiveSearch cs' _)
@@ -268,14 +288,14 @@ tryToMinimizeConflictSet runSolver sc cs cm =
268
288
++ " conflict set."
269
289
in -- Use the new conflict set, even if v wasn't removed,
270
290
-- because other variables may have been removed.
271
- failWith (msg ++ " Continuing with " ++ showCS cs' ++ " ." ) err
291
+ failWith (mkErrorMsg $ msg ++ " Continuing with " ++ showCS cs' ++ " ." ) err
272
292
| otherwise ->
273
- failWith (" Failed to find a smaller conflict set. The new "
293
+ failWith (mkErrorMsg $ " Failed to find a smaller conflict set. The new "
274
294
++ " conflict set is not a subset of the previous "
275
295
++ " conflict set: " ++ showCS cs') $
276
296
ExhaustiveSearch smallestKnownCS smallestKnownCM
277
297
BackjumpLimitReached ->
278
- failWith " Reached backjump limit while minimizing conflict set."
298
+ failWith (mkErrorMsg " Reached backjump limit while minimizing conflict set." )
279
299
BackjumpLimitReached
280
300
where
281
301
varStr = " \" " ++ showVar v ++ " \" "
@@ -290,9 +310,9 @@ tryToMinimizeConflictSet runSolver sc cs cm =
290
310
291
311
-- Like 'retry', except that it only applies the input function when the
292
312
-- backjump limit has not been reached.
293
- retryNoSolution :: RetryLog step SolverFailure done
294
- -> (ConflictSet -> ConflictMap -> RetryLog step SolverFailure done )
295
- -> RetryLog step SolverFailure done
313
+ retryNoSolution :: RetryLog SummarizedMessage SolverFailure done
314
+ -> (ConflictSet -> ConflictMap -> RetryLog SummarizedMessage SolverFailure done )
315
+ -> RetryLog SummarizedMessage SolverFailure done
296
316
retryNoSolution lg f = retry lg $ \ case
297
317
ExhaustiveSearch cs' cm' -> f cs' cm'
298
318
BackjumpLimitReached -> fromProgress (Fail BackjumpLimitReached )
0 commit comments