From 3e2bdb94ec0a87ed3a2c711c6aaffb1447b06dbf Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 8 Apr 2021 22:04:58 +0200 Subject: [PATCH] Don't store TyCtxt in UnwindContext --- src/allocator.rs | 4 ++-- src/debuginfo/unwind.rs | 18 +++++++++--------- src/driver/aot.rs | 2 +- src/lib.rs | 4 ++-- src/main_shim.rs | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index f60645a9f97..a09e3257786 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -11,7 +11,7 @@ use rustc_span::symbol::sym; pub(crate) fn codegen( tcx: TyCtxt<'_>, module: &mut impl Module, - unwind_context: &mut UnwindContext<'_>, + unwind_context: &mut UnwindContext, ) -> bool { let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { use rustc_middle::middle::dependency_format::Linkage; @@ -29,7 +29,7 @@ pub(crate) fn codegen( fn codegen_inner( module: &mut impl Module, - unwind_context: &mut UnwindContext<'_>, + unwind_context: &mut UnwindContext, kind: AllocatorKind, ) { let usize_ty = module.target_config().pointer_type(); diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 357c9fe6ed8..aeafc901fa5 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -5,17 +5,19 @@ use crate::prelude::*; use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa}; use gimli::write::{Address, CieId, EhFrame, FrameTable, Section}; +use gimli::RunTimeEndian; use crate::backend::WriteDebugInfo; -pub(crate) struct UnwindContext<'tcx> { - tcx: TyCtxt<'tcx>, +pub(crate) struct UnwindContext { + endian: RunTimeEndian, frame_table: FrameTable, cie_id: Option, } -impl<'tcx> UnwindContext<'tcx> { - pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self { +impl UnwindContext { + pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, pic_eh_frame: bool) -> Self { + let endian = super::target_endian(tcx); let mut frame_table = FrameTable::default(); let cie_id = if let Some(mut cie) = isa.create_systemv_cie() { @@ -28,7 +30,7 @@ impl<'tcx> UnwindContext<'tcx> { None }; - UnwindContext { tcx, frame_table, cie_id } + UnwindContext { endian, frame_table, cie_id } } pub(crate) fn add_function(&mut self, func_id: FuncId, context: &Context, isa: &dyn TargetIsa) { @@ -54,8 +56,7 @@ impl<'tcx> UnwindContext<'tcx> { } pub(crate) fn emit(self, product: &mut P) { - let mut eh_frame = - EhFrame::from(super::emit::WriterRelocate::new(super::target_endian(self.tcx))); + let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); if !eh_frame.0.writer.slice().is_empty() { @@ -75,8 +76,7 @@ impl<'tcx> UnwindContext<'tcx> { self, jit_module: &cranelift_jit::JITModule, ) -> Option { - let mut eh_frame = - EhFrame::from(super::emit::WriterRelocate::new(super::target_endian(self.tcx))); + let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); if eh_frame.0.writer.slice().is_empty() { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 1f731a756ed..db7d39fea4c 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -31,7 +31,7 @@ fn emit_module( kind: ModuleKind, module: ObjectModule, debug: Option>, - unwind_context: UnwindContext<'_>, + unwind_context: UnwindContext, ) -> ModuleCodegenResult { let mut product = module.finish(); diff --git a/src/lib.rs b/src/lib.rs index f94c9c1dab5..ee556bd2281 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,7 +124,7 @@ struct CodegenCx<'m, 'tcx: 'm> { global_asm: String, cached_context: Context, debug_context: Option>, - unwind_context: UnwindContext<'tcx>, + unwind_context: UnwindContext, } impl<'m, 'tcx> CodegenCx<'m, 'tcx> { @@ -151,7 +151,7 @@ impl<'m, 'tcx> CodegenCx<'m, 'tcx> { } } - fn finalize(self) -> (String, Option>, UnwindContext<'tcx>) { + fn finalize(self) -> (String, Option>, UnwindContext) { (self.global_asm, self.debug_context, self.unwind_context) } } diff --git a/src/main_shim.rs b/src/main_shim.rs index a6266f50776..22dc3f2bfe6 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -9,7 +9,7 @@ use crate::prelude::*; pub(crate) fn maybe_create_entry_wrapper( tcx: TyCtxt<'_>, module: &mut impl Module, - unwind_context: &mut UnwindContext<'_>, + unwind_context: &mut UnwindContext, ) { let (main_def_id, use_start_lang_item) = match tcx.entry_fn(LOCAL_CRATE) { Some((def_id, entry_ty)) => ( @@ -32,7 +32,7 @@ pub(crate) fn maybe_create_entry_wrapper( fn create_entry_fn( tcx: TyCtxt<'_>, m: &mut impl Module, - unwind_context: &mut UnwindContext<'_>, + unwind_context: &mut UnwindContext, rust_main_def_id: DefId, use_start_lang_item: bool, ) {