@@ -53,11 +53,16 @@ pub struct Context {
53
53
pub warnings : RcList < String > ,
54
54
}
55
55
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
+
56
62
/// 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`.
59
64
pub type Activations =
60
- im_rc:: HashMap < ( InternedString , SourceId , SemverCompatibility ) , ( Summary , usize ) > ;
65
+ im_rc:: HashMap < ( InternedString , SourceId , SemverCompatibility ) , ( Summary , ContextAge ) > ;
61
66
62
67
/// A type that represents when cargo treats two Versions as compatible.
63
68
/// Versions `a` and `b` are compatible if their left-most nonzero digit is the
@@ -110,7 +115,7 @@ impl Context {
110
115
/// Returns `true` if this summary with the given method is already activated.
111
116
pub fn flag_activated ( & mut self , summary : & Summary , method : & Method < ' _ > ) -> CargoResult < bool > {
112
117
let id = summary. package_id ( ) ;
113
- let activations_len = self . activations . len ( ) ;
118
+ let age : ContextAge = self . age ( ) ;
114
119
match self . activations . entry ( id. as_activations_key ( ) ) {
115
120
im_rc:: hashmap:: Entry :: Occupied ( o) => {
116
121
debug_assert_eq ! (
@@ -129,7 +134,7 @@ impl Context {
129
134
& * link
130
135
) ;
131
136
}
132
- v. insert ( ( summary. clone ( ) , activations_len ) ) ;
137
+ v. insert ( ( summary. clone ( ) , age ) ) ;
133
138
return Ok ( false ) ;
134
139
}
135
140
}
@@ -187,8 +192,15 @@ impl Context {
187
192
Ok ( deps)
188
193
}
189
194
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 > {
192
204
self . activations
193
205
. get ( & id. as_activations_key ( ) )
194
206
. and_then ( |( s, l) | if s. package_id ( ) == id { Some ( * l) } else { None } )
0 commit comments