From 259b21fd46b9ccfd084bce3ec8043543ca9ea61a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:25:26 +0000 Subject: [PATCH] Remove TyCtxt from DebugContext And explicitly thread it through everwhere it is needed. --- src/base.rs | 10 ++++++---- src/common.rs | 2 +- src/debuginfo/emit.rs | 2 +- src/debuginfo/line_info.rs | 10 +++++----- src/debuginfo/mod.rs | 13 ++++++------- src/driver/aot.rs | 2 +- src/driver/jit.rs | 8 ++++---- src/lib.rs | 8 ++++---- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/base.rs b/src/base.rs index b35f02e2d2d7..b2026f30d17a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -24,7 +24,7 @@ struct CodegenedFunction<'tcx> { pub(crate) fn codegen_and_compile_fn<'tcx>( tcx: TyCtxt<'tcx>, - cx: &mut crate::CodegenCx<'tcx>, + cx: &mut crate::CodegenCx, cached_context: &mut Context, module: &mut dyn Module, instance: Instance<'tcx>, @@ -35,12 +35,12 @@ pub(crate) fn codegen_and_compile_fn<'tcx>( let cached_func = std::mem::replace(&mut cached_context.func, Function::new()); let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance); - compile_fn(cx, cached_context, module, codegened_func); + compile_fn(tcx, cx, cached_context, module, codegened_func); } fn codegen_fn<'tcx>( tcx: TyCtxt<'tcx>, - cx: &mut crate::CodegenCx<'tcx>, + cx: &mut crate::CodegenCx, cached_func: Function, module: &mut dyn Module, instance: Instance<'tcx>, @@ -132,7 +132,8 @@ fn codegen_fn<'tcx>( } fn compile_fn<'tcx>( - cx: &mut crate::CodegenCx<'tcx>, + tcx: TyCtxt<'tcx>, + cx: &mut crate::CodegenCx, cached_context: &mut Context, module: &mut dyn Module, codegened_func: CodegenedFunction<'tcx>, @@ -214,6 +215,7 @@ fn compile_fn<'tcx>( cx.profiler.verbose_generic_activity("generate debug info").run(|| { if let Some(debug_context) = debug_context { debug_context.define_function( + tcx, codegened_func.func_id, codegened_func.symbol_name.name, context, diff --git a/src/common.rs b/src/common.rs index fc4953cea6fe..1adb64da8bd6 100644 --- a/src/common.rs +++ b/src/common.rs @@ -232,7 +232,7 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool { } pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { - pub(crate) cx: &'clif mut crate::CodegenCx<'tcx>, + pub(crate) cx: &'clif mut crate::CodegenCx, pub(crate) module: &'m mut dyn Module, pub(crate) tcx: TyCtxt<'tcx>, pub(crate) target_config: TargetFrontendConfig, // Cached from module diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index 589910ede968..9583cd2ec60f 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -9,7 +9,7 @@ use gimli::{RunTimeEndian, SectionId}; use super::object::WriteDebugInfo; use super::DebugContext; -impl DebugContext<'_> { +impl DebugContext { pub(crate) fn emit(&mut self, product: &mut ObjectProduct) { let unit_range_list_id = self.dwarf.unit.ranges.add(self.unit_range_list.clone()); let root = self.dwarf.unit.root(); diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index bbcb9591373d..de402a4c713f 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -96,9 +96,9 @@ fn line_program_add_file( } } -impl<'tcx> DebugContext<'tcx> { - pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) { - let loc = self.tcx.sess.source_map().lookup_char_pos(span.lo()); +impl DebugContext { + fn emit_location(&mut self, tcx: TyCtxt<'_>, entry_id: UnitEntryId, span: Span) { + let loc = tcx.sess.source_map().lookup_char_pos(span.lo()); let file_id = line_program_add_file( &mut self.dwarf.unit.line_program, @@ -115,13 +115,13 @@ impl<'tcx> DebugContext<'tcx> { pub(super) fn create_debug_lines( &mut self, + tcx: TyCtxt<'_>, symbol: usize, entry_id: UnitEntryId, context: &Context, function_span: Span, source_info_set: &indexmap::IndexSet, ) -> CodeOffset { - let tcx = self.tcx; let line_program = &mut self.dwarf.unit.line_program; let line_strings = &mut self.dwarf.line_strings; @@ -211,7 +211,7 @@ impl<'tcx> DebugContext<'tcx> { ); entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(func_end))); - self.emit_location(entry_id, function_span); + self.emit_location(tcx, entry_id, function_span); func_end } diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 9a0787508b75..3e42905c8406 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -16,17 +16,15 @@ use gimli::{Encoding, Format, LineEncoding, RunTimeEndian}; pub(crate) use emit::{DebugReloc, DebugRelocName}; pub(crate) use unwind::UnwindContext; -pub(crate) struct DebugContext<'tcx> { - tcx: TyCtxt<'tcx>, - +pub(crate) struct DebugContext { endian: RunTimeEndian, dwarf: DwarfUnit, unit_range_list: RangeList, } -impl<'tcx> DebugContext<'tcx> { - pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self { +impl DebugContext { + pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self { let encoding = Encoding { format: Format::Dwarf32, // FIXME this should be configurable @@ -92,11 +90,12 @@ impl<'tcx> DebugContext<'tcx> { root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0))); } - DebugContext { tcx, endian, dwarf, unit_range_list: RangeList(Vec::new()) } + DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) } } pub(crate) fn define_function( &mut self, + tcx: TyCtxt<'_>, func_id: FuncId, name: &str, context: &Context, @@ -116,7 +115,7 @@ impl<'tcx> DebugContext<'tcx> { entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id)); let end = - self.create_debug_lines(symbol, entry_id, context, function_span, source_info_set); + self.create_debug_lines(tcx, symbol, entry_id, context, function_span, source_info_set); self.unit_range_list.0.push(Range::StartLength { begin: Address::Symbol { symbol, addend: 0 }, diff --git a/src/driver/aot.rs b/src/driver/aot.rs index b2ad3cc4c4cd..971e5eeea873 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -120,7 +120,7 @@ fn emit_cgu( prof: &SelfProfilerRef, name: String, module: ObjectModule, - debug: Option>, + debug: Option, unwind_context: UnwindContext, global_asm_object_file: Option, ) -> Result { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 00e7263446b7..0e77e4004c0b 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -61,11 +61,11 @@ impl UnsafeMessage { } } -fn create_jit_module<'tcx>( - tcx: TyCtxt<'tcx>, +fn create_jit_module( + tcx: TyCtxt<'_>, backend_config: &BackendConfig, hotswap: bool, -) -> (JITModule, CodegenCx<'tcx>) { +) -> (JITModule, CodegenCx) { let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string()); let imported_symbols = load_imported_symbols_for_jit(tcx.sess, crate_info); @@ -353,7 +353,7 @@ fn load_imported_symbols_for_jit( fn codegen_shim<'tcx>( tcx: TyCtxt<'tcx>, - cx: &mut CodegenCx<'tcx>, + cx: &mut CodegenCx, cached_context: &mut Context, module: &mut JITModule, inst: Instance<'tcx>, diff --git a/src/lib.rs b/src/lib.rs index f4ffbbcf86ec..40dab58523c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,20 +122,20 @@ impl String> Drop for PrintOnPanic { /// The codegen context holds any information shared between the codegen of individual functions /// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). -struct CodegenCx<'tcx> { +struct CodegenCx { profiler: SelfProfilerRef, output_filenames: Arc, should_write_ir: bool, global_asm: String, inline_asm_index: Cell, - debug_context: Option>, + debug_context: Option, unwind_context: UnwindContext, cgu_name: Symbol, } -impl<'tcx> CodegenCx<'tcx> { +impl CodegenCx { fn new( - tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'_>, backend_config: BackendConfig, isa: &dyn TargetIsa, debug_info: bool,