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