Skip to content

Commit 77df2cd

Browse files
committed
spans are now indexmapped
1 parent 5f079dd commit 77df2cd

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
3030

3131
#[inline(always)]
3232
fn index(&self, index: stable_mir::ty::Span) -> &Self::Output {
33-
&self.spans[index.0]
33+
&self.spans.get_index(index.0).unwrap().0
3434
}
3535
}
3636

@@ -106,7 +106,6 @@ impl<'tcx> Tables<'tcx> {
106106
}
107107

108108
fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::AllocId {
109-
// FIXME: this becomes inefficient when we have too many ids
110109
if let Some(i) = self.alloc_ids.get(&aid) {
111110
return *i;
112111
} else {
@@ -117,14 +116,13 @@ impl<'tcx> Tables<'tcx> {
117116
}
118117

119118
pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span {
120-
for (i, &sp) in self.spans.iter().enumerate() {
121-
if sp == span {
122-
return stable_mir::ty::Span(i);
123-
}
119+
if let Some(i) = self.spans.get(&span) {
120+
return *i;
121+
} else {
122+
let id = self.spans.len();
123+
self.spans.insert(span, stable_mir::ty::Span(id));
124+
stable_mir::ty::Span(id)
124125
}
125-
let id = self.spans.len();
126-
self.spans.push(span);
127-
stable_mir::ty::Span(id)
128126
}
129127
}
130128

@@ -138,7 +136,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
138136
tcx,
139137
def_ids: fx::FxIndexMap::default(),
140138
alloc_ids: fx::FxIndexMap::default(),
141-
spans: vec![],
139+
spans: fx::FxIndexMap::default(),
142140
types: vec![],
143141
},
144142
f,

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub struct Tables<'tcx> {
197197
pub tcx: TyCtxt<'tcx>,
198198
pub def_ids: FxIndexMap<DefId, stable_mir::DefId>,
199199
pub alloc_ids: FxIndexMap<AllocId, stable_mir::AllocId>,
200-
pub spans: Vec<rustc_span::Span>,
200+
pub spans: FxIndexMap<rustc_span::Span, Span>,
201201
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
202202
}
203203

0 commit comments

Comments
 (0)