Skip to content

Commit

Permalink
trans: Allow base::internalize_symbols() to internalize #[no_mangle] …
Browse files Browse the repository at this point in the history
…symbols
  • Loading branch information
michaelwoerister committed Sep 16, 2016
1 parent 928c398 commit bfa6fdc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
19 changes: 2 additions & 17 deletions src/librustc_trans/base.rs
Expand Up @@ -1421,21 +1421,7 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
.iter()
.cloned()
.filter(|trans_item|{
let def_id = match *trans_item {
TransItem::DropGlue(..) => {
return false
},
TransItem::Fn(ref instance) => {
instance.def
}
TransItem::Static(node_id) => {
tcx.map.local_def_id(node_id)
}
};

trans_item.explicit_linkage(tcx).is_some() ||
attr::contains_extern_indicator(tcx.sess.diagnostic(),
&tcx.get_attrs(def_id))
trans_item.explicit_linkage(tcx).is_some()
})
.map(|trans_item| symbol_map.get_or_compute(scx, trans_item))
.collect();
Expand Down Expand Up @@ -1900,8 +1886,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
partitioning::partition(scx,
items.iter().cloned(),
strategy,
&inlining_map,
scx.reachable())
&inlining_map)
});

assert!(scx.tcx().sess.opts.cg.codegen_units == codegen_units.len() ||
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_trans/partitioning.rs
Expand Up @@ -133,7 +133,7 @@ use symbol_map::SymbolMap;
use syntax::ast::NodeId;
use syntax::parse::token::{self, InternedString};
use trans_item::TransItem;
use util::nodemap::{FnvHashMap, FnvHashSet, NodeSet};
use util::nodemap::{FnvHashMap, FnvHashSet};

pub enum PartitioningStrategy {
/// Generate one codegen unit per source-level module.
Expand Down Expand Up @@ -254,8 +254,7 @@ const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
trans_items: I,
strategy: PartitioningStrategy,
inlining_map: &InliningMap<'tcx>,
reachable: &NodeSet)
inlining_map: &InliningMap<'tcx>)
-> Vec<CodegenUnit<'tcx>>
where I: Iterator<Item = TransItem<'tcx>>
{
Expand All @@ -265,8 +264,7 @@ pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
// respective 'home' codegen unit. Regular translation items are all
// functions and statics defined in the local crate.
let mut initial_partitioning = place_root_translation_items(scx,
trans_items,
reachable);
trans_items);

debug_dump(tcx, "INITIAL PARTITONING:", initial_partitioning.codegen_units.iter());

Expand Down Expand Up @@ -304,8 +302,7 @@ struct PreInliningPartitioning<'tcx> {
struct PostInliningPartitioning<'tcx>(Vec<CodegenUnit<'tcx>>);

fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
trans_items: I,
_reachable: &NodeSet)
trans_items: I)
-> PreInliningPartitioning<'tcx>
where I: Iterator<Item = TransItem<'tcx>>
{
Expand Down Expand Up @@ -344,6 +341,10 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
// This is a non-generic functions, we always
// make it visible externally on the chance that
// it might be used in another codegen unit.
// Later on base::internalize_symbols() will
// assign "internal" linkage to those symbols
// that are not referenced from other codegen
// units (and are not publicly visible).
llvm::ExternalLinkage
} else {
// In the current setup, generic functions cannot
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_trans/trans_item.rs
Expand Up @@ -251,7 +251,11 @@ impl<'a, 'tcx> TransItem<'tcx> {

/// True if the translation item should only be translated to LLVM IR if
/// it is referenced somewhere (like inline functions, for example).
pub fn is_instantiated_only_on_demand(&self, tcx: TyCtxt) -> bool {
pub fn is_instantiated_only_on_demand(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
if self.explicit_linkage(tcx).is_some() {
return false;
}

match *self {
TransItem::Fn(ref instance) => {
!instance.def.is_local() ||
Expand Down

0 comments on commit bfa6fdc

Please sign in to comment.