Skip to content

Commit e2518ff

Browse files
committed
---
yaml --- r: 5041 b: refs/heads/master c: 7bbe8d2 h: refs/heads/master i: 5039: 62fbe40 v: v3
1 parent 7a2723e commit e2518ff

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
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: 61392f9f8295bc770487389d3240caed13bfd3d0
2+
refs/heads/master: 7bbe8d2e8c61165d539a9e4d916566a57f59d708

trunk/src/comp/middle/alias.rs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,32 @@ tag valid { valid; overwritten(span, ast::path); val_taken(span, ast::path); }
2828

2929
type restrict =
3030
@{root_vars: [node_id],
31-
block_defnum: node_id,
31+
local_id: uint,
3232
bindings: [node_id],
3333
tys: [ty::t],
3434
depends_on: [uint],
3535
mutable ok: valid};
3636

3737
type scope = @[restrict];
3838

39-
tag local_info { arg(ast::mode); objfield(ast::mutability); }
39+
tag local_info {
40+
arg(ast::mode);
41+
objfield(ast::mutability);
42+
local(uint);
43+
}
4044

4145
type mut_map = std::map::hashmap<node_id, ()>;
4246
type ctx = {tcx: ty::ctxt,
4347
local_map: std::map::hashmap<node_id, local_info>,
48+
mutable next_local: uint,
4449
mut_map: mut_map};
4550

4651
fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) -> mut_map {
4752
// Stores information about object fields and function
4853
// arguments that's otherwise not easily available.
4954
let cx = @{tcx: tcx,
5055
local_map: std::map::new_int_hash(),
56+
mutable next_local: 0u,
5157
mut_map: std::map::new_int_hash()};
5258
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
5359
visit_item: bind visit_item(cx, _, _, _),
@@ -83,7 +89,7 @@ fn visit_fn(cx: &@ctx, f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span,
8389
@[
8490
// I'm not sure if there is anything sensical to put here
8591
@{root_vars: [],
86-
block_defnum: 0,
92+
local_id: cx.next_local,
8793
bindings: dnums,
8894
tys: [],
8995
depends_on: [],
@@ -162,6 +168,13 @@ fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt<scope>) {
162168
if !handled { visit::visit_expr(ex, sc, v); }
163169
}
164170

171+
fn register_locals(cx: &ctx, pat: &@ast::pat) {
172+
for each pat in ast_util::pat_bindings(pat) {
173+
cx.local_map.insert(pat.id, local(cx.next_local));
174+
cx.next_local += 1u;
175+
}
176+
}
177+
165178
fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) {
166179
visit::visit_decl(d, sc, v);
167180
alt d.node {
@@ -175,6 +188,7 @@ fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) {
175188
}
176189
none. { }
177190
}
191+
register_locals(*cx, loc.node.pat);
178192
}
179193
}
180194
_ { }
@@ -331,55 +345,51 @@ fn check_tail_call(cx: &ctx, call: &@ast::expr) {
331345

332346
fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope,
333347
v: &vt<scope>) {
334-
visit::visit_expr(input, sc, v);
348+
v.visit_expr(input, sc, v);
335349
let root = expr_root(cx, input, true);
336350
let roots =
337351
alt path_def_id(cx, root.ex) { some(did) { [did.node] } _ { [] } };
338352
let forbidden_tp: [ty::t] =
339353
alt inner_mut(root.ds) { some(t) { [t] } _ { [] } };
340354
for a: ast::arm in arms {
341-
let dnums = arm_defnums(a);
355+
let dnums = ast_util::pat_binding_ids(a.pats[0]);
342356
let new_sc = sc;
343357
if vec::len(dnums) > 0u {
344-
new_sc =
345-
@(*sc +
346-
[@{root_vars: roots,
347-
block_defnum: dnums[vec::len(dnums) - 1u],
348-
bindings: dnums,
349-
tys: forbidden_tp,
350-
depends_on: deps(sc, roots),
351-
mutable ok: valid}]);
358+
new_sc = @(*sc + [@{root_vars: roots,
359+
local_id: cx.next_local,
360+
bindings: dnums,
361+
tys: forbidden_tp,
362+
depends_on: deps(sc, roots),
363+
mutable ok: valid}]);
352364
}
365+
register_locals(cx, a.pats[0]);
353366
visit::visit_arm(a, new_sc, v);
354367
}
355368
}
356369

