Skip to content

Commit 72be7f8

Browse files
committed
---
yaml --- r: 4298 b: refs/heads/master c: 985c32e h: refs/heads/master v: v3
1 parent 3a53ffa commit 72be7f8

File tree

20 files changed

+309
-251
lines changed

20 files changed

+309
-251
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: 48ec25da423cd6535e6354a00fa6c98f3f2b4065
2+
refs/heads/master: 985c32ef4c930cdfba23db2191014d772c354407

trunk/src/comp/middle/alias.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt[scope]) {
127127
visit::visit_decl(d, sc, v);
128128
alt d.node {
129129
ast::decl_local(locs) {
130-
for loc: @ast::local in locs {
130+
for loc: @ast::local in locs {
131131
alt loc.node.init {
132132
some(init) {
133133
if init.op == ast::init_move {
@@ -298,14 +298,12 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &ast::arm[], sc: &scope,
298298
let dnums = arm_defnums(a);
299299
let new_sc = sc;
300300
if ivec::len(dnums) > 0u {
301-
new_sc =
302-
@(*sc +
303-
~[@{root_vars: roots,
304-
block_defnum: dnums.(0),
305-
bindings: dnums,
306-
tys: forbidden_tp,
307-
depends_on: deps(sc, roots),
308-
mutable ok: valid}]);
301+
new_sc = @(*sc + ~[@{root_vars: roots,
302+
block_defnum: dnums.(ivec::len(dnums) - 1u),
303+
bindings: dnums,
304+
tys: forbidden_tp,
305+
depends_on: deps(sc, roots),
306+
mutable ok: valid}]);
309307
}
310308
visit::visit_arm(a, new_sc, v);
311309
}
@@ -336,14 +334,16 @@ fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
336334
alt call.node {
337335
ast::expr_call(f, args) {
338336
let data = check_call(cx, f, args, sc);
339-
let defnum = local.node.id;
340-
let new_sc =
341-
@{root_vars: data.root_vars,
342-
block_defnum: defnum,
343-
bindings: ~[defnum],
344-
tys: data.unsafe_ts,
345-
depends_on: deps(sc, data.root_vars),
346-
mutable ok: valid};
337+
let bindings = ~[];
338+
for p: @ast::pat in ast::pat_bindings(local.node.pat) {
339+
bindings += ~[p.id];
340+
}
341+
let new_sc = @{root_vars: data.root_vars,
342+
block_defnum: bindings.(ivec::len(bindings) - 1u),
343+
bindings: bindings,
344+
tys: data.unsafe_ts,
345+
depends_on: deps(sc, data.root_vars),
346+
mutable ok: valid};
347347
visit::visit_block(blk, @(*sc + ~[new_sc]), v);
348348
}
349349
}
@@ -352,7 +352,6 @@ fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
352352
fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
353353
sc: &scope, v: &vt[scope]) {
354354
visit::visit_expr(seq, sc, v);
355-
let defnum = local.node.id;
356355
let root = expr_root(cx, seq, false);
357356
let root_def =
358357
alt path_def_id(cx, root.ex) { some(did) { ~[did.node] } _ { ~[] } };
@@ -371,13 +370,16 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
371370
util::ppaux::ty_to_str(cx.tcx, seq_t));
372371
}
373372
}
374-
let new_sc =
375-
@{root_vars: root_def,
376-
block_defnum: defnum,
377-
bindings: ~[defnum],
378-
tys: unsafe,
379-
depends_on: deps(sc, root_def),
380-
mutable ok: valid};
373+
let bindings = ~[];
374+
for p: @ast::pat in ast::pat_bindings(local.node.pat) {
375+
bindings += ~[p.id];
376+
}
377+
let new_sc = @{root_vars: root_def,
378+
block_defnum: bindings.(ivec::len(bindings) - 1u),
379+
bindings: bindings,
380+
tys: unsafe,
381+
depends_on: deps(sc, root_def),
382+
mutable ok: valid};
381383
visit::visit_block(blk, @(*sc + ~[new_sc]), v);
382384
}
383385

@@ -388,10 +390,10 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
388390
let my_defnum = ast::def_id_of_def(def).node;
389391
let var_t = ty::expr_ty(cx.tcx, ex);
390392
for r: restrict in *sc {
391-
392393
// excludes variables introduced since the alias was made
394+
// FIXME This does not work anymore, now that we have macros.
393395
if my_defnum < r.block_defnum {
394-
for t: ty::t in r.tys {
396+
for t: ty::t in r.tys {
395397
if ty_can_unsafely_include(cx, t, var_t, assign) {
396398
r.ok = val_taken(ex.span, p);
397399
}
@@ -489,15 +491,14 @@ fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
489491
prob = sc.(dep).ok;
490492
}
491493
if prob != valid {
492-
let msg =
493-
alt prob {
494-
overwritten(sp, wpt) {
495-
{span: sp, msg: "overwriting " + ast::path_name(wpt)}
496-
}
497-
val_taken(sp, vpt) {
498-
{span: sp, msg: "taking the value of " + ast::path_name(vpt)}
499-
}
500-
};
494+
let msg = alt prob {
495+
overwritten(sp, wpt) {
496+
{span: sp, msg: "overwriting " + ast::path_name(wpt)}
497+
}
498+
val_taken(sp, vpt) {
499+
{span: sp, msg: "taking the value of " + ast::path_name(vpt)}
500+
}
501+
};
501502
cx.tcx.sess.span_err(msg.span,
502503
msg.msg + " will invalidate alias " +
503504
ast::path_name(p) + ", which is still used");

trunk/src/comp/middle/freevars.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ fn collect_freevars(def_map: &resolve::def_map, sess: &session::session,
6969
}
7070
}
7171
fn walk_local(e: env, local: &@ast::local) {
72-
set_add(e.decls, local.node.id);
72+
for b: @ast::pat in ast::pat_bindings(local.node.pat) {
73+
set_add(e.decls, b.id);
74+
}
7375
}
7476
fn walk_pat(e: env, p: &@ast::pat) {
7577
alt p.node { ast::pat_bind(_) { set_add(e.decls, p.id); } _ { } }
@@ -131,9 +133,13 @@ fn annotate_freevars(sess: &session::session, def_map: &resolve::def_map,
131133
fn start_walk(b: &ast::blk, v: &visit::vt[()]) {
132134
v.visit_block(b, (), v);
133135
}
136+
let bound = ~[];
137+
for b: @ast::pat in ast::pat_bindings(local.node.pat){
138+
bound += ~[b.id];
139+
}
134140
let vars =
135141
collect_freevars(e.def_map, e.sess, bind start_walk(body, _),
136-
~[local.node.id]);
142+
bound);
137143
e.freevars.insert(body.node.id, vars);
138144
}
139145
_ { }

trunk/src/comp/middle/resolve.rs

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
255255
visit_item: visit_item_with_scope,
256256
visit_block: visit_block_with_scope,
257257
visit_arm: bind walk_arm(e, _, _, _),
258+
visit_pat: bind walk_pat(e, _, _, _),
258259
visit_expr: bind walk_expr(e, _, _, _),
259260
visit_ty: bind walk_ty(e, _, _, _),
260261
visit_constr: bind walk_constr(e, _, _, _, _, _),
@@ -289,33 +290,23 @@ fn resolve_names(e: &@env, c: &@ast::crate) {
289290
maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p.node, ns_value));
290291
}
291292
fn walk_arm(e: @env, a: &ast::arm, sc: &scopes, v: &vt[scopes]) {
292-
for p: @ast::pat in a.pats { walk_pat(*e, sc, p); }
293293
visit_arm_with_scope(a, sc, v);
294294
}
295-
fn walk_pat(e: &env, sc: &scopes, pat: &@ast::pat) {
295+
fn walk_pat(e: &@env, pat: &@ast::pat, sc: &scopes, v: &vt[scopes]) {
296+
visit::visit_pat(pat, sc, v);
296297
alt pat.node {
297-
ast::pat_tag(p, children) {
298-
let fnd = lookup_path_strict(e, sc, p.span, p.node, ns_value);
299-
if option::is_some(fnd) {
300-
alt option::get(fnd) {
301-
ast::def_variant(did, vid) {
302-
e.def_map.insert(pat.id, option::get(fnd));
303-
for child: @ast::pat in children {
304-
walk_pat(e, sc, child);
305-
}
306-
}
307-
_ {
308-
e.sess.span_err(p.span,
309-
"not a tag variant: " +
310-
ast::path_name(p));
311-
}
312-
}
298+
ast::pat_tag(p, _) {
299+
let fnd = lookup_path_strict(*e, sc, p.span, p.node, ns_value);
300+
alt option::get(fnd) {
301+
ast::def_variant(did, vid) {
302+
e.def_map.insert(pat.id, option::get(fnd));
303+
}
304+
_ {
305+
e.sess.span_err
306+
(p.span, "not a tag variant: " + ast::path_name(p));
307+
}
313308
}
314309
}
315-
ast::pat_rec(fields, _) {
316-
for f: ast::field_pat in fields { walk_pat(e, sc, f.pat); }
317-
}
318-
ast::pat_box(inner) { walk_pat(e, sc, inner); }
319310
_ { }
320311
}
321312
}
@@ -653,14 +644,18 @@ fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident,
653644
}
654645
scope_loop(local) {
655646
if ns == ns_value {
656-
if str::eq(local.node.ident, name) {
657-
ret some(ast::def_local(local_def(local.node.id)));
647+
alt lookup_in_pat(name, *local.node.pat) {
648+
some(did) { ret some(ast::def_local(did)); }
649+
_ {}
658650
}
659651
}
660652
}
661653
scope_block(b) { ret lookup_in_block(name, b.node, ns); }
662654
scope_arm(a) {
663-
if ns == ns_value { ret lookup_in_pat(name, *a.pats.(0)); }
655+
if ns == ns_value {
656+
ret option::map(ast::def_binding,
657+
lookup_in_pat(name, *a.pats.(0)));
658+
}
664659
}
665660
}
666661
ret none[def];
@@ -716,11 +711,11 @@ fn lookup_in_ty_params(name: &ident, ty_params: &ast::ty_param[]) ->
716711
ret none[def];
717712
}
718713

719-
fn lookup_in_pat(name: &ident, pat: &ast::pat) -> option::t[def] {
714+
fn lookup_in_pat(name: &ident, pat: &ast::pat) -> option::t[def_id] {
720715
alt pat.node {
721716
ast::pat_bind(p_name) {
722717
if str::eq(p_name, name) {
723-
ret some(ast::def_binding(local_def(pat.id)));
718+
ret some(local_def(pat.id));
724719
}
725720
}
726721
ast::pat_wild. { }
@@ -739,7 +734,7 @@ fn lookup_in_pat(name: &ident, pat: &ast::pat) -> option::t[def] {
739734
}
740735
ast::pat_box(inner) { ret lookup_in_pat(name, *inner); }
741736
}
742-
ret none[def];
737+
ret none;
743738
}
744739

745740
fn lookup_in_fn(name: &ident, decl: &ast::fn_decl,
@@ -777,14 +772,17 @@ fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &ast::ty_param[],
777772

778773
fn lookup_in_block(name: &ident, b: &ast::blk_, ns: namespace) ->
779774
option::t[def] {
780-
for st: @ast::stmt in b.stmts {
775+
for st: @ast::stmt in b.stmts {
781776
alt st.node {
782777
ast::stmt_decl(d, _) {
783778
alt d.node {
784779
ast::decl_local(locs) {
785-
for loc: @ast::local in locs {
786-
if ns == ns_value && str::eq(name, loc.node.ident) {
787-
ret some(ast::def_local(local_def(loc.node.id)));
780+
for loc: @ast::local in locs {
781+
if ns == ns_value {
782+
alt lookup_in_pat(name, *loc.node.pat) {
783+
some(did) { ret some(ast::def_local(did)); }
784+
_ {}
785+
}
788786
}
789787
}
790788
}
@@ -1154,22 +1152,20 @@ fn lookup_external(e: &env, cnum: int, ids: &ident[], ns: namespace) ->
11541152
fn check_for_collisions(e: &@env, c: &ast::crate) {
11551153
// Module indices make checking those relatively simple -- just check each
11561154
// name for multiple entities in the same namespace.
1157-
1158-
for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items()
1159-
{
1160-
for each name: @{key: ident, val: list[mod_index_entry]} in
1161-
m.val.index.items() {
1155+
for each m: @{key: ast::node_id, val: @indexed_mod}
1156+
in e.mod_map.items() {
1157+
for each name: @{key: ident, val: list[mod_index_entry]}
1158+
in m.val.index.items() {
11621159
check_mod_name(*e, name.key, name.val);
11631160
}
11641161
}
11651162
// Other scopes have to be checked the hard way.
1166-
1167-
let v =
1168-
@{visit_item: bind check_item(e, _, _, _),
1169-
visit_block: bind check_block(e, _, _, _),
1170-
visit_arm: bind check_arm(e, _, _, _),
1171-
visit_expr: bind check_expr(e, _, _, _),
1172-
visit_ty: bind check_ty(e, _, _, _) with *visit::default_visitor()};
1163+
let v = @{visit_item: bind check_item(e, _, _, _),
1164+
visit_block: bind check_block(e, _, _, _),
1165+
visit_arm: bind check_arm(e, _, _, _),
1166+
visit_expr: bind check_expr(e, _, _, _),
1167+
visit_ty: bind check_ty(e, _, _, _)
1168+
with *visit::default_visitor()};
11731169
visit::visit_crate(c, (), visit::mk_vt(v));
11741170
}
11751171

@@ -1244,29 +1240,30 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt[()]) {
12441240
}
12451241
}
12461242

1243+
fn check_pat(ch: checker, p: &@ast::pat) {
1244+
alt p.node {
1245+
ast::pat_bind(name) { add_name(ch, p.span, name); }
1246+
ast::pat_tag(_, children) {
1247+
for child: @ast::pat in children { check_pat(ch, child); }
1248+
}
1249+
ast::pat_rec(fields, _) {
1250+
for f: ast::field_pat in fields { check_pat(ch, f.pat); }
1251+
}
1252+
ast::pat_box(inner) { check_pat(ch, inner); }
1253+
_ { }
1254+
}
1255+
}
1256+
12471257
fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt[()]) {
12481258
visit::visit_arm(a, x, v);
1249-
fn walk_pat(ch: checker, p: &@ast::pat) {
1250-
alt p.node {
1251-
ast::pat_bind(name) { add_name(ch, p.span, name); }
1252-
ast::pat_tag(_, children) {
1253-
for child: @ast::pat in children { walk_pat(ch, child); }
1254-
}
1255-
ast::pat_rec(fields, _) {
1256-
for f: ast::field_pat in fields { walk_pat(ch, f.pat); }
1257-
}
1258-
ast::pat_box(inner) { walk_pat(ch, inner); }
1259-
_ { }
1260-
}
1261-
}
12621259
let ch0 = checker(*e, "binding");
1263-
walk_pat(ch0, a.pats.(0));
1260+
check_pat(ch0, a.pats.(0));
12641261
let seen0 = ch0.seen;
12651262
let i = ivec::len(a.pats);
12661263
while i > 1u {
12671264
i -= 1u;
12681265
let ch = checker(*e, "binding");
1269-
walk_pat(ch, a.pats.(i));
1266+
check_pat(ch, a.pats.(i));
12701267

12711268
// Ensure the bindings introduced in this pattern are the same as in
12721269
// the first pattern.
@@ -1297,8 +1294,8 @@ fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt[()]) {
12971294
ast::stmt_decl(d, _) {
12981295
alt d.node {
12991296
ast::decl_local(locs) {
1300-
for loc: @ast::local in locs {
1301-
add_name(values, d.span, loc.node.ident);
1297+
for loc: @ast::local in locs {
1298+
check_pat(values, loc.node.pat);
13021299
}
13031300
}
13041301
ast::decl_item(it) {

0 commit comments

Comments
 (0)