@@ -51,8 +51,8 @@ import qualified Distribution.Solver.Modular.WeightedPSQ as W
51
51
-- children's versions, and package option. 'addWeights' prepends the new
52
52
-- weights to the existing weights, which gives precedence to preferences that
53
53
-- are applied later.
54
- addWeights :: [PN -> [Ver ] -> POption -> Weight ] -> Tree d c -> Tree d c
55
- addWeights fs = trav go
54
+ addWeights :: [PN -> [Ver ] -> POption -> Weight ] -> EndoTreeTrav d c
55
+ addWeights fs = go
56
56
where
57
57
go :: TreeF d c (Tree d c ) -> TreeF d c (Tree d c )
58
58
go (PChoiceF qpn@ (Q _ pn) rdm x cs) =
@@ -69,21 +69,21 @@ addWeights fs = trav go
69
69
W. mapWeightsWithKey (\ k w -> weights k ++ w) cs)
70
70
go x = x
71
71
72
- addWeight :: (PN -> [Ver ] -> POption -> Weight ) -> Tree d c -> Tree d c
72
+ addWeight :: (PN -> [Ver ] -> POption -> Weight ) -> EndoTreeTrav d c
73
73
addWeight f = addWeights [f]
74
74
75
75
version :: POption -> Ver
76
76
version (POption (I v _) _) = v
77
77
78
78
-- | Prefer to link packages whenever possible.
79
- preferLinked :: Tree d c -> Tree d c
79
+ preferLinked :: EndoTreeTrav d c
80
80
preferLinked = addWeight (const (const linked))
81
81
where
82
82
linked (POption _ Nothing ) = 1
83
83
linked (POption _ (Just _)) = 0
84
84
85
85
-- Works by setting weights on choice nodes. Also applies stanza preferences.
86
- preferPackagePreferences :: (PN -> PackagePreferences ) -> Tree d c -> Tree d c
86
+ preferPackagePreferences :: (PN -> PackagePreferences ) -> EndoTreeTrav d c
87
87
preferPackagePreferences pcs =
88
88
preferPackageStanzaPreferences pcs .
89
89
addWeights [
@@ -127,8 +127,20 @@ preferPackagePreferences pcs =
127
127
128
128
-- | Traversal that tries to establish package stanza enable\/disable
129
129
-- preferences. Works by reordering the branches of stanza choices.
130
+ <<<<<<< HEAD : cabal- install/ cabal- install- solver/ src/ Distribution / Solver / Modular / Preference. hs
130
131
preferPackageStanzaPreferences :: (PN -> PackagePreferences ) -> Tree d c -> Tree d c
131
132
preferPackageStanzaPreferences pcs = trav go
133
+ =======
134
+ -- Note that this works on packages lower in the path as well as at the top level.
135
+ -- This is because stanza preferences apply to local packages only
136
+ -- and for local packages, a single version is fixed, which means
137
+ -- (for now) that all stanza preferences must be uniform at all levels.
138
+ -- Further, even when we can have multiple versions of the same package,
139
+ -- the build plan will be more efficient if we can attempt to keep
140
+ -- stanza preferences aligned at all levels.
141
+ preferPackageStanzaPreferences :: (PN -> PackagePreferences ) -> EndoTreeTrav d c
142
+ preferPackageStanzaPreferences pcs = go
143
+ >>>>>>> 67 c440a40 (solver: swap catas with recursion, fuse travs (# 7519 )): cabal- install- solver/ src/ Distribution / Solver / Modular / Preference. hs
132
144
where
133
145
go (SChoiceF qsn@ (SN (Q pp pn) s) rdm gr _tr ts)
134
146
| primaryPP pp && enableStanzaPref pn s =
@@ -221,9 +233,8 @@ processPackageConstraintS qpn s c b' (LabeledPackageConstraint (PackageConstrain
221
233
-- by selectively disabling choices that have been ruled out by global user
222
234
-- constraints.
223
235
enforcePackageConstraints :: M. Map PN [LabeledPackageConstraint ]
224
- -> Tree d c
225
- -> Tree d c
226
- enforcePackageConstraints pcs = trav go
236
+ -> EndoTreeTrav d c
237
+ enforcePackageConstraints pcs = go
227
238
where
228
239
go (PChoiceF qpn@ (Q _ pn) rdm gr ts) =
229
240
let c = varToConflictSet (P qpn)
@@ -268,8 +279,8 @@ enforcePackageConstraints pcs = trav go
268
279
--
269
280
-- This function does not enforce any of the constraints, since that is done by
270
281
-- 'enforcePackageConstraints'.
271
- enforceManualFlags :: M. Map PN [LabeledPackageConstraint ] -> Tree d c -> Tree d c
272
- enforceManualFlags pcs = trav go
282
+ enforceManualFlags :: M. Map PN [LabeledPackageConstraint ] -> EndoTreeTrav d c
283
+ enforceManualFlags pcs = go
273
284
where
274
285
go (FChoiceF qfn@ (FN (Q _ pn) fn) rdm gr tr Manual d ts) =
275
286
FChoiceF qfn rdm gr tr Manual d $
@@ -295,8 +306,8 @@ enforceManualFlags pcs = trav go
295
306
go x = x
296
307
297
308
-- | Require installed packages.
298
- requireInstalled :: (PN -> Bool ) -> Tree d c -> Tree d c
299
- requireInstalled p = trav go
309
+ requireInstalled :: (PN -> Bool ) -> EndoTreeTrav d c
310
+ requireInstalled p = go
300
311
where
301
312
go (PChoiceF v@ (Q _ pn) rdm gr cs)
302
313
| p pn = PChoiceF v rdm gr (W. mapWithKey installed cs)
@@ -319,8 +330,8 @@ requireInstalled p = trav go
319
330
-- they are, perhaps this should just result in trying to reinstall those other
320
331
-- packages as well. However, doing this all neatly in one pass would require to
321
332
-- change the builder, or at least to change the goal set after building.
322
- avoidReinstalls :: (PN -> Bool ) -> Tree d c -> Tree d c
323
- avoidReinstalls p = trav go
333
+ avoidReinstalls :: (PN -> Bool ) -> EndoTreeTrav d c
334
+ avoidReinstalls p = go
324
335
where
325
336
go (PChoiceF qpn@ (Q _ pn) rdm gr cs)
326
337
| p pn = PChoiceF qpn rdm gr disableReinstalls
@@ -337,8 +348,8 @@ avoidReinstalls p = trav go
337
348
go x = x
338
349
339
350
-- | Require all packages to be mentioned in a constraint or as a goal.
340
- onlyConstrained :: (PN -> Bool ) -> Tree d QGoalReason -> Tree d QGoalReason
341
- onlyConstrained p = trav go
351
+ onlyConstrained :: (PN -> Bool ) -> EndoTreeTrav d QGoalReason
352
+ onlyConstrained p = go
342
353
where
343
354
go (PChoiceF v@ (Q _ pn) _ gr _) | not (p pn)
344
355
= FailF
@@ -348,8 +359,8 @@ onlyConstrained p = trav go
348
359
= x
349
360
350
361
-- | Sort all goals using the provided function.
351
- sortGoals :: (Variable QPN -> Variable QPN -> Ordering ) -> Tree d c -> Tree d c
352
- sortGoals variableOrder = trav go
362
+ sortGoals :: (Variable QPN -> Variable QPN -> Ordering ) -> EndoTreeTrav d c
363
+ sortGoals variableOrder = go
353
364
where
354
365
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. sortByKeys goalOrder xs)
355
366
go x = x
@@ -365,8 +376,8 @@ sortGoals variableOrder = trav go
365
376
-- | Reduce the branching degree of the search tree by removing all choices
366
377
-- after the first successful choice at each level. The returned tree is the
367
378
-- minimal subtree containing the path to the first backjump.
368
- pruneAfterFirstSuccess :: Tree d c -> Tree d c
369
- pruneAfterFirstSuccess = trav go
379
+ pruneAfterFirstSuccess :: EndoTreeTrav d c
380
+ pruneAfterFirstSuccess = go
370
381
where
371
382
go (PChoiceF qpn rdm gr ts) = PChoiceF qpn rdm gr (W. takeUntil active ts)
372
383
go (FChoiceF qfn rdm gr w m d ts) = FChoiceF qfn rdm gr w m d (W. takeUntil active ts)
@@ -379,8 +390,8 @@ pruneAfterFirstSuccess = trav go
379
390
-- This is unnecessary for the default search strategy, because
380
391
-- it descends only into the first goal choice anyway,
381
392
-- but may still make sense to just reduce the tree size a bit.
382
- firstGoal :: Tree d c -> Tree d c
383
- firstGoal = trav go
393
+ firstGoal :: EndoTreeTrav d c
394
+ firstGoal = go
384
395
where
385
396
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. firstOnly xs)
386
397
go x = x
@@ -390,8 +401,8 @@ firstGoal = trav go
390
401
-- possible by pruning all other goals when base is available. In nearly
391
402
-- all cases, there's a single choice for the base package. Also, fixing
392
403
-- base early should lead to better error messages.
393
- preferBaseGoalChoice :: Tree d c -> Tree d c
394
- preferBaseGoalChoice = trav go
404
+ preferBaseGoalChoice :: EndoTreeTrav d c
405
+ preferBaseGoalChoice = go
395
406
where
396
407
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. filterIfAnyByKeys isBase xs)
397
408
go x = x
@@ -400,10 +411,17 @@ preferBaseGoalChoice = trav go
400
411
isBase (Goal (P (Q _pp pn)) _) = unPN pn == " base"
401
412
isBase _ = False
402
413
414
+ <<<<<<< HEAD : cabal- install/ cabal- install- solver/ src/ Distribution / Solver / Modular / Preference. hs
403
415
-- | Deal with setup dependencies after regular dependencies, so that we can
404
416
-- will link setup dependencies against package dependencies when possible
405
417
deferSetupChoices :: Tree d c -> Tree d c
406
418
deferSetupChoices = trav go
419
+ =======
420
+ -- | Deal with setup and build-tool-depends dependencies after regular dependencies,
421
+ -- so we will link setup/exe dependencies against package dependencies when possible
422
+ deferSetupExeChoices :: EndoTreeTrav d c
423
+ deferSetupExeChoices = go
424
+ >>>>>>> 67 c440a40 (solver: swap catas with recursion, fuse travs (# 7519 )): cabal- install- solver/ src/ Distribution / Solver / Modular / Preference. hs
407
425
where
408
426
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. preferByKeys noSetup xs)
409
427
go x = x
@@ -415,8 +433,8 @@ deferSetupChoices = trav go
415
433
-- | Transformation that tries to avoid making weak flag choices early.
416
434
-- Weak flags are trivial flags (not influencing dependencies) or such
417
435
-- flags that are explicitly declared to be weak in the index.
418
- deferWeakFlagChoices :: Tree d c -> Tree d c
419
- deferWeakFlagChoices = trav go
436
+ deferWeakFlagChoices :: EndoTreeTrav d c
437
+ deferWeakFlagChoices = go
420
438
where
421
439
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. prefer noWeakFlag (P. prefer noWeakStanza xs))
422
440
go x = x
@@ -435,8 +453,8 @@ deferWeakFlagChoices = trav go
435
453
-- function prunes all other goals. This transformation can help the solver find
436
454
-- a solution in fewer steps by allowing it to backtrack sooner when it is
437
455
-- exploring a subtree with no solutions. However, each step is more expensive.
438
- preferReallyEasyGoalChoices :: Tree d c -> Tree d c
439
- preferReallyEasyGoalChoices = trav go
456
+ preferReallyEasyGoalChoices :: EndoTreeTrav d c
457
+ preferReallyEasyGoalChoices = go
440
458
where
441
459
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P. filterIfAny zeroOrOneChoices xs)
442
460
go x = x
@@ -454,15 +472,21 @@ type EnforceSIR = Reader (Map (PI PN) QPN)
454
472
-- goal resolving to that instance (there may be other goals _linking_ to that
455
473
-- instance however).
456
474
enforceSingleInstanceRestriction :: Tree d c -> Tree d c
457
- enforceSingleInstanceRestriction = (`runReader` M. empty) . cata go
475
+ enforceSingleInstanceRestriction = (`runReader` M. empty) . go
458
476
where
459
- go :: TreeF d c ( EnforceSIR ( Tree d c )) -> EnforceSIR (Tree d c )
477
+ go :: Tree d c -> EnforceSIR (Tree d c )
460
478
461
479
-- We just verify package choices.
462
- go (PChoiceF qpn rdm gr cs) =
463
- PChoice qpn rdm gr <$> sequenceA (W. mapWithKey (goP qpn) cs)
464
- go _otherwise =
465
- innM _otherwise
480
+ go (PChoice qpn rdm gr cs) =
481
+ PChoice qpn rdm gr <$> sequenceA (W. mapWithKey (goP qpn) (fmap go cs))
482
+ go (FChoice qfn rdm y t m d ts) =
483
+ FChoice qfn rdm y t m d <$> traverse go ts
484
+ go (SChoice qsn rdm y t ts) =
485
+ SChoice qsn rdm y t <$> traverse go ts
486
+ go (GoalChoice rdm ts) =
487
+ GoalChoice rdm <$> traverse go ts
488
+ go x@ (Fail _ _) = return x
489
+ go x@ (Done _ _) = return x
466
490
467
491
-- The check proper
468
492
goP :: QPN -> POption -> EnforceSIR (Tree d c ) -> EnforceSIR (Tree d c )
0 commit comments