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.
This commit is contained in:
parent
816f958ac3
commit
9570023ce1
10 changed files with 100 additions and 82 deletions
|
@ -224,6 +224,13 @@ pub struct PerfStats {
|
|||
pub normalize_projection_ty: AtomicUsize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum MetadataKind {
|
||||
None,
|
||||
Uncompressed,
|
||||
Compressed,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
|
||||
self.miri_unleashed_features.lock().push((span, feature_gate));
|
||||
|
@ -287,6 +294,38 @@ impl Session {
|
|||
self.crate_types.get().unwrap().as_slice()
|
||||
}
|
||||
|
||||
pub fn needs_crate_hash(&self) -> bool {
|
||||
// Why is the crate hash needed for these configurations?
|
||||
// - debug_assertions: for the "fingerprint the result" check in
|
||||
// `rustc_query_system::query::plumbing::execute_job`.
|
||||
// - incremental: for query lookups.
|
||||
// - needs_metadata: for putting into crate metadata.
|
||||
// - instrument_coverage: for putting into coverage data (see
|
||||
// `hash_mir_source`).
|
||||
cfg!(debug_assertions)
|
||||
|| self.opts.incremental.is_some()
|
||||
|| self.needs_metadata()
|
||||
|| self.instrument_coverage()
|
||||
}
|
||||
|
||||
pub fn metadata_kind(&self) -> MetadataKind {
|
||||
self.crate_types()
|
||||
.iter()
|
||||
.map(|ty| match *ty {
|
||||
CrateType::Executable | CrateType::Staticlib | CrateType::Cdylib => {
|
||||
MetadataKind::None
|
||||
}
|
||||
CrateType::Rlib => MetadataKind::Uncompressed,
|
||||
CrateType::Dylib | CrateType::ProcMacro => MetadataKind::Compressed,
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(MetadataKind::None)
|
||||
}
|
||||
|
||||
pub fn needs_metadata(&self) -> bool {
|
||||
self.metadata_kind() != MetadataKind::None
|
||||
}
|
||||
|
||||
pub fn init_crate_types(&self, crate_types: Vec<CrateType>) {
|
||||
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue