Skip to content

Commit

Permalink
spans are now indexmapped
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Oct 9, 2023
1 parent 5f079dd commit 77df2cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {

#[inline(always)]
fn index(&self, index: stable_mir::ty::Span) -> &Self::Output {
&self.spans[index.0]
&self.spans.get_index(index.0).unwrap().0
}
}

Expand Down Expand Up @@ -106,7 +106,6 @@ 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.get(&aid) {
return *i;
} else {
Expand All @@ -117,14 +116,13 @@ impl<'tcx> Tables<'tcx> {
}

pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span {
for (i, &sp) in self.spans.iter().enumerate() {
if sp == span {
return stable_mir::ty::Span(i);
}
if let Some(i) = self.spans.get(&span) {
return *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)
}
}

Expand All @@ -138,7 +136,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
tcx,
def_ids: fx::FxIndexMap::default(),
alloc_ids: fx::FxIndexMap::default(),
spans: vec![],
spans: fx::FxIndexMap::default(),
types: vec![],
},
f,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub struct Tables<'tcx> {
pub tcx: TyCtxt<'tcx>,
pub def_ids: FxIndexMap<DefId, stable_mir::DefId>,
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>>>,
}

Expand Down

0 comments on commit 77df2cd

Please sign in to comment.