Skip to content

Commit b0f05d4

Browse files
committed
On-demandify is_allocator and is_panic_runtime
1 parent 328c6c8 commit b0f05d4

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

src/librustc/middle/cstore.rs

-4
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ pub trait CrateStore {
251251
fn export_macros(&self, cnum: CrateNum);
252252
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
253253
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
254-
fn is_allocator(&self, cnum: CrateNum) -> bool;
255-
fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
256254
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
257255
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
258256
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
@@ -371,8 +369,6 @@ impl CrateStore for DummyCrateStore {
371369
{ bug!("missing_lang_items") }
372370
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
373371
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
374-
fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
375-
fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
376372
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
377373
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runtime") }
378374
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {

src/librustc/middle/dependency_format.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
9797
let mut fmts = sess.dependency_formats.borrow_mut();
9898
for &ty in sess.crate_types.borrow().iter() {
9999
let linkage = calculate_type(tcx, ty);
100-
verify_ok(sess, &linkage);
100+
verify_ok(tcx, &linkage);
101101
fmts.insert(ty, linkage);
102102
}
103103
sess.abort_if_errors();
@@ -116,7 +116,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
116116
// If the global prefer_dynamic switch is turned off, first attempt
117117
// static linkage (this can fail).
118118
config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => {
119-
if let Some(v) = attempt_static(sess) {
119+
if let Some(v) = attempt_static(tcx) {
120120
return v;
121121
}
122122
}
@@ -129,7 +129,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
129129
// to be found, we generate some nice pretty errors.
130130
config::CrateTypeStaticlib |
131131
config::CrateTypeCdylib => {
132-
if let Some(v) = attempt_static(sess) {
132+
if let Some(v) = attempt_static(tcx) {
133133
return v;
134134
}
135135
for cnum in sess.cstore.crates() {
@@ -146,7 +146,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
146146
// to try to eagerly statically link all dependencies. This is normally
147147
// done for end-product dylibs, not intermediate products.
148148
config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
149-
if let Some(v) = attempt_static(sess) {
149+
if let Some(v) = attempt_static(tcx) {
150150
return v;
151151
}
152152
}
@@ -215,9 +215,9 @@ 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_allocator.get(), &mut ret,
218-
&|cnum| sess.cstore.is_allocator(cnum));
218+
&|cnum| tcx.is_allocator(cnum));
219219
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
220-
&|cnum| sess.cstore.is_panic_runtime(cnum));
220+
&|cnum| tcx.is_panic_runtime(cnum));
221221

222222
// When dylib B links to dylib A, then when using B we must also link to A.
223223
// It could be the case, however, that the rlib for A is present (hence we
@@ -274,7 +274,8 @@ fn add_library(sess: &session::Session,
274274
}
275275
}
276276

277-
fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
277+
fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyList> {
278+
let sess = &tcx.sess;
278279
let crates = sess.cstore.used_crates(RequireStatic);
279280
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
280281
return None
@@ -295,9 +296,9 @@ fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
295296
// explicitly linked, which is the case for any injected dependency. Handle
296297
// that here and activate them.
297298
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
298-
&|cnum| sess.cstore.is_allocator(cnum));
299+
&|cnum| tcx.is_allocator(cnum));
299300
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
300-
&|cnum| sess.cstore.is_panic_runtime(cnum));
301+
&|cnum| tcx.is_panic_runtime(cnum));
301302

302303
Some(ret)
303304
}
@@ -332,7 +333,8 @@ fn activate_injected_dep(injected: Option<CrateNum>,
332333

333334
// After the linkage for a crate has been determined we need to verify that
334335
// there's only going to be one allocator in the output.
335-
fn verify_ok(sess: &session::Session, list: &[Linkage]) {
336+
fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
337+
let sess = &tcx.sess;
336338
if list.len() == 0 {
337339
return
338340
}
@@ -343,7 +345,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
343345
continue
344346
}
345347
let cnum = CrateNum::new(i + 1);
346-
if sess.cstore.is_allocator(cnum) {
348+
if tcx.is_allocator(cnum) {
347349
if let Some(prev) = allocator {
348350
let prev_name = sess.cstore.crate_name(prev);
349351
let cur_name = sess.cstore.crate_name(cnum);
@@ -354,7 +356,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
354356
allocator = Some(cnum);
355357
}
356358

357-
if sess.cstore.is_panic_runtime(cnum) {
359+
if tcx.is_panic_runtime(cnum) {
358360
if let Some((prev, _)) = panic_runtime {
359361
let prev_name = sess.cstore.crate_name(prev);
360362
let cur_name = sess.cstore.crate_name(cnum);

src/librustc/ty/maps.rs

+15
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,18 @@ impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
489489
}
490490
}
491491

492+
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
493+
fn describe(_: TyCtxt, _: CrateNum) -> String {
494+
"checking if the crate is_allocator".to_string()
495+
}
496+
}
497+
498+
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
499+
fn describe(_: TyCtxt, _: CrateNum) -> String {
500+
"checking if the crate is_panic_runtime".to_string()
501+
}
502+
}
503+
492504
macro_rules! define_maps {
493505
(<$tcx:tt>
494506
$($(#[$attr:meta])*
@@ -948,6 +960,9 @@ define_maps! { <'tcx>
948960

949961
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
950962
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
963+
964+
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
965+
[] is_panic_runtime: MetaDataByCrateNum(CrateNum) -> bool,
951966
}
952967

953968
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {

src/librustc_metadata/cstore_impl.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ provide! { <'tcx> tcx, def_id, cdata, cnum,
154154

155155
ByCrateNum {
156156
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
157+
is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
158+
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
157159
}
158160
}
159161

@@ -259,16 +261,6 @@ impl CrateStore for cstore::CStore {
259261
self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
260262
}
261263

262-
fn is_allocator(&self, cnum: CrateNum) -> bool
263-
{
264-
self.get_crate_data(cnum).is_allocator(&self.dep_graph)
265-
}
266-
267-
fn is_panic_runtime(&self, cnum: CrateNum) -> bool
268-
{
269-
self.get_crate_data(cnum).is_panic_runtime(&self.dep_graph)
270-
}
271-
272264
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
273265
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
274266
}

src/librustc_trans/back/symbol_export.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ impl ExportedSymbols {
9292
// Down below we'll hardwire all of the symbols to the `Rust` export
9393
// level instead.
9494
let special_runtime_crate =
95-
scx.sess().cstore.is_allocator(cnum) ||
96-
scx.sess().cstore.is_panic_runtime(cnum) ||
95+
scx.tcx().is_allocator(cnum) ||
96+
scx.tcx().is_panic_runtime(cnum) ||
9797
scx.sess().cstore.is_compiler_builtins(cnum);
9898

9999
let crate_exports = scx

0 commit comments

Comments
 (0)