Skip to content

Commit 5e647d7

Browse files
committed
Fix assumption that monomorphized method's impls are crate-local
1 parent 75e6fb4 commit 5e647d7

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

src/rustc/metadata/astencode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
671671
fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
672672
ebml_w: ebml::writer,
673673
id: ast::node_id) {
674-
675674
let ccx = ecx.ccx;
676675
let tcx = ccx.tcx;
677676

src/rustc/metadata/csearch.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export get_impls_for_mod;
1717
export get_iface_methods;
1818
export get_type;
1919
export get_impl_iface;
20+
export get_impl_method;
2021
export get_item_path;
2122
export maybe_get_item_ast;
2223

@@ -121,6 +122,12 @@ fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id)
121122
decoder::get_impl_iface(cdata, def.node, tcx)
122123
}
123124

125+
fn get_impl_method(cstore: cstore::cstore, def: ast::def_id, mname: str)
126+
-> ast::def_id {
127+
let cdata = cstore::get_crate_data(cstore, def.crate);
128+
decoder::get_impl_method(cdata, def.node, mname)
129+
}
130+
124131
// Local Variables:
125132
// mode: rust
126133
// fill-column: 78;

src/rustc/metadata/decoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export get_enum_variants;
1919
export get_type;
2020
export get_type_param_count;
2121
export get_impl_iface;
22+
export get_impl_method;
2223
export lookup_def;
2324
export lookup_item_name;
2425
export get_impl_iface;
@@ -256,6 +257,18 @@ fn get_impl_iface(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
256257
item_impl_iface(lookup_item(id, cdata.data), tcx, cdata)
257258
}
258259

260+
fn get_impl_method(cdata: cmd, id: ast::node_id, name: str) -> ast::def_id {
261+
let items = ebml::get_doc(ebml::new_doc(cdata.data), tag_items);
262+
let found = none;
263+
ebml::tagged_docs(find_item(id, items), tag_item_method) {|mid|
264+
let m_did = parse_def_id(ebml::doc_data(mid));
265+
if item_name(find_item(m_did.node, items)) == name {
266+
found = some(translate_def_id(cdata, m_did));
267+
}
268+
}
269+
option::get(found)
270+
}
271+
259272
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
260273
ret item_symbol(lookup_item(id, data));
261274
}

src/rustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
468468
encode_name(ebml_w, m.ident);
469469
encode_symbol(ecx, ebml_w, m.id);
470470
encode_path(ebml_w, impl_path, ast_map::path_name(m.ident));
471-
if should_inline(m.attrs) {
471+
if tps.len() > 0u || m.tps.len() > 0u || should_inline(m.attrs) {
472472
astencode::encode_inlined_item(
473473
ecx, ebml_w, impl_path,
474474
ii_method(local_def(item.id), m));

src/rustc/middle/trans/impl.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import common::*;
44
import type_of::*;
55
import build::*;
66
import driver::session::session;
7-
import syntax::{ast, ast_util};
7+
import syntax::ast;
8+
import syntax::ast_util::local_def;
89
import metadata::csearch;
910
import back::{link, abi};
1011
import lib::llvm::llvm;
@@ -144,25 +145,29 @@ fn trans_vtable_callee(bcx: block, env: callee_env, dict: ValueRef,
144145
generic: generic}
145146
}
146147

148+
fn method_with_name(ccx: crate_ctxt, impl_id: ast::def_id,
149+
name: ast::ident) -> ast::def_id {
150+
if impl_id.crate == ast::local_crate {
151+
alt check ccx.tcx.items.get(impl_id.node) {
152+
ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) {
153+
local_def(option::get(vec::find(ms, {|m| m.ident == name})).id)
154+
}
155+
}
156+
} else {
157+
csearch::get_impl_method(ccx.sess.cstore, impl_id, name)
158+
}
159+
}
160+
147161
fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
148162
base: @ast::expr, iface_id: ast::def_id,
149163
n_method: uint, n_param: uint, n_bound: uint,
150164
substs: param_substs) -> lval_maybe_callee {
151165
alt find_dict_in_fn_ctxt(substs, n_param, n_bound) {
152166
typeck::dict_static(impl_did, tys, sub_origins) {
153167
let tcx = bcx.tcx();
154-
if impl_did.crate != ast::local_crate {
155-
ret trans_param_callee(bcx, callee_id, base, iface_id,
156-
n_method, n_param, n_bound);
157-
}
158168
let mname = ty::iface_methods(tcx, iface_id)[n_method].ident;
159-
let mth = alt check tcx.items.get(impl_did.node) {
160-
ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) {
161-
option::get(vec::find(ms, {|m| m.ident == mname}))
162-
}
163-
};
164-
ret trans_static_callee(bcx, callee_id, base,
165-
ast_util::local_def(mth.id),
169+
let mth_id = method_with_name(bcx.ccx(), impl_did, mname);
170+
ret trans_static_callee(bcx, callee_id, base, mth_id,
166171
some((tys, sub_origins)));
167172
}
168173
typeck::dict_iface(iid) {
@@ -378,7 +383,7 @@ fn trans_iface_wrapper(ccx: @crate_ctxt, pt: path, m: ty::method,
378383

379384
fn trans_iface_vtable(ccx: @crate_ctxt, pt: path, it: @ast::item) {
380385
let new_pt = pt + [path_name(it.ident), path_name(int::str(it.id))];
381-
let i_did = ast_util::local_def(it.id), i = 0u;
386+
let i_did = local_def(it.id), i = 0u;
382387
let ptrs = vec::map(*ty::iface_methods(ccx.tcx, i_did), {|m|
383388
let w = trans_iface_wrapper(ccx, new_pt + [path_name(m.ident)], m, i);
384389
i += 1u;

0 commit comments

Comments
 (0)