Don't store TyCtxt in UnwindContext

This commit is contained in:
bjorn3 2021-04-08 22:04:58 +02:00
parent b09b8b1bd4
commit 3e2bdb94ec
5 changed files with 16 additions and 16 deletions

View File

@ -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();

View File

@ -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<CieId>,
}
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<P: WriteDebugInfo>(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<UnwindRegistry> {
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() {

View File

@ -31,7 +31,7 @@ fn emit_module(
kind: ModuleKind,
module: ObjectModule,
debug: Option<DebugContext<'_>>,
unwind_context: UnwindContext<'_>,
unwind_context: UnwindContext,
) -> ModuleCodegenResult {
let mut product = module.finish();

View File

@ -124,7 +124,7 @@ struct CodegenCx<'m, 'tcx: 'm> {
global_asm: String,
cached_context: Context,
debug_context: Option<DebugContext<'tcx>>,
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<DebugContext<'tcx>>, UnwindContext<'tcx>) {
fn finalize(self) -> (String, Option<DebugContext<'tcx>>, UnwindContext) {
(self.global_asm, self.debug_context, self.unwind_context)
}
}

View File

@ -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,
) {