On-demandify is_allocator and is_panic_runtime

This commit is contained in:
Taylor Cramer 2017-06-12 00:11:24 -07:00
parent 328c6c81bf
commit b0f05d4bc5
5 changed files with 33 additions and 28 deletions

View File

@ -251,8 +251,6 @@ pub trait CrateStore {
fn export_macros(&self, cnum: CrateNum);
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
fn is_allocator(&self, cnum: CrateNum) -> bool;
fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
@ -371,8 +369,6 @@ impl CrateStore for DummyCrateStore {
{ bug!("missing_lang_items") }
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runtime") }
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {

View File

@ -97,7 +97,7 @@ pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let mut fmts = sess.dependency_formats.borrow_mut();
for &ty in sess.crate_types.borrow().iter() {
let linkage = calculate_type(tcx, ty);
verify_ok(sess, &linkage);
verify_ok(tcx, &linkage);
fmts.insert(ty, linkage);
}
sess.abort_if_errors();
@ -116,7 +116,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// If the global prefer_dynamic switch is turned off, first attempt
// static linkage (this can fail).
config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => {
if let Some(v) = attempt_static(sess) {
if let Some(v) = attempt_static(tcx) {
return v;
}
}
@ -129,7 +129,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// to be found, we generate some nice pretty errors.
config::CrateTypeStaticlib |
config::CrateTypeCdylib => {
if let Some(v) = attempt_static(sess) {
if let Some(v) = attempt_static(tcx) {
return v;
}
for cnum in sess.cstore.crates() {
@ -146,7 +146,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// to try to eagerly statically link all dependencies. This is normally
// done for end-product dylibs, not intermediate products.
config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
if let Some(v) = attempt_static(sess) {
if let Some(v) = attempt_static(tcx) {
return v;
}
}
@ -215,9 +215,9 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Things like allocators and panic runtimes may not have been activated
// quite yet, so do so here.
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
&|cnum| sess.cstore.is_allocator(cnum));
&|cnum| tcx.is_allocator(cnum));
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
&|cnum| sess.cstore.is_panic_runtime(cnum));
&|cnum| tcx.is_panic_runtime(cnum));
// When dylib B links to dylib A, then when using B we must also link to A.
// 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,
}
}
fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyList> {
let sess = &tcx.sess;
let crates = sess.cstore.used_crates(RequireStatic);
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
return None
@ -295,9 +296,9 @@ fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
// explicitly linked, which is the case for any injected dependency. Handle
// that here and activate them.
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
&|cnum| sess.cstore.is_allocator(cnum));
&|cnum| tcx.is_allocator(cnum));
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
&|cnum| sess.cstore.is_panic_runtime(cnum));
&|cnum| tcx.is_panic_runtime(cnum));
Some(ret)
}
@ -332,7 +333,8 @@ fn activate_injected_dep(injected: Option<CrateNum>,
// After the linkage for a crate has been determined we need to verify that
// there's only going to be one allocator in the output.
fn verify_ok(sess: &session::Session, list: &[Linkage]) {
fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
let sess = &tcx.sess;
if list.len() == 0 {
return
}
@ -343,7 +345,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
continue
}
let cnum = CrateNum::new(i + 1);
if sess.cstore.is_allocator(cnum) {
if tcx.is_allocator(cnum) {
if let Some(prev) = allocator {
let prev_name = sess.cstore.crate_name(prev);
let cur_name = sess.cstore.crate_name(cnum);
@ -354,7 +356,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
allocator = Some(cnum);
}
if sess.cstore.is_panic_runtime(cnum) {
if tcx.is_panic_runtime(cnum) {
if let Some((prev, _)) = panic_runtime {
let prev_name = sess.cstore.crate_name(prev);
let cur_name = sess.cstore.crate_name(cnum);

View File

@ -489,6 +489,18 @@ impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
}
}
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
"checking if the crate is_allocator".to_string()
}
}
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
"checking if the crate is_panic_runtime".to_string()
}
}
macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
@ -948,6 +960,9 @@ define_maps! { <'tcx>
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
[] is_panic_runtime: MetaDataByCrateNum(CrateNum) -> bool,
}
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {

View File

@ -154,6 +154,8 @@ provide! { <'tcx> tcx, def_id, cdata, cnum,
ByCrateNum {
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
}
}
@ -259,16 +261,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
}
fn is_allocator(&self, cnum: CrateNum) -> bool
{
self.get_crate_data(cnum).is_allocator(&self.dep_graph)
}
fn is_panic_runtime(&self, cnum: CrateNum) -> bool
{
self.get_crate_data(cnum).is_panic_runtime(&self.dep_graph)
}
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
}

View File

@ -92,8 +92,8 @@ impl ExportedSymbols {
// Down below we'll hardwire all of the symbols to the `Rust` export
// level instead.
let special_runtime_crate =
scx.sess().cstore.is_allocator(cnum) ||
scx.sess().cstore.is_panic_runtime(cnum) ||
scx.tcx().is_allocator(cnum) ||
scx.tcx().is_panic_runtime(cnum) ||
scx.sess().cstore.is_compiler_builtins(cnum);
let crate_exports = scx