1
- {-# LANGUAGE CPP #-}
2
- #ifdef DEBUG_CONFLICT_SETS
3
- {-# LANGUAGE ImplicitParams #-}
4
- #endif
5
1
-- | Conflict sets
6
2
--
7
3
-- Intended for double import
@@ -13,9 +9,6 @@ module Distribution.Solver.Modular.ConflictSet (
13
9
, Conflict (.. )
14
10
, ConflictMap
15
11
, OrderedVersionRange (.. )
16
- #ifdef DEBUG_CONFLICT_SETS
17
- , conflictSetOrigin
18
- #endif
19
12
, showConflictSet
20
13
, showCSSortedByFrequency
21
14
, showCSWithFrequency
@@ -44,36 +37,17 @@ import Data.Function (on)
44
37
import qualified Data.Map.Strict as M
45
38
import qualified Data.Set as S
46
39
47
- #ifdef DEBUG_CONFLICT_SETS
48
- import Data.Tree
49
- import GHC.Stack
50
- #endif
51
-
52
40
import Distribution.Solver.Modular.Var
53
41
import Distribution.Solver.Modular.Version
54
42
import Distribution.Solver.Types.PackagePath
55
43
56
44
-- | The set of variables involved in a solver conflict, each paired with
57
45
-- details about the conflict.
58
- data ConflictSet = CS {
46
+ newtype ConflictSet = CS {
59
47
-- | The set of variables involved in the conflict
60
- conflictSetToMap :: ! (Map (Var QPN ) (Set Conflict ))
61
-
62
- # ifdef DEBUG_CONFLICT_SETS
63
- -- | The origin of the conflict set
64
- --
65
- -- When @DEBUG_CONFLICT_SETS@ is defined @(-f debug-conflict-sets)@,
66
- -- we record the origin of every conflict set. For new conflict sets
67
- -- ('empty', 'fromVars', ..) we just record the 'CallStack'; for operations
68
- -- that construct new conflict sets from existing conflict sets ('union',
69
- -- 'filter', ..) we record the 'CallStack' to the call to the combinator
70
- -- as well as the 'CallStack's of the input conflict sets.
71
- --
72
- -- Requires @GHC >= 7.10@.
73
- , conflictSetOrigin :: Tree CallStack
74
- # endif
48
+ conflictSetToMap :: Map (Var QPN ) (Set Conflict )
75
49
}
76
- deriving (Show )
50
+ deriving (Eq , Show )
77
51
78
52
-- | More detailed information about how a conflict set variable caused a
79
53
-- conflict. This information can be used to determine whether a second value
@@ -112,12 +86,6 @@ newtype OrderedVersionRange = OrderedVersionRange VR
112
86
instance Ord OrderedVersionRange where
113
87
compare = compare `on` show
114
88
115
- instance Eq ConflictSet where
116
- (==) = (==) `on` conflictSetToMap
117
-
118
- instance Ord ConflictSet where
119
- compare = compare `on` conflictSetToMap
120
-
121
89
showConflictSet :: ConflictSet -> String
122
90
showConflictSet = intercalate " , " . map showVar . toList
123
91
@@ -147,76 +115,37 @@ toSet = M.keysSet . conflictSetToMap
147
115
toList :: ConflictSet -> [Var QPN ]
148
116
toList = M. keys . conflictSetToMap
149
117
150
- union ::
151
- #ifdef DEBUG_CONFLICT_SETS
152
- (? loc :: CallStack ) =>
153
- #endif
154
- ConflictSet -> ConflictSet -> ConflictSet
118
+ union :: ConflictSet -> ConflictSet -> ConflictSet
155
119
union cs cs' = CS {
156
120
conflictSetToMap = M. unionWith S. union (conflictSetToMap cs) (conflictSetToMap cs')
157
- #ifdef DEBUG_CONFLICT_SETS
158
- , conflictSetOrigin = Node ? loc (map conflictSetOrigin [cs, cs'])
159
- #endif
160
121
}
161
122
162
- unions ::
163
- #ifdef DEBUG_CONFLICT_SETS
164
- (? loc :: CallStack ) =>
165
- #endif
166
- [ConflictSet ] -> ConflictSet
123
+ unions :: [ConflictSet ] -> ConflictSet
167
124
unions css = CS {
168
125
conflictSetToMap = M. unionsWith S. union (map conflictSetToMap css)
169
- #ifdef DEBUG_CONFLICT_SETS
170
- , conflictSetOrigin = Node ? loc (map conflictSetOrigin css)
171
- #endif
172
126
}
173
127
174
- insert ::
175
- #ifdef DEBUG_CONFLICT_SETS
176
- (? loc :: CallStack ) =>
177
- #endif
178
- Var QPN -> ConflictSet -> ConflictSet
128
+ insert :: Var QPN -> ConflictSet -> ConflictSet
179
129
insert var cs = CS {
180
130
conflictSetToMap = M. insert var (S. singleton OtherConflict ) (conflictSetToMap cs)
181
- #ifdef DEBUG_CONFLICT_SETS
182
- , conflictSetOrigin = Node ? loc [conflictSetOrigin cs]
183
- #endif
184
131
}
185
132
186
133
delete :: Var QPN -> ConflictSet -> ConflictSet
187
134
delete var cs = CS {
188
135
conflictSetToMap = M. delete var (conflictSetToMap cs)
189
136
}
190
137
191
- empty ::
192
- #ifdef DEBUG_CONFLICT_SETS
193
- (? loc :: CallStack ) =>
194
- #endif
195
- ConflictSet
138
+ empty :: ConflictSet
196
139
empty = CS {
197
140
conflictSetToMap = M. empty
198
- #ifdef DEBUG_CONFLICT_SETS
199
- , conflictSetOrigin = Node ? loc []
200
- #endif
201
141
}
202
142
203
- singleton ::
204
- #ifdef DEBUG_CONFLICT_SETS
205
- (? loc :: CallStack ) =>
206
- #endif
207
- Var QPN -> ConflictSet
143
+ singleton :: Var QPN -> ConflictSet
208
144
singleton var = singletonWithConflict var OtherConflict
209
145
210
- singletonWithConflict ::
211
- #ifdef DEBUG_CONFLICT_SETS
212
- (? loc :: CallStack ) =>
213
- #endif
214
- Var QPN -> Conflict -> ConflictSet
146
+ singletonWithConflict :: Var QPN -> Conflict -> ConflictSet
215
147
singletonWithConflict var conflict = CS {
216
148
conflictSetToMap = M. singleton var (S. singleton conflict)
217
- #ifdef DEBUG_CONFLICT_SETS
218
- , conflictSetOrigin = Node ? loc []
219
- #endif
220
149
}
221
150
222
151
size :: ConflictSet -> Int
@@ -228,17 +157,9 @@ member var = M.member var . conflictSetToMap
228
157
lookup :: Var QPN -> ConflictSet -> Maybe (Set Conflict )
229
158
lookup var = M. lookup var . conflictSetToMap
230
159
231
- fromList ::
232
- #ifdef DEBUG_CONFLICT_SETS
233
- (? loc :: CallStack ) =>
234
- #endif
235
- [Var QPN ] -> ConflictSet
160
+ fromList :: [Var QPN ] -> ConflictSet
236
161
fromList vars = CS {
237
162
conflictSetToMap = M. fromList [(var, S. singleton OtherConflict ) | var <- vars]
238
- #ifdef DEBUG_CONFLICT_SETS
239
- , conflictSetOrigin = Node ? loc []
240
- #endif
241
163
}
242
164
243
165
type ConflictMap = Map (Var QPN ) Int
244
-
0 commit comments