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 { fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::AllocId {
// FIXME: this becomes inefficient when we have too many ids // FIXME: this becomes inefficient when we have too many ids
if let Some(i) = self.alloc_ids.iter().position(|a| *a == aid) { if let Some(i) = self.alloc_ids.get(&aid) {
return stable_mir::AllocId(i); return *i;
}; } else {
let id = self.def_ids.len(); let id = self.def_ids.len();
self.alloc_ids.push(aid); self.alloc_ids.insert(aid, stable_mir::AllocId(id));
stable_mir::AllocId(id) stable_mir::AllocId(id)
}
} }
pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span { 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 { Tables {
tcx, tcx,
def_ids: fx::FxIndexMap::default(), def_ids: fx::FxIndexMap::default(),
alloc_ids: vec![], alloc_ids: fx::FxIndexMap::default(),
spans: vec![], spans: vec![],
types: vec![], types: vec![],
}, },

View File

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