Skip to content

Commit c6eb3ec

Browse files
committed
auto merge of #8758 : pnkfelix/rust/fsk-more-oldvisit-ports, r=pnkfelix
Further followup on #7081. There still remains writeback.rs, but I want to wait to investigate that one because I've seen `make check` issues with it in the past.
2 parents 5fc211a + 2f82d89 commit c6eb3ec

File tree

5 files changed

+123
-77
lines changed

5 files changed

+123
-77
lines changed

src/librustc/metadata/creader.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use syntax::codemap::{span, dummy_sp};
2525
use syntax::diagnostic::span_handler;
2626
use syntax::parse::token;
2727
use syntax::parse::token::ident_interner;
28-
use syntax::oldvisit;
28+
use syntax::visit;
2929

3030
// Traverses an AST, reading all the information about use'd crates and extern
3131
// libraries necessary for later resolving, typechecking, linking, etc.
@@ -46,17 +46,25 @@ pub fn read_crates(diag: @mut span_handler,
4646
next_crate_num: 1,
4747
intr: intr
4848
};
49-
let v =
50-
oldvisit::mk_simple_visitor(@oldvisit::SimpleVisitor {
51-
visit_view_item: |a| visit_view_item(e, a),
52-
visit_item: |a| visit_item(e, a),
53-
.. *oldvisit::default_simple_visitor()});
49+
let mut v = ReadCrateVisitor{ e:e };
5450
visit_crate(e, crate);
55-
oldvisit::visit_crate(crate, ((), v));
51+
visit::walk_crate(&mut v, crate, ());
5652
dump_crates(*e.crate_cache);
5753
warn_if_multiple_versions(e, diag, *e.crate_cache);
5854
}
5955

56+
struct ReadCrateVisitor { e:@mut Env }
57+
impl visit::Visitor<()> for ReadCrateVisitor {
58+
fn visit_view_item(&mut self, a:&ast::view_item, _:()) {
59+
visit_view_item(self.e, a);
60+
visit::walk_view_item(self, a, ());
61+
}
62+
fn visit_item(&mut self, a:@ast::item, _:()) {
63+
visit_item(self.e, a);
64+
visit::walk_item(self, a, ());
65+
}
66+
}
67+
6068
#[deriving(Clone)]
6169
struct cache_entry {
6270
cnum: int,

src/librustc/middle/lint.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use syntax::visit::Visitor;
5656
* lint attributes.
5757
*
5858
* At each node of the ast which can modify lint attributes, all known lint
59-
* passes are also applied. Each lint pass is an oldvisit::vt<()> structure.
59+
* passes are also applied. Each lint pass is a visit::Visitor implementator.
6060
* The visitors are constructed via the lint_*() functions below. There are
6161
* also some lint checks which operate directly on ast nodes (such as
6262
* @ast::item), and those are organized as check_item_*(). Each visitor added
@@ -508,7 +508,7 @@ impl Context {
508508
}
509509
}
510510

511-
fn add_oldvisit_lint(&mut self, v: @mut OuterLint) {
511+
fn add_old_lint(&mut self, v: @mut OuterLint) {
512512
self.visitors.push(OldVisitor(v, v.inner_variant()));
513513
}
514514

@@ -547,7 +547,7 @@ impl Context {
547547
}
548548
}
549549
}
550-
// Can't use oldvisit::visit_method_helper because the
550+
// Can't use visit::walk_method_helper because the
551551
// item_stopping_visitor has overridden visit_fn(&fk_method(... ))
552552
// to be a no-op, so manually invoke visit_fn.
553553
Method(m) => {
@@ -1450,14 +1450,14 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::Crate) {
14501450
}
14511451

14521452
// Register each of the lint passes with the context
1453-
cx.add_oldvisit_lint(lint_while_true());
1454-
cx.add_oldvisit_lint(lint_path_statement());
1455-
cx.add_oldvisit_lint(lint_heap());
1456-
cx.add_oldvisit_lint(lint_type_limits());
1457-
cx.add_oldvisit_lint(lint_unused_unsafe());
1458-
cx.add_oldvisit_lint(lint_unused_mut());
1459-
cx.add_oldvisit_lint(lint_unnecessary_allocations());
1460-
cx.add_oldvisit_lint(lint_missing_doc());
1453+
cx.add_old_lint(lint_while_true());
1454+
cx.add_old_lint(lint_path_statement());
1455+
cx.add_old_lint(lint_heap());
1456+
cx.add_old_lint(lint_type_limits());
1457+
cx.add_old_lint(lint_unused_unsafe());
1458+
cx.add_old_lint(lint_unused_mut());
1459+
cx.add_old_lint(lint_unnecessary_allocations());
1460+
cx.add_old_lint(lint_missing_doc());
14611461
cx.add_lint(lint_session(cx));
14621462

