Skip to content

Commit ac9ba10

Browse files
committed
hide the details of the type for Conflict
1 parent ed09ea2 commit ac9ba10

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

src/cargo/core/resolver/conflict_cache.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use std::collections::{BTreeMap, HashMap, HashSet};
22

33
use log::trace;
44

5-
use super::types::ConflictReason;
5+
use super::types::{Conflict, ConflictReason};
66
use crate::core::resolver::Context;
77
use crate::core::{Dependency, PackageId};
88

99
/// This is a trie for storing a large number of sets designed to
1010
/// efficiently see if any of the stored sets are a subset of a search set.
1111
enum ConflictStoreTrie {
1212
/// One of the stored sets.
13-
Leaf(BTreeMap<PackageId, ConflictReason>),
13+
Leaf(Conflict),
1414
/// A map from an element to a subtrie where
1515
/// all the sets in the subtrie contains that element.
1616
Node(BTreeMap<PackageId, ConflictStoreTrie>),
@@ -19,11 +19,7 @@ enum ConflictStoreTrie {
1919
impl ConflictStoreTrie {
2020
/// Finds any known set of conflicts, if any,
2121
/// which are activated in `cx` and pass the `filter` specified?
22-
fn find_conflicting(
23-
&self,
24-
cx: &Context,
25-
must_contain: Option<PackageId>,
26-
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
22+
fn find_conflicting(&self, cx: &Context, must_contain: Option<PackageId>) -> Option<&Conflict> {
2723
match self {
2824
ConflictStoreTrie::Leaf(c) => {
2925
if must_contain.is_none() {
@@ -57,11 +53,7 @@ impl ConflictStoreTrie {
5753
}
5854
}
5955

60-
fn insert(
61-
&mut self,
62-
mut iter: impl Iterator<Item = PackageId>,
63-
con: BTreeMap<PackageId, ConflictReason>,
64-
) {
56+
fn insert(&mut self, mut iter: impl Iterator<Item = PackageId>, con: Conflict) {
6557
if let Some(pid) = iter.next() {
6658
if let ConflictStoreTrie::Node(p) = self {
6759
p.entry(pid)
@@ -147,7 +139,7 @@ impl ConflictCache {
147139
cx: &Context,
148140
dep: &Dependency,
149141
must_contain: Option<PackageId>,
150-
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
142+
) -> Option<&Conflict> {
151143
let out = self
152144
.con_from_dep
153145
.get(dep)?
@@ -161,18 +153,14 @@ impl ConflictCache {
161153
}
162154
out
163155
}
164-
pub fn conflicting(
165-
&self,
166-
cx: &Context,
167-
dep: &Dependency,
168-
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
156+
pub fn conflicting(&self, cx: &Context, dep: &Dependency) -> Option<&Conflict> {
169157
self.find_conflicting(cx, dep, None)
170158
}
171159

172160
/// Adds to the cache a conflict of the form:
173161
/// `dep` is known to be unresolvable if
174162
/// all the `PackageId` entries are activated.
175-
pub fn insert(&mut self, dep: &Dependency, con: &BTreeMap<PackageId, ConflictReason>) {
163+
pub fn insert(&mut self, dep: &Dependency, con: &Conflict) {
176164
if con.values().any(|c| *c == ConflictReason::PublicDependency) {
177165
// TODO: needs more info for back jumping
178166
// for now refuse to cache it.

src/cargo/core/resolver/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::{BTreeMap, HashMap, HashSet};
1+
use std::collections::{HashMap, HashSet};
22
use std::rc::Rc;
33

44
// "ensure" seems to require "bail" be in scope (macro hygiene issue?).
@@ -12,7 +12,7 @@ use crate::util::CargoResult;
1212
use crate::util::Graph;
1313

1414
use super::errors::ActivateResult;
15-
use super::types::{ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer};
15+
use super::types::{Conflict, ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer};
1616

1717
pub use super::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
1818
pub use super::encode::{Metadata, WorkspaceResolve};
@@ -155,7 +155,7 @@ impl Context {
155155
pub fn is_conflicting(
156156
&self,
157157
parent: Option<PackageId>,
158-
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
158+
conflicting_activations: &Conflict,
159159
) -> bool {
160160
conflicting_activations
161161
.keys()

src/cargo/core/resolver/errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::BTreeMap;
21
use std::fmt;
32

43
use crate::core::{Dependency, PackageId, Registry, Summary};
@@ -8,7 +7,7 @@ use failure::{Error, Fail};
87
use semver;
98

109
use super::context::Context;
11-
use super::types::{Candidate, ConflictReason};
10+
use super::types::{Candidate, Conflict, ConflictReason};
1211

1312
/// Error during resolution providing a path of `PackageId`s.
1413
pub struct ResolveError {
@@ -73,7 +72,7 @@ pub(super) fn activation_error(
7372
registry: &mut dyn Registry,
7473
parent: &Summary,
7574
dep: &Dependency,
76-
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
75+
conflicting_activations: &Conflict,
7776
candidates: &[Candidate],
7877
config: Option<&Config>,
7978
) -> ResolveError {

src/cargo/core/resolver/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::util::errors::CargoResult;
6262
use crate::util::profile;
6363

6464
use self::context::{Activations, Context};
65-
use self::types::{Candidate, ConflictReason, DepsFrame, GraphNode};
65+
use self::types::{Candidate, Conflict, ConflictReason, DepsFrame, GraphNode};
6666
use self::types::{RcVecIter, RegistryQueryer, RemainingDeps, ResolverProgress};
6767

6868
pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
@@ -247,7 +247,7 @@ fn activate_deps_loop(
247247
//
248248
// This is a map of package ID to a reason why that packaged caused a
249249
// conflict for us.
250-
let mut conflicting_activations = BTreeMap::new();
250+
let mut conflicting_activations = Conflict::new();
251251

252252
// When backtracking we don't fully update `conflicting_activations`
253253
// especially for the cases that we didn't make a backtrack frame in the
@@ -680,7 +680,7 @@ struct BacktrackFrame {
680680
parent: Summary,
681681
dep: Dependency,
682682
features: Rc<Vec<InternedString>>,
683-
conflicting_activations: BTreeMap<PackageId, ConflictReason>,
683+
conflicting_activations: Conflict,
684684
}
685685

686686
/// A helper "iterator" used to extract candidates within a current `Context` of
@@ -727,7 +727,7 @@ impl RemainingCandidates {
727727
/// original list for the reason listed.
728728
fn next(
729729
&mut self,
730-
conflicting_prev_active: &mut BTreeMap<PackageId, ConflictReason>,
730+
conflicting_prev_active: &mut Conflict,
731731
cx: &Context,
732732
dep: &Dependency,
733733
parent: PackageId,
@@ -845,7 +845,7 @@ fn find_candidate(
845845
backtrack_stack: &mut Vec<BacktrackFrame>,
846846
parent: &Summary,
847847
backtracked: bool,
848-
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
848+
conflicting_activations: &Conflict,
849849
) -> Option<(Candidate, bool, BacktrackFrame)> {
850850
while let Some(mut frame) = backtrack_stack.pop() {
851851
let next = frame.remaining_candidates.next(

src/cargo/core/resolver/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::cmp::Ordering;
2-
use std::collections::{HashMap, HashSet};
2+
use std::collections::{BTreeMap, HashMap, HashSet};
33
use std::ops::Range;
44
use std::rc::Rc;
55
use std::time::{Duration, Instant};
@@ -425,6 +425,8 @@ impl ConflictReason {
425425
}
426426
}
427427

428+
pub type Conflict = BTreeMap<PackageId, ConflictReason>;
429+
428430
pub struct RcVecIter<T> {
429431
vec: Rc<Vec<T>>,
430432
rest: Range<usize>,

0 commit comments

Comments
 (0)