Revert "Revert "Merge CrateDisambiguator into StableCrateId""
This reverts commit 8176ab8bc1
.
This commit is contained in:
parent
9a27044f42
commit
489ad8b8b5
28 changed files with 116 additions and 193 deletions
|
@ -2,11 +2,9 @@ use rustc_ast::mut_visit::{visit_clobber, MutVisitor, *};
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, AttrVec, BlockCheckMode};
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
#[cfg(parallel_compiler)]
|
||||
use rustc_data_structures::jobserver;
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::registry::Registry;
|
||||
use rustc_metadata::dynamic_lib::DynamicLibrary;
|
||||
|
@ -18,7 +16,6 @@ use rustc_session::config::{self, CrateType};
|
|||
use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
|
||||
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
|
||||
use rustc_session::parse::CrateConfig;
|
||||
use rustc_session::CrateDisambiguator;
|
||||
use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session};
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::lev_distance::find_best_match_for_name;
|
||||
|
@ -487,39 +484,6 @@ pub fn get_codegen_sysroot(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {
|
||||
use std::hash::Hasher;
|
||||
|
||||
// The crate_disambiguator is a 128 bit hash. The disambiguator is fed
|
||||
// into various other hashes quite a bit (symbol hashes, incr. comp. hashes,
|
||||
// debuginfo type IDs, etc), so we don't want it to be too wide. 128 bits
|
||||
// should still be safe enough to avoid collisions in practice.
|
||||
let mut hasher = StableHasher::new();
|
||||
|
||||
let mut metadata = session.opts.cg.metadata.clone();
|
||||
// We don't want the crate_disambiguator to dependent on the order
|
||||
// -C metadata arguments, so sort them:
|
||||
metadata.sort();
|
||||
// Every distinct -C metadata value is only incorporated once:
|
||||
metadata.dedup();
|
||||
|
||||
hasher.write(b"metadata");
|
||||
for s in &metadata {
|
||||
// Also incorporate the length of a metadata string, so that we generate
|
||||
// different values for `-Cmetadata=ab -Cmetadata=c` and
|
||||
// `-Cmetadata=a -Cmetadata=bc`
|
||||
hasher.write_usize(s.len());
|
||||
hasher.write(s.as_bytes());
|
||||
}
|
||||
|
||||
// Also incorporate crate type, so that we don't get symbol conflicts when
|
||||
// linking against a library of the same name, if this is an executable.
|
||||
let is_exe = session.crate_types().contains(&CrateType::Executable);
|
||||
hasher.write(if is_exe { b"exe" } else { b"lib" });
|
||||
|
||||
CrateDisambiguator::from(hasher.finish::<Fingerprint>())
|
||||
}
|
||||
|
||||
pub(crate) fn check_attr_crate_type(
|
||||
sess: &Session,
|
||||
attrs: &[ast::Attribute],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue