| author | wenzelm | 
| Mon, 28 Feb 2022 13:02:40 +0100 | |
| changeset 75166 | 1f6da5d18340 | 
| parent 69597 | ff784d5a5bfb | 
| permissions | -rw-r--r-- | 
| 42150 | 1  | 
(* Title: HOL/MicroJava/BV/Typing_Framework_JVM.thy  | 
| 13224 | 2  | 
Author: Tobias Nipkow, Gerwin Klein  | 
3  | 
Copyright 2000 TUM  | 
|
4  | 
*)  | 
|
5  | 
||
| 61361 | 6  | 
section \<open>The Typing Framework for the JVM \label{sec:JVM}\<close>
 | 
| 13224 | 7  | 
|
| 
33954
 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 
haftmann 
parents: 
33639 
diff
changeset
 | 
8  | 
theory Typing_Framework_JVM  | 
| 
 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 
haftmann 
parents: 
33639 
diff
changeset
 | 
9  | 
imports "../DFA/Abstract_BV" JVMType EffectMono BVSpec  | 
| 
 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 
haftmann 
parents: 
33639 
diff
changeset
 | 
10  | 
begin  | 
| 13224 | 11  | 
|
| 
35416
 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 
haftmann 
parents: 
33954 
diff
changeset
 | 
12  | 
definition exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list \<Rightarrow> JVMType.state step_type" where  | 
| 13224 | 13  | 
"exec G maxs rT et bs ==  | 
14  | 
err_step (size bs) (\<lambda>pc. app (bs!pc) G maxs rT pc et) (\<lambda>pc. eff (bs!pc) G pc et)"  | 
|
15  | 
||
| 
35416
 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 
haftmann 
parents: 
33954 
diff
changeset
 | 
16  | 
definition opt_states :: "'c prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (ty list \<times> ty err list) option set" where  | 
| 13224 | 17  | 
  "opt_states G maxs maxr \<equiv> opt (\<Union>{list n (types G) |n. n \<le> maxs} \<times> list maxr (err (types G)))"
 | 
18  | 
||
19  | 
||
| 69597 | 20  | 
subsection \<open>Executability of \<^term>\<open>check_bounded\<close>\<close>  | 
| 39758 | 21  | 
|
22  | 
primrec list_all'_rec :: "('a \<Rightarrow> nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> bool"
 | 
|
23  | 
where  | 
|
| 13224 | 24  | 
"list_all'_rec P n [] = True"  | 
| 39758 | 25  | 
| "list_all'_rec P n (x#xs) = (P x n \<and> list_all'_rec P (Suc n) xs)"  | 
| 13224 | 26  | 
|
| 
35416
 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 
haftmann 
parents: 
33954 
diff
changeset
 | 
27  | 
definition list_all' :: "('a \<Rightarrow> nat \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool" where
 | 
