Skip to content

Commit

Permalink
reuse original symbols for inlined items
Browse files Browse the repository at this point in the history
When inlining an item from another crate, use the original symbol from that
crate's metadata instead of generating a new symbol using the `ast::NodeId` of
the inlined copy.  This requires exporting symbols in the crate metadata in a
few additional cases.  Having predictable symbols for inlined items will be
useful later to avoid generating duplicate object code for inlined items.
  • Loading branch information
spernsteiner committed Sep 5, 2014
1 parent cf67285 commit 2e7bc0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -892,7 +892,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
IITraitItemRef(local_def(parent_id),
RequiredInlinedTraitItemRef(
&*ast_method)));
} else {
}
if !any_types {
encode_symbol(ecx, rbml_w, m.def_id.node);
}
encode_method_argument_names(rbml_w, &*ast_method.pe_fn_decl());
Expand Down Expand Up @@ -1047,7 +1048,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_attributes(rbml_w, item.attrs.as_slice());
if tps_len > 0u || should_inline(item.attrs.as_slice()) {
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
} else {
}
if tps_len == 0 {
encode_symbol(ecx, rbml_w, item.id);
}
encode_visibility(rbml_w, vis);
Expand Down Expand Up @@ -1411,9 +1413,8 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
encode_name(rbml_w, nitem.ident.name);
if abi == abi::RustIntrinsic {
encode_inlined_item(ecx, rbml_w, IIForeignRef(nitem));
} else {
encode_symbol(ecx, rbml_w, nitem.id);
}
encode_symbol(ecx, rbml_w, nitem.id);
}
ForeignItemStatic(_, mutbl) => {
if mutbl {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -2554,6 +2554,15 @@ pub fn create_entry_wrapper(ccx: &CrateContext,

fn exported_name(ccx: &CrateContext, id: ast::NodeId,
ty: ty::t, attrs: &[ast::Attribute]) -> String {
match ccx.external_srcs().borrow().find(&id) {
Some(&did) => {
let sym = csearch::get_symbol(&ccx.sess().cstore, did);
debug!("found item {} in other crate...", sym);
return sym;
}
None => {}
}

match attr::first_attr_value_str_by_name(attrs, "export_name") {
// Use provided name
Some(name) => name.get().to_string(),
Expand Down Expand Up @@ -2597,16 +2606,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
// using the current crate's name/version
// information in the hash of the symbol
debug!("making {}", sym);
let (sym, is_local) = {
match ccx.external_srcs().borrow().find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
(csearch::get_symbol(&ccx.sess().cstore,
did), false)
}
None => (sym, true)
}
};
let is_local = !ccx.external_srcs().borrow().contains_key(&id);

// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
Expand Down

0 comments on commit 2e7bc0f

Please sign in to comment.