Skip to content

Commit 3be859e

Browse files
committed
---
yaml --- r: 4415 b: refs/heads/master c: cf9c0f9 h: refs/heads/master i: 4413: 25d1924 4411: ae48874 4407: 149e77b 4399: c7160f4 4383: 58a6b77 4351: 280c87a v: v3
1 parent b4ff835 commit 3be859e

File tree

2 files changed

+37
-58
lines changed

2 files changed

+37
-58
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 95680474e27064a5745e9477a04765247285fb87
2+
refs/heads/master: cf9c0f9d933cd1266256ca46c84e0dc9a85a58cc

trunk/src/comp/middle/typeck.rs

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,45 +1201,39 @@ type gather_result =
12011201
// Used only as a helper for check_fn.
12021202
fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
12031203
old_fcx: &option::t[@fn_ctxt]) -> gather_result {
1204-
fn next_var_id(nvi: @mutable int) -> int {
1204+
let {vb, locals, local_names, nvi} = alt old_fcx {
1205+
none. {
1206+
{ vb: ty::unify::mk_var_bindings(),
1207+
locals: new_int_hash[int](),
1208+
local_names: new_int_hash[ast::ident](),
1209+
nvi: @mutable 0 }
1210+
}
1211+
some(fcx) {
1212+
{ vb: fcx.var_bindings,
1213+
locals: fcx.locals,
1214+
local_names: fcx.local_names,
1215+
nvi: fcx.next_var_id }
1216+
}
1217+
};
1218+
let tcx = ccx.tcx;
1219+
1220+
let next_var_id = lambda(nvi: @mutable int) -> int {
12051221
let rv = *nvi;
12061222
*nvi += 1;
12071223
ret rv;
1208-
}
1209-
fn assign(tcx: &ty::ctxt, var_bindings: &@ty::unify::var_bindings,
1210-
locals: &hashmap[ast::node_id, int],
1211-
local_names: &hashmap[ast::node_id, ast::ident],
1212-
nvi: @mutable int, nid: ast::node_id, ident: &ast::ident,
1213-
ty_opt: option::t[ty::t]) {
1224+
};
1225+
let assign = lambda(nid: ast::node_id, ident: &ast::ident,
1226+
ty_opt: option::t[ty::t]) {
12141227
let var_id = next_var_id(nvi);
12151228
locals.insert(nid, var_id);
12161229
local_names.insert(nid, ident);
12171230
alt ty_opt {
1218-
none[ty::t]. {/* nothing to do */ }
1219-
some[ty::t](typ) {
1220-
ty::unify::unify(ty::mk_var(tcx, var_id), typ, var_bindings, tcx);
1231+
none. {/* nothing to do */ }
1232+
some(typ) {
1233+
ty::unify::unify(ty::mk_var(tcx, var_id), typ, vb, tcx);
12211234
}
12221235
}
1223-
}
1224-
1225-
let vb;
1226-
let locals;
1227-
let local_names;
1228-
let nvi;
1229-
alt old_fcx {
1230-
none. {
1231-
vb = ty::unify::mk_var_bindings();
1232-
locals = new_int_hash[int]();
1233-
local_names = new_int_hash[ast::ident]();
1234-
nvi = @mutable 0;
1235-
}
1236-
some(fcx) {
1237-
vb = fcx.var_bindings;
1238-
locals = fcx.locals;
1239-
local_names = fcx.local_names;
1240-
nvi = fcx.next_var_id;
1241-
}
1242-
}
1236+
};
12431237

12441238
// Add object fields, if any.
12451239
let obj_fields = ~[];
@@ -1254,68 +1248,53 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
12541248
}
12551249
for f: ast::obj_field in obj_fields {
12561250
let field_ty = ty::node_id_to_type(ccx.tcx, f.id);
1257-
assign(ccx.tcx, vb, locals, local_names, nvi, f.id, f.ident,
1258-
some(field_ty));
1251+
assign(f.id, f.ident, some(field_ty));
12591252
}
12601253

12611254
// Add formal parameters.
12621255
let args = ty::ty_fn_args(ccx.tcx, ty::node_id_to_type(ccx.tcx, id));
12631256
let i = 0u;
12641257
for arg: ty::arg in args {
1265-
assign(ccx.tcx, vb, locals, local_names, nvi, f.decl.inputs.(i).id,
1266-
f.decl.inputs.(i).ident, some[ty::t](arg.ty));
1258+
assign(f.decl.inputs.(i).id, f.decl.inputs.(i).ident, some(arg.ty));
12671259
i += 1u;
12681260
}
12691261

12701262
// Add explicitly-declared locals.
1271-
fn visit_local(ccx: @crate_ctxt, vb: @ty::unify::var_bindings,
1272-
locals: hashmap[ast::node_id, int],
1273-
local_names: hashmap[ast::node_id, ast::ident],
1274-
nvi: @mutable int, local: &@ast::local, e: &(),
1275-
v: &visit::vt[()]) {
1263+
let visit_local = lambda(local: &@ast::local, e: &(), v: &visit::vt[()]) {
12761264
alt local.node.ty {
12771265
none. {
12781266
// Auto slot.
1279-
assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
1280-
ident_for_local(local), none);
1267+
assign(local.node.id, ident_for_local(local), none);
12811268
}
12821269
some(ast_ty) {
12831270
// Explicitly typed slot.
12841271
let local_ty = ast_ty_to_ty_crate(ccx, ast_ty);
1285-
assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
1286-
ident_for_local(local), some(local_ty));
1272+
assign(local.node.id, ident_for_local(local), some(local_ty));
12871273
}
12881274
}
12891275
visit::visit_local(local, e, v);
1290-
}
1276+
};
12911277

12921278
// Add pattern bindings.
1293-
fn visit_pat(ccx: @crate_ctxt, vb: @ty::unify::var_bindings,
1294-
locals: hashmap[ast::node_id, int],
1295-
local_names: hashmap[ast::node_id, ast::ident],
1296-
nvi: @mutable int, p: &@ast::pat, e: &(),
1297-
v: &visit::vt[()]) {
1279+
let visit_pat = lambda(p: &@ast::pat, e: &(), v: &visit::vt[()]) {
12981280
alt p.node {
12991281
ast::pat_bind(ident) {
1300-
assign(ccx.tcx, vb, locals, local_names, nvi, p.id, ident, none);
1282+
assign(p.id, ident, none);
13011283
}
13021284
_ {/* no-op */ }
13031285
}
13041286
visit::visit_pat(p, e, v);
1305-
}
1287+
};
13061288

13071289
// Don't descend into fns and items
13081290
fn visit_fn[E](f: &ast::_fn, tp: &ast::ty_param[], sp: &span,
13091291
i: &ast::fn_ident, id: ast::node_id, e: &E,
1310-
v: &visit::vt[E]) {
1311-
}
1292+
v: &visit::vt[E]) { }
13121293
fn visit_item[E](i: &@ast::item, e: &E, v: &visit::vt[E]) { }
13131294

13141295
let visit =
1315-
@{visit_local:
1316-
bind visit_local(ccx, vb, locals, local_names, nvi, _, _, _),
1317-
visit_pat:
1318-
bind visit_pat(ccx, vb, locals, local_names, nvi, _, _, _),
1296+
@{visit_local: visit_local,
1297+
visit_pat: visit_pat,
13191298
visit_fn: visit_fn,
13201299
visit_item: visit_item with *visit::default_visitor()};
13211300
visit::visit_block(f.body, (), visit::mk_vt(visit));

0 commit comments

Comments
 (0)