| 13224 | 28  | 
"list_all' P xs \<equiv> list_all'_rec P 0 xs"  | 
29  | 
||
30  | 
lemma list_all'_rec:  | 
|
| 46742 | 31  | 
"list_all'_rec P n xs = (\<forall>p < size xs. P (xs!p) (p+n))"  | 
32  | 
apply (induct xs arbitrary: n)  | 
|
| 13224 | 33  | 
apply auto  | 
34  | 
apply (case_tac p)  | 
|
35  | 
apply auto  | 
|
36  | 
done  | 
|
37  | 
||
38  | 
lemma list_all' [iff]:  | 
|
39  | 
"list_all' P xs = (\<forall>n < size xs. P (xs!n) n)"  | 
|
40  | 
by (unfold list_all'_def) (simp add: list_all'_rec)  | 
|
41  | 
||
42  | 
lemma [code]:  | 
|
43  | 
"check_bounded ins et =  | 
|
44  | 
(list_all' (\<lambda>i pc. list_all (\<lambda>pc'. pc' < length ins) (succs i pc)) ins \<and>  | 
|
45  | 
list_all (\<lambda>e. fst (snd (snd e)) < length ins) et)"  | 
|
| 17090 | 46  | 
by (simp add: list_all_iff check_bounded_def)  | 
| 13224 | 47  | 
|
48  | 
||
| 61361 | 49  | 
subsection \<open>Connecting JVM and Framework\<close>  | 
| 13224 | 50  | 
|
51  | 
lemma check_bounded_is_bounded:  | 
|
52  | 
"check_bounded ins et \<Longrightarrow> bounded (\<lambda>pc. eff (ins!pc) G pc et) (length ins)"  | 
|
53  | 
by (unfold bounded_def) (blast dest: check_boundedD)  | 
|
54  | 
||
55  | 
lemma special_ex_swap_lemma [iff]:  | 
|
| 67613 | 56  | 
"(\<exists>X. (\<exists>n. X = A n \<and> P n) & Q X) = (\<exists>n. Q(A n) \<and> P n)"  | 
| 13224 | 57  | 
by blast  | 
58  | 
||
59  | 
lemmas [iff del] = not_None_eq  | 
|
60  | 
||
61  | 
theorem exec_pres_type:  | 
|
62  | 
"wf_prog wf_mb S \<Longrightarrow>  | 
|
63  | 
pres_type (exec S maxs rT et bs) (size bs) (states S maxs maxr)"  | 
|
64  | 
apply (unfold exec_def JVM_states_unfold)  | 
|
65  | 
apply (rule pres_type_lift)  | 
|
66  | 
apply clarify  | 
|
67  | 
apply (case_tac s)  | 
|
68  | 
apply simp  | 
|
69  | 
apply (drule effNone)  | 
|
70  | 
apply simp  | 
|
71  | 
apply (simp add: eff_def xcpt_eff_def norm_eff_def)  | 
|
72  | 
apply (case_tac "bs!p")  | 
|
73  | 
||
| 46226 | 74  | 
apply clarsimp  | 
| 13224 | 75  | 
apply (drule listE_nth_in, assumption)  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
76  | 
apply fastforce  | 
| 13224 | 77  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
78  | 
apply (fastforce simp add: not_None_eq)  | 
| 13224 | 79  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
80  | 
apply (fastforce simp add: not_None_eq typeof_empty_is_type)  | 
| 13224 | 81  | 
|
82  | 
apply clarsimp  | 
|
83  | 
apply (erule disjE)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
84  | 
apply fastforce  | 
| 13224 | 85  | 
apply clarsimp  | 
86  | 
apply (rule_tac x="1" in exI)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
87  | 
apply fastforce  | 
| 13224 | 88  | 
|
89  | 
apply clarsimp  | 
|
90  | 
apply (erule disjE)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
91  | 
apply (fastforce dest: field_fields fields_is_type)  | 
| 
41464
 
cb2e3e651893
adopting proofs due to new list comprehension to set comprehension simproc
 
bulwahn 
parents: 
39758 
diff
changeset
 | 
92  | 
apply (simp add: match_some_entry image_iff)  | 
| 13224 | 93  | 
apply (rule_tac x=1 in exI)  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
94  | 
apply fastforce  | 
| 13224 | 95  | 
|
96  | 
apply clarsimp  | 
|
97  | 
apply (erule disjE)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
98  | 
apply fastforce  | 
| 
41464
 
cb2e3e651893
adopting proofs due to new list comprehension to set comprehension simproc
 
bulwahn 
parents: 
39758 
diff
changeset
 | 