14631463
// Actually perform the lint checks (iterating the ast)

src/librustc/middle/moves.rs

+41-29
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ use std::at_vec;
139139
use std::hashmap::{HashSet, HashMap};
140140
use syntax::ast::*;
141141
use syntax::ast_util;
142-
use syntax::oldvisit;
143-
use syntax::oldvisit::vt;
142+
use syntax::visit;
143+
use syntax::visit::Visitor;
144144
use syntax::codemap::span;
145145

146146
#[deriving(Encodable, Decodable)]
@@ -190,16 +190,26 @@ enum UseMode {
190190
Read // Read no matter what the type.
191191
}
192192

193+
struct ComputeModesVisitor;
194+
195+
impl visit::Visitor<VisitContext> for ComputeModesVisitor {
196+
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&fn_decl,
197+
b:&Block, s:span, n:NodeId, e:VisitContext) {
198+
compute_modes_for_fn(*self, fk, fd, b, s, n, e);
199+
}
200+
fn visit_expr(&mut self, ex:@expr, e:VisitContext) {
201+
compute_modes_for_expr(*self, ex, e);
202+
}
203+
fn visit_local(&mut self, l:@Local, e:VisitContext) {
204+
compute_modes_for_local(*self, l, e);
205+
}
206+
}
207+
193208
pub fn compute_moves(tcx: ty::ctxt,
194209
method_map: method_map,
195210
crate: &Crate) -> MoveMaps
196211
{
197-
let visitor = oldvisit::mk_vt(@oldvisit::Visitor {
198-
visit_fn: compute_modes_for_fn,
199-
visit_expr: compute_modes_for_expr,
200-
visit_local: compute_modes_for_local,
201-
.. *oldvisit::default_visitor()
202-
});
212+
let mut visitor = ComputeModesVisitor;
203213
let visit_cx = VisitContext {
204214
tcx: tcx,
205215
method_map: method_map,
@@ -209,7 +219,7 @@ pub fn compute_moves(tcx: ty::ctxt,
209219
moved_variables_set: @mut HashSet::new()
210220
}
211221
};
212-
oldvisit::visit_crate(crate, (visit_cx, visitor));
222+
visit::walk_crate(&mut visitor, crate, visit_cx);
213223
return visit_cx.move_maps;
214224
}
215225

@@ -227,43 +237,44 @@ pub fn moved_variable_node_id_from_def(def: def) -> Option<NodeId> {
227237
///////////////////////////////////////////////////////////////////////////
228238
// Expressions
229239

230-
fn compute_modes_for_local<'a>(local: @Local,
231-
(cx, v): (VisitContext,
232-
vt<VisitContext>)) {
240+
fn compute_modes_for_local<'a>(v: ComputeModesVisitor,
241+
local: @Local,
242+
cx: VisitContext) {
233243
cx.use_pat(local.pat);
234244
for &init in local.init.iter() {
235245
cx.use_expr(init, Read, v);
236246
}
237247
}
238248

