Skip to content

Commit

Permalink
Add local version of is_dllimport_foreign_item
Browse files Browse the repository at this point in the history
  • Loading branch information
cramertj committed May 10, 2017
1 parent 51b4db7 commit 7382526
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/doc/nomicon
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
reachable::provide(&mut local_providers);
rustc_const_eval::provide(&mut local_providers);
middle::region::provide(&mut local_providers);
cstore::provide_local(&mut local_providers);

let mut extern_providers = ty::maps::Providers::default();
cstore::provide(&mut extern_providers);
cstore::provide_extern(&mut extern_providers);
trans::provide(&mut extern_providers);
ty::provide_extern(&mut extern_providers);
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
Expand Down
27 changes: 17 additions & 10 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use std::collections::BTreeMap;

macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
pub fn provide_extern<$lt>(providers: &mut Providers<$lt>) {
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
-> <ty::queries::$name<$lt> as
DepTrackingMapConfig>::Value {
Expand Down Expand Up @@ -136,10 +136,26 @@ provide! { <'tcx> tcx, def_id, cdata
}
}
is_dllimport_foreign_item => {
// extern case
cdata.dllimport_foreign_items.contains(&def_id.index)
}
}

pub fn provide_local(providers: &mut ty::maps::Providers) {
providers.is_dllimport_foreign_item = is_dllimport_foreign_item;
}

fn is_dllimport_foreign_item_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
tcx.dep_graph.read(DepNode::MetaData(def_id));

let cdata = tcx.sess.cstore.crate_data_as_rc_any(def_id.krate);
let cdata = cdata.downcast_ref::<cstore::CrateMetadata>()
.expect("CrateStore crated ata is not a CrateMetadata");

cdata.get_crate_data(def_id.krate)
.is_dllimport_foreign_item(def_id.index, &cdata.dep_graph)
}

impl CrateStore for cstore::CStore {
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> {
self.get_crate_data(krate)
Expand Down Expand Up @@ -222,15 +238,6 @@ impl CrateStore for cstore::CStore {
.contains(&def_id.index)
}

fn is_dllimport_foreign_item(&self, def_id: DefId) -> bool {
if def_id.krate == LOCAL_CRATE {
self.dllimport_foreign_items.borrow().contains(&def_id.index)
} else {
self.get_crate_data(def_id.krate)
.is_dllimport_foreign_item(def_id.index, &self.dep_graph)
}
}

fn dylib_dependency_formats(&self, cnum: CrateNum)
-> Vec<(CrateNum, LinkagePreference)>
{
Expand Down
2 changes: 1 addition & 1 deletion src/rust-installer

0 comments on commit 7382526

Please sign in to comment.