Skip to content

Commit

Permalink
rustc: Make all impls even more reachable
Browse files Browse the repository at this point in the history
With this we write metadata for all impls so that we can properly find
reexported impls.
  • Loading branch information
brson committed Jul 12, 2012
1 parent 200a2de commit 46fba10
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/rustc/middle/trans/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn find_reachable(crate_mod: _mod, exp_map: resolve::exp_map,
let rmap = std::map::int_hash();
let cx = {exp_map: exp_map, tcx: tcx, method_map: method_map, rmap: rmap};
traverse_public_mod(cx, crate_mod);
traverse_all_resources(cx, crate_mod);
traverse_all_resources_and_impls(cx, crate_mod);
rmap
}

Expand Down Expand Up @@ -81,18 +81,6 @@ fn traverse_public_mod(cx: ctx, m: _mod) {
if !traverse_exports(cx, m.view_items) {
// No exports, so every local item is exported
for vec::each(m.items) |item| { traverse_public_item(cx, item); }
} else {
// Make impls always reachable.
for vec::each(m.items) |item| {
alt item.node {
item_impl(*) {
traverse_public_item(cx, item);
}
_ {
// Nothing to do.
}
}
}
}
}

Expand Down Expand Up @@ -212,7 +200,7 @@ fn traverse_inline_body(cx: ctx, body: blk) {
}));
}

fn traverse_all_resources(cx: ctx, crate_mod: _mod) {
fn traverse_all_resources_and_impls(cx: ctx, crate_mod: _mod) {
visit::visit_mod(crate_mod, ast_util::dummy_sp(), 0, cx, visit::mk_vt(@{
visit_expr: |_e, _cx, _v| { },
visit_item: |i, cx, v| {
Expand All @@ -221,9 +209,13 @@ fn traverse_all_resources(cx: ctx, crate_mod: _mod) {
item_class(_, _, _, _, some(_)) {
traverse_public_item(cx, i);
}
item_impl(*) {
traverse_public_item(cx, i);
}
_ {}
}
}
with *visit::default_visitor()
}));
}

28 changes: 28 additions & 0 deletions src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[link(name = "crate_method_reexport_grrrrrrr2")];

export rust;

import name_pool::methods;

mod name_pool {

type name_pool = ();

impl methods for name_pool {
fn add(s: str) {
}
}
}

mod rust {

export rt;
export methods;

type rt = @();

impl methods for rt {
fn cx() {
}
}
}
15 changes: 15 additions & 0 deletions src/test/run-pass/crate-method-reexport-grrrrrrr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is a regression test that the metadata for the
// name_pool::methods impl in the other crate is reachable from this
// crate.

// aux-build:crate-method-reexport-grrrrrrr2.rs

use crate_method_reexport_grrrrrrr2;

fn main() {
import crate_method_reexport_grrrrrrr2::rust::methods;
let x = @();
x.cx();
let y = ();
y.add("hi");
}

0 comments on commit 46fba10

Please sign in to comment.