spans are now indexmapped
This commit is contained in:
parent
5f079dd2ff
commit
77df2cd9a5
@ -30,7 +30,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn index(&self, index: stable_mir::ty::Span) -> &Self::Output {
|
fn index(&self, index: stable_mir::ty::Span) -> &Self::Output {
|
||||||
&self.spans[index.0]
|
&self.spans.get_index(index.0).unwrap().0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,6 @@ 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
|
|
||||||
if let Some(i) = self.alloc_ids.get(&aid) {
|
if let Some(i) = self.alloc_ids.get(&aid) {
|
||||||
return *i;
|
return *i;
|
||||||
} else {
|
} else {
|
||||||
@ -117,14 +116,13 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
for (i, &sp) in self.spans.iter().enumerate() {
|
if let Some(i) = self.spans.get(&span) {
|
||||||
if sp == span {
|
return *i;
|
||||||
return stable_mir::ty::Span(i);
|
} else {
|
||||||
}
|
let id = self.spans.len();
|
||||||
|
self.spans.insert(span, stable_mir::ty::Span(id));
|
||||||
|
stable_mir::ty::Span(id)
|
||||||
}
|
}
|
||||||
let id = self.spans.len();
|
|
||||||
self.spans.push(span);
|
|
||||||
stable_mir::ty::Span(id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +136,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
|
|||||||
tcx,
|
tcx,
|
||||||
def_ids: fx::FxIndexMap::default(),
|
def_ids: fx::FxIndexMap::default(),
|
||||||
alloc_ids: fx::FxIndexMap::default(),
|
alloc_ids: fx::FxIndexMap::default(),
|
||||||
spans: vec![],
|
spans: fx::FxIndexMap::default(),
|
||||||
types: vec![],
|
types: vec![],
|
||||||
},
|
},
|
||||||
f,
|
f,
|
||||||
|
@ -197,7 +197,7 @@ 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: FxIndexMap<AllocId, stable_mir::AllocId>,
|
pub alloc_ids: FxIndexMap<AllocId, stable_mir::AllocId>,
|
||||||
pub spans: Vec<rustc_span::Span>,
|
pub spans: FxIndexMap<rustc_span::Span, Span>,
|
||||||
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
|
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user