357-
fn arm_defnums(arm: &ast::arm) -> [node_id] {
358-
ret ast_util::pat_binding_ids(arm.pats[0]);
359-
}
360-
361370
fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
362371
blk: &ast::blk, sc: &scope, v: &vt<scope>) {
363-
visit::visit_expr(call, sc, v);
372+
v.visit_expr(call, sc, v);
364373
alt call.node {
365374
ast::expr_call(f, args) {
366375
let data = check_call(cx, f, args, sc);
367376
let bindings = ast_util::pat_binding_ids(local.node.pat);
368377
let new_sc =
369378
@{root_vars: data.root_vars,
370-
block_defnum: bindings[vec::len(bindings) - 1u],
379+
local_id: cx.next_local,
371380
bindings: bindings,
372381
tys: data.unsafe_ts,
373382
depends_on: deps(sc, data.root_vars),
374383
mutable ok: valid};
384+
register_locals(cx, local.node.pat);
375385
visit::visit_block(blk, @(*sc + [new_sc]), v);
376386
}
377387
}
378388
}
379389

380390
fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
381391
sc: &scope, v: &vt<scope>) {
382-
visit::visit_expr(seq, sc, v);
392+
v.visit_expr(seq, sc, v);
383393
let root = expr_root(cx, seq, false);
384394
let root_def =
385395
alt path_def_id(cx, root.ex) { some(did) { [did.node] } _ { [] } };
@@ -400,11 +410,12 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
400410
let bindings = ast_util::pat_binding_ids(local.node.pat);
401411
let new_sc =
402412
@{root_vars: root_def,
403-
block_defnum: bindings[vec::len(bindings) - 1u],
413+
local_id: cx.next_local,
404414
bindings: bindings,
405415
tys: unsafe,
406416
depends_on: deps(sc, root_def),
407417
mutable ok: valid};
418+
register_locals(cx, local.node.pat);
408419
visit::visit_block(blk, @(*sc + [new_sc]), v);
409420
}
410421
@@ -413,12 +424,14 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
413424
let def = cx.tcx.def_map.get(id);
414425
if !def_is_local(def, true) { ret; }
415426
let my_defnum = ast_util::def_id_of_def(def).node;
427+
let my_local_id = alt cx.local_map.find(my_defnum) {
428+
some(local(id)) { id }
429+
_ { 0u }
430+
};
416431
let var_t = ty::expr_ty(cx.tcx, ex);
417432
for r: restrict in *sc {
418-
419433
// excludes variables introduced since the alias was made
420-
// FIXME This does not work anymore, now that we have macros.
421-
if my_defnum < r.block_defnum {
434+
if my_local_id < r.local_id {
422435
for t: ty::t in r.tys {
423436
if ty_can_unsafely_include(cx, t, var_t, assign) {
424437
r.ok = val_taken(ex.span, p);

trunk/src/comp/syntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) {
246246
}
247247
expr_tup(elts) { for el in elts { v.visit_expr(el, e, v); } }
248248
expr_call(callee, args) {
249-
v.visit_expr(callee, e, v);
250249
visit_exprs(args, e, v);
250+
v.visit_expr(callee, e, v);
251251
}
252252
expr_self_method(_) { }
253253
expr_bind(callee, args) {

trunk/src/lib/treemap.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ fn find<@K, @V>(m : &treemap<K, V>, k : &K) -> option<V> {
8080
fn traverse<@K, @V>(m : &treemap<K, V>, f : fn(&K, &V)) {
8181
alt *m {
8282
empty. { }
83-
node(@k, @v, _, _) {
84-
// copy v to make aliases work out
85-
let v1 = v;
83+
node(k, v, _, _) {
84+
let k1 = k, v1 = v;
8685
alt *m {
8786
node(_, _, left, _) {
8887
traverse(left, f);
8988
}
9089
}
91-
f(k, v1);
90+
f(*k1, *v1);
9291
alt *m {
9392
node(_, _, _, right) {
9493
traverse(right, f);

0 commit comments

Comments
 (0)