Querify local proc_macro_decls_static
This commit is contained in:
parent
2fadb0a16c
commit
fb6040096c
6 changed files with 31 additions and 15 deletions
|
@ -70,7 +70,6 @@ pub struct Session {
|
||||||
/// For a library crate, this is always none
|
/// For a library crate, this is always none
|
||||||
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
|
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
|
||||||
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
|
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
|
||||||
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
|
|
||||||
pub sysroot: PathBuf,
|
pub sysroot: PathBuf,
|
||||||
/// The name of the root source file of the crate, in the local file system.
|
/// The name of the root source file of the crate, in the local file system.
|
||||||
/// `None` means that there is no source file.
|
/// `None` means that there is no source file.
|
||||||
|
@ -1175,7 +1174,6 @@ pub fn build_session_(
|
||||||
// For a library crate, this is always none
|
// For a library crate, this is always none
|
||||||
entry_fn: Once::new(),
|
entry_fn: Once::new(),
|
||||||
plugin_registrar_fn: Once::new(),
|
plugin_registrar_fn: Once::new(),
|
||||||
proc_macro_decls_static: Once::new(),
|
|
||||||
sysroot,
|
sysroot,
|
||||||
local_crate_source_file,
|
local_crate_source_file,
|
||||||
working_dir,
|
working_dir,
|
||||||
|
|
|
@ -147,9 +147,8 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let Some(id) = *tcx.sess.proc_macro_decls_static.get() {
|
if let Some(id) = tcx.proc_macro_decls_static(LOCAL_CRATE) {
|
||||||
let def_id = tcx.hir().local_def_id(id);
|
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||||
reachable_non_generics.insert(def_id, SymbolExportLevel::C);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {
|
if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {
|
||||||
|
|
|
@ -247,7 +247,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
|
||||||
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);
|
||||||
}
|
}
|
||||||
if *tcx.sess.proc_macro_decls_static.get() == Some(id) {
|
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
|
||||||
let disambiguator = tcx.sess.local_crate_disambiguator();
|
let disambiguator = tcx.sess.local_crate_disambiguator();
|
||||||
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
|
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1158,6 +1158,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_provide(providers: &mut ty::query::Providers) {
|
pub fn default_provide(providers: &mut ty::query::Providers) {
|
||||||
|
proc_macro_decls::provide(providers);
|
||||||
hir::provide(providers);
|
hir::provide(providers);
|
||||||
borrowck::provide(providers);
|
borrowck::provide(providers);
|
||||||
mir::provide(providers);
|
mir::provide(providers);
|
||||||
|
@ -1216,8 +1217,6 @@ where
|
||||||
.set(time(sess, "looking for plugin registrar", || {
|
.set(time(sess, "looking for plugin registrar", || {
|
||||||
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
|
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
|
||||||
}));
|
}));
|
||||||
sess.proc_macro_decls_static
|
|
||||||
.set(proc_macro_decls::find(&hir_map));
|
|
||||||
|
|
||||||
let mut local_providers = ty::query::Providers::default();
|
let mut local_providers = ty::query::Providers::default();
|
||||||
default_provide(&mut local_providers);
|
default_provide(&mut local_providers);
|
||||||
|
@ -1250,6 +1249,10 @@ where
|
||||||
|
|
||||||
time(sess, "loop checking", || loops::check_crate(tcx));
|
time(sess, "loop checking", || loops::check_crate(tcx));
|
||||||
|
|
||||||
|
time(sess, "looking for derive registrar", || {
|
||||||
|
proc_macro_decls::find(tcx)
|
||||||
|
});
|
||||||
|
|
||||||
time(sess, "attribute checking", || {
|
time(sess, "attribute checking", || {
|
||||||
hir::check_attr::check_crate(tcx)
|
hir::check_attr::check_crate(tcx)
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc::hir::map::Map;
|
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
|
use rustc::ty::TyCtxt;
|
||||||
|
use rustc::ty::query::Providers;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
|
||||||
pub fn find(hir_map: &Map) -> Option<ast::NodeId> {
|
pub fn find<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
|
||||||
let krate = hir_map.krate();
|
tcx.proc_macro_decls_static(LOCAL_CRATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn proc_macro_decls_static<'tcx>(
|
||||||
|
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||||
|
cnum: CrateNum,
|
||||||
|
) -> Option<DefId> {
|
||||||
|
assert_eq!(cnum, LOCAL_CRATE);
|
||||||
|
|
||||||
let mut finder = Finder { decls: None };
|
let mut finder = Finder { decls: None };
|
||||||
krate.visit_all_item_likes(&mut finder);
|
tcx.hir().krate().visit_all_item_likes(&mut finder);
|
||||||
finder.decls
|
|
||||||
|
finder.decls.map(|id| tcx.hir().local_def_id(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Finder {
|
struct Finder {
|
||||||
|
@ -30,3 +40,9 @@ impl<'v> ItemLikeVisitor<'v> for Finder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn provide(providers: &mut Providers<'_>) {
|
||||||
|
*providers = Providers {
|
||||||
|
proc_macro_decls_static,
|
||||||
|
..*providers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -487,8 +487,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
.get()
|
.get()
|
||||||
.map(|id| tcx.hir().local_def_id(id).index),
|
.map(|id| tcx.hir().local_def_id(id).index),
|
||||||
proc_macro_decls_static: if is_proc_macro {
|
proc_macro_decls_static: if is_proc_macro {
|
||||||
let id = tcx.sess.proc_macro_decls_static.get().unwrap();
|
let id = tcx.proc_macro_decls_static(LOCAL_CRATE).unwrap();
|
||||||
Some(tcx.hir().local_def_id(id).index)
|
Some(id.index)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue