mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
alloc id is indexmapped
This commit is contained in:
parent
0f27c1b5b5
commit
5f079dd2ff
@ -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![],
|
||||||
},
|
},
|
||||||
|
@ -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>>>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user