Skip to content

Commit 8cc852a

Browse files
committed
Make ast::visit only descend into types when necessary
If visit_ty is not overridden, it uses a stub function which does not descend into types. Closes #1204
1 parent 1a13504 commit 8cc852a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/comp/middle/mut.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ type ctx = {tcx: ty::ctxt, mut_map: mut_map};
113113

114114
fn check_crate(tcx: ty::ctxt, crate: @crate) -> mut_map {
115115
let cx = @{tcx: tcx, mut_map: std::map::new_int_hash()};
116-
let v =
117-
@{visit_expr: bind visit_expr(cx, _, _, _),
118-
visit_decl: bind visit_decl(cx, _, _, _)
119-
with *visit::default_visitor::<()>()};
116+
let v = @{visit_expr: bind visit_expr(cx, _, _, _),
117+
visit_decl: bind visit_decl(cx, _, _, _)
118+
with *visit::default_visitor()};
120119
visit::visit_crate(*crate, (), visit::mk_vt(v));
121120
ret cx.mut_map;
122121
}

src/comp/syntax/visit.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn default_visitor<E>() -> visitor<E> {
4545
visit_pat: bind visit_pat::<E>(_, _, _),
4646
visit_decl: bind visit_decl::<E>(_, _, _),
4747
visit_expr: bind visit_expr::<E>(_, _, _),
48-
visit_ty: bind visit_ty::<E>(_, _, _),
48+
visit_ty: bind skip_ty::<E>(_, _, _),
4949
visit_constr: bind visit_constr::<E>(_, _, _, _, _),
5050
visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _)};
5151
}
@@ -109,6 +109,8 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
109109
}
110110
}
111111

112+
fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {}
113+
112114
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
113115
alt t.node {
114116
ty_nil. {/* no-op */ }
@@ -355,6 +357,8 @@ type simple_visitor =
355357
visit_constr: fn@(path, span, node_id),
356358
visit_fn: fn@(_fn, [ty_param], span, fn_ident, node_id)};
357359

360+
fn simple_ignore_ty(_t: @ty) {}
361+
358362
fn default_simple_visitor() -> simple_visitor {
359363
ret @{visit_mod: fn(_m: _mod, _sp: span) { },
360364
visit_view_item: fn(_vi: @view_item) { },
@@ -367,7 +371,7 @@ fn default_simple_visitor() -> simple_visitor {
367371
visit_pat: fn(_p: @pat) { },
368372
visit_decl: fn(_d: @decl) { },
369373
visit_expr: fn(_e: @expr) { },
370-
visit_ty: fn(_t: @ty) { },
374+
visit_ty: simple_ignore_ty,
371375
visit_constr: fn(_p: path, _sp: span, _id: node_id) { },
372376
visit_fn:
373377
fn(_f: _fn, _tps: [ty_param], _sp: span, _ident: fn_ident,
@@ -436,6 +440,11 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
436440
f(ff, tps, sp, ident, id);
437441
visit_fn(ff, tps, sp, ident, id, e, v);
438442
}
443+
let visit_ty = if v.visit_ty == simple_ignore_ty {
444+
bind skip_ty(_, _, _)
445+
} else {
446+
bind v_ty(v.visit_ty, _, _, _)
447+
};
439448
ret mk_vt(@{visit_mod: bind v_mod(v.visit_mod, _, _, _, _),
440449
visit_view_item: bind v_view_item(v.visit_view_item, _, _, _),
441450
visit_native_item:
@@ -448,7 +457,7 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
448457
visit_pat: bind v_pat(v.visit_pat, _, _, _),
449458
visit_decl: bind v_decl(v.visit_decl, _, _, _),
450459
visit_expr: bind v_expr(v.visit_expr, _, _, _),
451-
visit_ty: bind v_ty(v.visit_ty, _, _, _),
460+
visit_ty: visit_ty,
452461
visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _),
453462
visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _)});
454463
}

0 commit comments

Comments
 (0)