From 21f0dfd014fc5996b6f88b9565656f63b2f65c99 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 11 Nov 2019 20:49:20 +0100 Subject: [PATCH] Monomorphize locals --- src/base.rs | 4 ++-- src/debuginfo.rs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/base.rs b/src/base.rs index bb0ffb51bcec..ed587bf739d5 100644 --- a/src/base.rs +++ b/src/base.rs @@ -17,7 +17,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( let mut debug_context = cx .debug_context .as_mut() - .map(|debug_context| FunctionDebugContext::new(debug_context, mir, func_id, &name, &sig)); + .map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name, &sig)); // Make FunctionBuilder let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig); @@ -92,7 +92,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( let isa = cx.module.isa(); debug_context .as_mut() - .map(|x| x.define(tcx, context, isa, &source_info_set)); + .map(|x| x.define(context, isa, &source_info_set)); // Clear context to make it usable for the next function context.clear(); diff --git a/src/debuginfo.rs b/src/debuginfo.rs index b3de6449ff4b..8de7ab673849 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -260,18 +260,20 @@ pub struct FunctionDebugContext<'a, 'tcx> { debug_context: &'a mut DebugContext<'tcx>, entry_id: UnitEntryId, symbol: usize, - mir_span: Span, - local_decls: rustc_index::vec::IndexVec>, + instance: Instance<'tcx>, + mir: &'tcx mir::Body<'tcx>, } impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { pub fn new( debug_context: &'a mut DebugContext<'tcx>, - mir: &'tcx Body, + instance: Instance<'tcx>, func_id: FuncId, name: &str, _sig: &Signature, ) -> Self { + let mir = debug_context.tcx.instance_mir(instance.def); + let (symbol, _) = debug_context.symbols.insert_full(func_id, name.to_string()); // FIXME: add to appropriate scope intead of root @@ -299,18 +301,19 @@ pub fn new( debug_context, entry_id, symbol, - mir_span: mir.span, - local_decls: mir.local_decls.clone(), + instance, + mir, } } pub fn define( &mut self, - tcx: TyCtxt, context: &Context, isa: &dyn cranelift::codegen::isa::TargetIsa, source_info_set: &indexmap::IndexSet<(Span, mir::SourceScope)>, ) { + let tcx = self.debug_context.tcx; + let line_program = &mut self.debug_context.dwarf.unit.line_program; line_program.begin_sequence(Some(Address::Symbol { @@ -351,7 +354,7 @@ pub fn define( let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap(); create_row_for_span(line_program, source_info.0); } else { - create_row_for_span(line_program, self.mir_span); + create_row_for_span(line_program, self.mir.span); } end = offset + size; } @@ -386,7 +389,12 @@ pub fn define( ); let live_ranges_id = self.debug_context.dwarf.unit.ranges.add(live_ranges); - let local_type = self.debug_context.dwarf_ty(self.local_decls[mir::Local::from_u32(value_label.as_u32())].ty); + let local_ty = tcx.subst_and_normalize_erasing_regions( + self.instance.substs, + ty::ParamEnv::reveal_all(), + &self.mir.local_decls[mir::Local::from_u32(value_label.as_u32())].ty, + ); + let local_type = self.debug_context.dwarf_ty(local_ty); let var_id = self .debug_context