From a12eef4d863aa7ba43f145c41f1a16cf7032ce6d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Jan 2019 12:18:39 +0100 Subject: [PATCH] Use IndexSet and keep full source info in set_debug_loc --- Cargo.lock | 1 + Cargo.toml | 1 + src/base.rs | 6 +++--- src/common.rs | 8 +++----- src/debuginfo.rs | 28 ++++++++++++++++------------ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 828d4bb631f..c7d619dd36a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -597,6 +597,7 @@ dependencies = [ "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)", "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)", "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)", diff --git a/Cargo.toml b/Cargo.toml index 48714bd22c0..75f12add119 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ tempfile = "3.0.4" env_logger = "0.6" gimli = { git = "https://github.com/gimli-rs/gimli.git" } faerie = "0.7.1" +indexmap = "1.0.2" # Uncomment to use local checkout of cranelift #[patch."https://github.com/CraneStation/cranelift.git"] diff --git a/src/base.rs b/src/base.rs index 698a31312fc..0d130bb8a1b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -108,7 +108,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>( clif_comments, constants: &mut cx.ccx, caches: &mut cx.caches, - spans: Vec::new(), + source_info_set: indexmap::IndexSet::new(), }; // 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); 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 #[cfg(debug_assertions)] @@ -129,7 +129,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>( cx.caches.context.func = func; cx.module .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(); //let module = &mut cx.module; diff --git a/src/common.rs b/src/common.rs index ded45af6d5e..b88d439932a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -539,7 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> { pub clif_comments: crate::pretty_clif::CommentWriter, pub constants: &'a mut crate::constant::ConstantCx, pub caches: &'a mut Caches<'tcx>, - pub spans: Vec, + pub source_info_set: indexmap::IndexSet, } 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) { - // FIXME: record scope too - let index = self.spans.len() as u32; - self.spans.push(source_info.span); - self.bcx.set_srcloc(SourceLoc::new(index)); + let (index, _) = self.source_info_set.insert_full(source_info); + self.bcx.set_srcloc(SourceLoc::new(index as u32)); } } diff --git a/src/debuginfo.rs b/src/debuginfo.rs index 585271bb3cd..e86abcac0d6 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -36,14 +36,16 @@ pub struct DebugContext<'tcx> { version: u16, address_size: u8, + symbols: indexmap::IndexSet, + strings: StringTable, units: UnitTable, - unit_id: UnitId, line_programs: LineProgramTable, - global_line_program: LineProgramId, range_lists: RangeListTable, + + unit_id: UnitId, + global_line_program: LineProgramId, unit_range_list: RangeList, - symbol_names: Vec, _dummy: PhantomData<&'tcx ()>, } @@ -115,14 +117,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> { version, address_size, + symbols: indexmap::IndexSet::new(), + strings, units, - unit_id, line_programs, - global_line_program, range_lists, + + unit_id, + global_line_program, unit_range_list: RangeList(Vec::new()), - symbol_names: Vec::new(), + _dummy: PhantomData, } } @@ -345,8 +350,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> { name: &str, _sig: &Signature, ) -> Self { - let symbol = debug_context.symbol_names.len(); - debug_context.symbol_names.push(name.to_string()); + let (symbol, _) = debug_context.symbols.insert_full(name.to_string()); let unit = debug_context.units.get_mut(debug_context.unit_id); // FIXME: add to appropriate scope intead of root @@ -382,7 +386,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> { size: u32, context: &Context, isa: &cranelift::codegen::isa::TargetIsa, - spans: &[Span], + source_info_set: &indexmap::IndexSet, ) { let unit = self.debug_context.units.get_mut(self.debug_context.unit_id); // 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]; if !srcloc.is_default() { - let span = spans[srcloc.bits() as usize]; - create_row_for_span(tcx, line_program, offset as u64, span); + let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap(); + create_row_for_span(tcx, line_program, offset as u64, source_info.span); } else { 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 { offset: offset as u32, size, - name: self.ctx.symbol_names[symbol].clone(), + name: self.ctx.symbols.get_index(symbol).unwrap().clone(), addend: addend as i64, }); self.write_word(0, size)