Skip to content

Commit 59d7d7d

Browse files
committed
Querify local plugin_registrar_fn
1 parent fb60400 commit 59d7d7d

File tree

7 files changed

+35
-26
lines changed

7 files changed

+35
-26
lines changed

src/librustc/session/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub struct Session {
6969
pub parse_sess: ParseSess,
7070
/// For a library crate, this is always none
7171
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
72-
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
7372
pub sysroot: PathBuf,
7473
/// The name of the root source file of the crate, in the local file system.
7574
/// `None` means that there is no source file.
@@ -1173,7 +1172,6 @@ pub fn build_session_(
11731172
parse_sess: p_s,
11741173
// For a library crate, this is always none
11751174
entry_fn: Once::new(),
1176-
plugin_registrar_fn: Once::new(),
11771175
sysroot,
11781176
local_crate_source_file,
11791177
working_dir,

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
151151
reachable_non_generics.insert(id, SymbolExportLevel::C);
152152
}
153153

154-
if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {
155-
let def_id = tcx.hir().local_def_id(id);
156-
reachable_non_generics.insert(def_id, SymbolExportLevel::C);
154+
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
155+
reachable_non_generics.insert(id, SymbolExportLevel::C);
157156
}
158157

159158
Lrc::new(reachable_non_generics)

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
242242

243243
let node_id = tcx.hir().as_local_node_id(def_id);
244244

245-
if let Some(id) = node_id {
246-
if *tcx.sess.plugin_registrar_fn.get() == Some(id) {
245+
if def_id.is_local() {
246+
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
247247
let disambiguator = tcx.sess.local_crate_disambiguator();
248248
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
249249
}

src/librustc_driver/driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ where
11591159

11601160
pub fn default_provide(providers: &mut ty::query::Providers) {
11611161
proc_macro_decls::provide(providers);
1162+
plugin::build::provide(providers);
11621163
hir::provide(providers);
11631164
borrowck::provide(providers);
11641165
mir::provide(providers);
@@ -1213,11 +1214,6 @@ where
12131214
middle::entry::find_entry_point(sess, &hir_map, name)
12141215
});
12151216

1216-
sess.plugin_registrar_fn
1217-
.set(time(sess, "looking for plugin registrar", || {
1218-
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
1219-
}));
1220-
12211217
let mut local_providers = ty::query::Providers::default();
12221218
default_provide(&mut local_providers);
12231219
codegen_backend.provide(&mut local_providers);
@@ -1249,6 +1245,10 @@ where
12491245

12501246
time(sess, "loop checking", || loops::check_crate(tcx));
12511247

1248+
time(sess, "looking for plugin registrar", || {
1249+
plugin::build::find_plugin_registrar(tcx)
1250+
});
1251+
12521252
time(sess, "looking for derive registrar", || {
12531253
proc_macro_decls::find(tcx)
12541254
});

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! a `pub fn new()`.
2020
2121
use rustc::hir::def::Def;
22-
use rustc::hir::def_id::DefId;
22+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
2323
use rustc::ty::{self, Ty};
2424
use hir::Node;
2525
use util::nodemap::NodeSet;
@@ -860,7 +860,7 @@ impl LintPass for PluginAsLibrary {
860860

861861
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
862862
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
863-
if cx.sess().plugin_registrar_fn.get().is_some() {
863+
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
864864
// We're compiling a plugin; it's fine to link other plugins.
865865
return;
866866
}

src/librustc_metadata/encoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
482482
has_global_allocator: has_global_allocator,
483483
has_panic_handler: has_panic_handler,
484484
has_default_lib_allocator: has_default_lib_allocator,
485-
plugin_registrar_fn: tcx.sess
486-
.plugin_registrar_fn
487-
.get()
488-
.map(|id| tcx.hir().local_def_id(id).index),
485+
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
489486
proc_macro_decls_static: if is_proc_macro {
490487
let id = tcx.proc_macro_decls_static(LOCAL_CRATE).unwrap();
491488
Some(id.index)

src/librustc_plugin/build.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
33
use syntax::ast;
44
use syntax::attr;
5-
use errors;
65
use syntax_pos::Span;
7-
use rustc::hir::map::Map;
86
use rustc::hir::itemlikevisit::ItemLikeVisitor;
97
use rustc::hir;
8+
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
9+
use rustc::ty::TyCtxt;
10+
use rustc::ty::query::Providers;
1011

1112
struct RegistrarFinder {
1213
registrars: Vec<(ast::NodeId, Span)> ,
@@ -30,21 +31,27 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder {
3031
}
3132

3233
/// Find the function marked with `#[plugin_registrar]`, if any.
33-
pub fn find_plugin_registrar(diagnostic: &errors::Handler,
34-
hir_map: &Map)
35-
-> Option<ast::NodeId> {
36-
let krate = hir_map.krate();
34+
pub fn find_plugin_registrar<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
35+
tcx.plugin_registrar_fn(LOCAL_CRATE)
36+
}
37+
38+
fn plugin_registrar_fn<'tcx>(
39+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
40+
cnum: CrateNum,
41+
) -> Option<DefId> {
42+
assert_eq!(cnum, LOCAL_CRATE);
3743

3844
let mut finder = RegistrarFinder { registrars: Vec::new() };
39-
krate.visit_all_item_likes(&mut finder);
45+
tcx.hir().krate().visit_all_item_likes(&mut finder);
4046

4147
match finder.registrars.len() {
4248
0 => None,
4349
1 => {
4450
let (node_id, _) = finder.registrars.pop().unwrap();
45-
Some(node_id)
51+
Some(tcx.hir().local_def_id(node_id))
4652
},
4753
_ => {
54+
let diagnostic = tcx.sess.diagnostic();
4855
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
4956
for &(_, span) in &finder.registrars {
5057
e.span_note(span, "one is here");
@@ -55,3 +62,11 @@ pub fn find_plugin_registrar(diagnostic: &errors::Handler,
5562
}
5663
}
5764
}
65+
66+
67+
pub fn provide(providers: &mut Providers<'_>) {
68+
*providers = Providers {
69+
plugin_registrar_fn,
70+
..*providers
71+
};
72+
}

0 commit comments

Comments
 (0)