diff --git a/Cargo.toml b/Cargo.toml index 8c3065fb1..2eb0a7d58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ url = "1.1" clap = "2.31.2" unicode-width = "0.1.5" openssl = { version = '0.10.11', optional = true } +im-rc = "12.1.0" # A noop dependency that changes in the Rust repository, it's a bit of a hack. # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` diff --git a/src/cargo/core/resolver/context.rs b/src/cargo/core/resolver/context.rs index 96fdfd40d..4a6629f93 100644 --- a/src/cargo/core/resolver/context.rs +++ b/src/cargo/core/resolver/context.rs @@ -5,6 +5,7 @@ use core::interning::InternedString; use core::{Dependency, FeatureValue, PackageId, SourceId, Summary}; use util::CargoResult; use util::Graph; +use im_rc; use super::errors::ActivateResult; use super::types::{ConflictReason, DepInfo, GraphNode, Method, RcList, RegistryQueryer}; @@ -19,12 +20,9 @@ pub use super::resolve::Resolve; // possible. #[derive(Clone)] pub struct Context { - // TODO: Both this and the two maps below are super expensive to clone. We should - // switch to persistent hash maps if we can at some point or otherwise - // make these much cheaper to clone in general. pub activations: Activations, - pub resolve_features: HashMap>>, - pub links: HashMap, + pub resolve_features: im_rc::HashMap>>, + pub links: im_rc::HashMap, // These are two cheaply-cloneable lists (O(1) clone) which are effectively // hash maps but are built up as "construction lists". We'll iterate these @@ -36,16 +34,16 @@ pub struct Context { pub warnings: RcList, } -pub type Activations = HashMap<(InternedString, SourceId), Rc>>; +pub type Activations = im_rc::HashMap<(InternedString, SourceId), Rc>>; impl Context { pub fn new() -> Context { Context { resolve_graph: RcList::new(), - resolve_features: HashMap::new(), - links: HashMap::new(), + resolve_features: im_rc::HashMap::new(), + links: im_rc::HashMap::new(), resolve_replacements: RcList::new(), - activations: HashMap::new(), + activations: im_rc::HashMap::new(), warnings: RcList::new(), } } diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index e7fcac41d..8359facea 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -62,6 +62,7 @@ extern crate termcolor; extern crate toml; extern crate unicode_width; extern crate url; +extern crate im_rc; use std::fmt;