99  | 
apply (simp add: match_some_entry image_iff)  | 
| 13224 | 100  | 
apply (rule_tac x=1 in exI)  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
101  | 
apply fastforce  | 
| 13224 | 102  | 
|
103  | 
apply clarsimp  | 
|
104  | 
apply (erule disjE)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
105  | 
apply fastforce  | 
| 13224 | 106  | 
apply clarsimp  | 
107  | 
apply (rule_tac x=1 in exI)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
108  | 
apply fastforce  | 
| 13224 | 109  | 
|
110  | 
defer  | 
|
111  | 
||
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
112  | 
apply fastforce  | 
| 
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
113  | 
apply fastforce  | 
| 13224 | 114  | 
|
115  | 
apply clarsimp  | 
|
116  | 
apply (rule_tac x="n'+2" in exI)  | 
|
117  | 
apply simp  | 
|
118  | 
||
119  | 
apply clarsimp  | 
|
120  | 
apply (rule_tac x="Suc (Suc (Suc (length ST)))" in exI)  | 
|
121  | 
apply simp  | 
|
122  | 
||
123  | 
apply clarsimp  | 
|
124  | 
apply (rule_tac x="Suc (Suc (Suc (Suc (length ST))))" in exI)  | 
|
125  | 
apply simp  | 
|
126  | 
||
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
127  | 
apply fastforce  | 
| 
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
128  | 
apply fastforce  | 
| 
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
129  | 
apply fastforce  | 
| 
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
130  | 
apply fastforce  | 
| 13224 | 131  | 
|
132  | 
apply clarsimp  | 
|
133  | 
apply (erule disjE)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
134  | 
apply fastforce  | 
| 13224 | 135  | 
apply clarsimp  | 
136  | 
apply (rule_tac x=1 in exI)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
137  | 
apply fastforce  | 
| 13224 | 138  | 
|
139  | 
apply (erule disjE)  | 
|
| 32693 | 140  | 
apply clarsimp  | 
| 13224 | 141  | 
apply (drule method_wf_mdecl, assumption+)  | 
142  | 
apply (clarsimp simp add: wf_mdecl_def wf_mhead_def)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
143  | 
apply fastforce  | 
| 13224 | 144  | 
apply clarsimp  | 
145  | 
apply (rule_tac x=1 in exI)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
42150 
diff
changeset
 | 
