diff --git a/thys/Jinja/BV/BVConform.thy b/thys/Jinja/BV/BVConform.thy --- a/thys/Jinja/BV/BVConform.thy +++ b/thys/Jinja/BV/BVConform.thy @@ -1,152 +1,154 @@ (* Title: HOL/MicroJava/BV/Correct.thy Author: Cornelia Pusch, Gerwin Klein Copyright 1999 Technische Universitaet Muenchen The invariant for the type safety proof. *) section \BV Type Safety Invariant\ theory BVConform imports BVSpec "../JVM/JVMExec" "../Common/Conform" begin definition confT :: "'c prog \ heap \ val \ ty err \ bool" ("_,_ \ _ :\\<^sub>\ _" [51,51,51,51] 50) where "P,h \ v :\\<^sub>\ E \ case E of Err \ True | OK T \ P,h \ v :\ T" notation (ASCII) confT ("_,_ |- _ :<=T _" [51,51,51,51] 50) abbreviation confTs :: "'c prog \ heap \ val list \ ty\<^sub>l \ bool" ("_,_ \ _ [:\\<^sub>\] _" [51,51,51,51] 50) where "P,h \ vs [:\\<^sub>\] Ts \ list_all2 (confT P h) vs Ts" notation (ASCII) confTs ("_,_ |- _ [:<=T] _" [51,51,51,51] 50) definition conf_f :: "jvm_prog \ heap \ ty\<^sub>i \ bytecode \ frame \ bool" where "conf_f P h \ \(ST,LT) is (stk,loc,C,M,pc). P,h \ stk [:\] ST \ P,h \ loc [:\\<^sub>\] LT \ pc < size is" lemma conf_f_def2: "conf_f P h (ST,LT) is (stk,loc,C,M,pc) \ P,h \ stk [:\] ST \ P,h \ loc [:\\<^sub>\] LT \ pc < size is" by (simp add: conf_f_def) primrec conf_fs :: "[jvm_prog,heap,ty\<^sub>P,mname,nat,ty,frame list] \ bool" where "conf_fs P h \ M\<^sub>0 n\<^sub>0 T\<^sub>0 [] = True" | "conf_fs P h \ M\<^sub>0 n\<^sub>0 T\<^sub>0 (f#frs) = (let (stk,loc,C,M,pc) = f in (\ST LT Ts T mxs mxl\<^sub>0 is xt. \ C M ! pc = Some (ST,LT) \ (P \ C sees M:Ts \ T = (mxs,mxl\<^sub>0,is,xt) in C) \ (\D Ts' T' m D'. is!pc = (Invoke M\<^sub>0 n\<^sub>0) \ ST!n\<^sub>0 = Class D \ P \ D sees M\<^sub>0:Ts' \ T' = m in D' \ P \ T\<^sub>0 \ T') \ conf_f P h (ST, LT) is f \ conf_fs P h \ M (size Ts) T frs))" definition correct_state :: "[jvm_prog,ty\<^sub>P,jvm_state] \ bool" ("_,_ \ _ \" [61,0,0] 61) where "correct_state P \ \ \(xp,h,frs). case xp of None \ (case frs of [] \ True | (f#fs) \ P\ h\ \ (let (stk,loc,C,M,pc) = f in \Ts T mxs mxl\<^sub>0 is xt \. (P \ C sees M:Ts\T = (mxs,mxl\<^sub>0,is,xt) in C) \ \ C M ! pc = Some \ \ conf_f P h \ is f \ conf_fs P h \ M (size Ts) T fs)) | Some x \ frs = []" notation correct_state ("_,_ |- _ [ok]" [61,0,0] 61) subsection \Values and \\\\ lemma confT_Err [iff]: "P,h \ x :\\<^sub>\ Err" by (simp add: confT_def) lemma confT_OK [iff]: "P,h \ x :\\<^sub>\ OK T = (P,h \ x :\ T)" by (simp add: confT_def) lemma confT_cases: "P,h \ x :\\<^sub>\ X = (X = Err \ (\T. X = OK T \ P,h \ x :\ T))" by (cases X) auto lemma confT_hext [intro?, trans]: "\ P,h \ x :\\<^sub>\ T; h \ h' \ \ P,h' \ x :\\<^sub>\ T" by (cases T) (blast intro: conf_hext)+ lemma confT_widen [intro?, trans]: "\ P,h \ x :\\<^sub>\ T; P \ T \\<^sub>\ T' \ \ P,h \ x :\\<^sub>\ T'" by (cases T', auto intro: conf_widen) subsection \Stack and Registers\ lemmas confTs_Cons1 [iff] = list_all2_Cons1 [of "confT P h"] for P h lemma confTs_confT_sup: - "\ P,h \ loc [:\\<^sub>\] LT; n < size LT; LT!n = OK T; P \ T \ T' \ - \ P,h \ (loc!n) :\ T'" +assumes confTs: "P,h \ loc [:\\<^sub>\] LT" and n: "n < size LT" and + LTn: "LT!n = OK T" and subtype: "P \ T \ T'" +shows "P,h \ (loc!n) :\ T'" (*<*) - apply (frule list_all2_lengthD) - apply (drule list_all2_nthD, simp) - apply simp - apply (erule conf_widen, assumption+) - done +proof - + have len: "n < length loc" using list_all2_lengthD[OF confTs] n + by simp + show ?thesis + using list_all2_nthD[OF confTs len] conf_widen[OF _ subtype] LTn + by simp +qed (*>*) lemma confTs_hext [intro?]: "P,h \ loc [:\\<^sub>\] LT \ h \ h' \ P,h' \ loc [:\\<^sub>\] LT" by (fast elim: list_all2_mono confT_hext) lemma confTs_widen [intro?, trans]: "P,h \ loc [:\\<^sub>\] LT \ P \ LT [\\<^sub>\] LT' \ P,h \ loc [:\\<^sub>\] LT'" by (rule list_all2_trans, rule confT_widen) lemma confTs_map [iff]: "\vs. (P,h \ vs [:\\<^sub>\] map OK Ts) = (P,h \ vs [:\] Ts)" by (induct Ts) (auto simp add: list_all2_Cons2) lemma reg_widen_Err [iff]: "\LT. (P \ replicate n Err [\\<^sub>\] LT) = (LT = replicate n Err)" by (induct n) (auto simp add: list_all2_Cons1) lemma confTs_Err [iff]: "P,h \ replicate n v [:\\<^sub>\] replicate n Err" by (induct n) auto subsection \correct-frames\ lemmas [simp del] = fun_upd_apply lemma conf_fs_hext: "\M n T\<^sub>r. \ conf_fs P h \ M n T\<^sub>r frs; h \ h' \ \ conf_fs P h' \ M n T\<^sub>r frs" (*<*) -apply (induct frs) - apply simp -apply clarify -apply (simp (no_asm_use)) -apply clarify -apply (unfold conf_f_def) -apply (simp (no_asm_use)) -apply clarify -apply (fast elim!: confs_hext confTs_hext) -done +proof(induct frs) + case (Cons fr frs) + obtain stk ls C M pc where fr: "fr = (stk, ls, C, M, pc)" by(cases fr) simp + moreover obtain ST LT where \: "\ C M ! pc = \(ST, LT)\" and + ST: "P,h \ stk [:\] ST" and LT: "P,h \ ls [:\\<^sub>\] LT" + using Cons.prems(1) fr by(auto simp: conf_f_def) + ultimately show ?case using Cons confs_hext[OF ST Cons(3)] confTs_hext[OF LT Cons(3)] + by (fastforce simp: conf_f_def) +qed simp (*>*) end