Skip to content

Commit c38ff3b

Browse files
committed
Remove all but one call site of prepare_outputs and fetch the value from the TyCtxt instead
1 parent ab75d77 commit c38ff3b

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

compiler/rustc_interface/src/passes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -968,12 +968,10 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
968968
pub fn start_codegen<'tcx>(
969969
codegen_backend: &dyn CodegenBackend,
970970
tcx: TyCtxt<'tcx>,
971-
outputs: &OutputFilenames,
972971
) -> Box<dyn Any> {
973972
info!("Pre-codegen\n{:?}", tcx.debug_stats());
974973

975-
let (metadata, need_metadata_module) =
976-
rustc_metadata::fs::encode_and_write_metadata(tcx, outputs);
974+
let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx);
977975

978976
let codegen = tcx.sess.time("codegen_crate", move || {
979977
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
@@ -989,7 +987,7 @@ pub fn start_codegen<'tcx>(
989987
info!("Post-codegen\n{:?}", tcx.debug_stats());
990988

991989
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
992-
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
990+
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
993991
tcx.sess.emit_err(CantEmitMIR { error });
994992
tcx.sess.abort_if_errors();
995993
}

compiler/rustc_interface/src/queries.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_span::symbol::sym;
2020
use std::any::Any;
2121
use std::cell::{Ref, RefCell, RefMut};
2222
use std::rc::Rc;
23+
use std::sync::Arc;
2324

2425
/// Represent the result of a query.
2526
///
@@ -214,7 +215,7 @@ impl<'tcx> Queries<'tcx> {
214215
pub fn global_ctxt(&'tcx self) -> Result<&Query<QueryContext<'tcx>>> {
215216
self.global_ctxt.compute(|| {
216217
let crate_name = self.crate_name()?.peek().clone();
217-
let outputs = self.prepare_outputs()?.peek().clone();
218+
let outputs = self.prepare_outputs()?.take();
218219
let dep_graph = self.dep_graph()?.peek().clone();
219220
let (krate, resolver, lint_store) = self.expansion()?.take();
220221
Ok(passes::create_global_ctxt(
@@ -235,7 +236,6 @@ impl<'tcx> Queries<'tcx> {
235236

236237
pub fn ongoing_codegen(&'tcx self) -> Result<&Query<Box<dyn Any>>> {
237238
self.ongoing_codegen.compute(|| {
238-
let outputs = self.prepare_outputs()?;
239239
self.global_ctxt()?.peek_mut().enter(|tcx| {
240240
tcx.analysis(()).ok();
241241

@@ -249,7 +249,7 @@ impl<'tcx> Queries<'tcx> {
249249
// Hook for UI tests.
250250
Self::check_for_rustc_errors_attr(tcx);
251251

252-
Ok(passes::start_codegen(&***self.codegen_backend(), tcx, &*outputs.peek()))
252+
Ok(passes::start_codegen(&***self.codegen_backend(), tcx))
253253
})
254254
})
255255
}
@@ -293,8 +293,10 @@ impl<'tcx> Queries<'tcx> {
293293
let codegen_backend = self.codegen_backend().clone();
294294

295295
let dep_graph = self.dep_graph()?.peek().clone();
296-
let prepare_outputs = self.prepare_outputs()?.take();
297-
let crate_hash = self.global_ctxt()?.peek_mut().enter(|tcx| tcx.crate_hash(LOCAL_CRATE));
296+
let (crate_hash, prepare_outputs) = self
297+
.global_ctxt()?
298+
.peek_mut()
299+
.enter(|tcx| (tcx.crate_hash(LOCAL_CRATE), tcx.output_filenames(()).clone()));
298300
let ongoing_codegen = self.ongoing_codegen()?.take();
299301

300302
Ok(Linker {
@@ -316,7 +318,7 @@ pub struct Linker {
316318

317319
// compilation outputs
318320
dep_graph: DepGraph,
319-
prepare_outputs: OutputFilenames,
321+
prepare_outputs: Arc<OutputFilenames>,
320322
crate_hash: Svh,
321323
ongoing_codegen: Box<dyn Any>,
322324
}

compiler/rustc_metadata/src/fs.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{encode_metadata, EncodedMetadata};
66
use rustc_data_structures::temp_dir::MaybeTempDir;
77
use rustc_hir::def_id::LOCAL_CRATE;
88
use rustc_middle::ty::TyCtxt;
9-
use rustc_session::config::{CrateType, OutputFilenames, OutputType};
9+
use rustc_session::config::{CrateType, OutputType};
1010
use rustc_session::output::filename_for_metadata;
1111
use rustc_session::Session;
1212
use tempfile::Builder as TempFileBuilder;
@@ -38,10 +38,7 @@ pub fn emit_wrapper_file(
3838
out_filename
3939
}
4040

41-
pub fn encode_and_write_metadata(
42-
tcx: TyCtxt<'_>,
43-
outputs: &OutputFilenames,
44-
) -> (EncodedMetadata, bool) {
41+
pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> (EncodedMetadata, bool) {
4542
#[derive(PartialEq, Eq, PartialOrd, Ord)]
4643
enum MetadataKind {
4744
None,
@@ -64,7 +61,8 @@ pub fn encode_and_write_metadata(
6461
.unwrap_or(MetadataKind::None);
6562

6663
let crate_name = tcx.crate_name(LOCAL_CRATE);
67-
let out_filename = filename_for_metadata(tcx.sess, crate_name.as_str(), outputs);
64+
let out_filename =
65+
filename_for_metadata(tcx.sess, crate_name.as_str(), tcx.output_filenames(()));
6866
// To avoid races with another rustc process scanning the output directory,
6967
// we need to write the file somewhere else and atomically move it to its
7068
// final destination, with an `fs::rename` call. In order for the rename to

compiler/rustc_mir_transform/src/dump_mir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::MirPass;
88
use rustc_middle::mir::write_mir_pretty;
99
use rustc_middle::mir::Body;
1010
use rustc_middle::ty::TyCtxt;
11-
use rustc_session::config::{OutputFilenames, OutputType};
11+
use rustc_session::config::OutputType;
1212

1313
pub struct Marker(pub &'static str);
1414

@@ -20,8 +20,8 @@ impl<'tcx> MirPass<'tcx> for Marker {
2020
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
2121
}
2222

23-
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
24-
let path = outputs.path(OutputType::Mir);
23+
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
24+
let path = tcx.output_filenames(()).path(OutputType::Mir);
2525
let mut f = io::BufWriter::new(File::create(&path)?);
2626
write_mir_pretty(tcx, None, &mut f)?;
2727
Ok(())

0 commit comments

Comments
 (0)