Skip to content

Commit dff0c07

Browse files
committed
rustc: Move a few more cstore methods to queries
This comit applies the following changes: * Deletes the `is_allocator` query as it's no longer used * Moves the `is_sanitizer_runtime` method to a query * Moves the `is_profiler_runtime` method to a query * Moves the `panic_strategy` method to a query * Moves the `is_no_builtins` method to a query * Deletes the cstore method of `is_compiler_builtins`. The query was added in #42588 but the `CrateStore` method was not deleted A good bit of these methods were used late in linking during trans so a new dedicated structure was created to ship a calculated form of this information over to the linker rather than having to ship the whole of `TyCtxt` over to linking.
1 parent 2f1ef9e commit dff0c07

File tree

11 files changed

+150
-85
lines changed

11 files changed

+150
-85
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,16 +521,19 @@ define_dep_nodes!( <'tcx>
521521
[] IsMirAvailable(DefId),
522522
[] ItemAttrs(DefId),
523523
[] FnArgNames(DefId),
524-
[] DylibDepFormats(DefId),
525-
[] IsAllocator(DefId),
526-
[] IsPanicRuntime(DefId),
527-
[] IsCompilerBuiltins(DefId),
528-
[] HasGlobalAllocator(DefId),
524+
[] DylibDepFormats(CrateNum),
525+
[] IsPanicRuntime(CrateNum),
526+
[] IsCompilerBuiltins(CrateNum),
527+
[] HasGlobalAllocator(CrateNum),
529528
[] ExternCrate(DefId),
530529
[] LintLevels,
531530
[] Specializes { impl1: DefId, impl2: DefId },
532531
[] InScopeTraits(HirId),
533532
[] ModuleExports(HirId),
533+
[] IsSanitizerRuntime(CrateNum),
534+
[] IsProfilerRuntime(CrateNum),
535+
[] GetPanicStrategy(CrateNum),
536+
[] IsNoBuiltins(CrateNum),
534537
);
535538

536539
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use syntax::symbol::Symbol;
4444
use syntax_pos::Span;
4545
use rustc_back::target::Target;
4646
use hir;
47-
use rustc_back::PanicStrategy;
4847

4948
pub use self::NativeLibraryKind::*;
5049

@@ -252,10 +251,6 @@ pub trait CrateStore {
252251
fn export_macros(&self, cnum: CrateNum);
253252
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
254253
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
255-
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
256-
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
257-
fn is_profiler_runtime(&self, cnum: CrateNum) -> bool;
258-
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
259254
/// The name of the crate as it is referred to in source code of the current
260255
/// crate.
261256
fn crate_name(&self, cnum: CrateNum) -> Symbol;
@@ -267,7 +262,6 @@ pub trait CrateStore {
267262
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
268263
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
269264
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
270-
fn is_no_builtins(&self, cnum: CrateNum) -> bool;
271265

272266
// resolve
273267
fn def_key(&self, def: DefId) -> DefKey;
@@ -366,12 +360,6 @@ impl CrateStore for DummyCrateStore {
366360
{ bug!("missing_lang_items") }
367361
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
368362
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
369-
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
370-
fn is_profiler_runtime(&self, cnum: CrateNum) -> bool { bug!("is_profiler_runtime") }
371-
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runtime") }
372-
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
373-
bug!("panic_strategy")
374-
}
375363
fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
376364
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
377365
bug!("original_crate_name")
@@ -386,7 +374,6 @@ impl CrateStore for DummyCrateStore {
386374
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
387375
{ bug!("native_libraries") }
388376
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
389-
fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
390377

391378
// resolve
392379
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }

src/librustc/middle/dependency_format.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
172172
if src.dylib.is_some() {
173173
info!("adding dylib: {}", name);
174174
add_library(sess, cnum, RequireDynamic, &mut formats);
175-
let deps = tcx.dylib_dependency_formats(cnum.as_def_id());
175+
let deps = tcx.dylib_dependency_formats(cnum);
176176
for &(depnum, style) in deps.iter() {
177177
info!("adding {:?}: {}", style,
178178
sess.cstore.crate_name(depnum));
@@ -215,7 +215,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
215215
// Things like allocators and panic runtimes may not have been activated
216216
// quite yet, so do so here.
217217
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
218-
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
218+
&|cnum| tcx.is_panic_runtime(cnum));
219219
activate_injected_allocator(sess, &mut ret);
220220

221221
// When dylib B links to dylib A, then when using B we must also link to A.
@@ -295,7 +295,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
295295
// explicitly linked, which is the case for any injected dependency. Handle
296296
// that here and activate them.
297297
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
298-
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
298+
&|cnum| tcx.is_panic_runtime(cnum));
299299
activate_injected_allocator(sess, &mut ret);
300300

301301
Some(ret)
@@ -355,15 +355,15 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
355355
}
356356
let cnum = CrateNum::new(i + 1);
357357

358-
if tcx.is_panic_runtime(cnum.as_def_id()) {
358+
if tcx.is_panic_runtime(cnum) {
359359
if let Some((prev, _)) = panic_runtime {
360360
let prev_name = sess.cstore.crate_name(prev);
361361
let cur_name = sess.cstore.crate_name(cnum);
362362
sess.err(&format!("cannot link together two \
363363
panic runtimes: {} and {}",
364364
prev_name, cur_name));
365365
}
366-
panic_runtime = Some((cnum, sess.cstore.panic_strategy(cnum)));
366+
panic_runtime = Some((cnum, tcx.panic_strategy(cnum)));
367367
}
368368
}
369369

@@ -395,8 +395,8 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
395395
continue
396396
}
397397
let cnum = CrateNum::new(i + 1);
398-
let found_strategy = sess.cstore.panic_strategy(cnum);
399-
let is_compiler_builtins = sess.cstore.is_compiler_builtins(cnum);
398+
let found_strategy = tcx.panic_strategy(cnum);
399+
let is_compiler_builtins = tcx.is_compiler_builtins(cnum);
400400
if is_compiler_builtins || desired_strategy == found_strategy {
401401
continue
402402
}

