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

View File

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

View File

@ -115,9 +115,8 @@ pub fn provide(providers: &mut Providers) {
if let Some(id) = tcx.sess.derive_registrar_fn.get() { if let Some(id) = tcx.sess.derive_registrar_fn.get() {
let def_id = tcx.hir.local_def_id(id); let def_id = tcx.hir.local_def_id(id);
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator(); 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)); 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 let Some(id) = node_id {
if tcx.sess.plugin_registrar_fn.get() == Some(id) { if tcx.sess.plugin_registrar_fn.get() == Some(id) {
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator(); 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) { if tcx.sess.derive_registrar_fn.get() == Some(id) {
let idx = def_id.index;
let disambiguator = tcx.sess.local_crate_disambiguator(); let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_derive_registrar_symbol(disambiguator, idx); return tcx.sess.generate_derive_registrar_symbol(disambiguator);
} }
} }