Skip to content

Commit 9461fd2

Browse files
committed
Remove TyCtxt parameter from emit_cgu
TyCtxt isn't available on background threads.
1 parent 4c0766c commit 9461fd2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/driver/aot.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ use std::sync::Arc;
77

88
use rustc_codegen_ssa::back::metadata::create_compressed_metadata_file;
99
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
10+
use rustc_data_structures::profiling::SelfProfilerRef;
1011
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1112
use rustc_metadata::EncodedMetadata;
1213
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
1314
use rustc_middle::mir::mono::{CodegenUnit, MonoItem};
1415
use rustc_session::cgu_reuse_tracker::CguReuse;
15-
use rustc_session::config::{DebugInfo, OutputType};
16+
use rustc_session::config::{DebugInfo, OutputFilenames, OutputType};
1617
use rustc_session::Session;
1718

1819
use cranelift_object::{ObjectBuilder, ObjectModule};
@@ -115,7 +116,8 @@ fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) ->
115116
}
116117

117118
fn emit_cgu(
118-
tcx: TyCtxt<'_>,
119+
output_filenames: &OutputFilenames,
120+
prof: &SelfProfilerRef,
119121
name: String,
120122
module: ObjectModule,
121123
debug: Option<DebugContext<'_>>,
@@ -130,7 +132,8 @@ fn emit_cgu(
130132

131133
unwind_context.emit(&mut product);
132134

133-
let module_regular = emit_module(tcx, product.object, ModuleKind::Regular, name.clone())?;
135+
let module_regular =
136+
emit_module(output_filenames, prof, product.object, ModuleKind::Regular, name.clone())?;
134137

135138
Ok(ModuleCodegenResult {
136139
module_regular,
@@ -146,12 +149,13 @@ fn emit_cgu(
146149
}
147150

148151
fn emit_module(
149-
tcx: TyCtxt<'_>,
152+
output_filenames: &OutputFilenames,
153+
prof: &SelfProfilerRef,
150154
object: cranelift_object::object::write::Object<'_>,
151155
kind: ModuleKind,
152156
name: String,
153157
) -> Result<CompiledModule, String> {
154-
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
158+
let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name));
155159
let mut file = match File::create(&tmp_file) {
156160
Ok(file) => file,
157161
Err(err) => return Err(format!("error creating object file: {}", err)),
@@ -161,7 +165,7 @@ fn emit_module(
161165
return Err(format!("error writing object file: {}", err));
162166
}
163167

164-
tcx.sess.prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());
168+
prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());
165169

166170
Ok(CompiledModule { name, kind, object: Some(tmp_file), dwarf_object: None, bytecode: None })
167171
}
@@ -288,7 +292,8 @@ fn module_codegen(
288292
let unwind_context = cx.unwind_context;
289293
tcx.sess.time("write object file", || {
290294
emit_cgu(
291-
tcx,
295+
&global_asm_config.output_filenames,
296+
&tcx.sess.prof,
292297
cgu.name().as_str().to_string(),
293298
module,
294299
debug_context,
@@ -361,7 +366,13 @@ pub(crate) fn run_aot(
361366
let mut product = allocator_module.finish();
362367
allocator_unwind_context.emit(&mut product);
363368

364-
match emit_module(tcx, product.object, ModuleKind::Allocator, "allocator_shim".to_owned()) {
369+
match emit_module(
370+
tcx.output_filenames(()),
371+
&tcx.sess.prof,
372+
product.object,
373+
ModuleKind::Allocator,
374+
"allocator_shim".to_owned(),
375+
) {
365376
Ok(allocator_module) => Some(allocator_module),
366377
Err(err) => tcx.sess.fatal(err),
367378
}

src/global_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
3636
pub(crate) struct GlobalAsmConfig {
3737
asm_enabled: bool,
3838
assembler: PathBuf,
39-
output_filenames: Arc<OutputFilenames>,
39+
pub(crate) output_filenames: Arc<OutputFilenames>,
4040
}
4141

4242
impl GlobalAsmConfig {

0 commit comments

Comments
 (0)