Skip to content

Commit 7e6de51

Browse files
committed
---
yaml --- r: 85366 b: refs/heads/dist-snap c: 3d83010 h: refs/heads/master v: v3
1 parent 8b468fd commit 7e6de51

File tree

6 files changed

+167
-259
lines changed

6 files changed

+167
-259
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 356341192fdf8234b6a6ff8c3385ba227928ae9a
9+
refs/heads/dist-snap: 3d830106482e6096312404572486d11c6350a8f8
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/metadata/encoder.rs

Lines changed: 49 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ use syntax::attr;
3939
use syntax::attr::AttrMetaMethods;
4040
use syntax::diagnostic::span_handler;
4141
use syntax::parse::token::special_idents;
42-
use syntax::ast_util;
43-
use syntax::visit;
42+
use syntax::{ast_util, oldvisit};
4443
use syntax::parse::token;
4544
use syntax;
4645
use writer = extra::ebml::writer;
@@ -1185,74 +1184,6 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
11851184
ebml_w.end_tag();
11861185
}
11871186

1188-
fn my_visit_expr(_e:@expr) { }
1189-
1190-
fn my_visit_item(i:@item, items: ast_map::map, ebml_w:&writer::Encoder,
1191-
ecx_ptr:*int, index: @mut ~[entry<i64>]) {
1192-
match items.get_copy(&i.id) {
1193-
ast_map::node_item(_, pt) => {
1194-
let mut ebml_w = ebml_w.clone();
1195-
// See above
1196-
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
1197-
encode_info_for_item(ecx, &mut ebml_w, i, index, *pt);
1198-
}
1199-
_ => fail!("bad item")
1200-
}
1201-
}
1202-
1203-
fn my_visit_foreign_item(ni:@foreign_item, items: ast_map::map, ebml_w:&writer::Encoder,
1204-
ecx_ptr:*int, index: @mut ~[entry<i64>]) {
1205-
match items.get_copy(&ni.id) {
1206-
ast_map::node_foreign_item(_, abi, _, pt) => {
1207-
debug!("writing foreign item %s::%s",
1208-
ast_map::path_to_str(
1209-
*pt,
1210-
token::get_ident_interner()),
1211-
token::ident_to_str(&ni.ident));
1212-
1213-
let mut ebml_w = ebml_w.clone();
1214-
// See above
1215-
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
1216-
encode_info_for_foreign_item(ecx,
1217-
&mut ebml_w,
1218-
ni,
1219-
index,
1220-
pt,
1221-
abi);
1222-
}
1223-
// case for separate item and foreign-item tables
1224-
_ => fail!("bad foreign item")
1225-
}
1226-
}
1227-
1228-
struct EncodeVisitor {
1229-
ebml_w_for_visit_item: writer::Encoder,
1230-
ebml_w_for_visit_foreign_item: writer::Encoder,
1231-
ecx_ptr:*int,
1232-
items: ast_map::map,
1233-
index: @mut ~[entry<i64>],
1234-
}
1235-
1236-
impl visit::Visitor<()> for EncodeVisitor {
1237-
fn visit_expr(&mut self, ex:@expr, _:()) { my_visit_expr(ex); }
1238-
fn visit_item(&mut self, i:@item, _:()) {
1239-
visit::walk_item(self, i, ());
1240-
my_visit_item(i,
1241-
self.items,
1242-
&self.ebml_w_for_visit_item,
1243-
self.ecx_ptr,
1244-
self.index);
1245-
}
1246-
fn visit_foreign_item(&mut self, ni:@foreign_item, _:()) {
1247-
visit::walk_foreign_item(self, ni, ());
1248-
my_visit_foreign_item(ni,
1249-
self.items,
1250-
&self.ebml_w_for_visit_foreign_item,
1251-
self.ecx_ptr,
1252-
self.index);
1253-
}
1254-
}
1255-
12561187
fn encode_info_for_items(ecx: &EncodeContext,
12571188
ebml_w: &mut writer::Encoder,
12581189
crate: &Crate)
@@ -1270,17 +1201,54 @@ fn encode_info_for_items(ecx: &EncodeContext,
12701201
let items = ecx.tcx.items;
12711202

12721203
// See comment in `encode_side_tables_for_ii` in astencode
1273-
let ecx_ptr : *int = unsafe { cast::transmute(ecx) };
1274-
let mut visitor = EncodeVisitor {
1275-
index: index,
1276-
items: items,
1277-
ecx_ptr: ecx_ptr,
1278-
ebml_w_for_visit_item: (*ebml_w).clone(),
1279-
ebml_w_for_visit_foreign_item: (*ebml_w).clone(),
1280-
};
1281-
1282-
visit::walk_crate(&mut visitor, crate, ());
1283-
1204+
let ecx_ptr : *() = unsafe { cast::transmute(ecx) };
1205+
1206+
oldvisit::visit_crate(crate, ((), oldvisit::mk_vt(@oldvisit::Visitor {
1207+
visit_expr: |_e, (_cx, _v)| { },
1208+
visit_item: {
1209+
let ebml_w = (*ebml_w).clone();
1210+
|i, (cx, v)| {
1211+
oldvisit::visit_item(i, (cx, v));
1212+
match items.get_copy(&i.id) {
1213+
ast_map::node_item(_, pt) => {
1214+
let mut ebml_w = ebml_w.clone();
1215+
// See above
1216+
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
1217+
encode_info_for_item(ecx, &mut ebml_w, i, index, *pt);
1218+
}
1219+
_ => fail!("bad item")
1220+
}
1221+
}
1222+
},
1223+
visit_foreign_item: {
1224+
let ebml_w = (*ebml_w).clone();
1225+
|ni, (cx, v)| {
1226+
oldvisit::visit_foreign_item(ni, (cx, v));
1227+
match items.get_copy(&ni.id) {
1228+
ast_map::node_foreign_item(_, abi, _, pt) => {
1229+
debug!("writing foreign item %s::%s",
1230+
ast_map::path_to_str(
1231+
*pt,
1232+
token::get_ident_interner()),
1233+
token::ident_to_str(&ni.ident));
1234+
1235+
let mut ebml_w = ebml_w.clone();
1236+
// See above
1237+
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
1238+
encode_info_for_foreign_item(ecx,
1239+
&mut ebml_w,
1240+
ni,
1241+
index,
1242+
pt,
1243+
abi);
1244+
}
1245+
// case for separate item and foreign-item tables
1246+
_ => fail!("bad foreign item")
1247+
}
1248+
}
1249+
},
1250+
..*oldvisit::default_visitor()
1251+
})));
12841252
ebml_w.end_tag();
12851253
return /*bad*/(*index).clone();
12861254
}

