Skip to content

Commit 69dda4e

Browse files
committed
Use IndexSet and keep full source info in set_debug_loc
1 parent 1c307f3 commit 69dda4e

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tempfile = "3.0.4"
2929
env_logger = "0.6"
3030
gimli = { git = "https://github.com/gimli-rs/gimli.git" }
3131
faerie = "0.7.1"
32+
indexmap = "1.0.2"
3233

3334
# Uncomment to use local checkout of cranelift
3435
#[patch."https://github.com/CraneStation/cranelift.git"]

src/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
108108
clif_comments,
109109
constants: &mut cx.ccx,
110110
caches: &mut cx.caches,
111-
spans: Vec::new(),
111+
source_info_set: indexmap::IndexSet::new(),
112112
};
113113

114114
// Step 6. Codegen function
115115
with_unimpl_span(fx.mir.span, || {
116116
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
117117
codegen_fn_content(&mut fx);
118118
});
119-
let spans = fx.spans.clone();
119+
let source_info_set = fx.source_info_set.clone();
120120

121121
// Step 7. Write function to file for debugging
122122
#[cfg(debug_assertions)]
@@ -129,7 +129,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
129129
cx.caches.context.func = func;
130130
cx.module
131131
.define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| {
132-
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &spans[..]));
132+
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &source_info_set));
133133
})
134134
.unwrap();
135135
//let module = &mut cx.module;

src/common.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> {
539539
pub clif_comments: crate::pretty_clif::CommentWriter,
540540
pub constants: &'a mut crate::constant::ConstantCx,
541541
pub caches: &'a mut Caches<'tcx>,
542-
pub spans: Vec<Span>,
542+
pub source_info_set: indexmap::IndexSet<SourceInfo>,
543543
}
544544

545545
impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> {
@@ -620,9 +620,7 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
620620
}
621621

622622
pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
623-
// FIXME: record scope too
624-
let index = self.spans.len() as u32;
625-
self.spans.push(source_info.span);
626-
self.bcx.set_srcloc(SourceLoc::new(index));
623+
let (index, _) = self.source_info_set.insert_full(source_info);
624+
self.bcx.set_srcloc(SourceLoc::new(index as u32));
627625
}
628626
}

src/debuginfo.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ pub struct DebugContext<'tcx> {
3636
version: u16,
3737
address_size: u8,
3838

39+
symbols: indexmap::IndexSet<String>,
40+
3941
strings: StringTable,
4042
units: UnitTable,
41-
unit_id: UnitId,
4243
line_programs: LineProgramTable,
43-
global_line_program: LineProgramId,
4444
range_lists: RangeListTable,
45+
46+
unit_id: UnitId,
47+
global_line_program: LineProgramId,
4548
unit_range_list: RangeList,
46-
symbol_names: Vec<String>,
4749

4850
_dummy: PhantomData<&'tcx ()>,
4951
}
@@ -115,14 +117,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
115117
version,
116118
address_size,
117119

120+
symbols: indexmap::IndexSet::new(),
121+
118122
strings,
119123
units,
120-
unit_id,
121124
line_programs,
122-
global_line_program,
123125
range_lists,
126+
127+
unit_id,
128+
global_line_program,
124129
unit_range_list: RangeList(Vec::new()),
125-
symbol_names: Vec::new(),
130+
126131
_dummy: PhantomData,
127132
}
128133
}
@@ -345,8 +350,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
345350
name: &str,
346351
_sig: &Signature,
347352
) -> Self {
348-
let symbol = debug_context.symbol_names.len();
349-
debug_context.symbol_names.push(name.to_string());
353+
let (symbol, _) = debug_context.symbols.insert_full(name.to_string());
350354

351355
let unit = debug_context.units.get_mut(debug_context.unit_id);
352356
// FIXME: add to appropriate scope intead of root
@@ -382,7 +386,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
382386
size: u32,
383387
context: &Context,
384388
isa: &cranelift::codegen::isa::TargetIsa,
385-
spans: &[Span],
389+
source_info_set: &indexmap::IndexSet<SourceInfo>,
386390
) {
387391
let unit = self.debug_context.units.get_mut(self.debug_context.unit_id);
388392
// FIXME: add to appropriate scope intead of root
@@ -439,8 +443,8 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
439443

440444
let srcloc = func.srclocs[inst];
441445
if !srcloc.is_default() {
442-
let span = spans[srcloc.bits() as usize];
443-
create_row_for_span(tcx, line_program, offset as u64, span);
446+
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
447+
create_row_for_span(tcx, line_program, offset as u64, source_info.span);
444448
} else {
445449
create_row_for_span(tcx, line_program, offset as u64, self.mir_span);
446450
}
@@ -495,7 +499,7 @@ impl<'a, 'tcx> Writer for WriterRelocate<'a, 'tcx> {
495499
self.relocs.push(DebugReloc {
496500
offset: offset as u32,
497501
size,
498-
name: self.ctx.symbol_names[symbol].clone(),
502+
name: self.ctx.symbols.get_index(symbol).unwrap().clone(),
499503
addend: addend as i64,
500504
});
501505
self.write_word(0, size)

0 commit comments

Comments
 (0)