@@ -4,17 +4,17 @@ use super::types::ConflictReason;
4
4
use core:: resolver:: Context ;
5
5
use core:: { Dependency , PackageId } ;
6
6
7
- /// This is a data structure for storing a large number of Sets designed to
7
+ /// This is a Trie for storing a large number of Sets designed to
8
8
/// efficiently see if any of the stored Sets are a subset of a search Set.
9
- enum ConflictStore {
9
+ enum ConflictStoreTrie {
10
10
/// a Leaf is one of the stored Sets.
11
11
Leaf ( BTreeMap < PackageId , ConflictReason > ) ,
12
- /// a Node is a map from an element to a subset of the stored data
13
- /// where all the Sets in the subset contains that element.
14
- Node ( HashMap < PackageId , ConflictStore > ) ,
12
+ /// a Node is a map from an element to a subTrie where
13
+ /// all the Sets in the subTrie contains that element.
14
+ Node ( HashMap < PackageId , ConflictStoreTrie > ) ,
15
15
}
16
16
17
- impl ConflictStore {
17
+ impl ConflictStoreTrie {
18
18
/// Finds any known set of conflicts, if any,
19
19
/// which are activated in `cx` and pass the `filter` specified?
20
20
fn find_conflicting < F > (
@@ -26,26 +26,25 @@ impl ConflictStore {
26
26
for < ' r > F : Fn ( & ' r & BTreeMap < PackageId , ConflictReason > ) -> bool ,
27
27
{
28
28
match self {
29
- ConflictStore :: Leaf ( c) => {
29
+ ConflictStoreTrie :: Leaf ( c) => {
30
30
if filter ( & c) {
31
+ // is_conflicting checks that all the elements are active,
32
+ // but we have checked each one by the recursion of this function.
33
+ debug_assert ! ( cx. is_conflicting( None , c) ) ;
31
34
Some ( c)
32
35
} else {
33
36
None
34
37
}
35
38
}
36
- ConflictStore :: Node ( m) => {
39
+ ConflictStoreTrie :: Node ( m) => {
37
40
for ( pid, store) in m {
38
- // if the key is active then we need to check all of the corresponding subset,
39
- // but if it is not active then there is no way any of the corresponding subset
40
- // will be conflicting.
41
+ // if the key is active then we need to check all of the corresponding subTrie.
41
42
if cx. is_active ( pid) {
42
43
if let Some ( o) = store. find_conflicting ( cx, filter) {
43
- debug_assert ! ( cx. is_conflicting( None , o) ) ;
44
- // is_conflicting checks that all the elements are active,
45
- // but we have checked each one by the recursion of this function.
46
44
return Some ( o) ;
47
45
}
48
- }
46
+ } // else, if it is not active then there is no way any of the corresponding
47
+ // subTrie will be conflicting.
49
48
}
50
49
None
51
50
}
@@ -58,9 +57,9 @@ impl ConflictStore {
58
57
con : BTreeMap < PackageId , ConflictReason > ,
59
58
) {
60
59
if let Some ( pid) = iter. next ( ) {
61
- if let ConflictStore :: Node ( p) = self {
60
+ if let ConflictStoreTrie :: Node ( p) = self {
62
61
p. entry ( pid. clone ( ) )
63
- . or_insert_with ( || ConflictStore :: Node ( HashMap :: new ( ) ) )
62
+ . or_insert_with ( || ConflictStoreTrie :: Node ( HashMap :: new ( ) ) )
64
63
. insert ( iter, con) ;
65
64
} // else, We already have a subset of this in the ConflictStore
66
65
} else {
@@ -75,7 +74,14 @@ impl ConflictStore {
75
74
// 3. self is a Leaf that is in the same spot in the structure as
76
75
// the thing we are working on. So it is equivalent.
77
76
// We can replace it with `Leaf(con)`.
78
- * self = ConflictStore :: Leaf ( con)
77
+ if cfg ! ( debug_assertions) {
78
+ if let ConflictStoreTrie :: Leaf ( c) = self {
79
+ let a: Vec < _ > = con. keys ( ) . collect ( ) ;
80
+ let b: Vec < _ > = c. keys ( ) . collect ( ) ;
81
+ assert_eq ! ( a, b) ;
82
+ }
83
+ }
84
+ * self = ConflictStoreTrie :: Leaf ( con)
79
85
}
80
86
}
81
87
}
@@ -113,7 +119,7 @@ pub(super) struct ConflictCache {
113
119
// as a global cache which we never delete from. Any entry in this map is
114
120
// unconditionally true regardless of our resolution history of how we got
115
121
// here.
116
- con_from_dep : HashMap < Dependency , ConflictStore > ,
122
+ con_from_dep : HashMap < Dependency , ConflictStoreTrie > ,
117
123
// `dep_from_pid` is an inverse-index of `con_from_dep`.
118
124
// For every `PackageId` this lists the `Dependency`s that mention it in `dep_from_pid`.
119
125
dep_from_pid : HashMap < PackageId , HashSet < Dependency > > ,
@@ -153,7 +159,7 @@ impl ConflictCache {
153
159
pub fn insert ( & mut self , dep : & Dependency , con : & BTreeMap < PackageId , ConflictReason > ) {
154
160
self . con_from_dep
155
161
. entry ( dep. clone ( ) )
156
- . or_insert_with ( || ConflictStore :: Node ( HashMap :: new ( ) ) )
162
+ . or_insert_with ( || ConflictStoreTrie :: Node ( HashMap :: new ( ) ) )
157
163
. insert ( con. keys ( ) , con. clone ( ) ) ;
158
164
159
165
trace ! (
0 commit comments