Skip to content

Commit 1eb49a9

Browse files
committed
rustc: Migrate CStore::native_libraries to a query
1 parent 6a89f1c commit 1eb49a9

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
@@ -532,6 +532,7 @@ define_dep_nodes!( <'tcx>
532532
[] IsNoBuiltins(CrateNum),
533533
[] ImplDefaultness(DefId),
534534
[] ExportedSymbols(CrateNum),
535+
[] NativeLibraries(CrateNum),
535536
);
536537

537538
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;
1515
use hir;
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::RegionMaps;
2121
use mir;
@@ -565,6 +565,12 @@ impl<'tcx> QueryDescription for queries::exported_symbols<'tcx> {
565565
}
566566
}
567567

568+
impl<'tcx> QueryDescription for queries::native_libraries<'tcx> {
569+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
570+
format!("looking up the native libraries of a linked crate")
571+
}
572+
}
573+
568574
// If enabled, send a message to the profile-queries thread
569575
macro_rules! profq_msg {
570576
($tcx:expr, $msg:expr) => {
@@ -1139,6 +1145,7 @@ define_maps! { <'tcx>
11391145

11401146
[] impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
11411147
[] exported_symbols: ExportedSymbols(CrateNum) -> Rc<Vec<DefId>>,
1148+
[] native_libraries: NativeLibraries(CrateNum) -> Rc<Vec<NativeLibrary>>,
11421149
}
11431150

11441151
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
@@ -161,6 +161,7 @@ provide! { <'tcx> tcx, def_id, cdata,
161161
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
162162
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
163163
exported_symbols => { Rc::new(cdata.get_exported_symbols(&tcx.dep_graph)) }
164+
native_libraries => { Rc::new(cdata.get_native_libraries(&tcx.dep_graph)) }
164165
}
165166

166167
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -295,11 +296,6 @@ impl CrateStore for cstore::CStore {
295296
})
296297
}
297298

298-
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
299-
{
300-
self.get_crate_data(cnum).get_native_libraries(&self.dep_graph)
301-
}
302-
303299
/// Returns the `DefKey` for a given `DefId`. This indicates the
304300
/// parent `DefId` as well as some idea of what kind of data the
305301
/// `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);
@@ -964,7 +964,7 @@ fn link_args(cmd: &mut Linker,
964964
// on other dylibs (e.g. other native deps).
965965
add_local_native_libraries(cmd, sess);
966966
add_upstream_rust_crates(cmd, sess, trans, crate_type, tmpdir);
967-
add_upstream_native_libraries(cmd, sess, crate_type);
967+
add_upstream_native_libraries(cmd, sess, trans, crate_type);
968968

969969
// Tell the linker what we're doing.
970970
if crate_type != config::CrateTypeExecutable {
@@ -1201,7 +1201,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
12011201
// See the comment above in `link_staticlib` and `link_rlib` for why if
12021202
// there's a static library that's not relevant we skip all object
12031203
// files.
1204-
let native_libs = sess.cstore.native_libraries(cnum);
1204+
let native_libs = &trans.crate_info.native_libraries[&cnum];
12051205
let skip_native = native_libs.iter().any(|lib| {
12061206
lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib)
12071207
});
@@ -1314,7 +1314,10 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
13141314
// generic function calls a native function, then the generic function must
13151315
// be instantiated in the target crate, meaning that the native symbol must
13161316
// also be resolved in the target crate.
1317-
fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: config::CrateType) {
1317+
fn add_upstream_native_libraries(cmd: &mut Linker,
1318+
sess: &Session,
1319+
trans: &CrateTranslation,
1320+
crate_type: config::CrateType) {
13181321
// Be sure to use a topological sorting of crates because there may be
13191322
// interdependencies between native libraries. When passing -nodefaultlibs,
13201323
// for example, almost all native libraries depend on libc, so we have to
@@ -1329,7 +1332,7 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session, crate_type: c
13291332

13301333
let crates = sess.cstore.used_crates(LinkagePreference::RequireStatic);
13311334
for (cnum, _) in crates {
1332-
for lib in sess.cstore.native_libraries(cnum) {
1335+
for lib in trans.crate_info.native_libraries[&cnum].iter() {
13331336
if !relevant_lib(sess, &lib) {
13341337
continue
13351338
}

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)