Skip to content

Commit 205bc9a

Browse files
committed
rustc: Migrate CStore::native_libraries to a query
1 parent 98b74c5 commit 205bc9a

File tree

7 files changed

+27
-16
lines changed

7 files changed

+27
-16
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ define_dep_nodes!( <'tcx>
536536
[] IsNoBuiltins(CrateNum),
537537
[] ImplDefaultness(DefId),
538538
[] ExportedSymbols(CrateNum),
539+
[] NativeLibraries(CrateNum),
539540
);
540541

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

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ pub trait CrateStore {
257257
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
258258
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
259259
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
260-
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
261260

262261
// resolve
263262
fn def_key(&self, def: DefId) -> DefKey;
@@ -364,8 +363,6 @@ impl CrateStore for DummyCrateStore {
364363
{ bug!("plugin_registrar_fn") }
365364
fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
366365
{ bug!("derive_registrar_fn") }
367-
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
368-
{ bug!("native_libraries") }
369366

370367
// resolve
371368
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }

src/librustc/ty/maps.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir::def::{Def, Export};
1515
use hir::{self, TraitCandidate, HirId};
1616
use lint;
1717
use middle::const_val;
18-
use middle::cstore::{ExternCrate, LinkagePreference};
18+
use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary};
1919
use middle::privacy::AccessLevels;
2020
use middle::region;
2121
use mir;
@@ -593,6 +593,12 @@ impl<'tcx> QueryDescription for queries::exported_symbols<'tcx> {
593593
}
594594
}
595595

596+
impl<'tcx> QueryDescription for queries::native_libraries<'tcx> {
597+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
598+
format!("looking up the native libraries of a linked crate")
599+
}
600+
}
601+
596602
// If enabled, send a message to the profile-queries thread
597603
macro_rules! profq_msg {
598604
($tcx:expr, $msg:expr) => {
@@ -1170,6 +1176,7 @@ define_maps! { <'tcx>
11701176

11711177
[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
11721178
[] fn exported_symbols: ExportedSymbols(CrateNum) -> Rc<Vec<DefId>>,
1179+
[] fn native_libraries: NativeLibraries(CrateNum) -> Rc<Vec<NativeLibrary>>,
11731180
}
11741181

11751182
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ provide! { <'tcx> tcx, def_id, cdata,
164164
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
165165
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
166166
exported_symbols => { Rc::new(cdata.get_exported_symbols(&tcx.dep_graph)) }
167+
native_libraries => { Rc::new(cdata.get_native_libraries(&tcx.dep_graph)) }
167168
}
168169

169170
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -298,11 +299,6 @@ impl CrateStore for cstore::CStore {
298299
})
299300
}
300301

301-
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
302-
{
303-
self.get_crate_data(cnum).get_native_libraries(&self.dep_graph)
304-
}
305-
306302
/// Returns the `DefKey` for a given `DefId`. This indicates the
307303
/// parent `DefId` as well as some idea of what kind of data the
308304
/// `DefId` refers to.

src/librustc_trans/back/link.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ fn link_staticlib(sess: &Session,
613613

614614
let res = each_linked_rlib(sess, &mut |cnum, path| {
615615
let name = sess.cstore.crate_name(cnum);
616-
let native_libs = sess.cstore.native_libraries(cnum);
616+
let native_libs = &trans.crate_info.native_libraries[&cnum];
617617

618618
// Here when we include the rlib into our staticlib we need to make a
619619
// decision whether to include the extra object files along the way.
@@ -637,7 +637,7 @@ fn link_staticlib(sess: &Session,
637637
sess.lto() && !ignored_for_lto(&trans.crate_info, cnum),
638638
skip_object_files).unwrap();
639639

640-
all_native_libs.extend(sess.cstore.native_libraries(cnum));
640+
all_native_libs.extend(trans.crate_info.native_libraries[&cnum].iter().cloned());
641641
});
642642
if let Err(e) = res {
643643
sess.fatal(&e);
@@ -1002,7 +1002,7 @@ fn link_args(cmd: &mut Linker,
10021002
// on other dylibs (e.g. other native deps).
10031003
add_local_native_libraries(cmd, sess);
10041004
add_upstream_rust_crates(cmd, sess, trans, crate_type, tmpdir);
1005-
add_upstream_native_libraries(cmd, sess, crate_type);
1005+
add_upstream_native_libraries(cmd, sess, trans, crate_type);
10061006

10071007
// Tell the linker what we're doing.
10081008
if crate_type != config::CrateTypeExecutable {
@@ -1239,7 +1239,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
12391239
// See the comment above in `link_staticlib` and `link_rlib` for why if
12401240
// there's a static library that's not relevant we skip all object
12411241
// files.
1242-
let native_libs = sess.cstore.native_libraries(cnum);
1242+
let native_libs = &trans.crate_info.native_libraries[&cnum];
12431243
let skip_native = native_libs.iter().any(|lib| {
12441244
lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib)
12451245
});
@@ -1352,7 +1352,10 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
13521352
// generic function calls a native function, then the generic function must
13531353
// be instantiated in the target crate, meaning that the native symbol must
13541354
// also be resolved in the target crate.
1355-
fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: config::CrateType) {
1355+
fn add_upstream_native_libraries(cmd: &mut Linker,
1356+
sess: &Session,
1357+
trans: &CrateTranslation,
1358+
crate_type: config::CrateType) {
13561359
// Be sure to use a topological sorting of crates because there may be
13571360
// interdependencies between native libraries. When passing -nodefaultlibs,
13581361
// 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
13671370

13681371
let crates = sess.cstore.used_crates(LinkagePreference::RequireStatic);
13691372
for (cnum, _) in crates {
1370-
for lib in sess.cstore.native_libraries(cnum) {
1373+
for lib in trans.crate_info.native_libraries[&cnum].iter() {
13711374
if !relevant_lib(sess, &lib) {
13721375
continue
13731376
}

src/librustc_trans/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,11 @@ impl CrateInfo {
15151515
profiler_runtime: None,
15161516
sanitizer_runtime: None,
15171517
is_no_builtins: FxHashSet(),
1518+
native_libraries: FxHashMap(),
15181519
};
15191520

15201521
for cnum in tcx.sess.cstore.crates() {
1522+
info.native_libraries.insert(cnum, tcx.native_libraries(cnum));
15211523
if tcx.is_panic_runtime(cnum) {
15221524
info.panic_runtime = Some(cnum);
15231525
}

src/librustc_trans/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ pub use back::symbol_names::provide;
6565

6666
pub use metadata::LlvmMetadataLoader;
6767
pub use llvm_util::{init, target_features, print_version, print_passes, print, enable_llvm_debug};
68+
69+
use std::rc::Rc;
70+
6871
use rustc::hir::def_id::CrateNum;
69-
use rustc::util::nodemap::FxHashSet;
72+
use rustc::util::nodemap::{FxHashSet, FxHashMap};
73+
use rustc::middle::cstore::NativeLibrary;
7074

7175
pub mod back {
7276
mod archive;
@@ -229,6 +233,7 @@ pub struct CrateInfo {
229233
profiler_runtime: Option<CrateNum>,
230234
sanitizer_runtime: Option<CrateNum>,
231235
is_no_builtins: FxHashSet<CrateNum>,
236+
native_libraries: FxHashMap<CrateNum, Rc<Vec<NativeLibrary>>>,
232237
}
233238

234239
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }

0 commit comments

Comments
 (0)