diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-06-01 16:32:13 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-06-07 10:37:45 +0200 |
| commit | 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3 (patch) | |
| tree | 474b75784053dd164149e0aafc979b23bb45ba3c /compiler/rustc_metadata | |
| parent | 6c5b6985fdce0921fe4ac0247fd026355953c1ea (diff) | |
| download | rust-8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.tar.gz rust-8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.zip | |
Revert "Merge CrateDisambiguator into StableCrateId"
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
Diffstat (limited to 'compiler/rustc_metadata')
| -rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/mod.rs | 2 |
6 files changed, 29 insertions, 16 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 42c32219aba..e9ae22f8ced 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -21,7 +21,7 @@ use rustc_session::config::{self, CrateType, ExternLocation}; use rustc_session::lint::{self, BuiltinLintDiagnostics, ExternDepSpec}; use rustc_session::output::validate_crate_name; use rustc_session::search_paths::PathKind; -use rustc_session::Session; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::edition::Edition; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -222,8 +222,10 @@ impl<'a> CrateLoader<'a> { metadata_loader: &'a MetadataLoaderDyn, local_crate_name: &str, ) -> Self { + let local_crate_stable_id = + StableCrateId::new(local_crate_name, sess.local_crate_disambiguator()); let mut stable_crate_ids = FxHashMap::default(); - stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE); + stable_crate_ids.insert(local_crate_stable_id, LOCAL_CRATE); CrateLoader { sess, @@ -325,14 +327,17 @@ impl<'a> CrateLoader<'a> { fn verify_no_symbol_conflicts(&self, root: &CrateRoot<'_>) -> Result<(), CrateError> { // Check for (potential) conflicts with the local crate - if self.sess.local_stable_crate_id() == root.stable_crate_id() { + if self.local_crate_name == root.name() + && self.sess.local_crate_disambiguator() == root.disambiguator() + { return Err(CrateError::SymbolConflictsCurrent(root.name())); } // Check for conflicts with any crate loaded so far let mut res = Ok(()); self.cstore.iter_crate_data(|_, other| { - if other.stable_crate_id() == root.stable_crate_id() && // same stable crate id + if other.name() == root.name() && // same crate-name + other.disambiguator() == root.disambiguator() && // same crate-disambiguator other.hash() != root.hash() { // but different SVH @@ -406,7 +411,7 @@ impl<'a> CrateLoader<'a> { None => (&source, &crate_root), }; let dlsym_dylib = dlsym_source.dylib.as_ref().expect("no dylib for a proc-macro crate"); - Some(self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.stable_crate_id())?) + Some(self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.disambiguator())?) } else { None }; @@ -659,7 +664,7 @@ impl<'a> CrateLoader<'a> { fn dlsym_proc_macros( &self, path: &Path, - stable_crate_id: StableCrateId, + disambiguator: CrateDisambiguator, ) -> Result<&'static [ProcMacro], CrateError> { // Make sure the path contains a / or the linker will search for it. let path = env::current_dir().unwrap().join(path); @@ -668,7 +673,7 @@ impl<'a> CrateLoader<'a> { Err(s) => return Err(CrateError::DlOpen(s)), }; - let sym = self.sess.generate_proc_macro_decls_symbol(stable_crate_id); + let sym = self.sess.generate_proc_macro_decls_symbol(disambiguator); let decls = unsafe { let sym = match lib.symbol(&sym) { Ok(f) => f, diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index b830c6b2481..6e736095090 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -226,7 +226,7 @@ use rustc_session::config::{self, CrateType}; use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc_session::search_paths::PathKind; use rustc_session::utils::CanonicalizedPath; -use rustc_session::{Session, StableCrateId}; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; @@ -787,7 +787,7 @@ pub fn find_plugin_registrar( metadata_loader: &dyn MetadataLoader, span: Span, name: Symbol, -) -> (PathBuf, StableCrateId) { +) -> (PathBuf, CrateDisambiguator) { match find_plugin_registrar_impl(sess, metadata_loader, name) { Ok(res) => res, // `core` is always available if we got as far as loading plugins. @@ -799,7 +799,7 @@ fn find_plugin_registrar_impl<'a>( sess: &'a Session, metadata_loader: &dyn MetadataLoader, name: Symbol, -) -> Result<(PathBuf, StableCrateId), CrateError> { +) -> Result<(PathBuf, CrateDisambiguator), CrateError> { info!("find plugin registrar `{}`", name); let mut locator = CrateLocator::new( sess, @@ -816,7 +816,7 @@ fn find_plugin_registrar_impl<'a>( match locator.maybe_load_library_crate()? { Some(library) => match library.source.dylib { - Some(dylib) => Ok((dylib.0, library.metadata.get_root().stable_crate_id())), + Some(dylib) => Ok((dylib.0, library.metadata.get_root().disambiguator())), None => Err(CrateError::NonDylibPlugin(name)), }, None => Err(locator.into_error()), diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 59fec58f0a1..52cb1e1996e 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -620,6 +620,10 @@ impl CrateRoot<'_> { self.name } + crate fn disambiguator(&self) -> CrateDisambiguator { + self.disambiguator + } + crate fn hash(&self) -> Svh { self.hash } @@ -1923,8 +1927,8 @@ impl CrateMetadata { self.root.name } - crate fn stable_crate_id(&self) -> StableCrateId { - self.root.stable_crate_id + crate fn disambiguator(&self) -> CrateDisambiguator { + self.root.disambiguator } crate fn hash(&self) -> Svh { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 9e615e48a3c..7cec4ce1d91 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -19,7 +19,7 @@ use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt, Visibility}; use rustc_session::utils::NativeLibKind; -use rustc_session::{Session, StableCrateId}; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::source_map::{Span, Spanned}; use rustc_span::symbol::Symbol; @@ -186,6 +186,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, } native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) } foreign_modules => { cdata.get_foreign_modules(tcx) } + crate_disambiguator => { cdata.root.disambiguator } crate_hash => { cdata.root.hash } crate_host_hash => { cdata.host_hash } crate_name => { cdata.root.name } @@ -488,8 +489,8 @@ impl CrateStore for CStore { self.get_crate_data(cnum).root.name } - fn stable_crate_id_untracked(&self, cnum: CrateNum) -> StableCrateId { - self.get_crate_data(cnum).root.stable_crate_id + fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator { + self.get_crate_data(cnum).root.disambiguator } fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0883977821a..76007398000 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -671,6 +671,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { extra_filename: tcx.sess.opts.cg.extra_filename.clone(), triple: tcx.sess.opts.target_triple.clone(), hash: tcx.crate_hash(LOCAL_CRATE), + disambiguator: tcx.sess.local_crate_disambiguator(), stable_crate_id: tcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(), panic_strategy: tcx.sess.panic_strategy(), edition: tcx.sess.edition(), diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 9a3a6284c36..04fe5cf5890 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -18,6 +18,7 @@ use rustc_middle::mir; use rustc_middle::ty::{self, ReprOptions, Ty}; use rustc_serialize::opaque::Encoder; use rustc_session::config::SymbolManglingVersion; +use rustc_session::CrateDisambiguator; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{Ident, Symbol}; @@ -201,6 +202,7 @@ crate struct CrateRoot<'tcx> { triple: TargetTriple, extra_filename: String, hash: Svh, + disambiguator: CrateDisambiguator, stable_crate_id: StableCrateId, panic_strategy: PanicStrategy, edition: Edition, |
