Skip to content

Commit 2e7bc0f

Browse files
committed
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.
1 parent cf67285 commit 2e7bc0f

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
892892
IITraitItemRef(local_def(parent_id),
893893
RequiredInlinedTraitItemRef(
894894
&*ast_method)));
895-
} else {
895+
}
896+
if !any_types {
896897
encode_symbol(ecx, rbml_w, m.def_id.node);
897898
}
898899
encode_method_argument_names(rbml_w, &*ast_method.pe_fn_decl());
@@ -1047,7 +1048,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
10471048
encode_attributes(rbml_w, item.attrs.as_slice());
10481049
if tps_len > 0u || should_inline(item.attrs.as_slice()) {
10491050
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
1050-
} else {
1051+
}
1052+
if tps_len == 0 {
10511053
encode_symbol(ecx, rbml_w, item.id);
10521054
}
10531055
encode_visibility(rbml_w, vis);
@@ -1411,9 +1413,8 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
14111413
encode_name(rbml_w, nitem.ident.name);
14121414
if abi == abi::RustIntrinsic {
14131415
encode_inlined_item(ecx, rbml_w, IIForeignRef(nitem));
1414-
} else {
1415-
encode_symbol(ecx, rbml_w, nitem.id);
14161416
}
1417+
encode_symbol(ecx, rbml_w, nitem.id);
14171418
}
14181419
ForeignItemStatic(_, mutbl) => {
14191420
if mutbl {

src/librustc/middle/trans/base.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,15 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
25542554

25552555
fn exported_name(ccx: &CrateContext, id: ast::NodeId,
25562556
ty: ty::t, attrs: &[ast::Attribute]) -> String {
2557+
match ccx.external_srcs().borrow().find(&id) {
2558+
Some(&did) => {
2559+
let sym = csearch::get_symbol(&ccx.sess().cstore, did);
2560+
debug!("found item {} in other crate...", sym);
2561+
return sym;
2562+
}
2563+
None => {}
2564+
}
2565+
25572566
match attr::first_attr_value_str_by_name(attrs, "export_name") {
25582567
// Use provided name
25592568
Some(name) => name.get().to_string(),
@@ -2597,16 +2606,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
25972606
// using the current crate's name/version
25982607
// information in the hash of the symbol
25992608
debug!("making {}", sym);
2600-
let (sym, is_local) = {
2601-
match ccx.external_srcs().borrow().find(&i.id) {
2602-
Some(&did) => {
2603-
debug!("but found in other crate...");
2604-
(csearch::get_symbol(&ccx.sess().cstore,
2605-
did), false)
2606-
}
2607-
None => (sym, true)
2608-
}
2609-
};
2609+
let is_local = !ccx.external_srcs().borrow().contains_key(&id);
26102610

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

0 commit comments

Comments
 (0)