branches/dist-snap/src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ use syntax::ast;
3131
use syntax::ast_util::id_range;
3232
use syntax::codemap::span;
3333
use syntax::print::pprust;
34-
use syntax::visit;
35-
use syntax::visit::Visitor;
36-
use syntax::ast::{expr, fn_kind, fn_decl, Block, NodeId, stmt, pat, Local};
34+
use syntax::oldvisit;
3735

3836
mod lifetime;
3937
mod restrictions;
@@ -74,30 +72,6 @@ struct GatherLoanCtxt {
7472
repeating_ids: ~[ast::NodeId]
7573
}
7674

77-
struct GatherLoanVisitor;
78-
79-
impl visit::Visitor<@mut GatherLoanCtxt> for GatherLoanVisitor {
80-
fn visit_expr(&mut self, ex:@expr, e:@mut GatherLoanCtxt) {
81-
gather_loans_in_expr(self, ex, e);
82-
}
83-
fn visit_block(&mut self, b:&Block, e:@mut GatherLoanCtxt) {
84-
gather_loans_in_block(self, b, e);
85-
}
86-
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl, b:&Block,
87-
s:span, n:NodeId, e:@mut GatherLoanCtxt) {
88-
gather_loans_in_fn(self, fk, fd, b, s, n, e);
89-
}
90-
fn visit_stmt(&mut self, s:@stmt, e:@mut GatherLoanCtxt) {
91-
add_stmt_to_map(self, s, e);
92-
}
93-
fn visit_pat(&mut self, p:@pat, e:@mut GatherLoanCtxt) {
94-
add_pat_to_id_range(self, p, e);
95-
}
96-
fn visit_local(&mut self, l:@Local, e:@mut GatherLoanCtxt) {
97-
gather_loans_in_local(self, l, e);
98-
}
99-
}
100-
10175
pub fn gather_loans(bccx: @BorrowckCtxt,
10276
decl: &ast::fn_decl,
10377
body: &ast::Block)
@@ -111,57 +85,64 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
11185
move_data: @mut MoveData::new()
11286
};
11387
glcx.gather_fn_arg_patterns(decl, body);
114-
115-
let mut v = GatherLoanVisitor;
116-
v.visit_block(body, glcx);
88+
let v = oldvisit::mk_vt(@oldvisit::Visitor {
89+
visit_expr: gather_loans_in_expr,
90+
visit_block: gather_loans_in_block,
91+
visit_fn: gather_loans_in_fn,
92+
visit_stmt: add_stmt_to_map,
93+
visit_pat: add_pat_to_id_range,
94+
visit_local: gather_loans_in_local,
95+
.. *oldvisit::default_visitor()
96+
});
97+
(v.visit_block)(body, (glcx, v));
11798
return (glcx.id_range, glcx.all_loans, glcx.move_data);
11899
}
119100

