rustc: Migrate CStore::native_libraries
to a query
This commit is contained in:
parent
98b74c580f
commit
205bc9a80a
src
librustc
librustc_metadata
librustc_trans
@ -536,6 +536,7 @@ define_dep_nodes!( <'tcx>
|
||||
[] IsNoBuiltins(CrateNum),
|
||||
[] ImplDefaultness(DefId),
|
||||
[] ExportedSymbols(CrateNum),
|
||||
[] NativeLibraries(CrateNum),
|
||||
);
|
||||
|
||||
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
|
||||
|
@ -257,7 +257,6 @@ pub trait CrateStore {
|
||||
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
|
||||
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
|
||||
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
|
||||
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
|
||||
|
||||
// resolve
|
||||
fn def_key(&self, def: DefId) -> DefKey;
|
||||
@ -364,8 +363,6 @@ impl CrateStore for DummyCrateStore {
|
||||
{ bug!("plugin_registrar_fn") }
|
||||
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
|
||||
{ bug!("derive_registrar_fn") }
|
||||
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
|
||||
{ bug!("native_libraries") }
|
||||
|
||||
// resolve
|
||||
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
|
||||
|
@ -15,7 +15,7 @@ use hir::def::{Def, Export};
|
||||
use hir::{self, TraitCandidate, HirId};
|
||||
use lint;
|
||||
use middle::const_val;
|
||||
use middle::cstore::{ExternCrate, LinkagePreference};
|
||||
use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary};
|
||||
use middle::privacy::AccessLevels;
|
||||
use middle::region;
|
||||
use mir;
|
||||
@ -593,6 +593,12 @@ impl<'tcx> QueryDescription for queries::exported_symbols<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription for queries::native_libraries<'tcx> {
|
||||
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
|
||||
format!("looking up the native libraries of a linked crate")
|
||||
}
|
||||
}
|
||||
|
||||
// If enabled, send a message to the profile-queries thread
|
||||
macro_rules! profq_msg {
|
||||
($tcx:expr, $msg:expr) => {
|
||||
@ -1170,6 +1176,7 @@ define_maps! { <'tcx>
|
||||
|
||||
[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
|
||||
[] fn exported_symbols: ExportedSymbols(CrateNum) -> Rc<Vec<DefId>>,
|
||||
[] fn native_libraries: NativeLibraries(CrateNum) -> Rc<Vec<NativeLibrary>>,
|
||||
}
|
||||
|
||||
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
|
||||
|
@ -164,6 +164,7 @@ provide! { <'tcx> tcx, def_id, cdata,
|
||||
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
|
||||
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
|
||||
exported_symbols => { Rc::new(cdata.get_exported_symbols(&tcx.dep_graph)) }
|
||||
native_libraries => { Rc::new(cdata.get_native_libraries(&tcx.dep_graph)) }
|
||||
}
|
||||
|
||||
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
|
||||
@ -298,11 +299,6 @@ impl CrateStore for cstore::CStore {
|
||||
})
|
||||
}
|
||||
|
||||
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
|
||||
{
|
||||
self.get_crate_data(cnum).get_native_libraries(&self.dep_graph)
|
||||
}
|
||||
|
||||
/// Returns the `DefKey` for a given `DefId`. This indicates the
|
||||
/// parent `DefId` as well as some idea of what kind of data the
|
||||
/// `DefId` refers to.
|
||||
|
@ -613,7 +613,7 @@ fn link_staticlib(sess: &Session,
|
||||
|
||||
let res = each_linked_rlib(sess, &mut |cnum, path| {
|
||||
let name = sess.cstore.crate_name(cnum);
|
||||
let native_libs = sess.cstore.native_libraries(cnum);
|
||||
let native_libs = &trans.crate_info.native_libraries[&cnum];
|
||||
|
||||
// Here when we include the rlib into our staticlib we need to make a
|
||||
// decision whether to include the extra object files along the way.
|
||||
@ -637,7 +637,7 @@ fn link_staticlib(sess: &Session,
|
||||
sess.lto() && !ignored_for_lto(&trans.crate_info, cnum),
|
||||
skip_object_files).unwrap();
|
||||
|
||||
all_native_libs.extend(sess.cstore.native_libraries(cnum));
|
||||
all_native_libs.extend(trans.crate_info.native_libraries[&cnum].iter().cloned());
|
||||
});
|
||||
if let Err(e) = res {
|
||||
sess.fatal(&e);
|
||||
@ -1002,7 +1002,7 @@ fn link_args(cmd: &mut Linker,
|
||||
// on other dylibs (e.g. other native deps).
|
||||
add_local_native_libraries(cmd, sess);
|
||||
add_upstream_rust_crates(cmd, sess, trans, crate_type, tmpdir);
|
||||
add_upstream_native_libraries(cmd, sess, crate_type);
|
||||
add_upstream_native_libraries(cmd, sess, trans, crate_type);
|
||||
|
||||
// Tell the linker what we're doing.
|
||||
if crate_type != config::CrateTypeExecutable {
|
||||
@ -1239,7 +1239,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
|
||||
// See the comment above in `link_staticlib` and `link_rlib` for why if
|
||||
// there's a static library that's not relevant we skip all object
|
||||
// files.
|
||||
let native_libs = sess.cstore.native_libraries(cnum);
|
||||
let native_libs = &trans.crate_info.native_libraries[&cnum];
|
||||
let skip_native = native_libs.iter().any(|lib| {
|
||||
lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib)
|
||||
});
|
||||
@ -1352,7 +1352,10 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
|
||||
// generic function calls a native function, then the generic function must
|
||||
// be instantiated in the target crate, meaning that the native symbol must
|
||||
// also be resolved in the target crate.
|
||||
fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: config::CrateType) {
|
||||
fn add_upstream_native_libraries(cmd: &mut Linker,
|
||||
sess: &Session,
|
||||
trans: &CrateTranslation,
|
||||
crate_type: config::CrateType) {
|
||||
// Be sure to use a topological sorting of crates because there may be
|
||||
// interdependencies between native libraries. When passing -nodefaultlibs,
|
||||
// for example, almost all native libraries depend on libc, so we have to
|
||||
@ -1367,7 +1370,7 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: c
|
||||
|
||||
let crates = sess.cstore.used_crates(LinkagePreference::RequireStatic);
|
||||
for (cnum, _) in crates {
|
||||
for lib in sess.cstore.native_libraries(cnum) {
|
||||
for lib in trans.crate_info.native_libraries[&cnum].iter() {
|
||||
if !relevant_lib(sess, &lib) {
|
||||
continue
|
||||
}
|
||||
|
@ -1515,9 +1515,11 @@ impl CrateInfo {
|
||||
profiler_runtime: None,
|
||||
sanitizer_runtime: None,
|
||||
is_no_builtins: FxHashSet(),
|
||||
native_libraries: FxHashMap(),
|
||||
};
|
||||
|
||||
for cnum in tcx.sess.cstore.crates() {
|
||||
info.native_libraries.insert(cnum, tcx.native_libraries(cnum));
|
||||
if tcx.is_panic_runtime(cnum) {
|
||||
info.panic_runtime = Some(cnum);
|
||||
}
|
||||
|
@ -65,8 +65,12 @@ pub use back::symbol_names::provide;
|
||||
|
||||
pub use metadata::LlvmMetadataLoader;
|
||||
pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc::hir::def_id::CrateNum;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
||||
use rustc::middle::cstore::NativeLibrary;
|
||||
|
||||
pub mod back {
|
||||
mod archive;
|
||||
@ -229,6 +233,7 @@ pub struct CrateInfo {
|
||||
profiler_runtime: Option<CrateNum>,
|
||||
sanitizer_runtime: Option<CrateNum>,
|
||||
is_no_builtins: FxHashSet<CrateNum>,
|
||||
native_libraries: FxHashMap<CrateNum, Rc<Vec<NativeLibrary>>>,
|
||||
}
|
||||
|
||||
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
|
||||
|
Loading…
x
Reference in New Issue
Block a user