Skip to content

Commit 233ab9f

Browse files
committed
---
yaml --- r: 13150 b: refs/heads/master c: 41b02b7 h: refs/heads/master v: v3
1 parent 3ee0985 commit 233ab9f

File tree

8 files changed

+64
-50
lines changed

8 files changed

+64
-50
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3a2c92b46334d422c438061335f6f76669c8743f
2+
refs/heads/master: 41b02b7c57092f1da63beec60358061a9579d8c6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/tstate/auxiliary.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ type fn_info =
224224
{constrs: constr_map,
225225
num_constraints: uint,
226226
cf: ret_style,
227-
used_vars: @mut [node_id]};
227+
used_vars: @mut [node_id],
228+
ignore: bool};
228229

229230
/* mapping from node ID to typestate annotation */
230231
type node_ann_table = @mut [mut ts_ann];

trunk/src/rustc/middle/tstate/ck.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ fn fn_states(fk: visit::fn_kind, f_decl: ast::fn_decl, f_body: ast::blk,
116116
sp: span, id: node_id,
117117
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
118118

119+
visit::visit_fn(fk, f_decl, f_body, sp, id, ccx, v);
120+
119121
// We may not care about typestate for this function if it contains
120122
// no constrained calls
121-
if ccx.fm.contains_key(id) {
122-
visit::visit_fn(fk, f_decl, f_body, sp, id, ccx, v);
123+
if !ccx.fm.get(id).ignore {
123124
/* Look up the var-to-bit-num map for this function */
124125

125126
let f_info = ccx.fm.get(id);

trunk/src/rustc/middle/tstate/collect_locals.rs

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ fn add_constraint(tcx: ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) ->
6969
ret next + 1u;
7070
}
7171

72+
fn contains_constrained_calls(tcx: ty::ctxt, body: blk) -> bool {
73+
type cx = @{
74+
tcx: ty::ctxt,
75+
mut has: bool
76+
};
77+
let cx = @{
78+
tcx: tcx,
79+
mut has: false
80+
};
81+
let vtor = visit::default_visitor::<cx>();
82+
let vtor = @{visit_expr: visit_expr with *vtor};
83+
visit::visit_block(body, cx, visit::mk_vt(vtor));
84+
ret cx.has;
85+
86+
fn visit_expr(e: @expr, &&cx: cx, v: visit::vt<cx>) {
87+
import syntax::print::pprust;
88+
#debug("visiting %?", pprust::expr_to_str(e));
89+
90+
visit::visit_expr(e, cx, v);
91+
92+
if constraints_expr(cx.tcx, e).is_not_empty() {
93+
#debug("has constraints");
94+
cx.has = true;
95+
} else {
96+
#debug("has not constraints");
97+
}
98+
}
99+
}
72100

73101
/* builds a table mapping each local var defined in f
74102
to a bit number in the precondition/postcondition vectors */
@@ -86,24 +114,29 @@ fn mk_fn_info(ccx: crate_ctxt,
86114
/* now we have to add bit nums for both the constraints
87115
and the variables... */
88116

89-
let mut i = 0u, l = vec::len(*cx.cs);
90-
while i < l {
91-
next = add_constraint(cx.tcx, copy cx.cs[i], next, res_map);
92-
i += 1u;
93-
}
94-
/* if this function has any constraints, instantiate them to the
95-
argument names and add them */
96-
for f_decl.constraints.each {|c|
97-
let sc = ast_constr_to_sp_constr(cx.tcx, f_decl.inputs, c);
98-
next = add_constraint(cx.tcx, sc, next, res_map);
117+
let ignore = !contains_constrained_calls(ccx.tcx, f_body);
118+
119+
if !ignore {
120+
let mut i = 0u, l = vec::len(*cx.cs);
121+
while i < l {
122+
next = add_constraint(cx.tcx, copy cx.cs[i], next, res_map);
123+
i += 1u;
124+
}
125+
/* if this function has any constraints, instantiate them to the
126+
argument names and add them */
127+
for f_decl.constraints.each {|c|
128+
let sc = ast_constr_to_sp_constr(cx.tcx, f_decl.inputs, c);
129+
next = add_constraint(cx.tcx, sc, next, res_map);
130+
}
99131
}
100132

101133
let v: @mut [node_id] = @mut [];
102134
let rslt =
103135
{constrs: res_map,
104136
num_constraints: next,
105137
cf: f_decl.cf,
106-
used_vars: v};
138+
used_vars: v,
139+
ignore: ignore};
107140
ccx.fm.insert(id, rslt);
108141
#debug("%s has %u constraints", name, num_constraints(rslt));
109142
}

trunk/src/rustc/middle/tstate/pre_post_conditions.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -618,42 +618,13 @@ fn find_pre_post_fn(fcx: fn_ctxt, body: blk) {
618618
}
619619
}
620620

621-
fn contains_constrained_calls(tcx: ty::ctxt, body: blk) -> bool {
622-
type cx = @{
623-
tcx: ty::ctxt,
624-
mut has: bool
625-
};
626-
let cx = @{
627-
tcx: tcx,
628-
mut has: false
629-
};
630-
let vtor = visit::default_visitor::<cx>();
631-
let vtor = @{visit_expr: visit_expr with *vtor};
632-
visit::visit_block(body, cx, visit::mk_vt(vtor));
633-
ret cx.has;
634-
635-
fn visit_expr(e: @expr, &&cx: cx, v: visit::vt<cx>) {
636-
import syntax::print::pprust;
637-
#debug("visiting %?", pprust::expr_to_str(e));
638-
639-
visit::visit_expr(e, cx, v);
640-
641-
if constraints_expr(cx.tcx, e).is_not_empty() {
642-
#debug("has constraints");
643-
cx.has = true;
644-
} else {
645-
#debug("has not constraints");
646-
}
647-
}
648-
}
649-
650621
fn fn_pre_post(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
651622
id: node_id,
652623
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
653624

654-
if contains_constrained_calls(ccx.tcx, body) {
655-
visit::visit_fn(fk, decl, body, sp, id, ccx, v);
656-
assert (ccx.fm.contains_key(id));
625+
visit::visit_fn(fk, decl, body, sp, id, ccx, v);
626+
assert (ccx.fm.contains_key(id));
627+
if !ccx.fm.get(id).ignore {
657628
let fcx =
658629
{enclosing: ccx.fm.get(id),
659630
id: id,

trunk/src/snapshots.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ S 2012-05-30 0c0818b
66
macos-x86_64 d562f05c8911e7405b0a9ff5815f49fca69045d3
77
macos-i386 4d09cc2a4882d92f125718161e3d7086531748e6
88

9+
S 2012-05-30 02dde78
10+
winnt-i386 b394e3db0639942a9844ce6f78d34239a90127af
11+
linux-x86_64 bd3128bce34f2f131f37bc1c7077a4d2e367ff50
12+
linux-i386 ccd43b8d56a31d6cfb97ec7997a9ff6dd899f542
13+
freebsd-x86_64 408d720f3620ea534eae77fcc4fd6ecb395a6903
14+
macos-x86_64 ed29d1f7a72da3ad7dcddf49ef6c3b9a1eed2646
15+
macos-i386 dcf74f82ad65b9d5368ced4098827fc9343d694b
16+
917
S 2012-05-28 7b36d66
1018
winnt-i386 fe348cb80c7e2722032228643d932d1ba8041871
1119
linux-x86_64 ec562500380024118f2e9ef2a34e12b3448b5917

trunk/src/test/compile-fail/block-deinitializes-upvar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// error-pattern:tried to deinitialize a variable declared in a different
1+
// error-pattern:moving out of immutable upvar
22
fn force(f: fn()) { f(); }
33
fn main() {
4-
let x = @{x: 17, y: 2};
4+
let mut x = @{x: 17, y: 2};
55
let y = @{x: 5, y: 5};
66

77
force({|| x <- y;});

trunk/src/test/compile-fail/issue-1965.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:tried to deinitialize a variable declared in a different
1+
// error-pattern:moving out of immutable upvar
22
fn test(-x: uint) {}
33

44
fn main() {

0 commit comments

Comments
 (0)