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