Use () for plugin_registrar_fn.
This commit is contained in:
parent
829a9d33a9
commit
e9e1900af7
8 changed files with 20 additions and 37 deletions
|
@ -137,8 +137,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
||||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
|
if let Some(id) = tcx.plugin_registrar_fn(()) {
|
||||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
|
||||||
}
|
}
|
||||||
|
|
||||||
reachable_non_generics
|
reachable_non_generics
|
||||||
|
|
|
@ -822,9 +822,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||||
{
|
{
|
||||||
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
|
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
|
||||||
|
|
||||||
sess.time("looking_for_plugin_registrar", || {
|
sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
|
||||||
plugin::build::find_plugin_registrar(tcx)
|
|
||||||
});
|
|
||||||
|
|
||||||
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
|
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
|
||||||
|
|
||||||
|
|
|
@ -185,11 +185,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
}
|
}
|
||||||
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
|
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
|
||||||
foreign_modules => { cdata.get_foreign_modules(tcx) }
|
foreign_modules => { cdata.get_foreign_modules(tcx) }
|
||||||
plugin_registrar_fn => {
|
|
||||||
cdata.root.plugin_registrar_fn.map(|index| {
|
|
||||||
DefId { krate: def_id.krate, index }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
proc_macro_decls_static => {
|
proc_macro_decls_static => {
|
||||||
cdata.root.proc_macro_data.as_ref().map(|data| {
|
cdata.root.proc_macro_data.as_ref().map(|data| {
|
||||||
DefId {
|
DefId {
|
||||||
|
|
|
@ -653,7 +653,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
|
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
|
||||||
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
|
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
|
||||||
has_default_lib_allocator,
|
has_default_lib_allocator,
|
||||||
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
|
|
||||||
proc_macro_data,
|
proc_macro_data,
|
||||||
compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins),
|
compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins),
|
||||||
needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator),
|
needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator),
|
||||||
|
|
|
@ -209,7 +209,6 @@ crate struct CrateRoot<'tcx> {
|
||||||
has_global_allocator: bool,
|
has_global_allocator: bool,
|
||||||
has_panic_handler: bool,
|
has_panic_handler: bool,
|
||||||
has_default_lib_allocator: bool,
|
has_default_lib_allocator: bool,
|
||||||
plugin_registrar_fn: Option<DefIndex>,
|
|
||||||
|
|
||||||
crate_deps: Lazy<[CrateDep]>,
|
crate_deps: Lazy<[CrateDep]>,
|
||||||
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
|
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
|
||||||
|
|
|
@ -1204,7 +1204,7 @@ rustc_queries! {
|
||||||
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
|
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
|
||||||
desc { "looking up the entry function of a crate" }
|
desc { "looking up the entry function of a crate" }
|
||||||
}
|
}
|
||||||
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
|
query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
|
||||||
desc { "looking up the plugin registrar for a crate" }
|
desc { "looking up the plugin registrar for a crate" }
|
||||||
}
|
}
|
||||||
query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
|
query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Used by `rustc` when compiling a plugin crate.
|
//! Used by `rustc` when compiling a plugin crate.
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
@ -31,25 +31,16 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the function marked with `#[plugin_registrar]`, if any.
|
/// Finds the function marked with `#[plugin_registrar]`, if any.
|
||||||
pub fn find_plugin_registrar(tcx: TyCtxt<'_>) -> Option<DefId> {
|
fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
|
||||||
tcx.plugin_registrar_fn(LOCAL_CRATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
|
|
||||||
assert_eq!(cnum, LOCAL_CRATE);
|
|
||||||
|
|
||||||
let mut finder = RegistrarFinder { tcx, registrars: Vec::new() };
|
let mut finder = RegistrarFinder { tcx, registrars: Vec::new() };
|
||||||
tcx.hir().krate().visit_all_item_likes(&mut finder);
|
tcx.hir().krate().visit_all_item_likes(&mut finder);
|
||||||
|
|
||||||
match finder.registrars.len() {
|
let (def_id, span) = finder.registrars.pop()?;
|
||||||
0 => None,
|
|
||||||
1 => {
|
if !finder.registrars.is_empty() {
|
||||||
let (def_id, _) = finder.registrars.pop().unwrap();
|
|
||||||
Some(def_id.to_def_id())
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let diagnostic = tcx.sess.diagnostic();
|
let diagnostic = tcx.sess.diagnostic();
|
||||||
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
|
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
|
||||||
|
e.span_note(span, "one is here");
|
||||||
for &(_, span) in &finder.registrars {
|
for &(_, span) in &finder.registrars {
|
||||||
e.span_note(span, "one is here");
|
e.span_note(span, "one is here");
|
||||||
}
|
}
|
||||||
|
@ -57,7 +48,8 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
|
||||||
diagnostic.abort_if_errors();
|
diagnostic.abort_if_errors();
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Some(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
|
|
|
@ -165,7 +165,7 @@ fn compute_symbol_name(
|
||||||
|
|
||||||
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
|
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
|
||||||
let is_foreign = if let Some(def_id) = def_id.as_local() {
|
let is_foreign = if let Some(def_id) = def_id.as_local() {
|
||||||
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id.to_def_id()) {
|
if tcx.plugin_registrar_fn(()) == Some(def_id) {
|
||||||
let disambiguator = tcx.sess.local_crate_disambiguator();
|
let disambiguator = tcx.sess.local_crate_disambiguator();
|
||||||
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
|
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue