@@ -4,20 +4,7 @@ import std::option;
4
4
import std:: option:: none;
5
5
import std:: option:: some;
6
6
7
- import tstate:: ann:: pre_and_post;
8
- import tstate:: ann:: get_post;
9
- import tstate:: ann:: postcond;
10
- import tstate:: ann:: true_precond;
11
- import tstate:: ann:: false_postcond;
12
- import tstate:: ann:: empty_poststate;
13
- import tstate:: ann:: require;
14
- import tstate:: ann:: require_and_preserve;
15
- import tstate:: ann:: union;
16
- import tstate:: ann:: intersect;
17
- import tstate:: ann:: pp_clone;
18
- import tstate:: ann:: empty_prestate;
19
- import tstate:: ann:: set_precondition;
20
- import tstate:: ann:: set_postcondition;
7
+ import tstate:: ann:: * ;
21
8
import aux:: * ;
22
9
import bitvectors:: bit_num;
23
10
import bitvectors:: promises;
@@ -28,7 +15,7 @@ import bitvectors::declare_var;
28
15
import bitvectors:: gen_poststate;
29
16
import bitvectors:: relax_precond_block;
30
17
import bitvectors:: gen;
31
- import tritv:: tritv_clone ;
18
+ import tritv:: * ;
32
19
import syntax:: ast:: * ;
33
20
import syntax:: visit;
34
21
import std:: map:: new_int_hash;
@@ -591,6 +578,8 @@ fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
591
578
stmt_decl ( adecl, id) {
592
579
alt adecl. node {
593
580
decl_local ( alocals) {
581
+ let e_pp;
582
+ let prev_pp = empty_pre_post ( num_constraints ( fcx. enclosing ) ) ;
594
583
for alocal: @local in alocals {
595
584
alt alocal. node . init {
596
585
some ( an_init) {
@@ -611,7 +600,16 @@ fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
611
600
}
612
601
613
602
for each pat: @pat in pat_bindings ( alocal. node . pat ) {
614
- let ident = alt pat. node { pat_bind ( n) { n } } ;
603
+ /* FIXME: This won't be necessary when typestate
604
+ works well enough for pat_bindings to return a
605
+ refinement-typed thing. */
606
+ let ident = alt pat. node {
607
+ pat_bind ( n) { n }
608
+ _ {
609
+ fcx. ccx . tcx . sess . span_bug ( pat. span ,
610
+ "Impossible LHS" ) ;
611
+ }
612
+ } ;
615
613
alt p {
616
614
some( p) {
617
615
copy_in_postcond ( fcx, id,
@@ -629,6 +627,29 @@ fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
629
627
if an_init. op == init_move && is_path ( an_init. expr ) {
630
628
forget_in_postcond ( fcx, id, an_init. expr . id ) ;
631
629
}
630
+
631
+ /* Clear out anything that the previous initializer
632
+ guaranteed */
633
+ e_pp = expr_pp ( fcx. ccx , an_init. expr ) ;
634
+ tritv_copy ( prev_pp. precondition ,
635
+ seq_preconds ( fcx, [ prev_pp, e_pp] ) ) ;
636
+ /* Include the LHSs too, since those aren't in the
637
+ postconds of the RHSs themselves */
638
+ for each pat: @pat in pat_bindings ( alocal. node . pat ) {
639
+ alt pat. node {
640
+ pat_bind ( n) {
641
+ set_in_postcond ( bit_num ( fcx, ninit ( pat. id , n) ) ,
642
+ prev_pp) ;
643
+ }
644
+ _ {
645
+ fcx. ccx . tcx . sess . span_bug ( pat. span ,
646
+ "Impossible LHS" ) ;
647
+ }
648
+ } ;
649
+ }
650
+ copy_pre_post_ ( fcx. ccx , id,
651
+ prev_pp. precondition ,
652
+ prev_pp. postcondition ) ;
632
653
}
633
654
none. {
634
655
for each p: @pat in pat_bindings ( alocal. node . pat ) {
0 commit comments