Use IndexSet and keep full source info in set_debug_loc

This commit is contained in:
bjorn3 2019-01-19 12:18:39 +01:00
parent 6b5cbc540d
commit a12eef4d86
5 changed files with 24 additions and 20 deletions

1
Cargo.lock generated
View File

@ -597,6 +597,7 @@ dependencies = [
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"faerie 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "faerie 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gimli 0.16.1 (git+https://github.com/gimli-rs/gimli.git)", "gimli 0.16.1 (git+https://github.com/gimli-rs/gimli.git)",
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -29,6 +29,7 @@ tempfile = "3.0.4"
env_logger = "0.6" env_logger = "0.6"
gimli = { git = "https://github.com/gimli-rs/gimli.git" } gimli = { git = "https://github.com/gimli-rs/gimli.git" }
faerie = "0.7.1" faerie = "0.7.1"
indexmap = "1.0.2"
# Uncomment to use local checkout of cranelift # Uncomment to use local checkout of cranelift
#[patch."https://github.com/CraneStation/cranelift.git"] #[patch."https://github.com/CraneStation/cranelift.git"]

View File

@ -108,7 +108,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
clif_comments, clif_comments,
constants: &mut cx.ccx, constants: &mut cx.ccx,
caches: &mut cx.caches, caches: &mut cx.caches,
spans: Vec::new(), source_info_set: indexmap::IndexSet::new(),
}; };
// Step 6. Codegen function // Step 6. Codegen function
@ -116,7 +116,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
crate::abi::codegen_fn_prelude(&mut fx, start_ebb); crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
codegen_fn_content(&mut fx); codegen_fn_content(&mut fx);
}); });
let spans = fx.spans.clone(); let source_info_set = fx.source_info_set.clone();
// Step 7. Write function to file for debugging // Step 7. Write function to file for debugging
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@ -129,7 +129,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
cx.caches.context.func = func; cx.caches.context.func = func;
cx.module cx.module
.define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| { .define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| {
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &spans[..])); debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &source_info_set));
}) })
.unwrap(); .unwrap();
//let module = &mut cx.module; //let module = &mut cx.module;

View File

@ -539,7 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> {
pub clif_comments: crate::pretty_clif::CommentWriter, pub clif_comments: crate::pretty_clif::CommentWriter,
pub constants: &'a mut crate::constant::ConstantCx, pub constants: &'a mut crate::constant::ConstantCx,
pub caches: &'a mut Caches<'tcx>, pub caches: &'a mut Caches<'tcx>,
pub spans: Vec<Span>, pub source_info_set: indexmap::IndexSet<SourceInfo>,
} }
impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> { 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> {
} }
pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) { pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
// FIXME: record scope too let (index, _) = self.source_info_set.insert_full(source_info);
let index = self.spans.len() as u32; self.bcx.set_srcloc(SourceLoc::new(index as u32));
self.spans.push(source_info.span);
self.bcx.set_srcloc(SourceLoc::new(index));
} }
} }

View File

@ -36,14 +36,16 @@ pub struct DebugContext<'tcx> {
version: u16, version: u16,
address_size: u8, address_size: u8,
symbols: indexmap::IndexSet<String>,
strings: StringTable, strings: StringTable,
units: UnitTable, units: UnitTable,
unit_id: UnitId,
line_programs: LineProgramTable, line_programs: LineProgramTable,
global_line_program: LineProgramId,
range_lists: RangeListTable, range_lists: RangeListTable,
unit_id: UnitId,
global_line_program: LineProgramId,
unit_range_list: RangeList, unit_range_list: RangeList,
symbol_names: Vec<String>,
_dummy: PhantomData<&'tcx ()>, _dummy: PhantomData<&'tcx ()>,
} }
@ -115,14 +117,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
version, version,
address_size, address_size,
symbols: indexmap::IndexSet::new(),
strings, strings,
units, units,
unit_id,
line_programs, line_programs,
global_line_program,
range_lists, range_lists,
unit_id,
global_line_program,
unit_range_list: RangeList(Vec::new()), unit_range_list: RangeList(Vec::new()),
symbol_names: Vec::new(),
_dummy: PhantomData, _dummy: PhantomData,
} }
} }
@ -345,8 +350,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
name: &str, name: &str,
_sig: &Signature, _sig: &Signature,
) -> Self { ) -> Self {
let symbol = debug_context.symbol_names.len(); let (symbol, _) = debug_context.symbols.insert_full(name.to_string());
debug_context.symbol_names.push(name.to_string());
let unit = debug_context.units.get_mut(debug_context.unit_id); let unit = debug_context.units.get_mut(debug_context.unit_id);
// FIXME: add to appropriate scope intead of root // FIXME: add to appropriate scope intead of root
@ -382,7 +386,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
size: u32, size: u32,
context: &Context, context: &Context,
isa: &cranelift::codegen::isa::TargetIsa, isa: &cranelift::codegen::isa::TargetIsa,
spans: &[Span], source_info_set: &indexmap::IndexSet<SourceInfo>,
) { ) {
let unit = self.debug_context.units.get_mut(self.debug_context.unit_id); let unit = self.debug_context.units.get_mut(self.debug_context.unit_id);
// FIXME: add to appropriate scope intead of root // FIXME: add to appropriate scope intead of root
@ -439,8 +443,8 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
let srcloc = func.srclocs[inst]; let srcloc = func.srclocs[inst];
if !srcloc.is_default() { if !srcloc.is_default() {
let span = spans[srcloc.bits() as usize]; let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
create_row_for_span(tcx, line_program, offset as u64, span); create_row_for_span(tcx, line_program, offset as u64, source_info.span);
} else { } else {
create_row_for_span(tcx, line_program, offset as u64, self.mir_span); create_row_for_span(tcx, line_program, offset as u64, self.mir_span);
} }
@ -495,7 +499,7 @@ impl<'a, 'tcx> Writer for WriterRelocate<'a, 'tcx> {
self.relocs.push(DebugReloc { self.relocs.push(DebugReloc {
offset: offset as u32, offset: offset as u32,
size, size,
name: self.ctx.symbol_names[symbol].clone(), name: self.ctx.symbols.get_index(symbol).unwrap().clone(),
addend: addend as i64, addend: addend as i64,
}); });
self.write_word(0, size) self.write_word(0, size)