author | kleing |
Sun, 16 Dec 2001 00:17:44 +0100 | |
changeset 12516 | d09d0f160888 |
parent 12230 | b06cc3834ee5 |
child 12911 | 704713ca07ea |
permissions | -rw-r--r-- |
12516 | 1 |
(* Title: HOL/MicroJava/BV/JVM.thy |
10592 | 2 |
ID: $Id$ |
12516 | 3 |
Author: Tobias Nipkow, Gerwin Klein |
10592 | 4 |
Copyright 2000 TUM |
5 |
*) |
|
6 |
||
10637 | 7 |
header "Kildall for the JVM" |
10592 | 8 |
|
12516 | 9 |
theory JVM = Kildall_Lift + JVMType + Opt + Product + Typing_Framework_err + |
10 |
EffectMono + BVSpec: |
|
10592 | 11 |
|
12 |
constdefs |
|
12516 | 13 |
exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list \<Rightarrow> state step_type" |
14 |
"exec G maxs rT et bs == |
|
15 |
err_step (\<lambda>pc. app (bs!pc) G maxs rT pc et) (\<lambda>pc. eff (bs!pc) G pc et)" |
|
10592 | 16 |
|
12516 | 17 |
kiljvm :: "jvm_prog => nat => nat => ty => exception_table => |
18 |
instr list => state list => state list" |
|
19 |
"kiljvm G maxs maxr rT et bs == |
|
20 |
kildall (JVMType.le G maxs maxr) (JVMType.sup G maxs maxr) (exec G maxs rT et bs)" |
|
10592 | 21 |
|
12516 | 22 |
wt_kil :: "jvm_prog \<Rightarrow> cname \<Rightarrow> ty list \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> |
23 |
exception_table \<Rightarrow> instr list \<Rightarrow> bool" |
|
24 |
"wt_kil G C pTs rT mxs mxl et ins == |
|
25 |
bounded (exec G mxs rT et ins) (size ins) \<and> 0 < size ins \<and> |
|
10637 | 26 |
(let first = Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)); |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11299
diff
changeset
|
27 |
start = OK first#(replicate (size ins - 1) (OK None)); |
12516 | 28 |
result = kiljvm G mxs (1+size pTs+mxl) rT et ins start |
10637 | 29 |
in \<forall>n < size ins. result!n \<noteq> Err)" |
30 |
||
31 |
wt_jvm_prog_kildall :: "jvm_prog => bool" |
|
32 |
"wt_jvm_prog_kildall G == |
|
12516 | 33 |
wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b,et)). wt_kil G C (snd sig) rT maxs maxl et b) G" |
10592 | 34 |
|
35 |
||
36 |
lemma special_ex_swap_lemma [iff]: |
|
37 |
"(? X. (? n. X = A n & P n) & Q X) = (? n. Q(A n) & P n)" |
|
38 |
by blast |
|
39 |
||
10630 | 40 |
lemmas [iff del] = not_None_eq |
41 |
||
12516 | 42 |
lemma non_empty_succs: "succs i pc \<noteq> []" |
43 |
by (cases i) auto |
|
44 |
||
45 |
lemma non_empty: |
|
46 |
"non_empty (\<lambda>pc. eff (bs!pc) G pc et)" |
|
47 |
by (simp add: non_empty_def eff_def non_empty_succs) |
|
48 |
||
49 |
lemma listn_Cons_Suc [elim!]: |
|
50 |
"l#xs \<in> list n A \<Longrightarrow> (\<And>n'. n = Suc n' \<Longrightarrow> l \<in> A \<Longrightarrow> xs \<in> list n' A \<Longrightarrow> P) \<Longrightarrow> P" |
|
51 |
by (cases n) auto |
|
52 |
||
53 |
lemma listn_appendE [elim!]: |
|
54 |
"a@b \<in> list n A \<Longrightarrow> (\<And>n1 n2. n=n1+n2 \<Longrightarrow> a \<in> list n1 A \<Longrightarrow> b \<in> list n2 A \<Longrightarrow> P) \<Longrightarrow> P" |
|
55 |
proof - |
|
56 |
have "\<And>n. a@b \<in> list n A \<Longrightarrow> \<exists>n1 n2. n=n1+n2 \<and> a \<in> list n1 A \<and> b \<in> list n2 A" |
|
57 |
(is "\<And>n. ?list a n \<Longrightarrow> \<exists>n1 n2. ?P a n n1 n2") |
|
58 |
proof (induct a) |
|
59 |
fix n assume "?list [] n" |
|
60 |
hence "?P [] n 0 n" by simp |
|
61 |
thus "\<exists>n1 n2. ?P [] n n1 n2" by fast |
|
62 |
next |
|
63 |
fix n l ls |
|
64 |
assume "?list (l#ls) n" |
|
65 |
then obtain n' where n: "n = Suc n'" "l \<in> A" and "ls@b \<in> list n' A" by fastsimp |
|
66 |
assume "\<And>n. ls @ b \<in> list n A \<Longrightarrow> \<exists>n1 n2. n = n1 + n2 \<and> ls \<in> list n1 A \<and> b \<in> list n2 A" |
|
67 |
hence "\<exists>n1 n2. n' = n1 + n2 \<and> ls \<in> list n1 A \<and> b \<in> list n2 A" . |
|
68 |
then obtain n1 n2 where "n' = n1 + n2" "ls \<in> list n1 A" "b \<in> list n2 A" by fast |
|
69 |
with n have "?P (l#ls) n (n1+1) n2" by simp |
|
70 |
thus "\<exists>n1 n2. ?P (l#ls) n n1 n2" by fastsimp |
|
71 |
qed |
|
72 |
moreover |
|
73 |
assume "a@b \<in> list n A" "\<And>n1 n2. n=n1+n2 \<Longrightarrow> a \<in> list n1 A \<Longrightarrow> b \<in> list n2 A \<Longrightarrow> P" |
|
74 |
ultimately |
|
75 |
show ?thesis by blast |
|
76 |
qed |
|
77 |
||
78 |
||
10592 | 79 |
theorem exec_pres_type: |
12516 | 80 |
"wf_prog wf_mb S ==> |
81 |
pres_type (exec S maxs rT et bs) (size bs) (states S maxs maxr)" |
|
82 |
apply (unfold exec_def JVM_states_unfold) |
|
83 |
apply (rule pres_type_lift) |
|
84 |
apply clarify |
|
85 |
apply (case_tac s) |
|
86 |
apply simp |
|
87 |
apply (drule effNone) |
|
88 |
apply simp |
|
89 |
apply (simp add: eff_def xcpt_eff_def norm_eff_def) |
|
90 |
apply (case_tac "bs!p") |
|
91 |
||
92 |
apply (clarsimp simp add: not_Err_eq) |
|
93 |
apply (drule listE_nth_in, assumption) |
|
94 |
apply fastsimp |
|
95 |
||
96 |
apply (fastsimp simp add: not_None_eq) |
|
97 |
||
98 |
apply (fastsimp simp add: not_None_eq typeof_empty_is_type) |
|
99 |
||
100 |
apply clarsimp |
|
101 |
apply (erule disjE) |
|
102 |
apply fastsimp |
|
103 |
apply clarsimp |
|
104 |
apply (rule_tac x="1" in exI) |
|
105 |
apply fastsimp |
|
10592 | 106 |
|
12516 | 107 |
apply clarsimp |
108 |
apply (erule disjE) |
|
109 |
apply (fastsimp dest: field_fields fields_is_type) |
|
110 |
apply simp |
|
111 |
apply (rule_tac x=1 in exI) |
|
112 |
apply fastsimp |
|
113 |
||
114 |
apply clarsimp |
|
115 |
apply (erule disjE) |
|
116 |
apply fastsimp |
|
117 |
apply simp |
|
118 |
apply (rule_tac x=1 in exI) |
|
119 |
apply fastsimp |
|
120 |
||
121 |
apply clarsimp |
|
122 |
apply (erule disjE) |
|
123 |
apply fastsimp |
|
124 |
apply clarsimp |
|
125 |
apply (rule_tac x=1 in exI) |
|
126 |
apply fastsimp |
|
127 |
||
128 |
defer |
|
129 |
||
130 |
apply fastsimp |
|
131 |
apply fastsimp |
|
132 |
||
133 |
apply clarsimp |
|
134 |
apply (rule_tac x="n'+2" in exI) |
|
135 |
apply simp |
|
136 |
apply (drule listE_length)+ |
|
137 |
apply fastsimp |
|
10592 | 138 |
|
12516 | 139 |
apply clarsimp |
140 |
apply (rule_tac x="Suc (Suc (Suc (length ST)))" in exI) |
|
141 |
apply simp |
|
142 |
apply (drule listE_length)+ |
|
143 |
apply fastsimp |
|
144 |
||
145 |
apply clarsimp |
|
146 |
apply (rule_tac x="Suc (Suc (Suc (Suc (length ST))))" in exI) |
|
147 |
apply simp |
|
148 |
apply (drule listE_length)+ |
|
149 |
apply fastsimp |
|
150 |
||
151 |
apply fastsimp |
|
152 |
apply fastsimp |
|
153 |
apply fastsimp |
|
154 |
apply fastsimp |
|
10592 | 155 |
|
12516 | 156 |
apply clarsimp |
157 |
apply (erule disjE) |
|
158 |
apply fastsimp |
|
159 |
apply clarsimp |
|
160 |
apply (rule_tac x=1 in exI) |
|
161 |
apply fastsimp |
|
162 |
||
163 |
apply (erule disjE) |
|
164 |
apply (clarsimp simp add: Un_subset_iff) |
|
165 |
apply (drule method_wf_mdecl, assumption+) |
|
166 |
apply (clarsimp simp add: wf_mdecl_def wf_mhead_def) |
|
167 |
apply fastsimp |
|
168 |
apply clarsimp |
|
169 |
apply (rule_tac x=1 in exI) |
|
170 |
apply fastsimp |
|
171 |
done |
|
10630 | 172 |
|
173 |
lemmas [iff] = not_None_eq |
|
174 |
||
12516 | 175 |
lemma map_fst_eq: |
176 |
"map fst (map (\<lambda>z. (f z, x z)) a) = map fst (map (\<lambda>z. (f z, y z)) a)" |
|
177 |
by (induct a) auto |
|
178 |
||
179 |
lemma succs_stable_eff: |
|
180 |
"succs_stable (sup_state_opt G) (\<lambda>pc. eff (bs!pc) G pc et)" |
|
181 |
apply (unfold succs_stable_def eff_def xcpt_eff_def) |
|
182 |
apply (simp add: map_fst_eq) |
|
183 |
done |
|
184 |
||
185 |
lemma sup_state_opt_unfold: |
|
186 |
"sup_state_opt G \<equiv> Opt.le (Product.le (Listn.le (subtype G)) (Listn.le (Err.le (subtype G))))" |
|
187 |
by (simp add: sup_state_opt_def sup_state_def sup_loc_def sup_ty_opt_def) |
|
188 |
||
189 |
constdefs |
|
190 |
opt_states :: "'c prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (ty list \<times> ty err list) option set" |
|
191 |
"opt_states G maxs maxr \<equiv> opt (\<Union>{list n (types G) |n. n \<le> maxs} \<times> list maxr (err (types G)))" |
|
192 |
||
193 |
lemma app_mono: |
|
194 |
"app_mono (sup_state_opt G) (\<lambda>pc. app (bs!pc) G maxs rT pc et) (length bs) (opt_states G maxs maxr)" |
|
195 |
by (unfold app_mono_def lesub_def) (blast intro: EffectMono.app_mono) |
|
196 |
||
197 |
lemma le_list_appendI: |
|
198 |
"\<And>b c d. a <=[r] b \<Longrightarrow> c <=[r] d \<Longrightarrow> a@c <=[r] b@d" |
|
199 |
apply (induct a) |
|
200 |
apply simp |
|
201 |
apply (case_tac b) |
|
202 |
apply auto |
|
203 |
done |
|
204 |
||
205 |
lemma le_listI: |
|
206 |
"length a = length b \<Longrightarrow> (\<And>n. n < length a \<Longrightarrow> a!n <=_r b!n) \<Longrightarrow> a <=[r] b" |
|
207 |
apply (unfold lesub_def Listn.le_def) |
|
208 |
apply (simp add: list_all2_conv_all_nth) |
|
209 |
done |
|
210 |
||
211 |
lemma eff_mono: |
|
212 |
"\<lbrakk>p < length bs; s <=_(sup_state_opt G) t; app (bs!p) G maxs rT pc et t\<rbrakk> |
|
213 |
\<Longrightarrow> eff (bs!p) G p et s <=|sup_state_opt G| eff (bs!p) G p et t" |
|
214 |
apply (unfold eff_def) |
|
215 |
apply (rule le_list_appendI) |
|
216 |
apply (simp add: norm_eff_def) |
|
217 |
apply (rule le_listI) |
|
218 |
apply simp |
|
219 |
apply simp |
|
220 |
apply (simp add: lesub_def) |
|
221 |
apply (case_tac s) |
|
222 |
apply simp |
|
223 |
apply (simp del: split_paired_All split_paired_Ex) |
|
224 |
apply (elim exE conjE) |
|
225 |
apply simp |
|
226 |
apply (drule eff'_mono, assumption) |
|
227 |
apply assumption |
|
228 |
apply (simp add: xcpt_eff_def) |
|
229 |
apply (rule le_listI) |
|
230 |
apply simp |
|
231 |
apply simp |
|
232 |
apply (simp add: lesub_def) |
|
233 |
apply (case_tac s) |
|
234 |
apply simp |
|
235 |
apply simp |
|
236 |
apply (case_tac t) |
|
237 |
apply simp |
|
238 |
apply (clarsimp simp add: sup_state_conv) |
|
239 |
done |
|
240 |
||
241 |
lemma order_sup_state_opt: |
|
242 |
"wf_prog wf_mb G \<Longrightarrow> order (sup_state_opt G)" |
|
243 |
by (unfold sup_state_opt_unfold) (blast dest: acyclic_subcls1 order_widen) |
|
10630 | 244 |
|
10592 | 245 |
theorem exec_mono: |
246 |
"wf_prog wf_mb G ==> |
|
12516 | 247 |
mono (JVMType.le G maxs maxr) (exec G maxs rT et bs) (size bs) (states G maxs maxr)" |
248 |
apply (unfold exec_def JVM_le_unfold JVM_states_unfold) |
|
249 |
apply (rule mono_lift) |
|
250 |
apply (fold sup_state_opt_unfold opt_states_def) |
|
251 |
apply (erule order_sup_state_opt) |
|
252 |
apply (rule succs_stable_eff) |
|
253 |
apply (rule app_mono) |
|
10592 | 254 |
apply clarify |
12516 | 255 |
apply (rule eff_mono) |
256 |
apply assumption+ |
|
10592 | 257 |
done |
258 |
||
259 |
theorem semilat_JVM_slI: |
|
12516 | 260 |
"wf_prog wf_mb G ==> semilat (JVMType.sl G maxs maxr)" |
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
261 |
apply (unfold JVMType.sl_def stk_esl_def reg_sl_def) |
10592 | 262 |
apply (rule semilat_opt) |
263 |
apply (rule err_semilat_Product_esl) |
|
264 |
apply (rule err_semilat_upto_esl) |
|
265 |
apply (rule err_semilat_JType_esl, assumption+) |
|
266 |
apply (rule err_semilat_eslI) |
|
267 |
apply (rule semilat_Listn_sl) |
|
268 |
apply (rule err_semilat_JType_esl, assumption+) |
|
269 |
done |
|
270 |
||
271 |
lemma sl_triple_conv: |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
272 |
"JVMType.sl G maxs maxr == |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
273 |
(states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)" |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
274 |
by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def) |
10592 | 275 |
|
276 |
||
277 |
theorem is_bcv_kiljvm: |
|
12516 | 278 |
"[| wf_prog wf_mb G; bounded (exec G maxs rT et bs) (size bs) |] ==> |
279 |
is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT et bs) |
|
280 |
(size bs) (states G maxs maxr) (kiljvm G maxs maxr rT et bs)" |
|
10592 | 281 |
apply (unfold kiljvm_def sl_triple_conv) |
282 |
apply (rule is_bcv_kildall) |
|
283 |
apply (simp (no_asm) add: sl_triple_conv [symmetric]) |
|
284 |
apply (force intro!: semilat_JVM_slI dest: wf_acyclic simp add: symmetric sl_triple_conv) |
|
285 |
apply (simp (no_asm) add: JVM_le_unfold) |
|
286 |
apply (blast intro!: order_widen wf_converse_subcls1_impl_acc_subtype |
|
287 |
dest: wf_subcls1 wf_acyclic) |
|
288 |
apply (simp add: JVM_le_unfold) |
|
289 |
apply (erule exec_pres_type) |
|
290 |
apply assumption |
|
291 |
apply (erule exec_mono) |
|
292 |
done |
|
293 |
||
10637 | 294 |
|
295 |
theorem wt_kil_correct: |
|
12516 | 296 |
"[| wt_kil G C pTs rT maxs mxl et bs; wf_prog wf_mb G; |
10592 | 297 |
is_class G C; \<forall>x \<in> set pTs. is_type G x |] |
12516 | 298 |
==> \<exists>phi. wt_method G C pTs rT maxs mxl bs et phi" |
10592 | 299 |
proof - |
300 |
let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11299
diff
changeset
|
301 |
#(replicate (size bs - 1) (OK None))" |
10592 | 302 |
|
10637 | 303 |
assume wf: "wf_prog wf_mb G" |
304 |
assume isclass: "is_class G C" |
|
305 |
assume istype: "\<forall>x \<in> set pTs. is_type G x" |
|
306 |
||
12516 | 307 |
assume "wt_kil G C pTs rT maxs mxl et bs" |
10637 | 308 |
then obtain maxr r where |
12516 | 309 |
bounded: "bounded (exec G maxs rT et bs) (size bs)" and |
310 |
result: "r = kiljvm G maxs maxr rT et bs ?start" and |
|
10637 | 311 |
success: "\<forall>n < size bs. r!n \<noteq> Err" and |
312 |
instrs: "0 < size bs" and |
|
313 |
maxr: "maxr = Suc (length pTs + mxl)" |
|
314 |
by (unfold wt_kil_def) simp |
|
10592 | 315 |
|
316 |
from wf bounded |
|
317 |
have bcv: |
|
12516 | 318 |
"is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT et bs) |
319 |
(size bs) (states G maxs maxr) (kiljvm G maxs maxr rT et bs)" |
|
10592 | 320 |
by (rule is_bcv_kiljvm) |
321 |
||
12516 | 322 |
{ fix l x have "set (replicate l x) \<subseteq> {x}" by (cases "0 < l") simp+ |
10592 | 323 |
} note subset_replicate = this |
12516 | 324 |
from istype have "set pTs \<subseteq> types G" by auto |
325 |
hence "OK ` set pTs \<subseteq> err (types G)" by auto |
|
10592 | 326 |
with instrs maxr isclass |
327 |
have "?start \<in> list (length bs) (states G maxs maxr)" |
|
328 |
apply (unfold list_def JVM_states_unfold) |
|
329 |
apply simp |
|
330 |
apply (rule conjI) |
|
331 |
apply (simp add: Un_subset_iff) |
|
332 |
apply (rule_tac B = "{Err}" in subset_trans) |
|
333 |
apply (simp add: subset_replicate) |
|
334 |
apply simp |
|
335 |
apply (rule_tac B = "{OK None}" in subset_trans) |
|
336 |
apply (simp add: subset_replicate) |
|
337 |
apply simp |
|
338 |
done |
|
12516 | 339 |
with bcv success result have |
10592 | 340 |
"\<exists>ts\<in>list (length bs) (states G maxs maxr). |
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
341 |
?start <=[JVMType.le G maxs maxr] ts \<and> |
12516 | 342 |
wt_step (JVMType.le G maxs maxr) Err (exec G maxs rT et bs) ts" |
10592 | 343 |
by (unfold is_bcv_def) auto |
344 |
then obtain phi' where |
|
345 |
l: "phi' \<in> list (length bs) (states G maxs maxr)" and |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
346 |
s: "?start <=[JVMType.le G maxs maxr] phi'" and |
12516 | 347 |
w: "wt_step (JVMType.le G maxs maxr) Err (exec G maxs rT et bs) phi'" |
10592 | 348 |
by blast |
349 |
hence dynamic: |
|
12516 | 350 |
"dynamic_wt (sup_state_opt G) (exec G maxs rT et bs) phi'" |
10592 | 351 |
by (simp add: dynamic_wt_def exec_def JVM_le_Err_conv) |
352 |
||
12516 | 353 |
from s have le: "JVMType.le G maxs maxr (?start ! 0) (phi'!0)" |
10592 | 354 |
by (drule_tac p=0 in le_listD) (simp add: lesub_def)+ |
355 |
||
12516 | 356 |
from l have l: "size phi' = size bs" by simp |
357 |
with instrs w have "phi' ! 0 \<noteq> Err" by (unfold wt_step_def) simp |
|
358 |
with instrs l have phi0: "OK (map ok_val phi' ! 0) = phi' ! 0" |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10657
diff
changeset
|
359 |
by (clarsimp simp add: not_Err_eq) |
10592 | 360 |
|
12516 | 361 |
from l bounded |
362 |
have bounded': "bounded (\<lambda>pc. eff (bs!pc) G pc et) (length phi')" |
|
363 |
by (simp add: exec_def bounded_lift) |
|
364 |
with dynamic |
|
365 |
have "static_wt (sup_state_opt G) (\<lambda>pc. app (bs!pc) G maxs rT pc et) |
|
366 |
(\<lambda>pc. eff (bs!pc) G pc et) (map ok_val phi')" |
|
367 |
by (auto intro: dynamic_imp_static simp add: exec_def non_empty) |
|
368 |
with instrs l le bounded' |
|
369 |
have "wt_method G C pTs rT maxs mxl bs et (map ok_val phi')" |
|
10592 | 370 |
apply (unfold wt_method_def static_wt_def) |
371 |
apply simp |
|
372 |
apply (rule conjI) |
|
373 |
apply (unfold wt_start_def) |
|
374 |
apply (rule JVM_le_convert [THEN iffD1]) |
|
375 |
apply (simp (no_asm) add: phi0) |
|
376 |
apply clarify |
|
377 |
apply (erule allE, erule impE, assumption) |
|
378 |
apply (elim conjE) |
|
379 |
apply (clarsimp simp add: lesub_def wt_instr_def) |
|
380 |
apply (unfold bounded_def) |
|
381 |
apply blast |
|
382 |
done |
|
383 |
||
384 |
thus ?thesis by blast |
|
385 |
qed |
|
386 |
||
10651 | 387 |
|
388 |
theorem wt_kil_complete: |
|
12516 | 389 |
"[| wt_method G C pTs rT maxs mxl bs et phi; wf_prog wf_mb G; |
390 |
length phi = length bs; is_class G C; \<forall>x \<in> set pTs. is_type G x; |
|
391 |
map OK phi \<in> list (length bs) (states G maxs (1+size pTs+mxl)) |] |
|
392 |
==> wt_kil G C pTs rT maxs mxl et bs" |
|
10651 | 393 |
proof - |
12516 | 394 |
assume wf: "wf_prog wf_mb G" |
10651 | 395 |
assume isclass: "is_class G C" |
12516 | 396 |
assume istype: "\<forall>x \<in> set pTs. is_type G x" |
397 |
assume length: "length phi = length bs" |
|
398 |
assume istype_phi: "map OK phi \<in> list (length bs) (states G maxs (1+size pTs+mxl))" |
|
10651 | 399 |
|
12516 | 400 |
assume "wt_method G C pTs rT maxs mxl bs et phi" |
10651 | 401 |
then obtain |
402 |
instrs: "0 < length bs" and |
|
403 |
wt_start: "wt_start G C pTs mxl phi" and |
|
404 |
wt_ins: "\<forall>pc. pc < length bs \<longrightarrow> |
|
12516 | 405 |
wt_instr (bs ! pc) G rT phi maxs (length bs) et pc" |
10651 | 406 |
by (unfold wt_method_def) simp |
407 |
||
12516 | 408 |
let ?eff = "\<lambda>pc. eff (bs!pc) G pc et" |
409 |
let ?app = "\<lambda>pc. app (bs!pc) G maxs rT pc et" |
|
10651 | 410 |
|
12516 | 411 |
have bounded_eff: "bounded ?eff (size bs)" |
412 |
proof (unfold bounded_def, clarify) |
|
413 |
fix pc pc' s s' assume "pc < length bs" |
|
414 |
with wt_ins have "wt_instr (bs!pc) G rT phi maxs (length bs) et pc" by fast |
|
415 |
then obtain "\<forall>(pc',s') \<in> set (?eff pc (phi!pc)). pc' < length bs" |
|
416 |
by (unfold wt_instr_def) fast |
|
417 |
hence "\<forall>pc' \<in> set (map fst (?eff pc (phi!pc))). pc' < length bs" by auto |
|
418 |
also |
|
419 |
note succs_stable_eff |
|
420 |
hence "map fst (?eff pc (phi!pc)) = map fst (?eff pc s)" |
|
421 |
by (rule succs_stableD) |
|
422 |
finally have "\<forall>(pc',s') \<in> set (?eff pc s). pc' < length bs" by auto |
|
423 |
moreover assume "(pc',s') \<in> set (?eff pc s)" |
|
424 |
ultimately show "pc' < length bs" by blast |
|
425 |
qed |
|
426 |
hence bounded_exec: "bounded (exec G maxs rT et bs) (size bs)" |
|
427 |
by (simp add: exec_def bounded_lift) |
|
428 |
||
10651 | 429 |
from wt_ins |
12516 | 430 |
have "static_wt (sup_state_opt G) ?app ?eff phi" |
10651 | 431 |
apply (unfold static_wt_def wt_instr_def lesub_def) |
432 |
apply (simp (no_asm) only: length) |
|
433 |
apply blast |
|
434 |
done |
|
435 |
||
12516 | 436 |
with bounded_eff |
437 |
have "dynamic_wt (sup_state_opt G) (err_step ?app ?eff) (map OK phi)" |
|
10651 | 438 |
by - (erule static_imp_dynamic, simp add: length) |
439 |
hence dynamic: |
|
12516 | 440 |
"dynamic_wt (sup_state_opt G) (exec G maxs rT et bs) (map OK phi)" |
10651 | 441 |
by (unfold exec_def) |
442 |
||
443 |
let ?maxr = "1+size pTs+mxl" |
|
12516 | 444 |
from wf bounded_exec |
10651 | 445 |
have is_bcv: |
12516 | 446 |
"is_bcv (JVMType.le G maxs ?maxr) Err (exec G maxs rT et bs) |
447 |
(size bs) (states G maxs ?maxr) (kiljvm G maxs ?maxr rT et bs)" |
|
10651 | 448 |
by (rule is_bcv_kiljvm) |
449 |
||
450 |
let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11299
diff
changeset
|
451 |
#(replicate (size bs - 1) (OK None))" |
10651 | 452 |
|
12516 | 453 |
{ fix l x have "set (replicate l x) \<subseteq> {x}" by (cases "0 < l") simp+ |
10651 | 454 |
} note subset_replicate = this |
455 |
||
12516 | 456 |
from istype have "set pTs \<subseteq> types G" by auto |
457 |
hence "OK ` set pTs \<subseteq> err (types G)" by auto |
|
458 |
with instrs isclass have start: |
|
10651 | 459 |
"?start \<in> list (length bs) (states G maxs ?maxr)" |
460 |
apply (unfold list_def JVM_states_unfold) |
|
461 |
apply simp |
|
462 |
apply (rule conjI) |
|
463 |
apply (simp add: Un_subset_iff) |
|
464 |
apply (rule_tac B = "{Err}" in subset_trans) |
|
465 |
apply (simp add: subset_replicate) |
|
466 |
apply simp |
|
467 |
apply (rule_tac B = "{OK None}" in subset_trans) |
|
468 |
apply (simp add: subset_replicate) |
|
469 |
apply simp |
|
470 |
done |
|
471 |
||
12516 | 472 |
let ?phi = "map OK phi" |
473 |
have less_phi: "?start <=[JVMType.le G maxs ?maxr] ?phi" |
|
10657 | 474 |
proof - |
12516 | 475 |
from length instrs |
476 |
have "length ?start = length (map OK phi)" by simp |
|
477 |
moreover |
|
10657 | 478 |
{ fix n |
479 |
from wt_start |
|
480 |
have "G \<turnstile> ok_val (?start!0) <=' phi!0" |
|
481 |
by (simp add: wt_start_def) |
|
482 |
moreover |
|
483 |
from instrs length |
|
484 |
have "0 < length phi" by simp |
|
485 |
ultimately |
|
12516 | 486 |
have "JVMType.le G maxs ?maxr (?start!0) (?phi!0)" |
10657 | 487 |
by (simp add: JVM_le_Err_conv Err.le_def lesub_def) |
488 |
moreover |
|
489 |
{ fix n' |
|
12516 | 490 |
have "JVMType.le G maxs ?maxr (OK None) (?phi!n)" |
10657 | 491 |
by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def |
492 |
split: err.splits) |
|
493 |
hence "[| n = Suc n'; n < length ?start |] |
|
12516 | 494 |
==> JVMType.le G maxs ?maxr (?start!n) (?phi!n)" |
10657 | 495 |
by simp |
496 |
} |
|
497 |
ultimately |
|
12516 | 498 |
have "n < length ?start ==> (?start!n) <=_(JVMType.le G maxs ?maxr) (?phi!n)" |
499 |
by (unfold lesub_def) (cases n, blast+) |
|
500 |
} |
|
501 |
ultimately show ?thesis by (rule le_listI) |
|
10657 | 502 |
qed |
10651 | 503 |
|
504 |
from dynamic |
|
12516 | 505 |
have "wt_step (JVMType.le G maxs ?maxr) Err (exec G maxs rT et bs) ?phi" |
506 |
by (simp add: dynamic_wt_def JVM_le_Err_conv) |
|
507 |
with start istype_phi less_phi is_bcv |
|
508 |
have "\<forall>p. p < length bs \<longrightarrow> kiljvm G maxs ?maxr rT et bs ?start ! p \<noteq> Err" |
|
509 |
by (unfold is_bcv_def) auto |
|
510 |
with bounded_exec instrs |
|
511 |
show "wt_kil G C pTs rT maxs mxl et bs" by (unfold wt_kil_def) simp |
|
512 |
qed |
|
513 |
text {* |
|
514 |
The above theorem @{text wt_kil_complete} is all nice'n shiny except |
|
515 |
for one assumption: @{term "map OK phi \<in> list (length bs) (states G maxs (1+size pTs+mxl))"} |
|
516 |
It does not hold for all @{text phi} that satisfy @{text wt_method}. |
|
10651 | 517 |
|
12516 | 518 |
The assumption states mainly that all entries in @{text phi} are legal |
519 |
types in the program context, that the stack size is bounded by @{text maxs}, |
|
520 |
and that the register sizes are exactly @{term "1+size pTs+mxl"}. |
|
521 |
The BV specification, i.e.~@{text wt_method}, only gives us this |
|
522 |
property for \emph{reachable} code. For unreachable code, |
|
523 |
e.g.~unused registers may contain arbitrary garbage. Even the stack |
|
524 |
and register sizes can be different from the rest of the program (as |
|
525 |
long as they are consistent inside each chunk of unreachable code). |
|
526 |
||
527 |
All is not lost, though: for each @{text phi} that satisfies |
|
528 |
@{text wt_method} there is a @{text phi'} that also satisfies |
|
529 |
@{text wt_method} and that additionally satisfies our assumption. |
|
530 |
The construction is quite easy: the entries for reachable code |
|
531 |
are the same in @{text phi} and @{text phi'}, the entries for |
|
532 |
unreachable code are all @{text None} in @{text phi'} (as it would |
|
533 |
be produced by Kildall's algorithm). |
|
10651 | 534 |
|
12516 | 535 |
Although this is proved easily by comment, it requires some more |
536 |
overhead (i.e.~talking about reachable instructions) if you try |
|
537 |
it the hard way. Thus it is missing here for the time being. |
|
538 |
||
539 |
The other direction (@{text wt_kil_correct}) can be lifted to |
|
540 |
programs without problems: |
|
541 |
*} |
|
10637 | 542 |
lemma is_type_pTs: |
543 |
"[| wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls; |
|
544 |
t \<in> set (snd sig) |] |
|
545 |
==> is_type G t" |
|
546 |
proof - |
|
547 |
assume "wf_prog wf_mb G" |
|
548 |
"(C,S,fs,mdecls) \<in> set G" |
|
549 |
"(sig,rT,code) \<in> set mdecls" |
|
550 |
hence "wf_mdecl wf_mb G C (sig,rT,code)" |
|
551 |
by (unfold wf_prog_def wf_cdecl_def) auto |
|
552 |
hence "\<forall>t \<in> set (snd sig). is_type G t" |
|
553 |
by (unfold wf_mdecl_def wf_mhead_def) auto |
|
554 |
moreover |
|
555 |
assume "t \<in> set (snd sig)" |
|
556 |
ultimately |
|
557 |
show ?thesis by blast |
|
558 |
qed |
|
559 |
||
560 |
||
561 |
theorem jvm_kildall_correct: |
|
562 |
"wt_jvm_prog_kildall G ==> \<exists>Phi. wt_jvm_prog G Phi" |
|
563 |
proof - |
|
564 |
assume wtk: "wt_jvm_prog_kildall G" |
|
565 |
||
566 |
then obtain wf_mb where |
|
567 |
wf: "wf_prog wf_mb G" |
|
568 |
by (auto simp add: wt_jvm_prog_kildall_def) |
|
569 |
||
12516 | 570 |
let ?Phi = "\<lambda>C sig. let (C,rT,(maxs,maxl,ins,et)) = the (method (G,C) sig) in |
571 |
SOME phi. wt_method G C (snd sig) rT maxs maxl ins et phi" |
|
10637 | 572 |
|
573 |
{ fix C S fs mdecls sig rT code |
|
574 |
assume "(C,S,fs,mdecls) \<in> set G" "(sig,rT,code) \<in> set mdecls" |
|
575 |
with wf |
|
576 |
have "method (G,C) sig = Some (C,rT,code) \<and> is_class G C \<and> (\<forall>t \<in> set (snd sig). is_type G t)" |
|
577 |
by (simp add: methd is_type_pTs) |
|
578 |
} note this [simp] |
|
579 |
||
580 |
from wtk |
|
581 |
have "wt_jvm_prog G ?Phi" |
|
582 |
apply (unfold wt_jvm_prog_def wt_jvm_prog_kildall_def wf_prog_def wf_cdecl_def) |
|
583 |
apply clarsimp |
|
584 |
apply (drule bspec, assumption) |
|
585 |
apply (unfold wf_mdecl_def) |
|
586 |
apply clarsimp |
|
587 |
apply (drule bspec, assumption) |
|
588 |
apply clarsimp |
|
589 |
apply (drule wt_kil_correct [OF _ wf]) |
|
590 |
apply (auto intro: someI) |
|
591 |
done |
|
592 |
||
593 |
thus ?thesis by blast |
|
594 |
qed |
|
595 |
||
10592 | 596 |
end |