src/librustc/ty/maps.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use util::nodemap::{DefIdSet, NodeSet};
3232
use util::common::{profq_msg, ProfileQueriesMsg};
3333

3434
use rustc_data_structures::indexed_set::IdxSetBuf;
35+
use rustc_back::PanicStrategy;
3536
use rustc_data_structures::indexed_vec::IndexVec;
3637
use rustc_data_structures::fx::FxHashMap;
3738
use std::cell::{RefCell, RefMut, Cell};
@@ -509,31 +510,25 @@ impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
509510
}
510511

511512
impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
512-
fn describe(_: TyCtxt, _: DefId) -> String {
513+
fn describe(_: TyCtxt, _: CrateNum) -> String {
513514
"dylib dependency formats of crate".to_string()
514515
}
515516
}
516517

517-
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
518-
fn describe(_: TyCtxt, _: DefId) -> String {
519-
"checking if the crate is_allocator".to_string()
520-
}
521-
}
522-
523518
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
524-
fn describe(_: TyCtxt, _: DefId) -> String {
519+
fn describe(_: TyCtxt, _: CrateNum) -> String {
525520
"checking if the crate is_panic_runtime".to_string()
526521
}
527522
}
528523

529524
impl<'tcx> QueryDescription for queries::is_compiler_builtins<'tcx> {
530-
fn describe(_: TyCtxt, _: DefId) -> String {
525+
fn describe(_: TyCtxt, _: CrateNum) -> String {
531526
"checking if the crate is_compiler_builtins".to_string()
532527
}
533528
}
534529

535530
impl<'tcx> QueryDescription for queries::has_global_allocator<'tcx> {
536-
fn describe(_: TyCtxt, _: DefId) -> String {
531+
fn describe(_: TyCtxt, _: CrateNum) -> String {
537532
"checking if the crate has_global_allocator".to_string()
538533
}
539534
}
@@ -568,6 +563,30 @@ impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
568563
}
569564
}
570565

