On-demandify is_allocator and is_panic_runtime
This commit is contained in:
parent
328c6c81bf
commit
b0f05d4bc5
|
@ -251,8 +251,6 @@ pub trait CrateStore {
|
||||||
fn export_macros(&self, cnum: CrateNum);
|
fn export_macros(&self, cnum: CrateNum);
|
||||||
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
|
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
|
||||||
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
|
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_compiler_builtins(&self, cnum: CrateNum) -> bool;
|
||||||
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
|
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
|
||||||
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
|
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
|
||||||
|
@ -371,8 +369,6 @@ impl CrateStore for DummyCrateStore {
|
||||||
{ bug!("missing_lang_items") }
|
{ bug!("missing_lang_items") }
|
||||||
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
|
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
|
||||||
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
|
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_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
|
||||||
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runtime") }
|
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runtime") }
|
||||||
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
|
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
|
||||||
|
|
|
@ -97,7 +97,7 @@ pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
let mut fmts = sess.dependency_formats.borrow_mut();
|
let mut fmts = sess.dependency_formats.borrow_mut();
|
||||||
for &ty in sess.crate_types.borrow().iter() {
|
for &ty in sess.crate_types.borrow().iter() {
|
||||||
let linkage = calculate_type(tcx, ty);
|
let linkage = calculate_type(tcx, ty);
|
||||||
verify_ok(sess, &linkage);
|
verify_ok(tcx, &linkage);
|
||||||
fmts.insert(ty, linkage);
|
fmts.insert(ty, linkage);
|
||||||
}
|
}
|
||||||
sess.abort_if_errors();
|
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
|
// If the global prefer_dynamic switch is turned off, first attempt
|
||||||
// static linkage (this can fail).
|
// static linkage (this can fail).
|
||||||
config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => {
|
config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => {
|
||||||
if let Some(v) = attempt_static(sess) {
|
if let Some(v) = attempt_static(tcx) {
|
||||||
return v;
|
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.
|
// to be found, we generate some nice pretty errors.
|
||||||
config::CrateTypeStaticlib |
|
config::CrateTypeStaticlib |
|
||||||
config::CrateTypeCdylib => {
|
config::CrateTypeCdylib => {
|
||||||
if let Some(v) = attempt_static(sess) {
|
if let Some(v) = attempt_static(tcx) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
for cnum in sess.cstore.crates() {
|
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
|
// to try to eagerly statically link all dependencies. This is normally
|
||||||
// done for end-product dylibs, not intermediate products.
|
// done for end-product dylibs, not intermediate products.
|
||||||
config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
|
config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => {
|
||||||
if let Some(v) = attempt_static(sess) {
|
if let Some(v) = attempt_static(tcx) {
|
||||||
return v;
|
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
|
// Things like allocators and panic runtimes may not have been activated
|
||||||
// quite yet, so do so here.
|
// quite yet, so do so here.
|
||||||
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
|
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,
|
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.
|
// 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
|
// 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);
|
let crates = sess.cstore.used_crates(RequireStatic);
|
||||||
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
|
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
|
||||||
return None
|
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
|
// explicitly linked, which is the case for any injected dependency. Handle
|
||||||
// that here and activate them.
|
// that here and activate them.
|
||||||
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
|
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,
|
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)
|
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
|
// 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.
|
// 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 {
|
if list.len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -343,7 +345,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let cnum = CrateNum::new(i + 1);
|
let cnum = CrateNum::new(i + 1);
|
||||||
if sess.cstore.is_allocator(cnum) {
|
if tcx.is_allocator(cnum) {
|
||||||
if let Some(prev) = allocator {
|
if let Some(prev) = allocator {
|
||||||
let prev_name = sess.cstore.crate_name(prev);
|
let prev_name = sess.cstore.crate_name(prev);
|
||||||
let cur_name = sess.cstore.crate_name(cnum);
|
let cur_name = sess.cstore.crate_name(cnum);
|
||||||
|
@ -354,7 +356,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
|
||||||
allocator = Some(cnum);
|
allocator = Some(cnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if sess.cstore.is_panic_runtime(cnum) {
|
if tcx.is_panic_runtime(cnum) {
|
||||||
if let Some((prev, _)) = panic_runtime {
|
if let Some((prev, _)) = panic_runtime {
|
||||||
let prev_name = sess.cstore.crate_name(prev);
|
let prev_name = sess.cstore.crate_name(prev);
|
||||||
let cur_name = sess.cstore.crate_name(cnum);
|
let cur_name = sess.cstore.crate_name(cnum);
|
||||||
|
|
|
@ -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 {
|
macro_rules! define_maps {
|
||||||
(<$tcx:tt>
|
(<$tcx:tt>
|
||||||
$($(#[$attr:meta])*
|
$($(#[$attr:meta])*
|
||||||
|
@ -948,6 +960,9 @@ define_maps! { <'tcx>
|
||||||
|
|
||||||
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
|
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
|
||||||
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
|
-> 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 {
|
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {
|
||||||
|
|
|
@ -154,6 +154,8 @@ provide! { <'tcx> tcx, def_id, cdata, cnum,
|
||||||
|
|
||||||
ByCrateNum {
|
ByCrateNum {
|
||||||
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
|
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)
|
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 {
|
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool {
|
||||||
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
|
self.get_crate_data(cnum).is_compiler_builtins(&self.dep_graph)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,8 +92,8 @@ impl ExportedSymbols {
|
||||||
// Down below we'll hardwire all of the symbols to the `Rust` export
|
// Down below we'll hardwire all of the symbols to the `Rust` export
|
||||||
// level instead.
|
// level instead.
|
||||||
let special_runtime_crate =
|
let special_runtime_crate =
|
||||||
scx.sess().cstore.is_allocator(cnum) ||
|
scx.tcx().is_allocator(cnum) ||
|
||||||
scx.sess().cstore.is_panic_runtime(cnum) ||
|
scx.tcx().is_panic_runtime(cnum) ||
|
||||||
scx.sess().cstore.is_compiler_builtins(cnum);
|
scx.sess().cstore.is_compiler_builtins(cnum);
|
||||||
|
|
||||||
let crate_exports = scx
|
let crate_exports = scx
|
||||||
|
|
Loading…
Reference in New Issue