Skip to content

Commit fdd6a3e

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 rust-lang#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 9a59d69 commit fdd6a3e

File tree

11 files changed

+150
-84
lines changed

11 files changed

+150
-84
lines changed

src/librustc/dep_graph/dep_node.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,16 @@ define_dep_nodes!( <'tcx>
520520
[] IsMirAvailable(DefId),
521521
[] ItemAttrs(DefId),
522522
[] FnArgNames(DefId),
523-
[] DylibDepFormats(DefId),
524-
[] IsAllocator(DefId),
525-
[] IsPanicRuntime(DefId),
526-
[] IsCompilerBuiltins(DefId),
527-
[] HasGlobalAllocator(DefId),
523+
[] DylibDepFormats(CrateNum),
524+
[] IsPanicRuntime(CrateNum),
525+
[] IsCompilerBuiltins(CrateNum),
526+
[] HasGlobalAllocator(CrateNum),
528527
[] ExternCrate(DefId),
529528
[] LintLevels,
529+
[] IsSanitizerRuntime(CrateNum),
530+
[] IsProfilerRuntime(CrateNum),
531+
[] GetPanicStrategy(CrateNum),
532+
[] IsNoBuiltins(CrateNum),
530533
);
531534

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

src/librustc/middle/cstore.rs

-13
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

+7-7
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

+39-17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use ty::fast_reject::SimplifiedType;
3131
use util::nodemap::{DefIdSet, NodeSet};
3232
use util::common::{profq_msg, ProfileQueriesMsg};
3333

34+
use rustc_back::PanicStrategy;
3435
use rustc_data_structures::indexed_vec::IndexVec;
3536
use rustc_data_structures::fx::FxHashMap;
3637
use std::cell::{RefCell, RefMut, Cell};
@@ -499,31 +500,25 @@ impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
499500
}
500501

501502
impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
502-
fn describe(_: TyCtxt, _: DefId) -> String {
503+
fn describe(_: TyCtxt, _: CrateNum) -> String {
503504
"dylib dependency formats of crate".to_string()
504505
}
505506
}
506507

507-
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
508-
fn describe(_: TyCtxt, _: DefId) -> String {
509-
"checking if the crate is_allocator".to_string()
510-
}
511-
}
512-
513508
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
514-
fn describe(_: TyCtxt, _: DefId) -> String {
509+
fn describe(_: TyCtxt, _: CrateNum) -> String {
515510
"checking if the crate is_panic_runtime".to_string()
516511
}
517512
}
518513

519514
impl<'tcx> QueryDescription for queries::is_compiler_builtins<'tcx> {
520-
fn describe(_: TyCtxt, _: DefId) -> String {
515+
fn describe(_: TyCtxt, _: CrateNum) -> String {
521516
"checking if the crate is_compiler_builtins".to_string()
522517
}
523518
}
524519

525520
impl<'tcx> QueryDescription for queries::has_global_allocator<'tcx> {
526-
fn describe(_: TyCtxt, _: DefId) -> String {
521+
fn describe(_: TyCtxt, _: CrateNum) -> String {
527522
"checking if the crate has_global_allocator".to_string()
528523
}
529524
}
@@ -540,6 +535,30 @@ impl<'tcx> QueryDescription for queries::lint_levels<'tcx> {
540535
}
541536
}
542537

538+
impl<'tcx> QueryDescription for queries::is_no_builtins<'tcx> {
539+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
540+
format!("test whether a crate has #![no_builtins]")
541+
}
542+
}
543+
544+
impl<'tcx> QueryDescription for queries::panic_strategy<'tcx> {
545+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
546+
format!("query a crate's configured panic strategy")
547+
}
548+
}
549+
550+
impl<'tcx> QueryDescription for queries::is_profiler_runtime<'tcx> {
551+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
552+
format!("query a crate is #![profiler_runtime]")
553+
}
554+
}
555+
556+
impl<'tcx> QueryDescription for queries::is_sanitizer_runtime<'tcx> {
557+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
558+
format!("query a crate is #![sanitizer_runtime]")
559+
}
560+
}
561+
543562
// If enabled, send a message to the profile-queries thread
544563
macro_rules! profq_msg {
545564
($tcx:expr, $msg:expr) => {
@@ -1097,17 +1116,20 @@ define_maps! { <'tcx>
10971116
[] layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
10981117
-> Result<&'tcx Layout, LayoutError<'tcx>>,
10991118

1100-
[] dylib_dependency_formats: DylibDepFormats(DefId)
1119+
[] dylib_dependency_formats: DylibDepFormats(CrateNum)
11011120
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
11021121

1103-
[] is_allocator: IsAllocator(DefId) -> bool,
1104-
[] is_panic_runtime: IsPanicRuntime(DefId) -> bool,
1105-
[] is_compiler_builtins: IsCompilerBuiltins(DefId) -> bool,
1106-
[] has_global_allocator: HasGlobalAllocator(DefId) -> bool,
1122+
[] is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
1123+
[] is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
1124+
[] has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
1125+
[] is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
1126+
[] is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
1127+
[] panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
1128+
[] is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
11071129

11081130
[] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
11091131

1110-
[] lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>,
1132+
[] lint_levels: lint_levels_node(CrateNum) -> Rc<lint::LintLevelMap>,
11111133
}
11121134

11131135
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
@@ -1180,6 +1202,6 @@ fn layout_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'
11801202
DepConstructor::Layout
11811203
}
11821204

1183-
fn lint_levels<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1205+
fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
11841206
DepConstructor::LintLevels
11851207
}

