Skip to content

librustc: Inline cross-crate tuple struct constructors #9560

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

Merged
merged 1 commit into from
Oct 1, 2013
Merged
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
9 changes: 7 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
path: &[ast_map::path_elt],
name: ast::Ident,
ctor_id: NodeId,
index: @mut ~[entry<i64>]) {
index: @mut ~[entry<i64>],
struct_id: NodeId) {
index.push(entry { val: ctor_id as i64, pos: ebml_w.writer.tell() });

ebml_w.start_tag(tag_items_data_item);
Expand All @@ -756,6 +757,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
encode_name(ecx, ebml_w, name);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id));
encode_path(ecx, ebml_w, path, ast_map::path_name(name));
encode_parent_item(ebml_w, local_def(struct_id));

if ecx.item_symbols.contains_key(&ctor_id) {
encode_symbol(ecx, ebml_w, ctor_id);
Expand Down Expand Up @@ -1032,6 +1034,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
needs to know*/
encode_struct_fields(ecx, ebml_w, struct_def);

(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));

// Encode inherent implementations for this structure.
encode_inherent_implementations(ecx, ebml_w, def_id);

Expand All @@ -1054,7 +1058,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
path,
item.ident,
ctor_id,
index);
index,
def_id.node);
}
}
item_impl(_, ref opt_trait, ref ty, ref ast_methods) => {
Expand Down
11 changes: 10 additions & 1 deletion src/librustc/middle/trans/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
ccx.external.insert(there.id, Some(here.id.node));
}
}
ast::item_struct(ref struct_def, _) => {
match struct_def.ctor_id {
None => {}
Some(ctor_id) => {
let _ = ccx.external.insert(fn_id, Some(ctor_id));
my_id = ctor_id;
}
}
}
_ => ccx.sess.bug("maybe_instantiate_inline: item has a \
non-enum parent")
non-enum, non-struct parent")
}
trans_item(ccx, item);
local_def(my_id)
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ pub fn map_decoded_item(diag: @mut span_handler,
diag: diag,
};

// methods get added to the AST map when their impl is visited. Since we
// Methods get added to the AST map when their impl is visited. Since we
// don't decode and instantiate the impl, but just the method, we have to
// add it to the table now:
// add it to the table now. Likewise with foreign items.
match *ii {
ii_item(*) => {} // fallthrough
ii_foreign(i) => {
Expand Down
11 changes: 11 additions & 0 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,17 @@ impl Visitor<()> for IdVisitor {
self.operation.visit_id(struct_field.node.id);
visit::walk_struct_field(self, struct_field, env)
}

fn visit_struct_def(&mut self,
struct_def: @struct_def,
ident: ast::Ident,
generics: &ast::Generics,
id: NodeId,
_: ()) {
self.operation.visit_id(id);
struct_def.ctor_id.map(|&ctor_id| self.operation.visit_id(ctor_id));
visit::walk_struct_def(self, struct_def, ident, generics, id, ());
}
}

pub fn visit_ids_for_inlined_item(item: &inlined_item,
Expand Down