Skip to content

Visitor refactoring: Step 1, couple (Env, vt<Env>) together in a tuple. #7084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn steal(crate: @ast::crate, tm: test_mode) -> StolenStuff {
visit_ty: |a| stash_ty_if(safe_to_steal_ty, tys, a, tm),
.. *visit::default_simple_visitor()
});
visit::visit_crate(crate, (), v);
visit::visit_crate(crate, ((), v));
StolenStuff {
exprs: (*exprs).clone(),
tys: (*tys).clone(),
Expand Down Expand Up @@ -539,7 +539,7 @@ pub fn has_raw_pointers(c: @ast::crate) -> bool {
visit::mk_simple_visitor(@visit::SimpleVisitor {
visit_ty: |a| visit_ty(has_rp, a),
.. *visit::default_simple_visitor()});
visit::visit_crate(c, (), v);
visit::visit_crate(c, ((), v));
return *has_rp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn read_crates(diag: @span_handler,
visit_item: |a| visit_item(e, a),
.. *visit::default_simple_visitor()});
visit_crate(e, crate);
visit::visit_crate(crate, (), v);
visit::visit_crate(crate, ((), v));
dump_crates(e.crate_cache);
warn_if_multiple_versions(e, diag, e.crate_cache);
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,12 @@ fn encode_info_for_items(ecx: @EncodeContext,
encode_info_for_mod(ecx, ebml_w, &crate.node.module,
crate_node_id, [],
syntax::parse::token::special_idents::invalid);
visit::visit_crate(crate, (), visit::mk_vt(@visit::Visitor {
visit_expr: |_e, _cx, _v| { },
visit::visit_crate(crate, ((), visit::mk_vt(@visit::Visitor {
visit_expr: |_e, (_cx, _v)| { },
visit_item: {
let ebml_w = copy *ebml_w;
|i, cx, v| {
visit::visit_item(i, cx, v);
|i, (cx, v)| {
visit::visit_item(i, (cx, v));
match ecx.tcx.items.get_copy(&i.id) {
ast_map::node_item(_, pt) => {
let mut ebml_w = copy ebml_w;
Expand All @@ -1137,8 +1137,8 @@ fn encode_info_for_items(ecx: @EncodeContext,
},
visit_foreign_item: {
let ebml_w = copy *ebml_w;
|ni, cx, v| {
visit::visit_foreign_item(ni, cx, v);
|ni, (cx, v)| {
visit::visit_foreign_item(ni, (cx, v));
match ecx.tcx.items.get_copy(&ni.id) {
ast_map::node_foreign_item(_, abi, _, pt) => {
let mut ebml_w = copy ebml_w;
Expand All @@ -1155,7 +1155,7 @@ fn encode_info_for_items(ecx: @EncodeContext,
}
},
..*visit::default_visitor()
}));
})));
ebml_w.end_tag();
return /*bad*/copy *index;
}
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
visit_pat: check_loans_in_pat,
visit_fn: check_loans_in_fn,
.. *visit::default_visitor()});
(vt.visit_block)(body, clcx, vt);
(vt.visit_block)(body, (clcx, vt));
}

enum MoveError {
Expand Down Expand Up @@ -614,8 +614,8 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
body: &ast::blk,
sp: span,
id: ast::node_id,
this: @mut CheckLoanCtxt<'a>,
visitor: visit::vt<@mut CheckLoanCtxt<'a>>) {
(this, visitor): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
match *fk {
visit::fk_item_fn(*) |
visit::fk_method(*) => {
Expand All @@ -629,7 +629,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
}
}

visit::visit_fn(fk, decl, body, sp, id, this, visitor);
visit::visit_fn(fk, decl, body, sp, id, (this, visitor));

fn check_captured_variables(this: @mut CheckLoanCtxt,
closure_id: ast::node_id,
Expand Down Expand Up @@ -677,15 +677,15 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
}

fn check_loans_in_local<'a>(local: @ast::local,
this: @mut CheckLoanCtxt<'a>,
vt: visit::vt<@mut CheckLoanCtxt<'a>>) {
visit::visit_local(local, this, vt);
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
visit::visit_local(local, (this, vt));
}

fn check_loans_in_expr<'a>(expr: @ast::expr,
this: @mut CheckLoanCtxt<'a>,
vt: visit::vt<@mut CheckLoanCtxt<'a>>) {
visit::visit_expr(expr, this, vt);
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
visit::visit_expr(expr, (this, vt));

debug!("check_loans_in_expr(expr=%s)",
expr.repr(this.tcx()));
Expand Down Expand Up @@ -740,8 +740,8 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
}

fn check_loans_in_pat<'a>(pat: @ast::pat,
this: @mut CheckLoanCtxt<'a>,
vt: visit::vt<@mut CheckLoanCtxt<'a>>)
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>))
{
this.check_for_conflicting_loans(pat.id);

Expand All @@ -756,13 +756,13 @@ fn check_loans_in_pat<'a>(pat: @ast::pat,
// rewalk the patterns and rebuild the pattern
// categorizations.

visit::visit_pat(pat, this, vt);
visit::visit_pat(pat, (this, vt));
}

fn check_loans_in_block<'a>(blk: &ast::blk,
this: @mut CheckLoanCtxt<'a>,
vt: visit::vt<@mut CheckLoanCtxt<'a>>)
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>))
{
visit::visit_block(blk, this, vt);
visit::visit_block(blk, (this, vt));
this.check_for_conflicting_loans(blk.node.id);
}
54 changes: 27 additions & 27 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,28 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
visit_pat: add_pat_to_id_range,
visit_local: gather_loans_in_local,
.. *visit::default_visitor()});
(v.visit_block)(body, glcx, v);
(v.visit_block)(body, (glcx, v));
return (glcx.id_range, glcx.all_loans, glcx.move_data);
}

