@@ -18,20 +18,17 @@ enum ConflictStoreTrie {
18
18
19
19
impl ConflictStoreTrie {
20
20
/// Finds any known set of conflicts, if any,
21
- /// which are activated in `cx ` and contain `PackageId` specified.
21
+ /// where all elements return some from `is_active ` and contain `PackageId` specified.
22
22
/// If more then one are activated, then it will return
23
23
/// one that will allow for the most jump-back.
24
- fn find_conflicting (
24
+ fn find (
25
25
& self ,
26
- cx : & Context ,
26
+ is_active : & impl Fn ( PackageId ) -> Option < usize > ,
27
27
must_contain : Option < PackageId > ,
28
28
) -> Option < ( & ConflictMap , usize ) > {
29
29
match self {
30
30
ConflictStoreTrie :: Leaf ( c) => {
31
31
if must_contain. is_none ( ) {
32
- // `is_conflicting` checks that all the elements are active,
33
- // but we have checked each one by the recursion of this function.
34
- debug_assert ! ( cx. is_conflicting( None , c) . is_some( ) ) ;
35
32
Some ( ( c, 0 ) )
36
33
} else {
37
34
// We did not find `must_contain`, so we need to keep looking.
@@ -45,9 +42,9 @@ impl ConflictStoreTrie {
45
42
. unwrap_or_else ( || m. range ( ..) )
46
43
{
47
44
// If the key is active, then we need to check all of the corresponding subtrie.
48
- if let Some ( age_this) = cx . is_active ( pid) {
45
+ if let Some ( age_this) = is_active ( pid) {
49
46
if let Some ( ( o, age_o) ) =
50
- store. find_conflicting ( cx , must_contain. filter ( |& f| f != pid) )
47
+ store. find ( is_active , must_contain. filter ( |& f| f != pid) )
51
48
{
52
49
let age = if must_contain == Some ( pid) {
53
50
// all the results will include `must_contain`
@@ -102,28 +99,6 @@ impl ConflictStoreTrie {
102
99
* self = ConflictStoreTrie :: Leaf ( con)
103
100
}
104
101
}
105
-
106
- fn contains ( & self , mut iter : impl Iterator < Item = PackageId > , con : & ConflictMap ) -> bool {
107
- match ( self , iter. next ( ) ) {
108
- ( ConflictStoreTrie :: Leaf ( c) , None ) => {
109
- if cfg ! ( debug_assertions) {
110
- let a: Vec < _ > = con. keys ( ) . collect ( ) ;
111
- let b: Vec < _ > = c. keys ( ) . collect ( ) ;
112
- assert_eq ! ( a, b) ;
113
- }
114
- true
115
- }
116
- ( ConflictStoreTrie :: Leaf ( _) , Some ( _) ) => false ,
117
- ( ConflictStoreTrie :: Node ( _) , None ) => false ,
118
- ( ConflictStoreTrie :: Node ( m) , Some ( n) ) => {
119
- if let Some ( next) = m. get ( & n) {
120
- next. contains ( iter, con)
121
- } else {
122
- false
123
- }
124
- }
125
- }
126
- }
127
102
}
128
103
129
104
pub ( super ) struct ConflictCache {
@@ -172,6 +147,17 @@ impl ConflictCache {
172
147
dep_from_pid : HashMap :: new ( ) ,
173
148
}
174
149
}
150
+ pub fn find (
151
+ & self ,
152
+ dep : & Dependency ,
153
+ is_active : & impl Fn ( PackageId ) -> Option < usize > ,
154
+ must_contain : Option < PackageId > ,
155
+ ) -> Option < & ConflictMap > {
156
+ self . con_from_dep
157
+ . get ( dep) ?
158
+ . find ( is_active, must_contain)
159
+ . map ( |( c, _) | c)
160
+ }
175
161
/// Finds any known set of conflicts, if any,
176
162
/// which are activated in `cx` and contain `PackageId` specified.
177
163
/// If more then one are activated, then it will return
@@ -182,14 +168,11 @@ impl ConflictCache {
182
168
dep : & Dependency ,
183
169
must_contain : Option < PackageId > ,
184
170
) -> Option < & ConflictMap > {
185
- let out = self
186
- . con_from_dep
187
- . get ( dep) ?
188
- . find_conflicting ( cx, must_contain)
189
- . map ( |( c, _) | c) ;
171
+ let out = self . find ( dep, & |id| cx. is_active ( id) , must_contain) ;
190
172
if cfg ! ( debug_assertions) {
191
- if let Some ( f) = must_contain {
192
- if let Some ( c) = & out {
173
+ if let Some ( c) = & out {
174
+ assert ! ( cx. is_conflicting( None , c) . is_some( ) ) ;
175
+ if let Some ( f) = must_contain {
193
176
assert ! ( c. contains_key( & f) ) ;
194
177
}
195
178
}
@@ -229,17 +212,6 @@ impl ConflictCache {
229
212
}
230
213
}
231
214
232
- /// Check if a conflict was previously added of the form:
233
- /// `dep` is known to be unresolvable if
234
- /// all the `PackageId` entries are activated.
235
- pub fn contains ( & self , dep : & Dependency , con : & ConflictMap ) -> bool {
236
- if let Some ( cst) = self . con_from_dep . get ( dep) {
237
- cst. contains ( con. keys ( ) . cloned ( ) , con)
238
- } else {
239
- false
240
- }
241
- }
242
-
243
215
pub fn dependencies_conflicting_with ( & self , pid : PackageId ) -> Option < & HashSet < Dependency > > {
244
216
self . dep_from_pid . get ( & pid)
245
217
}
0 commit comments