Skip to content

Resume inlining globals across crates #9130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct EncodeParams<'self> {
reexports2: middle::resolve::ExportMap2,
item_symbols: &'self HashMap<ast::NodeId, ~str>,
discrim_symbols: &'self HashMap<ast::NodeId, @str>,
non_inlineable_statics: &'self HashSet<ast::NodeId>,
link_meta: &'self LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item<'self>,
Expand Down Expand Up @@ -89,6 +90,7 @@ pub struct EncodeContext<'self> {
reexports2: middle::resolve::ExportMap2,
item_symbols: &'self HashMap<ast::NodeId, ~str>,
discrim_symbols: &'self HashMap<ast::NodeId, @str>,
non_inlineable_statics: &'self HashSet<ast::NodeId>,
link_meta: &'self LinkMeta,
cstore: &'self cstore::CStore,
encode_inlined_item: encode_inlined_item<'self>,
Expand Down Expand Up @@ -907,7 +909,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ecx, ebml_w, item.ident);
let elt = ast_map::path_pretty_name(item.ident, item.id as u64);
encode_path(ecx, ebml_w, path, elt);
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
if !ecx.non_inlineable_statics.contains(&item.id) {
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
}
ebml_w.end_tag();
}
item_fn(_, purity, _, ref generics, _) => {
Expand Down Expand Up @@ -1728,6 +1732,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
encode_inlined_item,
link_meta,
reachable,
non_inlineable_statics,
_
} = parms;
let type_abbrevs = @mut HashMap::new();
Expand All @@ -1739,6 +1744,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
reexports2: reexports2,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
non_inlineable_statics: non_inlineable_statics,
link_meta: link_meta,
cstore: cstore,
encode_inlined_item: encode_inlined_item,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,16 @@ fn trans_opt(bcx: @mut Block, o: &Opt) -> opt_result {
return single_result(datumblock.to_result(bcx));
}
lit(ConstLit(lit_id)) => {
let llval = consts::get_const_val(bcx.ccx(), lit_id);
let (llval, _) = consts::get_const_val(bcx.ccx(), lit_id);
return single_result(rslt(bcx, llval));
}
var(disr_val, repr) => {
return adt::trans_case(bcx, repr, disr_val);
}
range(l1, l2) => {
return range_result(rslt(bcx, consts::const_expr(ccx, l1)),
rslt(bcx, consts::const_expr(ccx, l2)));
let (l1, _) = consts::const_expr(ccx, l1);
let (l2, _) = consts::const_expr(ccx, l2);
return range_result(rslt(bcx, l1), rslt(bcx, l2));
}
vec_len(n, vec_len_eq, _) => {
return single_result(rslt(bcx, C_int(ccx, n as int)));
Expand Down
24 changes: 21 additions & 3 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,12 +2494,29 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
let sym = exported_name(ccx, my_path, ty, i.attrs);

let v = match i.node {
ast::item_static(_, m, expr) => {
ast::item_static(_, _, expr) => {
// If this static came from an external crate, then
// we need to get the symbol from csearch instead of
// using the current crate's name/version
// information in the hash of the symbol
debug!("making %s", sym);
let sym = match ccx.external_srcs.find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
csearch::get_symbol(ccx.sess.cstore, did)
}
None => sym
};

// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
let v = consts::const_expr(ccx, expr);
let (v, inlineable) = consts::const_expr(ccx, expr);
ccx.const_values.insert(id, v);
exprt = (m == ast::MutMutable || i.vis == ast::public);
if !inlineable {
debug!("%s not inlined", sym);
ccx.non_inlineable_statics.insert(id);
}
exprt = true;

unsafe {
let llty = llvm::LLVMTypeOf(v);
Expand Down Expand Up @@ -2950,6 +2967,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_
reexports2: cx.exp_map2,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
non_inlineable_statics: &cx.non_inlineable_statics,
link_meta: link_meta,
cstore: cx.sess.cstore,
encode_inlined_item: ie,
Expand Down
Loading