Skip to content

Commit fb60400

Browse files
committed
Querify local proc_macro_decls_static
1 parent 2fadb0a commit fb60400

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

src/librustc/session/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub struct Session {
7070
/// For a library crate, this is always none
7171
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
7272
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
73-
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
7473
pub sysroot: PathBuf,
7574
/// The name of the root source file of the crate, in the local file system.
7675
/// `None` means that there is no source file.
@@ -1175,7 +1174,6 @@ pub fn build_session_(
11751174
// For a library crate, this is always none
11761175
entry_fn: Once::new(),
11771176
plugin_registrar_fn: Once::new(),
1178-
proc_macro_decls_static: Once::new(),
11791177
sysroot,
11801178
local_crate_source_file,
11811179
working_dir,

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
147147
})
148148
.collect();
149149

150-
if let Some(id) = *tcx.sess.proc_macro_decls_static.get() {
151-
let def_id = tcx.hir().local_def_id(id);
152-
reachable_non_generics.insert(def_id, SymbolExportLevel::C);
150+
if let Some(id) = tcx.proc_macro_decls_static(LOCAL_CRATE) {
151+
reachable_non_generics.insert(id, SymbolExportLevel::C);
153152
}
154153

155154
if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
247247
let disambiguator = tcx.sess.local_crate_disambiguator();
248248
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
249249
}
250-
if *tcx.sess.proc_macro_decls_static.get() == Some(id) {
250+
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
251251
let disambiguator = tcx.sess.local_crate_disambiguator();
252252
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
253253
}

src/librustc_driver/driver.rs

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

11601160
pub fn default_provide(providers: &mut ty::query::Providers) {
1161+
proc_macro_decls::provide(providers);
11611162
hir::provide(providers);
11621163
borrowck::provide(providers);
11631164
mir::provide(providers);
@@ -1216,8 +1217,6 @@ where
12161217
.set(time(sess, "looking for plugin registrar", || {
12171218
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
12181219
}));
1219-
sess.proc_macro_decls_static
1220-
.set(proc_macro_decls::find(&hir_map));
12211220

12221221
let mut local_providers = ty::query::Providers::default();
12231222
default_provide(&mut local_providers);
@@ -1250,6 +1249,10 @@ where
12501249

12511250
time(sess, "loop checking", || loops::check_crate(tcx));
12521251

1252+
time(sess, "looking for derive registrar", || {
1253+
proc_macro_decls::find(tcx)
1254+
});
1255+
12531256
time(sess, "attribute checking", || {
12541257
hir::check_attr::check_crate(tcx)
12551258
});

src/librustc_driver/proc_macro_decls.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2-
use rustc::hir::map::Map;
2+
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
33
use rustc::hir;
4+
use rustc::ty::TyCtxt;
5+
use rustc::ty::query::Providers;
46
use syntax::ast;
57
use syntax::attr;
68

7-
pub fn find(hir_map: &Map) -> Option<ast::NodeId> {
8-
let krate = hir_map.krate();
9+
pub fn find<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
10+
tcx.proc_macro_decls_static(LOCAL_CRATE)
11+
}
12+
13+
fn proc_macro_decls_static<'tcx>(
14+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
15+
cnum: CrateNum,
16+
) -> Option<DefId> {
17+
assert_eq!(cnum, LOCAL_CRATE);
918

1019
let mut finder = Finder { decls: None };
11-
krate.visit_all_item_likes(&mut finder);
12-
finder.decls
20+
tcx.hir().krate().visit_all_item_likes(&mut finder);
21+
22+
finder.decls.map(|id| tcx.hir().local_def_id(id))
1323
}
1424

1525
struct Finder {
@@ -30,3 +40,9 @@ impl<'v> ItemLikeVisitor<'v> for Finder {
3040
}
3141
}
3242

43+
pub(crate) fn provide(providers: &mut Providers<'_>) {
44+
*providers = Providers {
45+
proc_macro_decls_static,
46+
..*providers
47+
};
48+
}

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
487487
.get()
488488
.map(|id| tcx.hir().local_def_id(id).index),
489489
proc_macro_decls_static: if is_proc_macro {
490-
let id = tcx.sess.proc_macro_decls_static.get().unwrap();
491-
Some(tcx.hir().local_def_id(id).index)
490+
let id = tcx.proc_macro_decls_static(LOCAL_CRATE).unwrap();
491+
Some(id.index)
492492
} else {
493493
None
494494
},

0 commit comments

Comments
 (0)