Skip to content

Commit f417ffc

Browse files
committed
Port trans to use visit_all_items: this was mostly straight-forward, but
noteworthy because trans got mildly simpler, since it doesn't have to ensure that we walk the contents of all things just to find all the hidden items.
1 parent 287e85a commit f417ffc

File tree

2 files changed

+10
-52
lines changed

2 files changed

+10
-52
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ use syntax::parse::token::InternedString;
100100
use syntax::attr::AttrMetaMethods;
101101
use syntax::attr;
102102
use rustc_front;
103-
use rustc_front::visit::Visitor;
104-
use rustc_front::visit;
103+
use rustc_front::intravisit::{self, Visitor};
105104
use rustc_front::hir;
106105
use syntax::ast;
107106

@@ -1300,7 +1299,7 @@ impl<'v> Visitor<'v> for FindNestedReturn {
13001299
hir::ExprRet(..) => {
13011300
self.found = true;
13021301
}
1303-
_ => visit::walk_expr(self, e)
1302+
_ => intravisit::walk_expr(self, e)
13041303
}
13051304
}
13061305
}
@@ -1369,7 +1368,7 @@ fn has_nested_returns(tcx: &ty::ctxt, cfg: &cfg::CFG, blk_id: ast::NodeId) -> bo
13691368
Some(hir_map::NodeExpr(ex)) => {
13701369
if let hir::ExprRet(Some(ref ret_expr)) = ex.node {
13711370
let mut visitor = FindNestedReturn::new();
1372-
visit::walk_expr(&mut visitor, &**ret_expr);
1371+
intravisit::walk_expr(&mut visitor, &**ret_expr);
13731372
if visitor.found {
13741373
return true;
13751374
}
@@ -2302,11 +2301,6 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
23022301
}
23032302
}
23042303
}
2305-
2306-
// Be sure to travel more than just one layer deep to catch nested
2307-
// items in blocks and such.
2308-
let mut v = TransItemVisitor{ ccx: ccx };
2309-
v.visit_block(&**body);
23102304
}
23112305
hir::ItemImpl(_, _, ref generics, _, _, ref impl_items) => {
23122306
meth::trans_impl(ccx,
@@ -2315,8 +2309,9 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
23152309
generics,
23162310
item.id);
23172311
}
2318-
hir::ItemMod(ref m) => {
2319-
trans_mod(&ccx.rotate(), m);
2312+
hir::ItemMod(_) => {
2313+
// modules have no equivalent at runtime, they just affect
2314+
// the mangled names of things contained within
23202315
}
23212316
hir::ItemEnum(ref enum_definition, ref gens) => {
23222317
if gens.ty_params.is_empty() {
@@ -2325,16 +2320,9 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
23252320
enum_variant_size_lint(ccx, enum_definition, item.span, item.id);
23262321
}
23272322
}
2328-
hir::ItemConst(_, ref expr) => {
2329-
// Recurse on the expression to catch items in blocks
2330-
let mut v = TransItemVisitor{ ccx: ccx };
2331-
v.visit_expr(&**expr);
2323+
hir::ItemConst(..) => {
23322324
}
23332325
hir::ItemStatic(_, m, ref expr) => {
2334-
// Recurse on the expression to catch items in blocks
2335-
let mut v = TransItemVisitor{ ccx: ccx };
2336-
v.visit_expr(&**expr);
2337-
23382326
let g = match consts::trans_static(ccx, m, expr, item.id, &item.attrs) {
23392327
Ok(g) => g,
23402328
Err(err) => ccx.tcx().sess.span_fatal(expr.span, &err.description()),
@@ -2346,30 +2334,11 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
23462334
foreign::trans_foreign_mod(ccx, foreign_mod);
23472335
}
23482336
hir::ItemTrait(..) => {
2349-
// Inside of this trait definition, we won't be actually translating any
2350-
// functions, but the trait still needs to be walked. Otherwise default
2351-
// methods with items will not get translated and will cause ICE's when
2352-
// metadata time comes around.
2353-
let mut v = TransItemVisitor{ ccx: ccx };
2354-
visit::walk_item(&mut v, item);
23552337
}
23562338
_ => {/* fall through */ }
23572339
}
23582340
}
23592341

2360-
// Translate a module. Doing this amounts to translating the items in the
2361-
// module; there ends up being no artifact (aside from linkage names) of
2362-
// separate modules in the compiled program. That's because modules exist
2363-
// only as a convenience for humans working with the code, to organize names
2364-
// and control visibility.
2365-
pub fn trans_mod(ccx: &CrateContext, m: &hir::Mod) {
2366-
let _icx = push_ctxt("trans_mod");
2367-
for item in &m.items {
2368-
trans_item(ccx, &**item);
2369-
}
2370-
}
2371-
2372-
23732342
// only use this for foreign function ABIs and glue, use `register_fn` for Rust functions
23742343
pub fn register_fn_llvmty(ccx: &CrateContext,
23752344
sp: Span,
@@ -2994,10 +2963,10 @@ pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
29942963
// First, verify intrinsics.
29952964
intrinsic::check_intrinsics(&ccx);
29962965

2997-
// Next, translate the module.
2966+
// Next, translate all items.
29982967
{
29992968
let _icx = push_ctxt("text");
3000-
trans_mod(&ccx, &krate.module);
2969+
krate.visit_all_items(&mut TransItemVisitor { ccx: &ccx });
30012970
}
30022971
}
30032972

src/librustc_trans/trans/meth.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use syntax::attr;
4343
use syntax::codemap::DUMMY_SP;
4444
use syntax::ptr::P;
4545

46-
use rustc_front::visit;
4746
use rustc_front::hir;
4847

4948
// drop_glue pointer, size, align.
@@ -63,21 +62,12 @@ pub fn trans_impl(ccx: &CrateContext,
6362

6463
debug!("trans_impl(name={}, id={})", name, id);
6564

66-
let mut v = TransItemVisitor { ccx: ccx };
67-
6865
// Both here and below with generic methods, be sure to recurse and look for
6966
// items that we need to translate.
7067
if !generics.ty_params.is_empty() {
71-
for impl_item in impl_items {
72-
match impl_item.node {
73-
hir::ImplItemKind::Method(..) => {
74-
visit::walk_impl_item(&mut v, impl_item);
75-
}
76-
_ => {}
77-
}
78-
}
7968
return;
8069
}
70+
8171
for impl_item in impl_items {
8272
match impl_item.node {
8373
hir::ImplItemKind::Method(ref sig, ref body) => {
@@ -94,7 +84,6 @@ pub fn trans_impl(ccx: &CrateContext,
9484
if is_origin { OriginalTranslation } else { InlinedCopy });
9585
}
9686
}
97-
visit::walk_impl_item(&mut v, impl_item);
9887
}
9988
_ => {}
10089
}

0 commit comments

Comments
 (0)