diff --git a/src/librustc/dep_graph/dep_tracking_map.rs b/src/librustc/dep_graph/dep_tracking_map.rs index 96607582203..103f8ef653c 100644 --- a/src/librustc/dep_graph/dep_tracking_map.rs +++ b/src/librustc/dep_graph/dep_tracking_map.rs @@ -61,15 +61,10 @@ pub fn get(&self, k: &M::Key) -> Option<&M::Value> { self.map.get(k) } - pub fn get_mut(&mut self, k: &M::Key) -> Option<&mut M::Value> { - self.read(k); - self.write(k); - self.map.get_mut(k) - } - - pub fn insert(&mut self, k: M::Key, v: M::Value) -> Option { + pub fn insert(&mut self, k: M::Key, v: M::Value) { self.write(&k); - self.map.insert(k, v) + let _old_value = self.map.insert(k, v); + // assert!(old_value.is_none()); } pub fn contains_key(&self, k: &M::Key) -> bool { @@ -80,17 +75,6 @@ pub fn contains_key(&self, k: &M::Key) -> bool { pub fn keys(&self) -> Vec { self.map.keys().cloned().collect() } - - /// Append `elem` to the vector stored for `k`, creating a new vector if needed. - /// This is considered a write to `k`. - pub fn push(&mut self, k: M::Key, elem: E) - where M: DepTrackingMapConfig> - { - self.write(&k); - self.map.entry(k) - .or_insert(Vec::new()) - .push(elem); - } } impl MemoizationMap for RefCell> { diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index c71255dcc7c..b7f90682c7c 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -139,7 +139,7 @@ fn visit_nested_body(&mut self, body_id: hir::BodyId) { let mir = tcx.alloc_mir(mir); let def_id = tcx.hir.local_def_id(src.item_id()); - assert!(tcx.mir_map.borrow_mut().insert(def_id, mir).is_none()); + tcx.mir_map.borrow_mut().insert(def_id, mir); }); let body = self.tcx.hir.body(body_id); diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index e9c710d2fec..4a96a5e960d 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -29,17 +29,19 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::{Item, ItemImpl}; use rustc::hir; +use rustc::util::nodemap::DefIdMap; mod builtin; mod orphan; mod overlap; mod unsafety; -struct CoherenceChecker<'a, 'tcx: 'a> { +struct CoherenceCollect<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, + inherent_impls: DefIdMap>, } -impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CoherenceChecker<'a, 'tcx> { +impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CoherenceCollect<'a, 'tcx> { fn visit_item(&mut self, item: &Item) { if let ItemImpl(..) = item.node { self.check_implementation(item) @@ -53,7 +55,7 @@ fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) { } } -impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { +impl<'a, 'tcx> CoherenceCollect<'a, 'tcx> { // Returns the def ID of the base type, if there is one. fn get_base_type_def_id(&self, span: Span, ty: Ty<'tcx>) -> Option { match ty.sty { @@ -80,9 +82,14 @@ fn check(&mut self) { // containing the inherent methods and extension methods. It also // builds up the trait inheritance table. self.tcx.visit_all_item_likes_in_krate(DepNode::CoherenceCheckImpl, self); + + // Transfer the inherent impl lists, not that they are known, into the tcx + for (ty_def_id, impl_def_ids) in self.inherent_impls.drain() { + self.tcx.inherent_impls.borrow_mut().insert(ty_def_id, impl_def_ids); + } } - fn check_implementation(&self, item: &Item) { + fn check_implementation(&mut self, item: &Item) { let tcx = self.tcx; let impl_did = tcx.hir.local_def_id(item.id); let self_type = tcx.item_type(impl_did); @@ -119,8 +126,10 @@ fn check_implementation(&self, item: &Item) { } } - fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) { - self.tcx.inherent_impls.borrow_mut().push(base_def_id, impl_def_id); + fn add_inherent_impl(&mut self, base_def_id: DefId, impl_def_id: DefId) { + self.inherent_impls.entry(base_def_id) + .or_insert(vec![]) + .push(impl_def_id); } fn add_trait_impl(&self, impl_trait_ref: ty::TraitRef<'tcx>, impl_def_id: DefId) { @@ -161,7 +170,7 @@ fn enforce_trait_manually_implementable(tcx: TyCtxt, sp: Span, trait_def_id: Def pub fn check_coherence(ccx: &CrateCtxt) { let _task = ccx.tcx.dep_graph.in_task(DepNode::Coherence); - CoherenceChecker { tcx: ccx.tcx }.check(); + CoherenceCollect { tcx: ccx.tcx, inherent_impls: DefIdMap() }.check(); unsafety::check(ccx.tcx); orphan::check(ccx.tcx); overlap::check(ccx.tcx); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index bbd0c805815..cb0a6cccb03 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -634,7 +634,7 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ccx.tcx.item_types.borrow_mut().insert(ty_f.did, tt); let def_id = ccx.tcx.hir.local_def_id(field.id); - ccx.tcx.item_types.borrow_mut().insert(def_id, tt); + assert_eq!(def_id, ty_f.did); ccx.tcx.generics.borrow_mut().insert(def_id, struct_generics); ccx.tcx.predicates.borrow_mut().insert(def_id, struct_predicates.clone()); } @@ -1283,9 +1283,7 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) items); trait_predicates.predicates.extend(assoc_predicates); - let prev_predicates = tcx.predicates.borrow_mut().insert(def_id, trait_predicates); - assert!(prev_predicates.is_none()); - + tcx.predicates.borrow_mut().insert(def_id, trait_predicates); return; fn predicates_for_associated_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, @@ -1592,9 +1590,7 @@ fn predicates_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, }; let predicates = ty_generic_predicates(ccx, generics, None, vec![], false); - let prev_predicates = ccx.tcx.predicates.borrow_mut().insert(def_id, - predicates.clone()); - assert!(prev_predicates.is_none()); + ccx.tcx.predicates.borrow_mut().insert(def_id, predicates.clone()); predicates } @@ -1617,8 +1613,7 @@ fn convert_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, }; let predicates = ty_generic_predicates(ccx, generics, None, vec![], false); - let prev_predicates = ccx.tcx.predicates.borrow_mut().insert(def_id, predicates); - assert!(prev_predicates.is_none()); + ccx.tcx.predicates.borrow_mut().insert(def_id, predicates); } // Is it marked with ?Sized diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index bdf1d0590bc..3ccec97d606 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -137,11 +137,9 @@ fn write(&self) { item_variances); } - let newly_added = tcx.item_variance_map - .borrow_mut() - .insert(item_def_id, Rc::new(item_variances)) - .is_none(); - assert!(newly_added); + tcx.item_variance_map + .borrow_mut() + .insert(item_def_id, Rc::new(item_variances)); } } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 0e09d34cc9b..253d7a25b63 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -178,12 +178,10 @@ fn add_inferreds_for_item(&mut self, // parameters". if self.num_inferred() == inferreds_on_entry { let item_def_id = self.tcx.hir.local_def_id(item_id); - let newly_added = self.tcx + self.tcx .item_variance_map .borrow_mut() - .insert(item_def_id, self.empty_variances.clone()) - .is_none(); - assert!(newly_added); + .insert(item_def_id, self.empty_variances.clone()); } }