Skip to content

Add some consistency checks for value interning in ty::ctxt. #30135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/librustc/middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ impl<'tcx> ctxt<'tcx> {
-> &'tcx ty::TraitDef<'tcx> {
let did = def.trait_ref.def_id;
let interned = self.arenas.trait_defs.alloc(def);
self.trait_defs.borrow_mut().insert(did, interned);
if let Some(prev) = self.trait_defs.borrow_mut().insert(did, interned) {
self.sess.bug(&format!("Tried to overwrite interned TraitDef: {:?}",
prev))
}
interned
}

Expand All @@ -425,7 +428,10 @@ impl<'tcx> ctxt<'tcx> {
let def = ty::AdtDefData::new(self, did, kind, variants);
let interned = self.arenas.adt_defs.alloc(def);
// this will need a transmute when reverse-variance is removed
self.adt_defs.borrow_mut().insert(did, interned);
if let Some(prev) = self.adt_defs.borrow_mut().insert(did, interned) {
self.sess.bug(&format!("Tried to overwrite interned AdtDef: {:?}",
prev))
}
interned
}

Expand All @@ -435,13 +441,20 @@ impl<'tcx> ctxt<'tcx> {
}

let interned = self.arenas.stability.alloc(stab);
self.stability_interner.borrow_mut().insert(interned, interned);
if let Some(prev) = self.stability_interner
.borrow_mut()
.insert(interned, interned) {
self.sess.bug(&format!("Tried to overwrite interned Stability: {:?}",
prev))
}
interned
}

pub fn store_free_region_map(&self, id: NodeId, map: FreeRegionMap) {
self.free_region_maps.borrow_mut()
.insert(id, map);
if self.free_region_maps.borrow_mut().insert(id, map).is_some() {
self.sess.bug(&format!("Tried to overwrite interned FreeRegionMap for NodeId {:?}",
id))
}
}

pub fn free_region_map(&self, id: NodeId) -> FreeRegionMap {
Expand Down