Skip to content

Commit

Permalink
metadata: Add is_exported_symbol() method to CrateStore.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Jan 9, 2017
1 parent 4dca459 commit 02c7b11
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/librustc/middle/cstore.rs
Expand Up @@ -211,6 +211,7 @@ pub trait CrateStore<'tcx> {
fn is_foreign_item(&self, did: DefId) -> bool;
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
fn is_exported_symbol(&self, def_id: DefId) -> bool;

// crate metadata
fn dylib_dependency_formats(&self, cnum: CrateNum)
Expand Down Expand Up @@ -368,6 +369,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
fn is_exported_symbol(&self, def_id: DefId) -> bool { false }

// crate metadata
fn dylib_dependency_formats(&self, cnum: CrateNum)
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_metadata/creader.rs
Expand Up @@ -302,10 +302,13 @@ impl<'a> CrateLoader<'a> {
crate_root.def_path_table.decode(&metadata)
});

let exported_symbols = crate_root.exported_symbols.decode(&metadata).collect();

let mut cmeta = cstore::CrateMetadata {
name: name,
extern_crate: Cell::new(None),
def_path_table: def_path_table,
exported_symbols: exported_symbols,
proc_macros: crate_root.macro_derive_registrar.map(|_| {
self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)
}),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -80,6 +80,8 @@ pub struct CrateMetadata {
/// compilation support.
pub def_path_table: DefPathTable,

pub exported_symbols: FxHashSet<DefIndex>,

pub dep_kind: Cell<DepKind>,
pub source: CrateSource,

Expand Down
12 changes: 10 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -226,6 +226,10 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
self.do_is_statically_included_foreign_item(def_id)
}

fn is_exported_symbol(&self, def_id: DefId) -> bool {
self.get_crate_data(def_id.krate).exported_symbols.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)
Expand Down Expand Up @@ -467,8 +471,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
}

fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool {
self.dep_graph.read(DepNode::MetaData(def));
def.is_local() || self.get_crate_data(def.krate).can_have_local_instance(tcx, def.index)
if def.is_local() {
true
} else {
self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).can_have_local_instance(tcx, def.index)
}
}

fn crates(&self) -> Vec<CrateNum>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/decoder.rs
Expand Up @@ -1031,7 +1031,7 @@ impl<'a, 'tcx> CrateMetadata {
}

pub fn get_exported_symbols(&self) -> Vec<DefId> {
self.root.exported_symbols.decode(self).map(|index| self.local_def_id(index)).collect()
self.exported_symbols.iter().map(|&index| self.local_def_id(index)).collect()
}

pub fn get_macro(&self, id: DefIndex) -> (ast::Name, MacroDef) {
Expand Down

0 comments on commit 02c7b11

Please sign in to comment.