Skip to content

Commit a979c9b

Browse files
committed
add a type alias for Age and add some comments
1 parent 5fea76b commit a979c9b

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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`.
5964
pub 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 })

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ fn find_candidate(
976976
// make any progress. As a result if we hit this condition we can
977977
// completely skip this backtrack frame and move on to the next.
978978
if let Some(age) = age {
979-
if frame.context.activations.len() > age {
979+
if frame.context.age() > age {
980980
trace!(
981981
"{} = \"{}\" skip as not solving {}: {:?}",
982982
frame.dep.package_name(),

src/cargo/core/resolver/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ impl ConflictReason {
425425
}
426426
}
427427

428+
/// A list of packages that have gotten in the way of resolving a dependency.
429+
/// If resolving a dependency fails then this represents an incompatibility,
430+
/// that dependency will never be resolve while all of these packages are active.
431+
/// This is useless if the packages can't be simultaneously activated for other reasons.
428432
pub type ConflictMap = BTreeMap<PackageId, ConflictReason>;
429433

430434
pub struct RcVecIter<T> {

0 commit comments

Comments
 (0)