reuse original symbols for inlined items
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.
This commit is contained in:
parent
cf672850df
commit
2e7bc0f808
@ -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());
|
||||
@ -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);
|
||||
@ -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 {
|
||||
|
@ -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(),
|
||||
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user