alloc id is indexmapped

This commit is contained in:
Oğuz Ağcayazı 2023-10-09 12:58:41 +03:00
parent 0f27c1b5b5
commit 5f079dd2ff
2 changed files with 9 additions and 8 deletions

View File

@ -107,12 +107,13 @@ impl<'tcx> Tables<'tcx> {
fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::AllocId {
// FIXME: this becomes inefficient when we have too many ids
if let Some(i) = self.alloc_ids.iter().position(|a| *a == aid) {
return stable_mir::AllocId(i);
};
let id = self.def_ids.len();
self.alloc_ids.push(aid);
stable_mir::AllocId(id)
if let Some(i) = self.alloc_ids.get(&aid) {
return *i;
} else {
let id = self.def_ids.len();
self.alloc_ids.insert(aid, stable_mir::AllocId(id));
stable_mir::AllocId(id)
}
}
pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span {
@ -136,7 +137,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
Tables {
tcx,
def_ids: fx::FxIndexMap::default(),
alloc_ids: vec![],
alloc_ids: fx::FxIndexMap::default(),
spans: vec![],
types: vec![],
},

View File

@ -196,7 +196,7 @@ impl<S, R: PartialEq> PartialEq<R> for MaybeStable<S, R> {
pub struct Tables<'tcx> {
pub tcx: TyCtxt<'tcx>,
pub def_ids: FxIndexMap<DefId, stable_mir::DefId>,
pub alloc_ids: Vec<AllocId>,
pub alloc_ids: FxIndexMap<AllocId, stable_mir::AllocId>,
pub spans: Vec<rustc_span::Span>,
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
}