1 | include "Clight/switchRemoval.ma". |
---|
2 | include "Clight/labelSimulation.ma". |
---|
3 | |
---|
4 | axiom switch_final_related : ∀ge1,s1,s2. |
---|
5 | switch_state_sim ge1 s1 s2 → |
---|
6 | is_final s1 = is_final s2. |
---|
7 | |
---|
8 | lemma after_aux_result : ∀avs,n,s,tr,P. |
---|
9 | after_aux avs n s tr P → |
---|
10 | ∃tr',s'. P tr' s' ∧ after_aux avs n s tr (λtr'',s''. 〈tr'',s''〉 = 〈tr',s'〉). |
---|
11 | #avs #n elim n |
---|
12 | [ #s #tr #P #A whd in A; %{tr} %{s} % [ @A | % ] |
---|
13 | | #n' #IH #s #tr #P |
---|
14 | whd in ⊢ (% → ?); |
---|
15 | lapply (refl ? (is_final … s)) |
---|
16 | cases (is_final … s) in ⊢ (???% → %); |
---|
17 | [ #F whd in ⊢ (% → ?); |
---|
18 | lapply (refl ? (step … s)) |
---|
19 | cases (step … s) in ⊢ (???% → %); |
---|
20 | [ #o #k #_ * |
---|
21 | | * #tr1 #s1 #ST whd in ⊢ (% → ?); |
---|
22 | cases n' in IH ⊢ %; |
---|
23 | [ #_ whd in ⊢ (% → ?); #p % [2: % [2: %{p} whd >F whd >ST whd % | skip ] | skip ] |
---|
24 | | #n'' #IH lapply (refl ? (avs_inv avs s1)) cases (avs_inv avs s1) in ⊢ (???% → %); |
---|
25 | [ #INV #AF |
---|
26 | cases (IH … AF) #tr' * #s' * #p #AF' |
---|
27 | % [2: % [2: %{p} whd >F whd >ST whd >INV @AF' | skip ] | skip ] |
---|
28 | | #_ * |
---|
29 | ] |
---|
30 | ] |
---|
31 | | #m #_ * |
---|
32 | ] |
---|
33 | | #r #F * |
---|
34 | ] |
---|
35 | ] qed. |
---|
36 | |
---|
37 | lemma after_n_result : ∀n,O,I,exec,g,s,P,inv. |
---|
38 | after_n_steps n O I exec g s inv P → |
---|
39 | ∃tr',s'. |
---|
40 | P tr' s' ∧ |
---|
41 | after_n_steps n O I exec g s inv (λtr'',s''. 〈tr'',s''〉 = 〈tr',s'〉). |
---|
42 | #n #O #I #exec #g #s #P #inv #A |
---|
43 | cases (after_aux_result … A) #tr * #s' * #p #A' |
---|
44 | %{tr} %{s'} %{p} @A' |
---|
45 | qed. |
---|
46 | |
---|
47 | |
---|
48 | lemma after_1_of_n_steps' : ∀n,O,I,exec,g,tr,s',s. |
---|
49 | after_n_steps (S n) O I exec g s (λ_.true) (λtrx,sx. 〈trx,sx〉 = 〈tr,s'〉) → |
---|
50 | ∃tr1,tr2,s1. |
---|
51 | is_final … exec g s = None ? ∧ |
---|
52 | step … exec g s = Value … 〈tr1,s1〉 ∧ |
---|
53 | tr = tr1⧺tr2 ∧ |
---|
54 | after_n_steps n O I exec g s1 (λ_.true) (λtrx,sx. 〈trx,sx〉 = 〈tr2,s'〉). |
---|
55 | #n #O #I #exec #g #tr #s' #s #A |
---|
56 | cases (after_1_of_n_steps … A) |
---|
57 | #tr1 * #s1 * * * #F #ST #_ #A' |
---|
58 | cases (after_n_result … A') |
---|
59 | #tr'' * #s'' * #E #A'' destruct |
---|
60 | % [2: % [2: % [2: % [ % [% [ @F | @ST ] | % ] | @A'' ] | skip ] | skip ] | skip ] |
---|
61 | qed. |
---|
62 | |
---|
63 | theorem steps_with_labels : ∀ge,ge'. |
---|
64 | related_globals_gen … label_fundef ge ge' → |
---|
65 | ∀n,s1,s1',tr,s2. |
---|
66 | state_with_labels s1 s1' → |
---|
67 | after_n_steps (S n) … clight_exec ge s1 (λ_.true) (λtr',s'.〈tr',s'〉 = 〈tr,s2〉) → |
---|
68 | ∃m. after_n_steps (S m) … clight_exec ge' s1' (λ_.true) |
---|
69 | (λtr',s2'. trace_with_extra_labels tr tr' ∧ |
---|
70 | state_with_labels s2 s2'). |
---|
71 | #ge #ge' #RG |
---|
72 | #n elim n |
---|
73 | [ #s1 #s1' #tr #s2 #SWL #AFTER |
---|
74 | cases (after_1_step … AFTER) #tr' * #s' * * #F1 #ST1 #E destruct |
---|
75 | @(step_with_labels … RG … ST1) // |
---|
76 | | #n #IH #s1 #s1' #tr #s2 #SWL #AFTER |
---|
77 | cases (after_1_of_n_steps' … AFTER) #tr1 * #tr2 * #s' * * * #F1 #ST1 #E #AFTER' |
---|
78 | destruct |
---|
79 | cases (step_with_labels … RG … SWL ST1) #m1 #AF1 |
---|
80 | cases (after_n_result … AF1) #tr2 * #s2' * * #TWEL #SWL' #AF'' |
---|
81 | cases (IH … SWL' AFTER') |
---|
82 | #m2 #AF2 |
---|
83 | %{(m1+S m2)} |
---|
84 | @(after_n_m (S m1) (S m2) … AF2) // |
---|
85 | @(after_n_covariant … AF'') |
---|
86 | |
---|
87 | #tr #s #E destruct %{(refl ??)} |
---|
88 | #tr'' #s'' * #TWEL #SWL % /2/ |
---|
89 | ] qed. |
---|
90 | |
---|
91 | lemma interactive_switch_step : ∀ge,ge'. |
---|
92 | switch_removal_globals ? fundef_switch_removal ge ge' → |
---|
93 | ∀s1,s1',o,k. |
---|
94 | exec_step ge s1 = Interact … o k → |
---|
95 | switch_state_sim ge s1 s1' → |
---|
96 | ∃k'. |
---|
97 | exec_step ge' s1' = Interact … o k' ∧ |
---|
98 | ∀i. ∃tr,s2. |
---|
99 | k i = Value … 〈tr,s2〉 ∧ |
---|
100 | ∃s2'. |
---|
101 | k' i = Value … 〈tr,s2'〉 ∧ |
---|
102 | switch_state_sim ge s2 s2'. |
---|
103 | #ge #ge' #RG #s1 #s1' #o #k #EX |
---|
104 | cases (exec_step_interaction … EX) |
---|
105 | #vf * #fn * #argtys * #retty * #vargs * #k' * #m #E |
---|
106 | destruct |
---|
107 | #S inversion S |
---|
108 | [1,3,4: #H1 #H2 #H3 #H4 destruct |
---|
109 | #H5 #H6 #H7 #H8 #H9 #H10 #H11 #H12 destruct |
---|
110 | #H13 #H14 #H15 #H16 #H17 #H18 #H19 #H20 #H21 #H22 #H23 #H24 #H25 #H26 #H27 #H28 #H29 destruct |
---|
111 | ] |
---|
112 | #s_vf #s_fd #s_args #s_k #s_k_ext #s_m #s_m_ext #s_writeable #s_me #s_H |
---|
113 | #E1 #E2 #E3 destruct |
---|
114 | whd in EX:(??%?); |
---|
115 | @(bindIO_res_interact ?????????? EX) -EX |
---|
116 | #vs #CHECK #EX whd in EX:(??%?); destruct |
---|
117 | % [2: % |
---|
118 | [ whd in ⊢ (??%?); |
---|
119 | >CHECK in ⊢ (??%?); |
---|
120 | whd in ⊢ (??%?); |
---|
121 | @refl |
---|
122 | | #i |
---|
123 | % [2: % [2: % |
---|
124 | [ @refl |
---|
125 | | % [2: % |
---|
126 | [ @refl |
---|
127 | | @(sws_returnstate … s_me) // ] |
---|
128 | | skip ] ] | skip ] |
---|
129 | ] ]| skip |
---|
130 | ] qed. |
---|
131 | |
---|
132 | lemma Value_eq_l : ∀tr,s,tr',s'. |
---|
133 | Value io_out io_in (trace×state) 〈tr,s〉 = Value io_out io_in (trace×state) 〈tr',s'〉 → |
---|
134 | tr = tr'. |
---|
135 | #tr #s #tr' #s' #E destruct % |
---|
136 | qed. |
---|
137 | |
---|
138 | lemma Value_eq_r : ∀tr,s,tr',s'. |
---|
139 | Value io_out io_in (trace×state) 〈tr,s〉 = Value io_out io_in (trace×state) 〈tr',s'〉 → |
---|
140 | s = s'. |
---|
141 | #tr #s #tr' #s' #E destruct % |
---|
142 | qed. |
---|
143 | |
---|
144 | let corec build_exec |
---|
145 | (ge1,ge2,ge3:genv) |
---|
146 | (SRG:switch_removal_globals ? fundef_switch_removal ge1 ge2) |
---|
147 | (RG:related_globals_gen … label_fundef ge2 ge3) |
---|
148 | (s1,s2,s3:state) |
---|
149 | (S1:switch_state_sim ge1 s1 s2) |
---|
150 | (S2:state_with_labels s2 s3) |
---|
151 | (NW:not_wrong state (exec_inf_aux … clight_fullexec ge1 (exec_step ge1 s1))) |
---|
152 | : sim_with_labels (exec_inf_aux … clight_fullexec ge1 (exec_step ge1 s1)) (exec_inf_aux … clight_fullexec ge3 (exec_step ge3 s3)) ≝ |
---|
153 | match NW return λe,NW. exec_inf_aux … clight_fullexec ?? = e → sim_with_labels e ? with |
---|
154 | [ nw_stop tr i s ⇒ ? |
---|
155 | | nw_step tr1 s1' e1 NW1 ⇒ ? |
---|
156 | | nw_interact o k NWk ⇒ ? |
---|
157 | ] (refl ? (exec_inf_aux … clight_fullexec ge1 (exec_step ge1 s1))). |
---|
158 | [ #E1 |
---|
159 | cases (exec_inf_stops_at_final ?? clight_fullexec … E1) |
---|
160 | #EX1 #F1 |
---|
161 | cases (switch_removal_correction … SRG … S1 EX1) |
---|
162 | #n1 #A1 |
---|
163 | cases (after_n_result … A1) #tr1' * #s1' * * #E destruct #S1' #A1' |
---|
164 | cases (steps_with_labels … RG … S2 A1') |
---|
165 | #n2 #A2 cases (after_inv clight_fullexec ????? A2) #tr' * #s' * * #TWL #S' |
---|
166 | lapply F1 whd in ⊢ (??%? → ?); >(switch_final_related … S1') >(final_related … S') #F3 |
---|
167 | whd in match (is_final … s'); >F3 * |
---|
168 | #tr2' #S2 |
---|
169 | @(swl_stop … S2 TWL) |
---|
170 | | #E1 |
---|
171 | cases (extract_step ?? clight_fullexec … E1) |
---|
172 | #EX1 #E1' |
---|
173 | cases (switch_removal_correction … SRG … S1 EX1) |
---|
174 | #n1 #A1 |
---|
175 | cases (after_n_result … A1) #tr1' * #s2' * * #E @(match E with [refl ⇒ ?]) #S1' #A1' |
---|
176 | cases (steps_with_labels … RG … S2 A1') |
---|
177 | #n #AF cases (after_inv clight_fullexec ????? AF) #tr' * #s' * * #TWL #S' |
---|
178 | whd in match (is_final … s'); lapply (refl ? (is_final s')) |
---|
179 | cases (is_final s') in ⊢ (???% → %); |
---|
180 | [ #NF #H whd in H; @(swl_steps … H) // |
---|
181 | @(match sym_eq … E1' return λe,E1'. sim_with_labels e ? with [refl ⇒ ?]) |
---|
182 | @(build_exec … SRG RG … S1' S') >E1' in NW1; // |
---|
183 | | #r <(final_related … S') <(switch_final_related … S1') change with (is_final … clight_fullexec ge1 s1') in ⊢ (??%? → ?); |
---|
184 | >(exec_e_step_not_final ?? clight_fullexec … E1) #E' destruct |
---|
185 | ] |
---|
186 | | #E1 |
---|
187 | cases (extract_interact ?? clight_fullexec … E1) |
---|
188 | #k' * #EX1 #Ek lapply NWk -NWk @(match sym_eq … Ek with [refl ⇒ ?]) #NWk |
---|
189 | cases (interactive_switch_step … SRG … EX1 S1) #k2' * #EX2 #H2 |
---|
190 | cases (interactive_step_with_labels … RG … EX2 S2) |
---|
191 | #k3' * #EX3 #H3 @(match sym_eq … EX3 with [refl ⇒ ?]) @(match sym_eq … (exec_inf_aux_unfold …) with [refl ⇒ ?]) (* XXX why is this necessary? *) whd in ⊢ (??%); |
---|
192 | @swl_interact |
---|
193 | #i cases (H3 i) #tr2 * #s2' * #K2 * #tr3 * #s3' * * #K3 #TR2 #S2' |
---|
194 | cases (H2 i) #tr1 * #s1' * #K1 * #s2x' * @(match sym_eq … K2 with [refl ⇒ ?]) #Ex |
---|
195 | @(match (Value_eq_r … Ex) with [refl ⇒ ?]) #S1' |
---|
196 | lapply (NWk i) |
---|
197 | @(match sym_eq … K1 with [refl ⇒ ?]) @(match sym_eq … (exec_inf_aux_unfold …) with [refl ⇒ ?]) whd in ⊢ (??% → ?%%); whd in match (is_final ?????); |
---|
198 | @(match sym_eq … (switch_final_related … S1') with [refl ⇒ ?]) @(match sym_eq … (final_related … S2') with [refl ⇒ ?]) |
---|
199 | @(match sym_eq … K2 with [refl ⇒ ?]) @(match sym_eq … (exec_inf_aux_unfold ?? clight_fullexec ge3 …) with [refl ⇒ ?]) whd in ⊢ (? → ??%); |
---|
200 | @(match sym_eq … K3 with [refl ⇒ ?]) whd in ⊢ (? → ??%); whd in match (is_final ?????); |
---|
201 | cases (is_final s3') |
---|
202 | [ whd in ⊢ (??% → ?%%); #NW' @(swl_steps … (steps_step …)) |
---|
203 | [ destruct // |
---|
204 | | @build_exec // |
---|
205 | inversion NW' |
---|
206 | [ #H1 #H2 #H3 #H4 #H5 destruct |
---|
207 | | #H7 #H8 #H9 #H10 #H11 #H12 destruct // |
---|
208 | | #H14 #H15 #H16 #H17 #H18 destruct |
---|
209 | ] |
---|
210 | ] |
---|
211 | | #r whd in ⊢ (??% → ?%%); #NW' @(swl_stop … (steps_stop …)) destruct // |
---|
212 | ] |
---|
213 | ] qed. |
---|