@@ -53,11 +53,16 @@ pub struct Context {
5353 pub warnings : RcList < String > ,
5454}
5555
56+ /// When backtracking it can be useful to know how far back to go.
57+ /// The `ContextAge` of a `Context` is a monotonically increasing counter of the number
58+ /// of decisions made to get to this state.
59+ /// Several structures store the `ContextAge` when it was added, this lets use jump back.
60+ pub type ContextAge = usize ;
61+
5662/// find the activated version of a crate based on the name, source, and semver compatibility
57- /// This all so stores the size of `Activations` when that version was add as an "age".
58- /// This is used to speed up backtracking.
63+ /// This all so stores the `ContextAge`.
5964pub type Activations =
60- im_rc:: HashMap < ( InternedString , SourceId , SemverCompatibility ) , ( Summary , usize ) > ;
65+ im_rc:: HashMap < ( InternedString , SourceId , SemverCompatibility ) , ( Summary , ContextAge ) > ;
6166
6267/// A type that represents when cargo treats two Versions as compatible.
6368/// Versions `a` and `b` are compatible if their left-most nonzero digit is the
@@ -110,7 +115,7 @@ impl Context {
110115 /// Returns `true` if this summary with the given method is already activated.
111116 pub fn flag_activated ( & mut self , summary : & Summary , method : & Method < ' _ > ) -> CargoResult < bool > {
112117 let id = summary. package_id ( ) ;
113- let activations_len = self . activations . len ( ) ;
118+ let age : ContextAge = self . age ( ) ;
114119 match self . activations . entry ( id. as_activations_key ( ) ) {
115120 im_rc:: hashmap:: Entry :: Occupied ( o) => {
116121 debug_assert_eq ! (
@@ -129,7 +134,7 @@ impl Context {
129134 & * link
130135 ) ;
131136 }
132- v. insert ( ( summary. clone ( ) , activations_len ) ) ;
137+ v. insert ( ( summary. clone ( ) , age ) ) ;
133138 return Ok ( false ) ;
134139 }
135140 }
@@ -187,8 +192,15 @@ impl Context {
187192 Ok ( deps)
188193 }
189194
190- /// If the package is active returns the "age" (len of activations) when it was added
191- pub fn is_active ( & self , id : PackageId ) -> Option < usize > {
195+ /// Returns the `ContextAge` of this `Context`.
196+ /// For now we use (len of activations) as the age.
197+ /// See the `ContextAge` docs for more details.
198+ pub fn age ( & self ) -> ContextAge {
199+ self . activations . len ( )
200+ }
201+
202+ /// If the package is active returns the `ContextAge` when it was added
203+ pub fn is_active ( & self , id : PackageId ) -> Option < ContextAge > {
192204 self . activations
193205 . get ( & id. as_activations_key ( ) )
194206 . and_then ( |( s, l) | if s. package_id ( ) == id { Some ( * l) } else { None } )
0 commit comments