Skip to content

Commit ccc7651

Browse files
committed
In reachability, don't ignore nested items
Reachability was considering nested items to be unreachable, which was causing the bug in #2383. Once I fixed that, I also had to make impl::make_impl_vtable instantiate methods where necessary, before calling monomorphic_fn. Closes #2383
1 parent 730e8e9 commit ccc7651

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import link::{mangle_internal_name_by_type_only,
4040
import metadata::{csearch, cstore, encoder};
4141
import metadata::common::link_meta;
4242
import util::ppaux::{ty_to_str, ty_to_short_str};
43+
import syntax::diagnostic::expect;
4344

4445
import common::*;
4546
import build::*;
@@ -2052,7 +2053,10 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
20522053
let tpt = ty::lookup_item_type(ccx.tcx, fn_id);
20532054
let mut item_ty = tpt.ty;
20542055

2055-
let map_node = ccx.tcx.items.get(fn_id.node);
2056+
let map_node = session::expect(ccx.sess, ccx.tcx.items.find(fn_id.node),
2057+
{|| #fmt("While monomorphizing %?, couldn't find it in the item map \
2058+
(may have attempted to monomorphize an item defined in a different \
2059+
crate?)", fn_id)});
20562060
// Get the path so that we can create a symbol
20572061
let (pt, name, span) = alt map_node {
20582062
ast_map::node_item(i, pt) {

src/rustc/middle/trans/impl.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,13 @@ fn make_impl_vtable(ccx: @crate_ctxt, impl_id: ast::def_id, substs: [ty::t],
258258
if (*im.tps).len() > 0u || ty::type_has_self(fty) {
259259
C_null(T_ptr(T_nil()))
260260
} else {
261-
let m_id = method_with_name(ccx, impl_id, im.ident);
261+
let mut m_id = method_with_name(ccx, impl_id, im.ident);
262262
if has_tps {
263+
// If the method is in another crate, need to make an inlined
264+
// copy first
265+
if m_id.crate != ast::local_crate {
266+
m_id = maybe_instantiate_inline(ccx, m_id);
267+
}
263268
monomorphic_fn(ccx, m_id, substs, some(vtables), none).val
264269
} else if m_id.crate == ast::local_crate {
265270
get_item_val(ccx, m_id.node)

src/rustc/middle/trans/reachable.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
9898
for vec::each(ms) {|m|
9999
if tps.len() > 0u || m.tps.len() > 0u ||
100100
attr::find_inline_attr(m.attrs) != attr::ia_none {
101+
cx.rmap.insert(m.id, ());
101102
traverse_inline_body(cx, m.body);
102103
}
103104
}
@@ -141,9 +142,13 @@ fn traverse_inline_body(cx: ctx, body: blk) {
141142
}
142143
visit::visit_expr(e, cx, v);
143144
}
144-
// Ignore nested items
145-
fn traverse_item(_i: @item, _cx: ctx, _v: visit::vt<ctx>) {}
146-
visit::visit_block(body, cx, visit::mk_vt(@{
145+
// Don't ignore nested items: for example if a generic fn contains a
146+
// generic impl (as in deque::create), we need to monomorphize the
147+
// impl as well
148+
fn traverse_item(i: @item, cx: ctx, _v: visit::vt<ctx>) {
149+
traverse_public_item(cx, i);
150+
}
151+
visit::visit_block(body, cx, visit::mk_vt(@{
147152
visit_expr: traverse_expr,
148153
visit_item: traverse_item
149154
with *visit::default_visitor()

src/test/run-pass/issue-2383.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std;
2+
import std::deque;
3+
import std::deque::t;
4+
5+
fn main() {
6+
let Q = deque::create();
7+
Q.add_back(10);
8+
}

0 commit comments

Comments
 (0)