1
1
//! There are 2 sources of facts for the resolver:
2
2
//!
3
- //! - The Registry tells us for a Dependency what versions are available to fulfil it.
4
- //! - The Summary tells us for a version (and features) what dependencies need to be fulfilled for it to be activated.
3
+ //! - The ` Registry` tells us for a ` Dependency` what versions are available to fulfil it.
4
+ //! - The ` Summary` tells us for a version (and features) what dependencies need to be fulfilled for it to be activated.
5
5
//!
6
6
//! These constitute immutable facts, the soled ground truth that all other inference depends on.
7
7
//! Theoretically this could all be enumerated ahead of time, but we want to be lazy and only
8
8
//! look up things we need to. The compromise is to cache the results as they are computed.
9
9
//!
10
- //! The structs in this module impl that cache in all the gory details
10
+ //! This module impl that cache in all the gory details
11
11
12
12
use std:: cmp:: Ordering ;
13
13
use std:: collections:: { BTreeSet , HashMap , HashSet } ;
@@ -26,11 +26,18 @@ pub struct RegistryQueryer<'a> {
26
26
pub registry : & ' a mut ( dyn Registry + ' a ) ,
27
27
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
28
28
try_to_use : & ' a HashSet < PackageId > ,
29
- // If set the list of dependency candidates will be sorted by minimal
30
- // versions first. That allows `cargo update -Z minimal-versions` which will
31
- // specify minimum dependency versions to be used.
29
+ /// If set the list of dependency candidates will be sorted by minimal
30
+ /// versions first. That allows `cargo update -Z minimal-versions` which will
31
+ /// specify minimum dependency versions to be used.
32
32
minimal_versions : bool ,
33
- cache : HashMap < Dependency , Rc < Vec < Candidate > > > ,
33
+ /// a cache of `Candidate`s that fulfil a `Dependency`
34
+ registry_cache : HashMap < Dependency , Rc < Vec < Candidate > > > ,
35
+ /// a cache of `Dependency`s that are required for a `Summary`
36
+ summary_cache : HashMap <
37
+ ( Option < PackageId > , Summary , Method ) ,
38
+ Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > ,
39
+ > ,
40
+ /// all the cases we ended up using a supplied replacement
34
41
used_replacements : HashMap < PackageId , PackageId > ,
35
42
}
36
43
@@ -46,7 +53,8 @@ impl<'a> RegistryQueryer<'a> {
46
53
replacements,
47
54
try_to_use,
48
55
minimal_versions,
49
- cache : HashMap :: new ( ) ,
56
+ registry_cache : HashMap :: new ( ) ,
57
+ summary_cache : HashMap :: new ( ) ,
50
58
used_replacements : HashMap :: new ( ) ,
51
59
}
52
60
}
@@ -62,7 +70,7 @@ impl<'a> RegistryQueryer<'a> {
62
70
/// applied by performing a second query for what the override should
63
71
/// return.
64
72
pub fn query ( & mut self , dep : & Dependency ) -> CargoResult < Rc < Vec < Candidate > > > {
65
- if let Some ( out) = self . cache . get ( dep) . cloned ( ) {
73
+ if let Some ( out) = self . registry_cache . get ( dep) . cloned ( ) {
66
74
return Ok ( out) ;
67
75
}
68
76
@@ -182,27 +190,10 @@ impl<'a> RegistryQueryer<'a> {
182
190
183
191
let out = Rc :: new ( ret) ;
184
192
185
- self . cache . insert ( dep. clone ( ) , out. clone ( ) ) ;
193
+ self . registry_cache . insert ( dep. clone ( ) , out. clone ( ) ) ;
186
194
187
195
Ok ( out)
188
196
}
189
- }
190
-
191
- pub struct DepsCache < ' a > {
192
- pub registry : RegistryQueryer < ' a > ,
193
- cache : HashMap <
194
- ( Option < PackageId > , Summary , Method ) ,
195
- Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > ,
196
- > ,
197
- }
198
-
199
- impl < ' a > DepsCache < ' a > {
200
- pub fn new ( registry : RegistryQueryer < ' a > ) -> Self {
201
- DepsCache {
202
- registry,
203
- cache : HashMap :: new ( ) ,
204
- }
205
- }
206
197
207
198
/// Find out what dependencies will be added by activating `candidate`,
208
199
/// with features described in `method`. Then look up in the `registry`
@@ -217,7 +208,7 @@ impl<'a> DepsCache<'a> {
217
208
// if we have calculated a result before, then we can just return it,
218
209
// as it is a "pure" query of its arguments.
219
210
if let Some ( out) = self
220
- . cache
211
+ . summary_cache
221
212
. get ( & ( parent, candidate. clone ( ) , method. clone ( ) ) )
222
213
. cloned ( )
223
214
{
@@ -233,7 +224,7 @@ impl<'a> DepsCache<'a> {
233
224
let mut deps = deps
234
225
. into_iter ( )
235
226
. map ( |( dep, features) | {
236
- let candidates = self . registry . query ( & dep) ?;
227
+ let candidates = self . query ( & dep) ?;
237
228
Ok ( ( dep, candidates, features) )
238
229
} )
239
230
. collect :: < CargoResult < Vec < DepInfo > > > ( ) ?;
@@ -248,7 +239,7 @@ impl<'a> DepsCache<'a> {
248
239
249
240
// If we succeed we add the result to the cache so we can use it again next time.
250
241
// We dont cache the failure cases as they dont impl Clone.
251
- self . cache
242
+ self . summary_cache
252
243
. insert ( ( parent, candidate. clone ( ) , method. clone ( ) ) , out. clone ( ) ) ;
253
244
254
245
Ok ( out)
0 commit comments