From 23110bdf763142b1c3ecd688ce95bf819f2da461 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:13:53 +0200 Subject: [PATCH] Remove output_filenames from CodegenCx --- src/base.rs | 6 ++++-- src/driver/aot.rs | 2 ++ src/driver/jit.rs | 13 ++++++++++++- src/lib.rs | 2 -- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index c6352ba6112f..57009b4ff8eb 100644 --- a/src/base.rs +++ b/src/base.rs @@ -12,6 +12,7 @@ use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv}; use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_session::config::OutputFilenames; use crate::constant::ConstantCx; use crate::debuginfo::{FunctionDebugContext, TypeDebugContext}; @@ -138,6 +139,7 @@ pub(crate) fn codegen_fn<'tcx>( pub(crate) fn compile_fn( cx: &mut crate::CodegenCx, profiler: &SelfProfilerRef, + output_filenames: &OutputFilenames, cached_context: &mut Context, module: &mut dyn Module, codegened_func: CodegenedFunction, @@ -215,7 +217,7 @@ pub(crate) fn compile_fn( if cx.should_write_ir { // Write optimized function to file for debugging crate::pretty_clif::write_clif_file( - &cx.output_filenames, + output_filenames, &codegened_func.symbol_name, "opt", module.isa(), @@ -225,7 +227,7 @@ pub(crate) fn compile_fn( if let Some(disasm) = &context.compiled_code().unwrap().vcode { crate::pretty_clif::write_ir_file( - &cx.output_filenames, + output_filenames, &format!("{}.vcode", codegened_func.symbol_name), |file| file.write_all(disasm.as_bytes()), ) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index b3f91fc84b0e..d2337c0059b8 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -594,6 +594,7 @@ fn module_codegen( let profiler = tcx.prof.clone(); let invocation_temp = tcx.sess.invocation_temp.clone(); + let output_filenames = tcx.output_filenames(()).clone(); OngoingModuleCodegen::Async(std::thread::spawn(move || { profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| { @@ -606,6 +607,7 @@ fn module_codegen( crate::base::compile_fn( &mut cx, &profiler, + &output_filenames, &mut cached_context, &mut module, codegened_func, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index b1f185b551c3..52551d7c0767 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -9,6 +9,7 @@ use rustc_codegen_ssa::CrateInfo; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::mono::MonoItem; use rustc_session::Session; +use rustc_session::config::OutputFilenames; use rustc_span::sym; use crate::CodegenCx; @@ -41,6 +42,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { tcx.dcx().fatal("can't jit non-executable crate"); } + let output_filenames = tcx.output_filenames(()); let (mut jit_module, mut cx) = create_jit_module(tcx); let mut cached_context = Context::new(); @@ -60,6 +62,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { MonoItem::Fn(inst) => { codegen_and_compile_fn( tcx, + &output_filenames, &mut cx, &mut cached_context, &mut jit_module, @@ -122,6 +125,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec) -> ! { fn codegen_and_compile_fn<'tcx>( tcx: TyCtxt<'tcx>, + output_filenames: &OutputFilenames, cx: &mut crate::CodegenCx, cached_context: &mut Context, module: &mut dyn Module, @@ -149,7 +153,14 @@ fn codegen_and_compile_fn<'tcx>( module, instance, ); - crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func); + crate::base::compile_fn( + cx, + &tcx.prof, + output_filenames, + cached_context, + module, + codegened_func, + ); }); } diff --git a/src/lib.rs b/src/lib.rs index 39bfeb1bf303..3e4351f660bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,6 @@ 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 { - output_filenames: Arc, should_write_ir: bool, global_asm: String, debug_context: Option, @@ -142,7 +141,6 @@ impl CodegenCx { None }; CodegenCx { - output_filenames: tcx.output_filenames(()).clone(), should_write_ir: crate::pretty_clif::should_write_ir(tcx), global_asm: String::new(), debug_context,