trans: Rename reachable to exported_symbols where appropriate.

This commit is contained in:
Michael Woerister 2016-11-28 18:05:53 -05:00
parent d1a6d47f94
commit 5fd7c2bfef
12 changed files with 62 additions and 62 deletions

View file

@ -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
@ -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

View file

@ -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 {

View file

@ -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) {

View file

@ -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>,
@ -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>> {
@ -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();
@ -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,
});
@ -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);
@ -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();
@ -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(),

View file

@ -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>,
}

View file

@ -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(),
}
}
@ -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
@ -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.
@ -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)
}));

View file

@ -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 {
@ -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();

View file

@ -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(),
@ -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);
});
@ -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);
}
@ -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.

View file

@ -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)]
@ -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;
}
@ -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();
@ -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 {
@ -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
@ -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
@ -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 {
@ -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,
@ -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
@ -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(_)) => {
@ -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())
});
@ -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");
@ -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,

View file

@ -67,7 +67,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
metadata_llcx: ContextRef,
export_map: ExportMap,
reachable: NodeSet,
exported_symbols: NodeSet,
link_meta: LinkMeta,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
stats: Stats,
@ -437,7 +437,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
export_map: ExportMap,
link_meta: LinkMeta,
reachable: NodeSet,
exported_symbols: NodeSet,
check_overflow: bool)
-> SharedCrateContext<'b, 'tcx> {
let (metadata_llcx, metadata_llmod) = unsafe {
@ -454,7 +454,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
// they're not available to be linked against. This poses a few problems
// for the compiler, some of which are somewhat fundamental, but we use
// the `use_dll_storage_attrs` variable below to attach the `dllexport`
// attribute to all LLVM functions that are reachable (e.g. they're
// attribute to all LLVM functions that are exported e.g. they're
// already tagged with external linkage). This is suboptimal for a few
// reasons:
//
@ -493,7 +493,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
metadata_llmod: metadata_llmod,
metadata_llcx: metadata_llcx,
export_map: export_map,
reachable: reachable,
exported_symbols: exported_symbols,
link_meta: link_meta,
tcx: tcx,
stats: Stats {
@ -527,8 +527,8 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
&self.export_map
}
pub fn reachable<'a>(&'a self) -> &'a NodeSet {
&self.reachable
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
&self.exported_symbols
}
pub fn trait_cache(&self) -> &RefCell<DepTrackingMap<TraitSelectionCache<'tcx>>> {
@ -768,8 +768,8 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
&self.shared.export_map
}
pub fn reachable<'a>(&'a self) -> &'a NodeSet {
&self.shared.reachable
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
&self.shared.exported_symbols
}
pub fn link_meta<'a>(&'a self) -> &'a LinkMeta {

View file

@ -34,7 +34,7 @@ pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
// visible). It might better to use the `exported_items` set from
// `driver::CrateAnalysis` in the future, but (atm) this set is not
// available in the translation pass.
!cx.reachable().contains(&node_id)
!cx.exported_symbols().contains(&node_id)
}
#[allow(non_snake_case)]

View file

@ -169,7 +169,7 @@ pub struct CrateTranslation {
pub metadata_module: ModuleTranslation,
pub link: middle::cstore::LinkMeta,
pub metadata: Vec<u8>,
pub reachable: Vec<String>,
pub exported_symbols: Vec<String>,
pub no_builtins: bool,
pub windows_subsystem: Option<String>,
pub linker_info: back::linker::LinkerInfo