fn add_pat_to_id_range(p: @ast::pat,
this: @mut GatherLoanCtxt,
v: visit::vt<@mut GatherLoanCtxt>) {
(this, v): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
// NB: This visitor function just adds the pat ids into the id
// range. We gather loans that occur in patterns using the
// `gather_pat()` method below. Eventually these two should be
// brought together.
this.id_range.add(p.id);
visit::visit_pat(p, this, v);
visit::visit_pat(p, (this, v));
}

fn gather_loans_in_fn(fk: &visit::fn_kind,
decl: &ast::fn_decl,
body: &ast::blk,
sp: span,
id: ast::node_id,
this: @mut GatherLoanCtxt,
v: visit::vt<@mut GatherLoanCtxt>) {
(this, v): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
match fk {
// Do not visit items here, the outer loop in borrowck/mod
// will visit them for us in turn.
Expand All @@ -124,22 +124,22 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
// Visit closures as part of the containing item.
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
this.push_repeating_id(body.node.id);
visit::visit_fn(fk, decl, body, sp, id, this, v);
visit::visit_fn(fk, decl, body, sp, id, (this, v));
this.pop_repeating_id(body.node.id);
}
}
}

fn gather_loans_in_block(blk: &ast::blk,
this: @mut GatherLoanCtxt,
vt: visit::vt<@mut GatherLoanCtxt>) {
(this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
this.id_range.add(blk.node.id);
visit::visit_block(blk, this, vt);
visit::visit_block(blk, (this, vt));
}

fn gather_loans_in_local(local: @ast::local,
this: @mut GatherLoanCtxt,
vt: visit::vt<@mut GatherLoanCtxt>) {
(this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
if local.node.init.is_none() {
// Variable declarations without initializers are considered "moves":
let tcx = this.bccx.tcx;
Expand All @@ -163,12 +163,12 @@ fn gather_loans_in_local(local: @ast::local,
}
}

visit::visit_local(local, this, vt);
visit::visit_local(local, (this, vt));
}

fn gather_loans_in_expr(ex: @ast::expr,
this: @mut GatherLoanCtxt,
vt: visit::vt<@mut GatherLoanCtxt>) {
(this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
let bccx = this.bccx;
let tcx = bccx.tcx;

Expand Down Expand Up @@ -208,7 +208,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
// for the lifetime `scope_r` of the resulting ptr:
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}

ast::expr_assign(l, _) | ast::expr_assign_op(_, _, l, _) => {
Expand All @@ -225,7 +225,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
// with moves etc, just ignore.
}
}
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}

ast::expr_match(ex_v, ref arms) => {
Expand All @@ -235,7 +235,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
this.gather_pat(cmt, *pat, arm.body.node.id, ex.id);
}
}
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}

