|
1 | | -{-# LANGUAGE CPP #-} |
2 | | -#ifdef DEBUG_TRACETREE |
3 | | -{-# LANGUAGE FlexibleInstances #-} |
4 | | -{-# OPTIONS_GHC -Wno-orphans #-} |
5 | | -#endif |
6 | 1 | module Distribution.Solver.Modular.Solver |
7 | 2 | ( SolverConfig(..) |
8 | 3 | , solve |
@@ -46,16 +41,6 @@ import qualified Distribution.Solver.Modular.PSQ as PSQ |
46 | 41 | import Distribution.Simple.Setup (BooleanFlag(..)) |
47 | 42 | import Distribution.Solver.Types.Stage (Staged, Stage(..)) |
48 | 43 |
|
49 | | -#ifdef DEBUG_TRACETREE |
50 | | -import qualified Distribution.Solver.Modular.ConflictSet as CS |
51 | | -import qualified Distribution.Solver.Modular.WeightedPSQ as W |
52 | | -import Distribution.Solver.Modular.Version (showVer) |
53 | | - |
54 | | -import Debug.Trace.Tree (gtraceJson) |
55 | | -import Debug.Trace.Tree.Simple |
56 | | -import Debug.Trace.Tree.Generic |
57 | | -import Debug.Trace.Tree.Assoc (Assoc(..)) |
58 | | -#endif |
59 | 44 |
|
60 | 45 | -- | Various options for the modular solver. |
61 | 46 | data SolverConfig = SolverConfig { |
@@ -98,19 +83,14 @@ solve :: SolverConfig -- ^ solver parameters |
98 | 83 | -> RetryLog Message SolverFailure (Assignment, RevDepMap) |
99 | 84 | solve sc cinfo pkgConfigDB idx userPrefs userConstraints userGoals = |
100 | 85 | explorePhase . |
101 | | - traceTree "cycles.json" id . |
102 | 86 | detectCycles . |
103 | | - traceTree "heuristics.json" id . |
104 | 87 | trav ( |
105 | | - heuristicsPhase . |
106 | | - preferencesPhase . |
107 | | - validationPhase |
108 | | - ) . |
109 | | - traceTree "semivalidated.json" id . |
| 88 | + heuristicsPhase . |
| 89 | + preferencesPhase . |
| 90 | + validationPhase |
| 91 | + ) $ |
110 | 92 | validationCata . |
111 | | - traceTree "pruned.json" id . |
112 | | - trav prunePhase . |
113 | | - traceTree "build.json" id $ |
| 93 | + trav prunePhase $ |
114 | 94 | buildPhase |
115 | 95 | where |
116 | 96 | explorePhase = backjumpAndExplore (maxBackjumps sc) |
@@ -168,65 +148,6 @@ solve sc cinfo pkgConfigDB idx userPrefs userConstraints userGoals = |
168 | 148 | | asBool (reorderGoals sc) = P.preferReallyEasyGoalChoices |
169 | 149 | | otherwise = id {- P.firstGoal -} |
170 | 150 |
|
171 | | --- | Dump solver tree to a file (in debugging mode) |
172 | | --- |
173 | | --- This only does something if the @debug-tracetree@ configure argument was |
174 | | --- given; otherwise this is just the identity function. |
175 | | -{- FOURMOLU_DISABLE -} |
176 | | -traceTree :: |
177 | | -#ifdef DEBUG_TRACETREE |
178 | | - GSimpleTree a => |
179 | | -#endif |
180 | | - FilePath -- ^ Output file |
181 | | - -> (a -> a) -- ^ Function to summarize the tree before dumping |
182 | | - -> a -> a |
183 | | -#ifdef DEBUG_TRACETREE |
184 | | -traceTree = gtraceJson |
185 | | -#else |
186 | | -traceTree _ _ = id |
187 | | -#endif |
188 | | -{- FOURMOLU_ENABLE -} |
189 | | - |
190 | | -#ifdef DEBUG_TRACETREE |
191 | | -instance GSimpleTree (Tree d c) where |
192 | | - fromGeneric = go |
193 | | - where |
194 | | - go :: Tree d c -> SimpleTree |
195 | | - go (PChoice qpn _ _ psq) = Node "P" $ Assoc $ L.map (uncurry (goP qpn)) $ psqToList psq |
196 | | - go (FChoice _ _ _ _ _ _ psq) = Node "F" $ Assoc $ L.map (uncurry goFS) $ psqToList psq |
197 | | - go (SChoice _ _ _ _ psq) = Node "S" $ Assoc $ L.map (uncurry goFS) $ psqToList psq |
198 | | - go (GoalChoice _ psq) = Node "G" $ Assoc $ L.map (uncurry goG) $ PSQ.toList psq |
199 | | - go (Done _rdm _s) = Node "D" $ Assoc [] |
200 | | - go (Fail cs _reason) = Node "X" $ Assoc [("CS", Leaf $ goCS cs)] |
201 | | - |
202 | | - psqToList :: W.WeightedPSQ w k v -> [(k, v)] |
203 | | - psqToList = L.map (\(_, k, v) -> (k, v)) . W.toList |
204 | | - |
205 | | - -- Show package choice |
206 | | - goP :: QPN -> POption -> Tree d c -> (String, SimpleTree) |
207 | | - goP _ (POption (I _stage ver _loc) Nothing) subtree = (showVer ver, go subtree) |
208 | | - goP (Q _ pn) (POption _ (Just pp)) subtree = (showQPN (Q pp pn), go subtree) |
209 | | - |
210 | | - -- Show flag or stanza choice |
211 | | - goFS :: Bool -> Tree d c -> (String, SimpleTree) |
212 | | - goFS val subtree = (show val, go subtree) |
213 | | - |
214 | | - -- Show goal choice |
215 | | - goG :: Goal QPN -> Tree d c -> (String, SimpleTree) |
216 | | - goG (Goal var gr) subtree = (showVar var ++ " (" ++ shortGR gr ++ ")", go subtree) |
217 | | - |
218 | | - -- Variation on 'showGR' that produces shorter strings |
219 | | - -- (Actually, QGoalReason records more info than necessary: we only need |
220 | | - -- to know the variable that introduced the goal, not the value assigned |
221 | | - -- to that variable) |
222 | | - shortGR :: QGoalReason -> String |
223 | | - shortGR UserGoal = "user" |
224 | | - shortGR (DependencyGoal dr) = showDependencyReason dr |
225 | | - |
226 | | - -- Show conflict set |
227 | | - goCS :: ConflictSet -> String |
228 | | - goCS cs = "{" ++ (intercalate "," . L.map showVar . CS.toList $ cs) ++ "}" |
229 | | -#endif |
230 | 151 |
|
231 | 152 | -- | Replace all goal reasons with a dummy goal reason in the tree |
232 | 153 | -- |
|
0 commit comments