Skip to content

Commit

Permalink
trans: Rename reachable to exported_symbols where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Dec 5, 2016
1 parent d1a6d47 commit 5fd7c2b
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/cstore.rs
Expand Up @@ -329,7 +329,7 @@ pub trait CrateStore<'tcx> {
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId>;
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
fn is_no_builtins(&self, cnum: CrateNum) -> bool;

// resolve
Expand Down Expand Up @@ -493,7 +493,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
{ bug!("plugin_registrar_fn") }
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
{ bug!("native_libraries") }
fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId> { bug!("reachable_ids") }
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }

// resolve
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -311,9 +311,9 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
self.get_crate_data(cnum).get_native_libraries()
}

fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId>
fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>
{
self.get_crate_data(cnum).get_reachable_ids()
self.get_crate_data(cnum).get_exported_symbols()
}

fn is_no_builtins(&self, cnum: CrateNum) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -1038,8 +1038,8 @@ impl<'a, 'tcx> CrateMetadata {
arg_names.decode(self).collect()
}

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

pub fn get_macro(&self, id: DefIndex) -> (ast::Name, MacroDef) {
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -50,7 +50,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
reexports: &'a def::ExportMap,
link_meta: &'a LinkMeta,
cstore: &'a cstore::CStore,
reachable: &'a NodeSet,
exported_symbols: &'a NodeSet,

lazy_state: LazyState,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
Expand Down Expand Up @@ -1223,16 +1223,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_seq(all_impls)
}

// Encodes all reachable symbols in this crate into the metadata.
// Encodes all symbols exported from this crate into the metadata.
//
// This pass is seeded off the reachability list calculated in the
// middle::reachable module but filters out items that either don't have a
// symbol associated with them (they weren't translated) or if they're an FFI
// definition (as that's not defined in this crate).
fn encode_reachable(&mut self) -> LazySeq<DefIndex> {
let reachable = self.reachable;
fn encode_exported_symbols(&mut self) -> LazySeq<DefIndex> {
let exported_symbols = self.exported_symbols;
let tcx = self.tcx;
self.lazy_seq(reachable.iter().map(|&id| tcx.map.local_def_id(id).index))
self.lazy_seq(exported_symbols.iter().map(|&id| tcx.map.local_def_id(id).index))
}

fn encode_dylib_dependency_formats(&mut self) -> LazySeq<Option<LinkagePreference>> {
Expand Down Expand Up @@ -1278,10 +1278,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let impls = self.encode_impls();
let impl_bytes = self.position() - i;

// Encode reachability info.
// Encode exported symbols info.
i = self.position();
let reachable_ids = self.encode_reachable();
let reachable_bytes = self.position() - i;
let exported_symbols = self.encode_exported_symbols();
let exported_symbols_bytes = self.position() - i;

// Encode and index the items.
i = self.position();
Expand Down Expand Up @@ -1319,7 +1319,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
native_libraries: native_libraries,
codemap: codemap,
impls: impls,
reachable_ids: reachable_ids,
exported_symbols: exported_symbols,
index: index,
});

Expand All @@ -1339,7 +1339,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
println!(" native bytes: {}", native_lib_bytes);
println!(" codemap bytes: {}", codemap_bytes);
println!(" impl bytes: {}", impl_bytes);
println!(" reachable bytes: {}", reachable_bytes);
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
println!(" item bytes: {}", item_bytes);
println!(" index bytes: {}", index_bytes);
println!(" zero bytes: {}", zero_bytes);
Expand Down Expand Up @@ -1377,7 +1377,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cstore: &cstore::CStore,
reexports: &def::ExportMap,
link_meta: &LinkMeta,
reachable: &NodeSet)
exported_symbols: &NodeSet)
-> Vec<u8> {
let mut cursor = Cursor::new(vec![]);
cursor.write_all(METADATA_HEADER).unwrap();
Expand All @@ -1392,7 +1392,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
reexports: reexports,
link_meta: link_meta,
cstore: cstore,
reachable: reachable,
exported_symbols: exported_symbols,
lazy_state: LazyState::NoNode,
type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/schema.rs
Expand Up @@ -180,7 +180,7 @@ pub struct CrateRoot {
pub native_libraries: LazySeq<NativeLibrary>,
pub codemap: LazySeq<syntax_pos::FileMap>,
pub impls: LazySeq<TraitImpls>,
pub reachable_ids: LazySeq<DefIndex>,
pub exported_symbols: LazySeq<DefIndex>,
pub index: LazySeq<index::Index>,
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_trans/back/linker.rs
Expand Up @@ -34,10 +34,10 @@ pub struct LinkerInfo {

impl<'a, 'tcx> LinkerInfo {
pub fn new(scx: &SharedCrateContext<'a, 'tcx>,
reachable: &[String]) -> LinkerInfo {
exports: &[String]) -> LinkerInfo {
LinkerInfo {
exports: scx.sess().crate_types.borrow().iter().map(|&c| {
(c, exported_symbols(scx, reachable, c))
(c, exported_symbols(scx, exports, c))
}).collect(),
}
}
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'a> Linker for MsvcLinker<'a> {
}

fn exported_symbols(scx: &SharedCrateContext,
reachable: &[String],
exported_symbols: &[String],
crate_type: CrateType)
-> Vec<String> {
// See explanation in GnuLinker::export_symbols, for
Expand All @@ -485,7 +485,7 @@ fn exported_symbols(scx: &SharedCrateContext,
}
}

let mut symbols = reachable.to_vec();
let mut symbols = exported_symbols.to_vec();

// If we're producing anything other than a dylib then the `reachable` array
// above is the exhaustive set of symbols we should be exporting.
Expand All @@ -507,7 +507,7 @@ fn exported_symbols(scx: &SharedCrateContext,
None
}
}).flat_map(|cnum| {
cstore.reachable_ids(cnum)
cstore.exported_symbols(cnum)
}).map(|did| -> String {
Instance::mono(scx, did).symbol_name(scx)
}));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/back/lto.rs
Expand Up @@ -25,7 +25,7 @@ use std::ffi::CString;
use std::path::Path;

pub fn run(sess: &session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[String],
tm: TargetMachineRef, exported_symbols: &[String],
config: &ModuleConfig,
temp_no_opt_bc_filename: &Path) {
if sess.opts.cg.prefer_dynamic {
Expand Down Expand Up @@ -118,8 +118,8 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
}
});