239-
fn compute_modes_for_fn(fk: &oldvisit::fn_kind,
249+
fn compute_modes_for_fn(v: ComputeModesVisitor,
250+
fk: &visit::fn_kind,
240251
decl: &fn_decl,
241252
body: &Block,
242253
span: span,
243254
id: NodeId,
244-
(cx, v): (VisitContext,
245-
vt<VisitContext>)) {
255+
cx: VisitContext) {
256+
let mut v = v;
246257
for a in decl.inputs.iter() {
247258
cx.use_pat(a.pat);
248259
}
249-
oldvisit::visit_fn(fk, decl, body, span, id, (cx, v));
260+
visit::walk_fn(&mut v, fk, decl, body, span, id, cx);
250261
}
251262

252-
fn compute_modes_for_expr(expr: @expr,
253-
(cx, v): (VisitContext,
254-
vt<VisitContext>))
263+
fn compute_modes_for_expr(v: ComputeModesVisitor,
264+
expr: @expr,
265+
cx: VisitContext)
255266
{
256267
cx.consume_expr(expr, v);
257268
}
258269

259270
impl VisitContext {
260-
pub fn consume_exprs(&self, exprs: &[@expr], visitor: vt<VisitContext>) {
271+
pub fn consume_exprs(&self, exprs: &[@expr], visitor: ComputeModesVisitor) {
261272
for expr in exprs.iter() {
262273
self.consume_expr(*expr, visitor);
263274
}
264275
}
265276

266-
pub fn consume_expr(&self, expr: @expr, visitor: vt<VisitContext>) {
277+
pub fn consume_expr(&self, expr: @expr, visitor: ComputeModesVisitor) {
267278
/*!
268279
* Indicates that the value of `expr` will be consumed,
269280
* meaning either copied or moved depending on its type.
@@ -281,7 +292,7 @@ impl VisitContext {
281292
};
282293
}
283294

284-
pub fn consume_block(&self, blk: &Block, visitor: vt<VisitContext>) {
295+
pub fn consume_block(&self, blk: &Block, visitor: ComputeModesVisitor) {
285296
/*!
286297
* Indicates that the value of `blk` will be consumed,
287298
* meaning either copied or moved depending on its type.
@@ -290,7 +301,8 @@ impl VisitContext {
290301
debug!("consume_block(blk.id=%?)", blk.id);
291302

292303
for stmt in blk.stmts.iter() {
293-
(visitor.visit_stmt)(*stmt, (*self, visitor));
304+
let mut v = visitor;
305+
v.visit_stmt(*stmt, *self);
294306
}
295307

296308
for tail_expr in blk.expr.iter() {
@@ -301,7 +313,7 @@ impl VisitContext {
301313
pub fn use_expr(&self,
302314
expr: @expr,
303315
expr_mode: UseMode,
304-
visitor: vt<VisitContext>) {
316+
visitor: ComputeModesVisitor) {
305317
/*!
306318
* Indicates that `expr` is used with a given mode. This will
307319
* in turn trigger calls to the subcomponents of `expr`.
@@ -570,7 +582,7 @@ impl VisitContext {
570582
expr: &expr,
571583
receiver_expr: @expr,
572584
arg_exprs: &[@expr],
573-
visitor: vt<VisitContext>)
585+
visitor: ComputeModesVisitor)
574586
-> bool {
575587
if !self.method_map.contains_key(&expr.id) {
576588
return false;
@@ -587,7 +599,7 @@ impl VisitContext {
587599
return true;
588600
}
589601

590-
pub fn consume_arm(&self, arm: &arm, visitor: vt<VisitContext>) {
602+
pub fn consume_arm(&self, arm: &arm, visitor: ComputeModesVisitor) {
591603
for pat in arm.pats.iter() {
592604
self.use_pat(*pat);
593605
}
@@ -630,21 +642,21 @@ impl VisitContext {
630642

631643
pub fn use_receiver(&self,
632644
receiver_expr: @expr,
633-
visitor: vt<VisitContext>) {
645+
visitor: ComputeModesVisitor) {
634646
self.use_fn_arg(receiver_expr, visitor);
635647
}
636648

637649
pub fn use_fn_args(&self,
638650
_: NodeId,
639651
arg_exprs: &[@expr],
640-
visitor: vt<VisitContext>) {
652+
visitor: ComputeModesVisitor) {
641653
//! Uses the argument expressions.
642654
for arg_expr in arg_exprs.iter() {
643655
self.use_fn_arg(*arg_expr, visitor);
644656
}
645657
}
646658

647-
pub fn use_fn_arg(&self, arg_expr: @expr, visitor: vt<VisitContext>) {
659+
pub fn use_fn_arg(&self, arg_expr: @expr, visitor: ComputeModesVisitor) {
648660
//! Uses the argument.
649661
self.consume_expr(arg_expr, visitor)
650662
}

src/librustc/middle/stack_check.rs

+37-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use syntax::ast;
2222
use syntax::ast_map;
2323
use syntax::attr;
2424
use syntax::codemap::span;
25-
use visit = syntax::oldvisit;
25+
use syntax::visit;
26+
use syntax::visit::Visitor;
2627
use util::ppaux::Repr;
2728

2829
#[deriving(Clone)]
@@ -31,44 +32,56 @@ struct Context {
3132
safe_stack: bool
3233
}
3334

35+
struct StackCheckVisitor;
36+
37+
impl Visitor<Context> for StackCheckVisitor {
38+
fn visit_item(&mut self, i:@ast::item, e:Context) {
39+
stack_check_item(*self, i, e);
40+
}
41+
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&ast::fn_decl,
42+
b:&ast::Block, s:span, n:ast::NodeId, e:Context) {
43+
stack_check_fn(*self, fk, fd, b, s, n, e);
44+
}
45+
fn visit_expr(&mut self, ex:@ast::expr, e:Context) {
46+
stack_check_expr(*self, ex, e);
47+
}
48+
}
49+
3450
pub fn stack_check_crate(tcx: ty::ctxt,
3551
crate: &ast::Crate) {
3652
let new_cx = Context {
3753
tcx: tcx,
3854
safe_stack: false
3955
};
40-
let visitor = visit::mk_vt(@visit::Visitor {
41-
visit_item: stack_check_item,
42-
visit_fn: stack_check_fn,
43-
visit_expr: stack_check_expr,
44-
..*visit::default_visitor()
45-
});
46-
visit::visit_crate(crate, (new_cx, visitor));
56+
let mut visitor = StackCheckVisitor;
57+
visit::walk_crate(&mut visitor, crate, new_cx);
4758
}
4859

49-
fn stack_check_item(item: @ast::item,
50-
(in_cx, v): (Context, visit::vt<Context>)) {
60+
fn stack_check_item(v: StackCheckVisitor,
61+
item: @ast::item,
62+
in_cx: Context) {
63+
let mut v = v;
5164
match item.node {
5265
ast::item_fn(_, ast::extern_fn, _, _, _) => {
5366
// an extern fn is already being called from C code...
5467
let new_cx = Context {safe_stack: true, ..in_cx};
55-
visit::visit_item(item, (new_cx, v));
68+
visit::walk_item(&mut v, item, new_cx);
5669
}
5770
ast::item_fn(*) => {
5871
let safe_stack = fixed_stack_segment(item.attrs);
5972
let new_cx = Context {safe_stack: safe_stack, ..in_cx};
60-
visit::visit_item(item, (new_cx, v));
73+
visit::walk_item(&mut v, item, new_cx);
6174
}
6275
ast::item_impl(_, _, _, ref methods) => {
6376
// visit_method() would make this nicer
6477
for &method in methods.iter() {
6578
let safe_stack = fixed_stack_segment(method.attrs);
6679
let new_cx = Context {safe_stack: safe_stack, ..in_cx};
67-
visit::visit_method_helper(method, (new_cx, v));
80+
visit::walk_method_helper(&mut v, method, new_cx);
6881
}
6982
}
7083
_ => {
71-
visit::visit_item(item, (in_cx, v));
84+
visit::walk_item(&mut v, item, in_cx);
7285
}
7386
}
7487

@@ -77,12 +90,13 @@ fn stack_check_item(item: @ast::item,
7790
}
7891
}
7992

80-
fn stack_check_fn<'a>(fk: &visit::fn_kind,
93+
fn stack_check_fn<'a>(v: StackCheckVisitor,
94+
fk: &visit::fn_kind,
8195
decl: &ast::fn_decl,
8296
body: &ast::Block,
8397
sp: span,
8498
id: ast::NodeId,
85-
(in_cx, v): (Context, visit::vt<Context>)) {
99+
in_cx: Context) {
86100
let safe_stack = match *fk {
87101
visit::fk_method(*) | visit::fk_item_fn(*) => {
88102
in_cx.safe_stack // see stack_check_item above
@@ -102,11 +116,13 @@ fn stack_check_fn<'a>(fk: &visit::fn_kind,
102116
};
103117
let new_cx = Context {safe_stack: safe_stack, ..in_cx};
104118
debug!("stack_check_fn(safe_stack=%b, id=%?)", safe_stack, id);
105-
visit::visit_fn(fk, decl, body, sp, id, (new_cx, v));
119+
let mut v = v;
120+
visit::walk_fn(&mut v, fk, decl, body, sp, id, new_cx);
106121
}
107122

108-
fn stack_check_expr<'a>(expr: @ast::expr,
109-
(cx, v): (Context, visit::vt<Context>)) {
123+
fn stack_check_expr<'a>(v: StackCheckVisitor,
124+
expr: @ast::expr,
125+
cx: Context) {
110126
debug!("stack_check_expr(safe_stack=%b, expr=%s)",
111127
cx.safe_stack, expr.repr(cx.tcx));
112128
if !cx.safe_stack {
@@ -126,7 +142,8 @@ fn stack_check_expr<'a>(expr: @ast::expr,
126142
_ => {}
127143
}
128144
}
129-
visit::visit_expr(expr, (cx, v));
145+
let mut v = v;
146+
visit::walk_expr(&mut v, expr, cx);
130147
}
131148

132149
fn call_to_extern_fn(cx: Context, callee: @ast::expr) {

0 commit comments

Comments
 (0)