Skip to content

Commit

Permalink
hide the details of the type for Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Feb 28, 2019
1 parent ed09ea2 commit ac9ba10
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
26 changes: 7 additions & 19 deletions src/cargo/core/resolver/conflict_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use std::collections::{BTreeMap, HashMap, HashSet};

use log::trace;

use super::types::ConflictReason;
use super::types::{Conflict, ConflictReason};
use crate::core::resolver::Context;
use crate::core::{Dependency, PackageId};

/// This is a trie for storing a large number of sets designed to
/// efficiently see if any of the stored sets are a subset of a search set.
enum ConflictStoreTrie {
/// One of the stored sets.
Leaf(BTreeMap<PackageId, ConflictReason>),
Leaf(Conflict),
/// A map from an element to a subtrie where
/// all the sets in the subtrie contains that element.
Node(BTreeMap<PackageId, ConflictStoreTrie>),
Expand All @@ -19,11 +19,7 @@ enum ConflictStoreTrie {
impl ConflictStoreTrie {
/// Finds any known set of conflicts, if any,
/// which are activated in `cx` and pass the `filter` specified?
fn find_conflicting(
&self,
cx: &Context,
must_contain: Option<PackageId>,
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
fn find_conflicting(&self, cx: &Context, must_contain: Option<PackageId>) -> Option<&Conflict> {
match self {
ConflictStoreTrie::Leaf(c) => {
if must_contain.is_none() {
Expand Down Expand Up @@ -57,11 +53,7 @@ impl ConflictStoreTrie {
}
}

fn insert(
&mut self,
mut iter: impl Iterator<Item = PackageId>,
con: BTreeMap<PackageId, ConflictReason>,
) {
fn insert(&mut self, mut iter: impl Iterator<Item = PackageId>, con: Conflict) {
if let Some(pid) = iter.next() {
if let ConflictStoreTrie::Node(p) = self {
p.entry(pid)
Expand Down Expand Up @@ -147,7 +139,7 @@ impl ConflictCache {
cx: &Context,
dep: &Dependency,
must_contain: Option<PackageId>,
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
) -> Option<&Conflict> {
let out = self
.con_from_dep
.get(dep)?
Expand All @@ -161,18 +153,14 @@ impl ConflictCache {
}
out
}
pub fn conflicting(
&self,
cx: &Context,
dep: &Dependency,
) -> Option<&BTreeMap<PackageId, ConflictReason>> {
pub fn conflicting(&self, cx: &Context, dep: &Dependency) -> Option<&Conflict> {
self.find_conflicting(cx, dep, None)
}

/// Adds to the cache a conflict of the form:
/// `dep` is known to be unresolvable if
/// all the `PackageId` entries are activated.
pub fn insert(&mut self, dep: &Dependency, con: &BTreeMap<PackageId, ConflictReason>) {
pub fn insert(&mut self, dep: &Dependency, con: &Conflict) {
if con.values().any(|c| *c == ConflictReason::PublicDependency) {
// TODO: needs more info for back jumping
// for now refuse to cache it.
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/resolver/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{HashMap, HashSet};
use std::rc::Rc;

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

use super::errors::ActivateResult;
use super::types::{ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer};
use super::types::{Conflict, ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer};

pub use super::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
pub use super::encode::{Metadata, WorkspaceResolve};
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Context {
pub fn is_conflicting(
&self,
parent: Option<PackageId>,
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
conflicting_activations: &Conflict,
) -> bool {
conflicting_activations
.keys()
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeMap;
use std::fmt;

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

use super::context::Context;
use super::types::{Candidate, ConflictReason};
use super::types::{Candidate, Conflict, ConflictReason};

/// Error during resolution providing a path of `PackageId`s.
pub struct ResolveError {
Expand Down Expand Up @@ -73,7 +72,7 @@ pub(super) fn activation_error(
registry: &mut dyn Registry,
parent: &Summary,
dep: &Dependency,
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
conflicting_activations: &Conflict,
candidates: &[Candidate],
config: Option<&Config>,
) -> ResolveError {
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::util::errors::CargoResult;
use crate::util::profile;

use self::context::{Activations, Context};
use self::types::{Candidate, ConflictReason, DepsFrame, GraphNode};
use self::types::{Candidate, Conflict, ConflictReason, DepsFrame, GraphNode};
use self::types::{RcVecIter, RegistryQueryer, RemainingDeps, ResolverProgress};

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

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

/// A helper "iterator" used to extract candidates within a current `Context` of
Expand Down Expand Up @@ -727,7 +727,7 @@ impl RemainingCandidates {
/// original list for the reason listed.
fn next(
&mut self,
conflicting_prev_active: &mut BTreeMap<PackageId, ConflictReason>,
conflicting_prev_active: &mut Conflict,
cx: &Context,
dep: &Dependency,
parent: PackageId,
Expand Down Expand Up @@ -845,7 +845,7 @@ fn find_candidate(
backtrack_stack: &mut Vec<BacktrackFrame>,
parent: &Summary,
backtracked: bool,
conflicting_activations: &BTreeMap<PackageId, ConflictReason>,
conflicting_activations: &Conflict,
) -> Option<(Candidate, bool, BacktrackFrame)> {
while let Some(mut frame) = backtrack_stack.pop() {
let next = frame.remaining_candidates.next(
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::ops::Range;
use std::rc::Rc;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -425,6 +425,8 @@ impl ConflictReason {
}
}

pub type Conflict = BTreeMap<PackageId, ConflictReason>;

pub struct RcVecIter<T> {
vec: Rc<Vec<T>>,
rest: Range<usize>,
Expand Down

0 comments on commit ac9ba10

Please sign in to comment.