120-
fn add_pat_to_id_range(v: &mut GatherLoanVisitor,
121-
p: @ast::pat,
122-
this: @mut GatherLoanCtxt) {
101+
fn add_pat_to_id_range(p: @ast::pat,
102+
(this, v): (@mut GatherLoanCtxt,
103+
oldvisit::vt<@mut GatherLoanCtxt>)) {
123104
// NB: This visitor function just adds the pat ids into the id
124105
// range. We gather loans that occur in patterns using the
125106
// `gather_pat()` method below. Eventually these two should be
126107
// brought together.
127108
this.id_range.add(p.id);
128-
visit::walk_pat(v, p, this);
109+
oldvisit::visit_pat(p, (this, v));
129110
}
130111

131-
fn gather_loans_in_fn(v: &mut GatherLoanVisitor,
132-
fk: &fn_kind,
112+
fn gather_loans_in_fn(fk: &oldvisit::fn_kind,
133113
decl: &ast::fn_decl,
134114
body: &ast::Block,
135115
sp: span,
136116
id: ast::NodeId,
137-
this: @mut GatherLoanCtxt) {
117+
(this, v): (@mut GatherLoanCtxt,
118+
oldvisit::vt<@mut GatherLoanCtxt>)) {
138119
match fk {
139120
// Do not visit items here, the outer loop in borrowck/mod
140121
// will visit them for us in turn.
141-
&visit::fk_item_fn(*) | &visit::fk_method(*) => {
122+
&oldvisit::fk_item_fn(*) | &oldvisit::fk_method(*) => {
142123
return;
143124
}
144125

145126
// Visit closures as part of the containing item.
146-
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
127+
&oldvisit::fk_anon(*) | &oldvisit::fk_fn_block(*) => {
147128
this.push_repeating_id(body.id);
148-
visit::walk_fn(v, fk, decl, body, sp, id, this);
129+
oldvisit::visit_fn(fk, decl, body, sp, id, (this, v));
149130
this.pop_repeating_id(body.id);
150131
this.gather_fn_arg_patterns(decl, body);
151132
}
152133
}
153134
}
154135

155-
fn gather_loans_in_block(v: &mut GatherLoanVisitor,
156-
blk: &ast::Block,
157-
this: @mut GatherLoanCtxt) {
136+
fn gather_loans_in_block(blk: &ast::Block,
137+
(this, vt): (@mut GatherLoanCtxt,
138+
oldvisit::vt<@mut GatherLoanCtxt>)) {
158139
this.id_range.add(blk.id);
159-
visit::walk_block(v, blk, this);
140+
oldvisit::visit_block(blk, (this, vt));
160141
}
161142

162-
fn gather_loans_in_local(v: &mut GatherLoanVisitor,
163-
local: @ast::Local,
164-
this: @mut GatherLoanCtxt) {
143+
fn gather_loans_in_local(local: @ast::Local,
144+
(this, vt): (@mut GatherLoanCtxt,
145+
oldvisit::vt<@mut GatherLoanCtxt>)) {
165146
match local.init {
166147
None => {
167148
// Variable declarations without initializers are considered "moves":
@@ -192,13 +173,12 @@ fn gather_loans_in_local(v: &mut GatherLoanVisitor,
192173
}
193174
}
194175

195-
visit::walk_local(v, local, this);
176+
oldvisit::visit_local(local, (this, vt));
196177
}
197178

198-
199-
fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
200-
ex: @ast::expr,
201-
this: @mut GatherLoanCtxt) {
179+
fn gather_loans_in_expr(ex: @ast::expr,
180+
(this, vt): (@mut GatherLoanCtxt,
181+
oldvisit::vt<@mut GatherLoanCtxt>)) {
202182
let bccx = this.bccx;
203183
let tcx = bccx.tcx;
204184

@@ -238,7 +218,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
238218
// for the lifetime `scope_r` of the resulting ptr:
239219
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
240220
this.guarantee_valid(ex.id, ex.span, base_cmt, mutbl, scope_r);
241-
visit::walk_expr(v, ex, this);
221+
oldvisit::visit_expr(ex, (this, vt));
242222
}
243223

244224
ast::expr_assign(l, _) | ast::expr_assign_op(_, _, l, _) => {
@@ -255,7 +235,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
255235
// with moves etc, just ignore.
256236
}
257237
}
258-
visit::walk_expr(v, ex, this);
238+
oldvisit::visit_expr(ex, (this, vt));
259239
}
260240

261241
ast::expr_match(ex_v, ref arms) => {
@@ -265,7 +245,7 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
265245
this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
266246
}
267247
}
268-
visit::walk_expr(v, ex, this);
248+
oldvisit::visit_expr(ex, (this, vt));
269249
}
270250

271251
ast::expr_index(_, _, arg) |
@@ -279,36 +259,36 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
279259
let scope_r = ty::re_scope(ex.id);
280260
let arg_cmt = this.bccx.cat_expr(arg);
281261
this.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
282-
visit::walk_expr(v, ex, this);
262+
oldvisit::visit_expr(ex, (this, vt));
283263
}
284264

285265
// see explanation attached to the `root_ub` field:
286266
ast::expr_while(cond, ref body) => {
287267
// during the condition, can only root for the condition
288268
this.push_repeating_id(cond.id);
289-
v.visit_expr(cond, this);
269+
(vt.visit_expr)(cond, (this, vt));
290270
this.pop_repeating_id(cond.id);
291271

292272
// during body, can only root for the body
293273
this.push_repeating_id(body.id);
294-
v.visit_block(body, this);
274+
(vt.visit_block)(body, (this, vt));
295275
this.pop_repeating_id(body.id);
296276
}
297277

298278
// see explanation attached to the `root_ub` field:
299279
ast::expr_loop(ref body, _) => {
300280
this.push_repeating_id(body.id);
301-
visit::walk_expr(v, ex, this);
281+
oldvisit::visit_expr(ex, (this, vt));
302282
this.pop_repeating_id(body.id);
303283
}
304284

305285
ast::expr_fn_block(*) => {
306286
gather_moves::gather_captures(this.bccx, this.move_data, ex);
307-
visit::walk_expr(v, ex, this);
287+
oldvisit::visit_expr(ex, (this, vt));
308288
}
309289

310290
_ => {
311-
visit::walk_expr(v, ex, this);
291+
oldvisit::visit_expr(ex, (this, vt));
312292
}
313293
}
314294
}
@@ -790,14 +770,14 @@ impl GatherLoanCtxt {
790770

791771
// Setting up info that preserve needs.
792772
// This is just the most convenient place to do it.
793-
fn add_stmt_to_map(v: &mut GatherLoanVisitor,
794-
stmt: @ast::stmt,
795-
this: @mut GatherLoanCtxt) {
773+
fn add_stmt_to_map(stmt: @ast::stmt,
774+
(this, vt): (@mut GatherLoanCtxt,
775+
oldvisit::vt<@mut GatherLoanCtxt>)) {
796776
match stmt.node {
797777
ast::stmt_expr(_, id) | ast::stmt_semi(_, id) => {
798778
this.bccx.stmt_map.insert(id);
799779
}
800780
_ => ()
801781
}
802-
visit::walk_stmt(v, stmt, this);
782+
oldvisit::visit_stmt(stmt, (this, vt));
803783
}

0 commit comments

Comments
 (0)