(* Title: HOL/Bali/Conform.thy Author: David von Oheimb
*)
subsection \<open>Conformance notions for the type soundness proof for Java\<close>
theory Conform imports State begin
text\<open>
design issues: \begin{itemize} \item lconf allows for (arbitrary) inaccessible values \item ''conforms'' does not directly imply that the dynamic types of all
objects on the heap are indeed existing classes. Yet this can be
inferred for all referenced objs. \end{itemize} \<close>
type_synonym env' = "prog \ (lname, ty) table" (* same as env of WellType.thy *)
subsubsection "extension of global store"
definition gext :: "st \ st \ bool" (\_\|_\ [71,71] 70) where "s\|s' \ \r. \obj\globs s r: \obj'\globs s' r: tag obj'= tag obj"
text\<open>For the the proof of type soundness we will need the
property that during execution, objects are not lost andmoreover retain the
values of their tags. So the object store grows conservatively. Note that if
we considered garbage collection, we would havetorestrict this property to
accessible objects. \<close>
lemma gext_objD: "\s\|s'; globs s r = Some obj\ \<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj" apply (simp only: gext_def) by force
lemma rev_gext_objD: "\globs s r = Some obj; s\|s'\ \<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj" by (auto elim: gext_objD)
lemma init_class_obj_inited: "init_class_obj G C s1\|s2 \ inited C (globs s2)" apply (unfold inited_def init_obj_def) apply (auto dest!: gext_objD) done
lemma gext_upd_gobj [intro!]: "s\|upd_gobj r n v s" apply (simp only: gext_def) apply auto apply (case_tac "ra = r") apply auto apply (case_tac "globs s r = None") apply auto done
lemma gext_cong1 [simp]: "set_locals l s1\|s2 = s1\|s2" by (auto simp: gext_def)
lemma gext_cong2 [simp]: "s1\|set_locals l s2 = s1\|s2" by (auto simp: gext_def)
lemma gext_lupd1 [simp]: "lupd(vn\v)s1\|s2 = s1\|s2" by (auto simp: gext_def)
lemma gext_lupd2 [simp]: "s1\|lupd(vn\v)s2 = s1\|s2" by (auto simp: gext_def)
lemma inited_gext: "\inited C (globs s); s\|s'\ \ inited C (globs s')" apply (unfold inited_def) apply (auto dest: gext_objD) done
subsubsection "value conformance"
definition conf :: "prog \ st \ val \ ty \ bool" (\_,_\_\\_\ [71,71,71,71] 70) where"G,s\v\\T = (\T'\typeof (\a. map_option obj_ty (heap s a)) v:G\T'\T)"
lemma conf_cong [simp]: "G,set_locals l s\v\\T = G,s\v\\T" by (auto simp: conf_def)
lemma conf_lupd [simp]: "G,lupd(vn\va)s\v\\T = G,s\v\\T" by (auto simp: conf_def)
lemma conf_PrimT [simp]: "\dt. typeof dt v = Some (PrimT t) \ G,s\v\\PrimT t" apply (simp add: conf_def) done
lemma conf_Boolean: "G,s\v\\PrimT Boolean \ \ b. v=Bool b" by (cases v)
(auto simp: conf_def obj_ty_def
dest: widen_Boolean2
split: obj_tag.splits)
lemma conf_litval [rule_format (no_asm)]: "typeof (\a. None) v = Some T \ G,s\v\\T" apply (unfold conf_def) apply (rule val.induct) apply auto done
lemma conf_Null [simp]: "G,s\Null\\T = G\NT\T" by (simp add: conf_def)
lemma conf_Addr: "G,s\Addr a\\T = (\obj. heap s a = Some obj \ G\obj_ty obj\T)" by (auto simp: conf_def)
lemma conf_AddrI:"\heap s a = Some obj; G\obj_ty obj\T\ \ G,s\Addr a\\T" apply (rule conf_Addr [THEN iffD2]) by fast
lemma lconf_init_vals [intro!]: " \n. \T\fs n:is_type G T \ G,s\init_vals fs[\\]fs" apply (unfold lconf_def) apply force done
subsubsection "weak value list conformance"
text\<open>Only if the value is defined it has to conform to its type.
This is the contribution of the definite assignment analysis to
the notion of conformance. The definite assignment analysis ensures
that the program only attempts to access local variables that
actually have a defined valuein the state.
So conformance must only ensure that the
defined values are of the right type, and not also that the value is defined. \<close>
definition
oconf :: "prog \ st \ obj \ oref \ bool" (\_,_\_\\\_\ [71,71,71,71] 70) where "(G,s\obj\\\r) = (G,s\values obj[\\]var_tys G (tag obj) r \
(case r of
Heap a \<Rightarrow> is_type G (obj_ty obj)
| Stat C \<Rightarrow> True))"
lemma oconf_is_type: "G,s\obj\\\Heap a \ is_type G (obj_ty obj)" by (auto simp: oconf_def Let_def)
lemma oconf_lconf: "G,s\obj\\\r \ G,s\values obj[\\]var_tys G (tag obj) r" by (simp add: oconf_def)
lemma oconf_cong [simp]: "G,set_locals l s\obj\\\r = G,s\obj\\\r" by (auto simp: oconf_def Let_def)
lemma oconf_init_obj_lemma: "\\C c. class G C = Some c \ unique (DeclConcepts.fields G C); \<And>C c f fld. \<lbrakk>class G C = Some c;
table_of (DeclConcepts.fields G C) f = Some fld \<rbrakk> \<Longrightarrow> is_type G (type fld);
(case r of
Heap a \<Rightarrow> is_type G (obj_ty obj)
| Stat C \<Rightarrow> is_class G C) \<rbrakk> \<Longrightarrow> G,s\<turnstile>obj \<lparr>values:=init_vals (var_tys G (tag obj) r)\<rparr>\<Colon>\<preceq>\<surd>r" apply (auto simp add: oconf_def) apply (drule_tac var_tys_Some_eq [THEN iffD1]) defer apply (subst obj_ty_cong) apply (auto dest!: fields_table_SomeD split: sum.split_asm obj_tag.split_asm) done
subsubsection "state conformance"
definition
conforms :: "state \ env' \ bool" (\_\\_\ [71,71] 70) where "xs\\E =
(let (G, L) = E; s = snd xs; l = locals s in
(\<forall>r. \<forall>obj\<in>globs s r: G,s\<turnstile>obj \<Colon>\<preceq>\<surd>r) \<and> G,s\<turnstile>l [\<sim>\<Colon>\<preceq>]L \<and>
(\<forall>a. fst xs=Some(Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)) \<and>
(fst xs=Some(Jump Ret) \<longrightarrow> l Result \<noteq> None))"
subsubsection "conforms"
lemma conforms_globsD: "\(x, s)\\(G, L); globs s r = Some obj\ \ G,s\obj\\\r" by (auto simp: conforms_def Let_def)
lemma conformsI: "\\r. \obj\globs s r: G,s\obj\\\r;
G,s\<turnstile>locals s[\<sim>\<Colon>\<preceq>]L; \<forall>a. x = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable);
x = Some (Jump Ret)\<longrightarrow> locals s Result \<noteq> None\<rbrakk> \<Longrightarrow>
(x, s)\<Colon>\<preceq>(G, L)" by (auto simp: conforms_def Let_def)
lemma conforms_xconf: "\(x, s)\\(G,L); \<forall>a. x' = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable);
x' = Some (Jump Ret) \ locals s Result \ None\ \
(x',s)\\(G,L)" by (fast intro: conformsI elim: conforms_globsD conforms_localD)
lemma conforms_lupd: "\(x, s)\\(G, L); L vn = Some T; G,s\v\\T\ \ (x, lupd(vn\v)s)\\(G, L)" by (force intro: conformsI wlconf_upd dest: conforms_globsD conforms_localD
conforms_XcptLocD conforms_RetD
simp: oconf_def)
lemma conforms_locals: "\(a,b)\\(G, L); L x = Some T;locals b x \None\ \<Longrightarrow> G,b\<turnstile>the (locals b x)\<Colon>\<preceq>T" apply (force simp: conforms_def Let_def wlconf_def) done
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.