diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-03-03 17:02:11 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-03-08 09:30:22 +1100 |
| commit | 9570023ce13d0b2fb3d5b79ce9db57e6d28c31d1 (patch) | |
| tree | 36d1d334f8537e7db9745b2abf160e19591386dc /compiler/rustc_interface/src | |
| parent | 816f958ac3db8931855c42649809aead01d20d9b (diff) | |
| download | rust-9570023ce13d0b2fb3d5b79ce9db57e6d28c31d1.tar.gz rust-9570023ce13d0b2fb3d5b79ce9db57e6d28c31d1.zip | |
Only compute the crate hash when necessary.
The crate hash is needed: - if debug assertions are enabled, or - if incr. comp. is enabled, or - if metadata is being generated, or - if `-C instrumentation-coverage` is enabled. This commit avoids computing the crate hash when these conditions are all false, such as when doing a release build of a binary crate. It uses `Option` to store the hashes when needed, rather than computing them on demand, because some of them are needed in multiple places and computing them on demand would make compilation slower. The commit also removes `Owner::hash_without_bodies`. There is no benefit to pre-computing that one, it can just be done in the normal fashion.
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index a96cc95a384..58ad044b399 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -284,7 +284,11 @@ impl<'tcx> Queries<'tcx> { let codegen_backend = self.codegen_backend().clone(); let (crate_hash, prepare_outputs, dep_graph) = self.global_ctxt()?.enter(|tcx| { - (tcx.crate_hash(LOCAL_CRATE), tcx.output_filenames(()).clone(), tcx.dep_graph.clone()) + ( + if tcx.sess.needs_crate_hash() { Some(tcx.crate_hash(LOCAL_CRATE)) } else { None }, + tcx.output_filenames(()).clone(), + tcx.dep_graph.clone(), + ) }); let ongoing_codegen = self.ongoing_codegen()?.steal(); @@ -308,7 +312,8 @@ pub struct Linker { // compilation outputs dep_graph: DepGraph, prepare_outputs: Arc<OutputFilenames>, - crate_hash: Svh, + // Only present when incr. comp. is enabled. + crate_hash: Option<Svh>, ongoing_codegen: Box<dyn Any>, } |
