Skip to content

Commit

Permalink
Consider only libs that aren't excluded by #[link(cfg=...)]
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimcn committed Dec 6, 2016
1 parent b700dd3 commit 7d05d1e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
24 changes: 20 additions & 4 deletions src/librustc_metadata/creader.rs
Expand Up @@ -113,6 +113,13 @@ fn register_native_lib(sess: &Session,
cstore.add_used_library(lib);
}

fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool {
match lib.cfg {
Some(ref cfg) => attr::cfg_matches(cfg, &sess.parse_sess, None),
None => true,
}
}

// Extra info about a crate loaded for plugins or exported macros.
struct ExtensionCrate {
metadata: PMDSource,
Expand Down Expand Up @@ -290,7 +297,7 @@ impl<'a> CrateLoader<'a> {

let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);

let cmeta = Rc::new(cstore::CrateMetadata {
let mut cmeta = cstore::CrateMetadata {
name: name,
extern_crate: Cell::new(None),
key_map: metadata.load_key_map(crate_root.index),
Expand All @@ -308,9 +315,18 @@ impl<'a> CrateLoader<'a> {
rlib: rlib,
rmeta: rmeta,
},
dllimport_foreign_items: RefCell::new(None),
});
dllimport_foreign_items: FxHashSet(),
};

let dllimports: Vec<_> = cmeta.get_native_libraries().iter()
.filter(|lib| relevant_lib(self.sess, lib) &&
lib.kind == cstore::NativeLibraryKind::NativeUnknown)
.flat_map(|lib| &lib.foreign_items)
.map(|id| *id)
.collect();
cmeta.dllimport_foreign_items.extend(dllimports);

let cmeta = Rc::new(cmeta);
self.cstore.set_crate_data(cnum, cmeta.clone());
(cnum, cmeta)
}
Expand Down Expand Up @@ -643,7 +659,7 @@ impl<'a> CrateLoader<'a> {
let mut items = vec![];
let libs = self.cstore.get_used_libraries();
for lib in libs.borrow().iter() {
if lib.kind == kind {
if relevant_lib(self.sess, lib) && lib.kind == kind {
items.extend(&lib.foreign_items);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/cstore.rs
Expand Up @@ -85,7 +85,7 @@ pub struct CrateMetadata {

pub proc_macros: Option<Vec<(ast::Name, Rc<SyntaxExtension>)>>,
// Foreign items imported from a dylib (Windows only)
pub dllimport_foreign_items: RefCell<Option<FxHashSet<DefIndex>>>,
pub dllimport_foreign_items: FxHashSet<DefIndex>,
}

pub struct CachedInlinedItem {
Expand Down
15 changes: 3 additions & 12 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -11,13 +11,13 @@
// Decoding metadata from a single crate's metadata

use astencode::decode_inlined_item;
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, NativeLibraryKind};
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
use index::Index;
use schema::*;

use rustc::hir::map as hir_map;
use rustc::hir::map::{DefKey, DefPathData};
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc::util::nodemap::FxHashMap;
use rustc::hir;
use rustc::hir::intravisit::IdRange;

Expand All @@ -36,7 +36,6 @@ use rustc::mir::Mir;
use std::borrow::Cow;
use std::cell::Ref;
use std::io;
use std::iter::FromIterator;
use std::mem;
use std::str;
use std::u32;
Expand Down Expand Up @@ -1089,15 +1088,7 @@ impl<'a, 'tcx> CrateMetadata {
}

pub fn is_dllimport_foreign_item(&self, id: DefIndex) -> bool {
if self.dllimport_foreign_items.borrow().is_none() {
*self.dllimport_foreign_items.borrow_mut() = Some(FxHashSet::from_iter(
self.get_native_libraries().iter()
.filter(|lib| lib.kind == NativeLibraryKind::NativeUnknown)
.flat_map(|lib| &lib.foreign_items)
.map(|id| *id)
));
}
self.dllimport_foreign_items.borrow().as_ref().unwrap().contains(&id)
self.dllimport_foreign_items.contains(&id)
}

pub fn is_defaulted_trait(&self, trait_id: DefIndex) -> bool {
Expand Down

0 comments on commit 7d05d1e

Please sign in to comment.