Skip to content

Commit 3c905eb

Browse files
committed
---
yaml --- r: 6413 b: refs/heads/master c: 86c1f16 h: refs/heads/master i: 6411: feb8fef v: v3
1 parent 2ed36d8 commit 3c905eb

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
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: ff04cb1eb02083641c6a960581fe857ef95b6cc2
2+
refs/heads/master: 86c1f16a1066317fdde988c0357e21ecdb336fca

trunk/src/comp/driver/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
139139
bind freevars::annotate_freevars(def_map, crate));
140140
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, ast_map, freevars);
141141
time(time_passes, "typechecking", bind typeck::check_crate(ty_cx, crate));
142-
let last_uses = time(time_passes, "last use finding",
143-
bind last_use::find_last_uses(crate, def_map, ty_cx));
144142
time(time_passes, "function usage",
145143
bind fn_usage::check_crate_fn_usage(ty_cx, crate));
146144
time(time_passes, "alt checking",
@@ -150,9 +148,11 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
150148
let mut_map =
151149
time(time_passes, "mutability checking",
152150
bind middle::mut::check_crate(ty_cx, crate));
153-
let copy_map =
151+
let (copy_map, ref_map) =
154152
time(time_passes, "alias checking",
155153
bind middle::alias::check_crate(ty_cx, crate));
154+
let last_uses = time(time_passes, "last use finding",
155+
bind last_use::find_last_uses(crate, def_map, ref_map, ty_cx));
156156
time(time_passes, "kind checking",
157157
bind kind::check_crate(ty_cx, last_uses, crate));
158158
time(time_passes, "const checking",

trunk/src/comp/middle/alias.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type scope = {bs: [binding],
3636

3737
fn mk_binding(cx: ctx, id: node_id, span: span, root_var: option::t<node_id>,
3838
unsafe_tys: [unsafe_ty]) -> binding {
39+
alt root_var {
40+
some(r_id) { cx.ref_map.insert(id, r_id); }
41+
_ {}
42+
}
3943
ret @{node_id: id, span: span, root_var: root_var,
4044
local_id: local_id_of_node(cx, id),
4145
unsafe_tys: unsafe_tys,
@@ -45,16 +49,19 @@ fn mk_binding(cx: ctx, id: node_id, span: span, root_var: option::t<node_id>,
4549
tag local_info { local(uint); }
4650

4751
type copy_map = std::map::hashmap<node_id, ()>;
52+
type ref_map = std::map::hashmap<node_id, node_id>;
4853

4954
type ctx = {tcx: ty::ctxt,
5055
copy_map: copy_map,
56+
ref_map: ref_map,
5157
mutable silent: bool};
5258

53-
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map {
59+
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
5460
// Stores information about object fields and function
5561
// arguments that's otherwise not easily available.
5662
let cx = @{tcx: tcx,
5763
copy_map: std::map::new_int_hash(),
64+
ref_map: std::map::new_int_hash(),
5865
mutable silent: false};
5966
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
6067
visit_expr: bind visit_expr(cx, _, _, _),
@@ -63,7 +70,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map {
6370
let sc = {bs: [], ret_info: other, invalid: @mutable list::nil};
6471
visit::visit_crate(*crate, sc, visit::mk_vt(v));
6572
tcx.sess.abort_if_errors();
66-
ret cx.copy_map;
73+
ret (cx.copy_map, cx.ref_map);
6774
}
6875

6976
fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span,

trunk/src/comp/middle/last_use.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ type bl = @{type: block_type, mutable second: bool, mutable exits: [set]};
3232

3333
type ctx = {last_uses: std::map::hashmap<node_id, bool>,
3434
def_map: resolve::def_map,
35+
ref_map: alias::ref_map,
3536
tcx: ty::ctxt,
3637
// The current set of local last uses
3738
mutable current: set,
3839
mutable blocks: list<bl>};
3940

40-
fn find_last_uses(c: @crate, def_map: resolve::def_map, tcx: ty::ctxt)
41-
-> last_uses {
41+
fn find_last_uses(c: @crate, def_map: resolve::def_map,
42+
ref_map: alias::ref_map, tcx: ty::ctxt) -> last_uses {
4243
let v = visit::mk_vt(@{visit_expr: visit_expr,
4344
visit_fn: visit_fn
4445
with *visit::default_visitor()});
4546
let cx = {last_uses: std::map::new_int_hash(),
4647
def_map: def_map,
48+
ref_map: ref_map,
4749
tcx: tcx,
4850
mutable current: [],
4951
mutable blocks: nil};
@@ -99,11 +101,17 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
99101
cx.current = join_branches([cur, cx.current]);
100102
}
101103
expr_path(_) {
102-
alt clear_if_path(cx, ex, v, false) {
103-
option::some(my_def) {
104-
cx.current += [{def: my_def, exprs: cons(ex.id, @nil)}];
104+
let my_def = ast_util::def_id_of_def(cx.def_map.get(ex.id)).node;
105+
alt cx.ref_map.find(my_def) {
106+
option::some(root_id) { clear_in_current(cx, root_id, false); }
107+
_ {
108+
alt clear_if_path(cx, ex, v, false) {
109+
option::some(my_def) {
110+
cx.current += [{def: my_def, exprs: cons(ex.id, @nil)}];
111+
}
112+
_ {}
113+
}
105114
}
106-
_ {}
107115
}
108116
}
109117
expr_swap(lhs, rhs) {

trunk/src/comp/middle/trans.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,10 +4524,12 @@ fn init_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
45244524

45254525
fn init_ref_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
45264526
let init_expr = option::get(local.node.init).expr;
4527-
let val = trans_lval(bcx, init_expr);
4528-
assert val.kind == owned;
4529-
ret trans_alt::bind_irrefutable_pat(val.bcx, local.node.pat, val.val,
4530-
false);
4527+
let {bcx, val, kind} = trans_lval(bcx, init_expr);
4528+
alt kind {
4529+
owned_imm. { val = do_spill_noroot(bcx, val); }
4530+
owned. {}
4531+
}
4532+
ret trans_alt::bind_irrefutable_pat(bcx, local.node.pat, val, false);
45314533
}
45324534

45334535
fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t)

0 commit comments

Comments
 (0)