ast::expr_index(_, _, arg) |
Expand All @@ -249,36 +249,36 @@ fn gather_loans_in_expr(ex: @ast::expr,
let scope_r = ty::re_scope(ex.id);
let arg_cmt = this.bccx.cat_expr(arg);
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}

// see explanation attached to the `root_ub` field:
ast::expr_while(cond, ref body) => {
// during the condition, can only root for the condition
this.push_repeating_id(cond.id);
(vt.visit_expr)(cond, this, vt);
(vt.visit_expr)(cond, (this, vt));
this.pop_repeating_id(cond.id);

// during body, can only root for the body
this.push_repeating_id(body.node.id);
(vt.visit_block)(body, this, vt);
(vt.visit_block)(body, (this, vt));
this.pop_repeating_id(body.node.id);
}

// see explanation attached to the `root_ub` field:
ast::expr_loop(ref body, _) => {
this.push_repeating_id(body.node.id);
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
this.pop_repeating_id(body.node.id);
}

ast::expr_fn_block(*) => {
gather_moves::gather_captures(this.bccx, this.move_data, ex);
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}

_ => {
visit::visit_expr(ex, this, vt);
visit::visit_expr(ex, (this, vt));
}
}
}
Expand Down Expand Up @@ -702,13 +702,13 @@ impl GatherLoanCtxt {
// Setting up info that preserve needs.
// This is just the most convenient place to do it.
fn add_stmt_to_map(stmt: @ast::stmt,
this: @mut GatherLoanCtxt,
vt: visit::vt<@mut GatherLoanCtxt>) {
(this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
match stmt.node {
ast::stmt_expr(_, id) | ast::stmt_semi(_, id) => {
this.bccx.stmt_map.insert(id);
}
_ => ()
}
visit::visit_stmt(stmt, this, vt);
visit::visit_stmt(stmt, (this, vt));
}
8 changes: 4 additions & 4 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn check_crate(

let v = visit::mk_vt(@visit::Visitor {visit_fn: borrowck_fn,
..*visit::default_visitor()});
visit::visit_crate(crate, bccx, v);
visit::visit_crate(crate, (bccx, v));

if tcx.sess.borrowck_stats() {
io::println("--- borrowck stats ---");
Expand Down Expand Up @@ -111,8 +111,8 @@ fn borrowck_fn(fk: &visit::fn_kind,
body: &ast::blk,
sp: span,
id: ast::node_id,
this: @BorrowckCtxt,
v: visit::vt<@BorrowckCtxt>) {
(this, v): (@BorrowckCtxt,
visit::vt<@BorrowckCtxt>)) {
match fk {
&visit::fk_anon(*) |
&visit::fk_fn_block(*) => {
Expand Down Expand Up @@ -149,7 +149,7 @@ fn borrowck_fn(fk: &visit::fn_kind,
}
}

visit::visit_fn(fk, decl, body, sp, id, this, v);
visit::visit_fn(fk, decl, body, sp, id, (this, v));
}

// ----------------------------------------------------------------------
Expand Down
Loading