566+
impl<'tcx> QueryDescription for queries::is_no_builtins<'tcx> {
567+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
568+
format!("test whether a crate has #![no_builtins]")
569+
}
570+
}
571+
572+
impl<'tcx> QueryDescription for queries::panic_strategy<'tcx> {
573+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
574+
format!("query a crate's configured panic strategy")
575+
}
576+
}
577+
578+
impl<'tcx> QueryDescription for queries::is_profiler_runtime<'tcx> {
579+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
580+
format!("query a crate is #![profiler_runtime]")
581+
}
582+
}
583+
584+
impl<'tcx> QueryDescription for queries::is_sanitizer_runtime<'tcx> {
585+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
586+
format!("query a crate is #![sanitizer_runtime]")
587+
}
588+
}
589+
571590
// If enabled, send a message to the profile-queries thread
572591
macro_rules! profq_msg {
573592
($tcx:expr, $msg:expr) => {
@@ -1125,21 +1144,23 @@ define_maps! { <'tcx>
11251144
[] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
11261145
-> Result<&'tcx Layout, LayoutError<'tcx>>,
11271146

1128-
[] fn dylib_dependency_formats: DylibDepFormats(DefId)
1147+
[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
11291148
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
11301149

1131-
[] fn is_allocator: IsAllocator(DefId) -> bool,
1132-
[] fn is_panic_runtime: IsPanicRuntime(DefId) -> bool,
1133-
[] fn is_compiler_builtins: IsCompilerBuiltins(DefId) -> bool,
1134-
[] fn has_global_allocator: HasGlobalAllocator(DefId) -> bool,
1150+
[] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
1151+
[] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
1152+
[] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
1153+
[] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
1154+
[] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
1155+
[] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
1156+
[] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
11351157

11361158
[] fn extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
11371159

1138-
[] fn lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>,
1139-
11401160
[] fn specializes: specializes_node((DefId, DefId)) -> bool,
11411161
[] fn in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
11421162
[] fn module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
1163+
[] fn lint_levels: lint_levels_node(CrateNum) -> Rc<lint::LintLevelMap>,
11431164
}
11441165

11451166
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
@@ -1212,7 +1233,7 @@ fn layout_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'
12121233
DepConstructor::Layout
12131234
}
12141235

1215-
fn lint_levels<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1236+
fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
12161237
DepConstructor::LintLevels
12171238
}
12181239

src/librustc_metadata/cstore_impl.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc::hir::map::{DefKey, DefPath, DefPathHash};
2727
use rustc::hir::map::blocks::FnLikeNode;
2828
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
2929
use rustc::util::nodemap::{NodeSet, DefIdMap};
30-
use rustc_back::PanicStrategy;
3130

3231
use std::any::Any;
3332
use std::rc::Rc;
@@ -45,9 +44,12 @@ use rustc::hir;
4544
macro_rules! provide {
4645
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $($name:ident => $compute:block)*) => {
4746
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
48-
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
47+
$(fn $name<'a, $lt:$lt, T>($tcx: TyCtxt<'a, $lt, $lt>, def_id_arg: T)
4948
-> <ty::queries::$name<$lt> as
50-
QueryConfig>::Value {
49+
QueryConfig>::Value
50+
where T: IntoDefId,
51+
{
52+
let $def_id = def_id_arg.into_def_id();
5153
assert!(!$def_id.is_local());
5254

5355
let def_path_hash = $tcx.def_path_hash($def_id);
@@ -69,6 +71,18 @@ macro_rules! provide {
6971
}
7072
}
7173

74+
trait IntoDefId {
75+
fn into_def_id(self) -> DefId;
76+
}
77+
78+
impl IntoDefId for DefId {
79+
fn into_def_id(self) -> DefId { self }
80+
}
81+
82+
impl IntoDefId for CrateNum {
83+
fn into_def_id(self) -> DefId { self.as_def_id() }
84+
}
85+
7286
provide! { <'tcx> tcx, def_id, cdata,
7387
type_of => { cdata.get_type(def_id.index, tcx) }
7488
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
@@ -143,7 +157,11 @@ provide! { <'tcx> tcx, def_id, cdata,
143157
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
144158
is_compiler_builtins => { cdata.is_compiler_builtins(&tcx.dep_graph) }
145159
has_global_allocator => { cdata.has_global_allocator(&tcx.dep_graph) }
160+
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(&tcx.dep_graph) }
161+
is_profiler_runtime => { cdata.is_profiler_runtime(&tcx.dep_graph) }
162+
panic_strategy => { cdata.panic_strategy(&tcx.dep_graph) }
146163
extern_crate => { Rc::new(cdata.extern_crate.get()) }
164+
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
147165
}
148166

149167
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -248,22 +266,6 @@ impl CrateStore for cstore::CStore {
248266
self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
249267
}
250268

251-
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
252-
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
253-
}
254-
255-
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool {
256-
self.get_crate_data(cnum).is_sanitizer_runtime(&self.dep_graph)
257-
}
258-
259-
fn is_profiler_runtime(&self, cnum: CrateNum) -> bool {
260-
self.get_crate_data(cnum).is_profiler_runtime(&self.dep_graph)
261-
}
262-
263-
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
264-
self.get_crate_data(cnum).panic_strategy(&self.dep_graph)
265-
}
266-
267269
fn crate_name(&self, cnum: CrateNum) -> Symbol
268270
{
269271
self.get_crate_data(cnum).name
@@ -310,10 +312,6 @@ impl CrateStore for cstore::CStore {
310312
self.get_crate_data(cnum).get_exported_symbols(&self.dep_graph)
311313
}
312314

313-
fn is_no_builtins(&self, cnum: CrateNum) -> bool {
314-
self.get_crate_data(cnum).is_no_builtins(&self.dep_graph)
315-
}
316-
317315
/// Returns the `DefKey` for a given `DefId`. This indicates the
318316
/// parent `DefId` as well as some idea of what kind of data the
319317
/// `DefId` refers to.

0 commit comments

Comments
 (0)