146  | 
apply fastforce  | 
| 13224 | 147  | 
done  | 
148  | 
||
149  | 
lemmas [iff] = not_None_eq  | 
|
150  | 
||
151  | 
lemma sup_state_opt_unfold:  | 
|
152  | 
"sup_state_opt G \<equiv> Opt.le (Product.le (Listn.le (subtype G)) (Listn.le (Err.le (subtype G))))"  | 
|
153  | 
by (simp add: sup_state_opt_def sup_state_def sup_loc_def sup_ty_opt_def)  | 
|
154  | 
||
155  | 
||
156  | 
lemma app_mono:  | 
|
157  | 
"app_mono (sup_state_opt G) (\<lambda>pc. app (bs!pc) G maxs rT pc et) (length bs) (opt_states G maxs maxr)"  | 
|
158  | 
by (unfold app_mono_def lesub_def) (blast intro: EffectMono.app_mono)  | 
|
159  | 
||
160  | 
||
161  | 
lemma list_appendI:  | 
|
162  | 
"\<lbrakk>a \<in> list x A; b \<in> list y A\<rbrakk> \<Longrightarrow> a @ b \<in> list (x+y) A"  | 
|
163  | 
apply (unfold list_def)  | 
|
164  | 
apply (simp (no_asm))  | 
|
165  | 
apply blast  | 
|
166  | 
done  | 
|
167  | 
||
168  | 
lemma list_map [simp]:  | 
|
169  | 
"(map f xs \<in> list (length xs) A) = (f ` set xs \<subseteq> A)"  | 
|
170  | 
apply (unfold list_def)  | 
|
171  | 
apply simp  | 
|
172  | 
done  | 
|
173  | 
||
174  | 
lemma [iff]:  | 
|
175  | 
"(OK ` A \<subseteq> err B) = (A \<subseteq> B)"  | 
|
176  | 
apply (unfold err_def)  | 
|
177  | 
apply blast  | 
|
178  | 
done  | 
|
179  | 
||
180  | 
lemma [intro]:  | 
|
181  | 
"x \<in> A \<Longrightarrow> replicate n x \<in> list n A"  | 
|
182  | 
by (induct n, auto)  | 
|
183  | 
||
184  | 
lemma lesubstep_type_simple:  | 
|
| 67399 | 185  | 
"a <=[Product.le (=) r] b \<Longrightarrow> a \<le>|r| b"  | 
| 13224 | 186  | 
apply (unfold lesubstep_type_def)  | 
187  | 
apply clarify  | 
|
188  | 
apply (simp add: set_conv_nth)  | 
|
189  | 
apply clarify  | 
|
190  | 
apply (drule le_listD, assumption)  | 
|
191  | 
apply (clarsimp simp add: lesub_def Product.le_def)  | 
|
192  | 
apply (rule exI)  | 
|
193  | 
apply (rule conjI)  | 
|
194  | 
apply (rule exI)  | 
|
195  | 
apply (rule conjI)  | 
|
196  | 
apply (rule sym)  | 
|
197  | 
apply assumption  | 
|
198  | 
apply assumption  | 
|
199  | 
apply assumption  | 
|
200  | 
done  | 
|
201  | 
||
202  | 
||
203  | 
lemma eff_mono:  | 
|
204  | 
"\<lbrakk>p < length bs; s <=_(sup_state_opt G) t; app (bs!p) G maxs rT pc et t\<rbrakk>  | 
|
| 61994 | 205  | 
\<Longrightarrow> eff (bs!p) G p et s \<le>|sup_state_opt G| eff (bs!p) G p et t"  | 
| 13224 | 206  | 
apply (unfold eff_def)  | 
207  | 
apply (rule lesubstep_type_simple)  | 
|
208  | 
apply (rule le_list_appendI)  | 
|
209  | 
apply (simp add: norm_eff_def)  | 
|
210  | 
apply (rule le_listI)  | 
|
211  | 
apply simp  | 
|
212  | 
apply simp  | 
|
213  | 
apply (simp add: lesub_def)  | 
|
214  | 
apply (case_tac s)  | 
|
215  | 
apply simp  | 
|
216  | 
apply (simp del: split_paired_All split_paired_Ex)  | 
|
217  | 
apply (elim exE conjE)  | 
|
218  | 
apply simp  | 
|
219  | 
apply (drule eff'_mono, assumption)  | 
|
220  | 
apply assumption  | 
|
221  | 
apply (simp add: xcpt_eff_def)  | 
|
222  | 
apply (rule le_listI)  | 
|
223  | 
apply simp  | 
|
224  | 
apply simp  | 
|
225  | 
apply (simp add: lesub_def)  | 
|
226  | 
apply (case_tac s)  | 
|
227  | 
apply simp  | 
|
228  | 
apply simp  | 
|
229  | 
apply (case_tac t)  | 
|
230  | 
apply simp  | 
|
231  | 
apply (clarsimp simp add: sup_state_conv)  | 
|
232  | 
done  | 
|
233  | 
||
234  | 
lemma order_sup_state_opt:  | 
|
| 14045 | 235  | 
"ws_prog G \<Longrightarrow> order (sup_state_opt G)"  | 
| 13224 | 236  | 
by (unfold sup_state_opt_unfold) (blast dest: acyclic_subcls1 order_widen)  | 
237  | 
||
238  | 
theorem exec_mono:  | 
|
| 14045 | 239  | 
"ws_prog G \<Longrightarrow> bounded (exec G maxs rT et bs) (size bs) \<Longrightarrow>  | 
| 13224 | 240  | 
mono (JVMType.le G maxs maxr) (exec G maxs rT et bs) (size bs) (states G maxs maxr)"  | 
241  | 
apply (unfold exec_def JVM_le_unfold JVM_states_unfold)  | 
|
242  | 
apply (rule mono_lift)  | 
|
243  | 
apply (fold sup_state_opt_unfold opt_states_def)  | 
|
244  | 
apply (erule order_sup_state_opt)  | 
|
245  | 
apply (rule app_mono)  | 
|
246  | 
apply assumption  | 
|
247  | 
apply clarify  | 
|
248  | 
apply (rule eff_mono)  | 
|
249  | 
apply assumption+  | 
|
250  | 
done  | 
|
251  | 
||
252  | 
theorem semilat_JVM_slI:  | 
|
| 14045 | 253  | 
"ws_prog G \<Longrightarrow> semilat (JVMType.sl G maxs maxr)"  | 
| 13224 | 254  | 
apply (unfold JVMType.sl_def stk_esl_def reg_sl_def)  | 
255  | 
apply (rule semilat_opt)  | 
|
256  | 
apply (rule err_semilat_Product_esl)  | 
|
257  | 
apply (rule err_semilat_upto_esl)  | 
|
258  | 
apply (rule err_semilat_JType_esl, assumption+)  | 
|
259  | 
apply (rule err_semilat_eslI)  | 
|
260  | 
apply (rule Listn_sl)  | 
|
261  | 
apply (rule err_semilat_JType_esl, assumption+)  | 
|
262  | 
done  | 
|
263  | 
||
264  | 
lemma sl_triple_conv:  | 
|
265  | 
"JVMType.sl G maxs maxr ==  | 
|
266  | 
(states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)"  | 
|
267  | 
by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def)  | 
|
268  | 
||
269  | 
lemma is_type_pTs:  | 
|
270  | 
"\<lbrakk> wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; ((mn,pTs),rT,code) \<in> set mdecls \<rbrakk>  | 
|
271  | 
\<Longrightarrow> set pTs \<subseteq> types G"  | 
|
272  | 
proof  | 
|
273  | 
assume "wf_prog wf_mb G"  | 
|
274  | 
"(C,S,fs,mdecls) \<in> set G"  | 
|
275  | 
"((mn,pTs),rT,code) \<in> set mdecls"  | 
|
276  | 
hence "wf_mdecl wf_mb G C ((mn,pTs),rT,code)"  | 
|
| 14045 | 277  | 
by (rule wf_prog_wf_mdecl)  | 
| 13224 | 278  | 
hence "\<forall>t \<in> set pTs. is_type G t"  | 
279  | 
by (unfold wf_mdecl_def wf_mhead_def) auto  | 
|
280  | 
moreover  | 
|
281  | 
fix t assume "t \<in> set pTs"  | 
|
282  | 
ultimately  | 
|
283  | 
have "is_type G t" by blast  | 
|
284  | 
thus "t \<in> types G" ..  | 
|
285  | 
qed  | 
|
286  | 
||
287  | 
||
288  | 
lemma jvm_prog_lift:  | 
|
289  | 
assumes wf:  | 
|
290  | 
"wf_prog (\<lambda>G C bd. P G C bd) G"  | 
|
291  | 
||
292  | 
assumes rule:  | 
|
293  | 
"\<And>wf_mb C mn pTs C rT maxs maxl b et bd.  | 
|
294  | 
wf_prog wf_mb G \<Longrightarrow>  | 
|
295  | 
method (G,C) (mn,pTs) = Some (C,rT,maxs,maxl,b,et) \<Longrightarrow>  | 
|
296  | 
is_class G C \<Longrightarrow>  | 
|
297  | 
set pTs \<subseteq> types G \<Longrightarrow>  | 
|
298  | 
bd = ((mn,pTs),rT,maxs,maxl,b,et) \<Longrightarrow>  | 
|
299  | 
P G C bd \<Longrightarrow>  | 
|
300  | 
Q G C bd"  | 
|
301  | 
||
302  | 
shows  | 
|
303  | 
"wf_prog (\<lambda>G C bd. Q G C bd) G"  | 
|
| 52620 | 304  | 
using wf  | 
305  | 
apply (unfold wf_prog_def wf_cdecl_def)  | 
|
306  | 
apply clarsimp  | 
|
307  | 
apply (drule bspec, assumption)  | 
|
308  | 
apply (unfold wf_cdecl_mdecl_def)  | 
|
309  | 
apply clarsimp  | 
|
310  | 
apply (drule bspec, assumption)  | 
|
311  | 
apply (frule methd [OF wf [THEN wf_prog_ws_prog]], assumption+)  | 
|
312  | 
apply (frule is_type_pTs [OF wf], assumption+)  | 
|
313  | 
apply clarify  | 
|
314  | 
apply (drule rule [OF wf], assumption+)  | 
|
315  | 
apply (rule HOL.refl)  | 
|
316  | 
apply assumption+  | 
|
317  | 
done  | 
|
| 13224 | 318  | 
|
319  | 
end  |