src/librustc_metadata/cstore_impl.rs

+21-23
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;
@@ -44,9 +43,12 @@ use rustc::hir;
4443
macro_rules! provide {
4544
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $($name:ident => $compute:block)*) => {
4645
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
47-
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
46+
$(fn $name<'a, $lt:$lt, T>($tcx: TyCtxt<'a, $lt, $lt>, def_id_arg: T)
4847
-> <ty::queries::$name<$lt> as
49-
QueryConfig>::Value {
48+
QueryConfig>::Value
49+
where T: IntoDefId,
50+
{
51+
let $def_id = def_id_arg.into_def_id();
5052
assert!(!$def_id.is_local());
5153

5254
let def_path_hash = $tcx.def_path_hash($def_id);
@@ -68,6 +70,18 @@ macro_rules! provide {
6870
}
6971
}
7072

73+
trait IntoDefId {
74+
fn into_def_id(self) -> DefId;
75+
}
76+
77+
impl IntoDefId for DefId {
78+
fn into_def_id(self) -> DefId { self }
79+
}
80+
81+
impl IntoDefId for CrateNum {
82+
fn into_def_id(self) -> DefId { self.as_def_id() }
83+
}
84+
7185
provide! { <'tcx> tcx, def_id, cdata,
7286
type_of => { cdata.get_type(def_id.index, tcx) }
7387
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
@@ -140,7 +154,11 @@ provide! { <'tcx> tcx, def_id, cdata,
140154
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
141155
is_compiler_builtins => { cdata.is_compiler_builtins(&tcx.dep_graph) }
142156
has_global_allocator => { cdata.has_global_allocator(&tcx.dep_graph) }
157+
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(&tcx.dep_graph) }
158+
is_profiler_runtime => { cdata.is_profiler_runtime(&tcx.dep_graph) }
159+
panic_strategy => { cdata.panic_strategy(&tcx.dep_graph) }
143160
extern_crate => { Rc::new(cdata.extern_crate.get()) }
161+
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
144162
}
145163

146164
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -245,22 +263,6 @@ impl CrateStore for cstore::CStore {
245263
self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
246264
}
247265

248-
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
249-
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
250-
}
251-
252-
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool {
253-
self.get_crate_data(cnum).is_sanitizer_runtime(&self.dep_graph)
254-
}
255-
256-
fn is_profiler_runtime(&self, cnum: CrateNum) -> bool {
257-
self.get_crate_data(cnum).is_profiler_runtime(&self.dep_graph)
258-
}
259-
260-
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
261-
self.get_crate_data(cnum).panic_strategy(&self.dep_graph)
262-
}
263-
264266
fn crate_name(&self, cnum: CrateNum) -> Symbol
265267
{
266268
self.get_crate_data(cnum).name
@@ -307,10 +309,6 @@ impl CrateStore for cstore::CStore {
307309
self.get_crate_data(cnum).get_exported_symbols(&self.dep_graph)
308310
}
309311

310-
fn is_no_builtins(&self, cnum: CrateNum) -> bool {
311-
self.get_crate_data(cnum).is_no_builtins(&self.dep_graph)
312-
}
313-
314312
/// Returns the `DefKey` for a given `DefId`. This indicates the
315313
/// parent `DefId` as well as some idea of what kind of data the
316314
/// `DefId` refers to.

0 commit comments

Comments
 (0)