Skip to content

Commit 1da1348

Browse files
committed
Remove Queries::ongoing_codegen.
There's no need to store it in `Queries`. We can just use a local variable, because it's always used shortly after it's produced. The commit also removes the `tcx.analysis()` call in `ongoing_codegen`, because it's easy to ensure that's done beforehand. All this makes the dataflow within `run_compiler` easier to follow, at the cost of making one test slightly more verbose, which I think is a good tradeoff.
1 parent c696307 commit 1da1348

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn run_compiler(
424424
return early_exit();
425425
}
426426

427-
queries.ongoing_codegen()?;
427+
let ongoing_codegen = queries.ongoing_codegen()?;
428428

429429
if sess.opts.unstable_opts.print_type_sizes {
430430
sess.code_stats.print_type_sizes();
@@ -437,7 +437,7 @@ fn run_compiler(
437437
sess.code_stats.print_vtable_sizes(crate_name);
438438
}
439439

440-
let linker = queries.linker()?;
440+
let linker = queries.linker(ongoing_codegen)?;
441441
Ok(Some(linker))
442442
})?;
443443

compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ pub fn create_global_ctxt<'tcx>(
740740
})
741741
}
742742

743-
/// Runs the resolution, type-checking, region checking and other
744-
/// miscellaneous analysis passes on the crate.
743+
/// Runs the type-checking, region checking and other miscellaneous analysis
744+
/// passes on the crate.
745745
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
746746
rustc_passes::hir_id_validator::check_crate(tcx);
747747

compiler/rustc_interface/src/queries.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ pub struct Queries<'tcx> {
9393
dep_graph: Query<DepGraph>,
9494
// This just points to what's in `gcx_cell`.
9595
gcx: Query<&'tcx GlobalCtxt<'tcx>>,
96-
ongoing_codegen: Query<Box<dyn Any>>,
9796
}
9897

9998
impl<'tcx> Queries<'tcx> {
@@ -110,7 +109,6 @@ impl<'tcx> Queries<'tcx> {
110109
register_plugins: Default::default(),
111110
dep_graph: Default::default(),
112111
gcx: Default::default(),
113-
ongoing_codegen: Default::default(),
114112
}
115113
}
116114

@@ -249,23 +247,19 @@ impl<'tcx> Queries<'tcx> {
249247
})
250248
}
251249

252-
pub fn ongoing_codegen(&'tcx self) -> Result<QueryResult<'_, Box<dyn Any>>> {
253-
self.ongoing_codegen.compute(|| {
254-
self.global_ctxt()?.enter(|tcx| {
255-
tcx.analysis(()).ok();
250+
pub fn ongoing_codegen(&'tcx self) -> Result<Box<dyn Any>> {
251+
self.global_ctxt()?.enter(|tcx| {
252+
// Don't do code generation if there were any errors
253+
self.session().compile_status()?;
256254

257-
// Don't do code generation if there were any errors
258-
self.session().compile_status()?;
255+
// If we have any delayed bugs, for example because we created TyKind::Error earlier,
256+
// it's likely that codegen will only cause more ICEs, obscuring the original problem
257+
self.session().diagnostic().flush_delayed();
259258

260-
// If we have any delayed bugs, for example because we created TyKind::Error earlier,
261-
// it's likely that codegen will only cause more ICEs, obscuring the original problem
262-
self.session().diagnostic().flush_delayed();
259+
// Hook for UI tests.
260+
Self::check_for_rustc_errors_attr(tcx);
263261

264-
// Hook for UI tests.
265-
Self::check_for_rustc_errors_attr(tcx);
266-
267-
Ok(passes::start_codegen(&***self.codegen_backend(), tcx))
268-
})
262+
Ok(passes::start_codegen(&***self.codegen_backend(), tcx))
269263
})
270264
}
271265

@@ -303,7 +297,7 @@ impl<'tcx> Queries<'tcx> {
303297
}
304298
}
305299

306-
pub fn linker(&'tcx self) -> Result<Linker> {
300+
pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> {
307301
let sess = self.session().clone();
308302
let codegen_backend = self.codegen_backend().clone();
309303

@@ -314,7 +308,6 @@ impl<'tcx> Queries<'tcx> {
314308
tcx.dep_graph.clone(),
315309
)
316310
});
317-
let ongoing_codegen = self.ongoing_codegen()?.steal();
318311

319312
Ok(Linker {
320313
sess,

tests/run-make-fulldeps/issue-19371/foo.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
6363
};
6464

6565
interface::run_compiler(config, |compiler| {
66-
// This runs all the passes prior to linking, too.
67-
let linker = compiler.enter(|queries| queries.linker());
68-
if let Ok(linker) = linker {
69-
linker.link();
70-
}
66+
let linker = compiler.enter(|queries| {
67+
queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?;
68+
let ongoing_codegen = queries.ongoing_codegen()?;
69+
queries.linker(ongoing_codegen)
70+
});
71+
linker.unwrap().link();
7172
});
7273
}

0 commit comments

Comments
 (0)