// Internalize everything but the reachable symbols of the current module
let cstrs: Vec<CString> = reachable.iter().map(|s| {
// Internalize everything but the exported symbols of the current module
let cstrs: Vec<CString> = exported_symbols.iter().map(|s| {
CString::new(s.clone()).unwrap()
}).collect();
let arr: Vec<*const libc::c_char> = cstrs.iter().map(|c| c.as_ptr()).collect();
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_trans/back/write.rs
Expand Up @@ -343,9 +343,9 @@ struct CodegenContext<'a> {
}

impl<'a> CodegenContext<'a> {
fn new_with_session(sess: &'a Session, reachable: &'a [String]) -> CodegenContext<'a> {
fn new_with_session(sess: &'a Session, exported_symbols: &'a [String]) -> CodegenContext<'a> {
CodegenContext {
lto_ctxt: Some((sess, reachable)),
lto_ctxt: Some((sess, exported_symbols)),
handler: sess.diagnostic(),
plugin_passes: sess.plugin_llvm_passes.borrow().clone(),
remark: sess.opts.cg.remark.clone(),
Expand Down Expand Up @@ -516,14 +516,14 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
llvm::LLVMDisposePassManager(mpm);

match cgcx.lto_ctxt {
Some((sess, reachable)) if sess.lto() => {
Some((sess, exported_symbols)) if sess.lto() => {
time(sess.time_passes(), "all lto passes", || {
let temp_no_opt_bc_filename =
output_names.temp_path_ext("no-opt.lto.bc", module_name);
lto::run(sess,
llmod,
tm,
reachable,
exported_symbols,
&config,
&temp_no_opt_bc_filename);
});
Expand Down Expand Up @@ -753,7 +753,7 @@ pub fn run_passes(sess: &Session,
// potentially create hundreds of them).
let num_workers = work_items.len() - 1;
if num_workers == 1 {
run_work_singlethreaded(sess, &trans.reachable, work_items);
run_work_singlethreaded(sess, &trans.exported_symbols, work_items);
} else {
run_work_multithreaded(sess, work_items, num_workers);
}
Expand Down Expand Up @@ -997,9 +997,9 @@ fn execute_work_item(cgcx: &CodegenContext,
}

fn run_work_singlethreaded(sess: &Session,
reachable: &[String],
exported_symbols: &[String],
work_items: Vec<WorkItem>) {
let cgcx = CodegenContext::new_with_session(sess, reachable);
let cgcx = CodegenContext::new_with_session(sess, exported_symbols);

// Since we're running single-threaded, we can pass the session to
// the proc, allowing `optimize_and_codegen` to perform LTO.
Expand Down
36 changes: 18 additions & 18 deletions src/librustc_trans/base.rs
Expand Up @@ -1243,7 +1243,7 @@ fn contains_null(s: &str) -> bool {
}

fn write_metadata(cx: &SharedCrateContext,
reachable_ids: &NodeSet) -> Vec<u8> {
exported_symbols: &NodeSet) -> Vec<u8> {
use flate;

#[derive(PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -1275,7 +1275,7 @@ fn write_metadata(cx: &SharedCrateContext,
let metadata = cstore.encode_metadata(cx.tcx(),
cx.export_map(),
cx.link_meta(),
reachable_ids);
exported_symbols);
if kind == MetadataKind::Uncompressed {
return metadata;
}
Expand Down Expand Up @@ -1313,7 +1313,7 @@ fn write_metadata(cx: &SharedCrateContext,
fn internalize_symbols<'a, 'tcx>(sess: &Session,
ccxs: &CrateContextList<'a, 'tcx>,
symbol_map: &SymbolMap<'tcx>,
reachable: &FxHashSet<&str>) {
exported_symbols: &FxHashSet<&str>) {
let scx = ccxs.shared();
let tcx = scx.tcx();

Expand Down Expand Up @@ -1379,7 +1379,7 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
let name_cow = Cow::Borrowed(name_str);

let is_referenced_somewhere = referenced_somewhere.contains(&name_cstr);
let is_reachable = reachable.contains(&name_str);
let is_reachable = exported_symbols.contains(&name_str);
let has_fixed_linkage = linkage_fixed_explicitly.contains(&name_cow);

if !is_referenced_somewhere && !is_reachable && !has_fixed_linkage {
Expand Down Expand Up @@ -1481,7 +1481,7 @@ fn iter_functions(llmod: llvm::ModuleRef) -> ValueIter {
///
/// This list is later used by linkers to determine the set of symbols needed to
/// be exposed from a dynamic library and it's also encoded into the metadata.
pub fn filter_reachable_ids(tcx: TyCtxt, reachable: NodeSet) -> NodeSet {
pub fn find_exported_symbols(tcx: TyCtxt, reachable: NodeSet) -> NodeSet {
reachable.into_iter().filter(|&id| {
// Next, we want to ignore some FFI functions that are not exposed from
// this crate. Reachable FFI functions can be lumped into two
Expand Down Expand Up @@ -1535,7 +1535,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let krate = tcx.map.krate();

let ty::CrateAnalysis { export_map, reachable, name, .. } = analysis;
let reachable = filter_reachable_ids(tcx, reachable);
let exported_symbols = find_exported_symbols(tcx, reachable);

let check_overflow = if let Some(v) = tcx.sess.opts.debugging_opts.force_overflow_checks {
v
Expand All @@ -1548,11 +1548,11 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let shared_ccx = SharedCrateContext::new(tcx,
export_map,
link_meta.clone(),
reachable,
exported_symbols,
check_overflow);
// Translate the metadata.
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
write_metadata(&shared_ccx, shared_ccx.reachable())
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
});

let metadata_module = ModuleTranslation {
Expand Down Expand Up @@ -1608,7 +1608,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
metadata_module: metadata_module,
link: link_meta,
metadata: metadata,
reachable: vec![],
exported_symbols: vec![],
no_builtins: no_builtins,
linker_info: linker_info,
windows_subsystem: None,
Expand Down Expand Up @@ -1688,17 +1688,17 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

let sess = shared_ccx.sess();
let mut reachable_symbols = shared_ccx.reachable().iter().map(|&id| {
let mut exported_symbols = shared_ccx.exported_symbols().iter().map(|&id| {
let def_id = shared_ccx.tcx().map.local_def_id(id);
symbol_for_def_id(def_id, &shared_ccx, &symbol_map)
}).collect::<Vec<_>>();

if sess.entry_fn.borrow().is_some() {
reachable_symbols.push("main".to_string());
exported_symbols.push("main".to_string());
}

if sess.crate_types.borrow().contains(&config::CrateTypeDylib) {
reachable_symbols.push(shared_ccx.metadata_symbol_name());
exported_symbols.push(shared_ccx.metadata_symbol_name());
}

// For the purposes of LTO or when creating a cdylib, we add to the
Expand All @@ -1708,10 +1708,10 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
//
// Note that this happens even if LTO isn't requested or we're not creating
// a cdylib. In those cases, though, we're not even reading the
// `reachable_symbols` list later on so it should be ok.
// `exported_symbols` list later on so it should be ok.
for cnum in sess.cstore.crates() {
let syms = sess.cstore.reachable_ids(cnum);
reachable_symbols.extend(syms.into_iter().filter(|&def_id| {
let syms = sess.cstore.exported_symbols(cnum);
exported_symbols.extend(syms.into_iter().filter(|&def_id| {
let applicable = match sess.cstore.describe_def(def_id) {
Some(Def::Static(..)) => true,
Some(Def::Fn(_)) => {
Expand All @@ -1735,7 +1735,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
internalize_symbols(sess,
&crate_context_list,
&symbol_map,
&reachable_symbols.iter()
&exported_symbols.iter()
.map(|s| &s[..])
.collect())
});
Expand All @@ -1749,7 +1749,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
create_imps(&crate_context_list);
}

let linker_info = LinkerInfo::new(&shared_ccx, &reachable_symbols);
let linker_info = LinkerInfo::new(&shared_ccx, &exported_symbols);

let subsystem = attr::first_attr_value_str_by_name(&krate.attrs,
"windows_subsystem");
Expand All @@ -1767,7 +1767,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
metadata_module: metadata_module,
link: link_meta,
metadata: metadata,
reachable: reachable_symbols,
exported_symbols: exported_symbols,
no_builtins: no_builtins,
linker_info: linker_info,
windows_subsystem: windows_subsystem,
Expand Down

0 comments on commit 5fd7c2b

Please sign in to comment.