11//! There are 2 sources of facts for the resolver:
22//!
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.
55//!
66//! These constitute immutable facts, the soled ground truth that all other inference depends on.
77//! Theoretically this could all be enumerated ahead of time, but we want to be lazy and only
88//! look up things we need to. The compromise is to cache the results as they are computed.
99//!
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
1111
1212use std:: cmp:: Ordering ;
1313use std:: collections:: { BTreeSet , HashMap , HashSet } ;
@@ -26,11 +26,18 @@ pub struct RegistryQueryer<'a> {
2626 pub registry : & ' a mut ( dyn Registry + ' a ) ,
2727 replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
2828 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.
3232 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
3441 used_replacements : HashMap < PackageId , PackageId > ,
3542}
3643
@@ -46,7 +53,8 @@ impl<'a> RegistryQueryer<'a> {
4653 replacements,
4754 try_to_use,
4855 minimal_versions,
49- cache : HashMap :: new ( ) ,
56+ registry_cache : HashMap :: new ( ) ,
57+ summary_cache : HashMap :: new ( ) ,
5058 used_replacements : HashMap :: new ( ) ,
5159 }
5260 }
@@ -62,7 +70,7 @@ impl<'a> RegistryQueryer<'a> {
6270 /// applied by performing a second query for what the override should
6371 /// return.
6472 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 ( ) {
6674 return Ok ( out) ;
6775 }
6876
@@ -182,27 +190,10 @@ impl<'a> RegistryQueryer<'a> {
182190
183191 let out = Rc :: new ( ret) ;
184192
185- self . cache . insert ( dep. clone ( ) , out. clone ( ) ) ;
193+ self . registry_cache . insert ( dep. clone ( ) , out. clone ( ) ) ;
186194
187195 Ok ( out)
188196 }
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- }
206197
207198 /// Find out what dependencies will be added by activating `candidate`,
208199 /// with features described in `method`. Then look up in the `registry`
@@ -217,7 +208,7 @@ impl<'a> DepsCache<'a> {
217208 // if we have calculated a result before, then we can just return it,
218209 // as it is a "pure" query of its arguments.
219210 if let Some ( out) = self
220- . cache
211+ . summary_cache
221212 . get ( & ( parent, candidate. clone ( ) , method. clone ( ) ) )
222213 . cloned ( )
223214 {
@@ -233,7 +224,7 @@ impl<'a> DepsCache<'a> {
233224 let mut deps = deps
234225 . into_iter ( )
235226 . map ( |( dep, features) | {
236- let candidates = self . registry . query ( & dep) ?;
227+ let candidates = self . query ( & dep) ?;
237228 Ok ( ( dep, candidates, features) )
238229 } )
239230 . collect :: < CargoResult < Vec < DepInfo > > > ( ) ?;
@@ -248,7 +239,7 @@ impl<'a> DepsCache<'a> {
248239
249240 // If we succeed we add the result to the cache so we can use it again next time.
250241 // We dont cache the failure cases as they dont impl Clone.
251- self . cache
242+ self . summary_cache
252243 . insert ( ( parent, candidate. clone ( ) , method. clone ( ) ) , out. clone ( ) ) ;
253244
254245 Ok ( out)
0 commit comments