Don't include DefIndex in plugin- and proc-macro registrar fn symbol.

This commit is contained in:
Michael Woerister 2018-01-16 17:30:11 +01:00
parent da569fa9dd
commit 8756ef6385
5 changed files with 19 additions and 26 deletions

View File

@ -11,7 +11,7 @@
pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
use hir::def_id::{CrateNum, DefIndex};
use hir::def_id::CrateNum;
use ich::Fingerprint;
use lint;
@ -558,18 +558,16 @@ impl Session {
/// Returns the symbol name for the registrar function,
/// given the crate Svh and the function DefIndex.
pub fn generate_plugin_registrar_symbol(&self, disambiguator: CrateDisambiguator,
index: DefIndex)
pub fn generate_plugin_registrar_symbol(&self,
disambiguator: CrateDisambiguator)
-> String {
format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
index.to_proc_macro_index())
format!("__rustc_plugin_registrar_{}__", disambiguator.to_fingerprint().to_hex())
}
pub fn generate_derive_registrar_symbol(&self, disambiguator: CrateDisambiguator,
index: DefIndex)
pub fn generate_derive_registrar_symbol(&self,
disambiguator: CrateDisambiguator)
-> String {
format!("__rustc_derive_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
index.to_proc_macro_index())
format!("__rustc_derive_registrar_{}__", disambiguator.to_fingerprint().to_hex())
}
pub fn sysroot<'a>(&'a self) -> &'a Path {

View File

@ -15,7 +15,7 @@ use locator::{self, CratePaths};
use native_libs::relevant_lib;
use schema::CrateRoot;
use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
use rustc::hir::svh::Svh;
use rustc::middle::allocator::AllocatorKind;
use rustc::middle::cstore::DepKind;
@ -532,8 +532,7 @@ impl<'a> CrateLoader<'a> {
Err(err) => self.sess.span_fatal(span, &err),
};
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
root.macro_derive_registrar.unwrap());
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator);
let registrar = unsafe {
let sym = match lib.symbol(&sym) {
Ok(f) => f,
@ -588,7 +587,7 @@ impl<'a> CrateLoader<'a> {
pub fn find_plugin_registrar(&mut self,
span: Span,
name: &str)
-> Option<(PathBuf, CrateDisambiguator, DefIndex)> {
-> Option<(PathBuf, CrateDisambiguator)> {
let name = Symbol::intern(name);
let ekrate = self.read_extension_crate(span, name, name);
@ -603,11 +602,11 @@ impl<'a> CrateLoader<'a> {
}
let root = ekrate.metadata.get_root();
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
(Some(dylib), Some(reg)) => {
Some((dylib.to_path_buf(), root.disambiguator, reg))
match ekrate.dylib.as_ref() {
Some(dylib) => {
Some((dylib.to_path_buf(), root.disambiguator))
}
(None, Some(_)) => {
None => {
span_err!(self.sess, span, E0457,
"plugin `{}` only found in rlib format, but must be available \
in dylib format",
@ -616,7 +615,6 @@ impl<'a> CrateLoader<'a> {
// empty dylib.
None
}
_ => None,
}
}

View File

@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
let registrar = self.reader.find_plugin_registrar(span, name);
if let Some((lib, disambiguator, index)) = registrar {
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
if let Some((lib, disambiguator)) = registrar {
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator);
let fun = self.dylink_registrar(span, lib, symbol);
self.plugins.push(PluginRegistrar {
fun,

View File

@ -115,9 +115,8 @@ pub fn provide(providers: &mut Providers) {
if let Some(id) = tcx.sess.derive_registrar_fn.get() {
let def_id = tcx.hir.local_def_id(id);
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator();
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator);
local_crate.push((registrar, Some(def_id), SymbolExportLevel::C));
}

View File

@ -257,14 +257,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
if let Some(id) = node_id {
if tcx.sess.plugin_registrar_fn.get() == Some(id) {
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_plugin_registrar_symbol(disambiguator, idx);
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
}
if tcx.sess.derive_registrar_fn.get() == Some(id) {
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
return tcx.sess.generate_derive_registrar_symbol(disambiguator);
}
}