src/HOL/Bali/Conform.thy
author berghofe
Sat Jan 30 17:03:46 2010 +0100 (2010-01-30)
changeset 34990 81e8fdfeb849
parent 32960 69916a850301
child 35069 09154b995ed8
permissions -rw-r--r--
Adapted to changes in cases method.
wenzelm@12857
     1
(*  Title:      HOL/Bali/Conform.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
schirmer@12854
     4
*)
schirmer@12854
     5
schirmer@12854
     6
header {* Conformance notions for the type soundness proof for Java *}
schirmer@12854
     7
haftmann@16417
     8
theory Conform imports State begin
schirmer@12854
     9
schirmer@12854
    10
text {*
schirmer@12854
    11
design issues:
schirmer@12854
    12
\begin{itemize}
schirmer@12854
    13
\item lconf allows for (arbitrary) inaccessible values
schirmer@12854
    14
\item ''conforms'' does not directly imply that the dynamic types of all 
schirmer@12854
    15
      objects on the heap are indeed existing classes. Yet this can be 
schirmer@12854
    16
      inferred for all referenced objs.
schirmer@12854
    17
\end{itemize}
schirmer@12854
    18
*}
schirmer@12854
    19
wenzelm@32960
    20
types env' = "prog \<times> (lname, ty) table" (* same as env of WellType.thy *)
schirmer@12854
    21
schirmer@12854
    22
schirmer@12854
    23
section "extension of global store"
schirmer@12854
    24
schirmer@12925
    25
schirmer@12854
    26
constdefs
schirmer@12854
    27
wenzelm@14674
    28
  gext    :: "st \<Rightarrow> st \<Rightarrow> bool"                ("_\<le>|_"       [71,71]   70)
schirmer@12854
    29
   "s\<le>|s' \<equiv> \<forall>r. \<forall>obj\<in>globs s r: \<exists>obj'\<in>globs s' r: tag obj'= tag obj"
schirmer@12854
    30
schirmer@12925
    31
text {* For the the proof of type soundness we will need the 
schirmer@12925
    32
property that during execution, objects are not lost and moreover retain the 
schirmer@12925
    33
values of their tags. So the object store grows conservatively. Note that if 
schirmer@12925
    34
we considered garbage collection, we would have to restrict this property to 
schirmer@12925
    35
accessible objects.
schirmer@12925
    36
*}
schirmer@12925
    37
schirmer@12854
    38
lemma gext_objD: 
schirmer@12854
    39
"\<lbrakk>s\<le>|s'; globs s r = Some obj\<rbrakk> 
schirmer@12854
    40
\<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj"
schirmer@12854
    41
apply (simp only: gext_def)
schirmer@12854
    42
by force
schirmer@12854
    43
schirmer@12854
    44
lemma rev_gext_objD: 
schirmer@12854
    45
"\<lbrakk>globs s r = Some obj; s\<le>|s'\<rbrakk> 
schirmer@12854
    46
 \<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj"
schirmer@12854
    47
by (auto elim: gext_objD)
schirmer@12854
    48
schirmer@12854
    49
lemma init_class_obj_inited: 
schirmer@12854
    50
   "init_class_obj G C s1\<le>|s2 \<Longrightarrow> inited C (globs s2)"
schirmer@12854
    51
apply (unfold inited_def init_obj_def)
schirmer@12854
    52
apply (auto dest!: gext_objD)
schirmer@12854
    53
done
schirmer@12854
    54
schirmer@12854
    55
lemma gext_refl [intro!, simp]: "s\<le>|s"
schirmer@12854
    56
apply (unfold gext_def)
schirmer@12854
    57
apply (fast del: fst_splitE)
schirmer@12854
    58
done
schirmer@12854
    59
schirmer@12854
    60
lemma gext_gupd [simp, elim!]: "\<And>s. globs s r = None \<Longrightarrow> s\<le>|gupd(r\<mapsto>x)s"
schirmer@12854
    61
by (auto simp: gext_def)
schirmer@12854
    62
schirmer@12854
    63
lemma gext_new [simp, elim!]: "\<And>s. globs s r = None \<Longrightarrow> s\<le>|init_obj G oi r s"
schirmer@12854
    64
apply (simp only: init_obj_def)
schirmer@12854
    65
apply (erule_tac gext_gupd)
schirmer@12854
    66
done
schirmer@12854
    67
schirmer@12854
    68
lemma gext_trans [elim]: "\<And>X. \<lbrakk>s\<le>|s'; s'\<le>|s''\<rbrakk> \<Longrightarrow> s\<le>|s''" 
schirmer@12854
    69
by (force simp: gext_def)
schirmer@12854
    70
schirmer@12854
    71
lemma gext_upd_gobj [intro!]: "s\<le>|upd_gobj r n v s"
schirmer@12854
    72
apply (simp only: gext_def)
schirmer@12854
    73
apply auto
schirmer@12854
    74
apply (case_tac "ra = r")
schirmer@12854
    75
apply auto
schirmer@12854
    76
apply (case_tac "globs s r = None")
schirmer@12854
    77
apply auto
schirmer@12854
    78
done
schirmer@12854
    79
schirmer@12854
    80
lemma gext_cong1 [simp]: "set_locals l s1\<le>|s2 = s1\<le>|s2"
schirmer@12854
    81
by (auto simp: gext_def)
schirmer@12854
    82
schirmer@12854
    83
lemma gext_cong2 [simp]: "s1\<le>|set_locals l s2 = s1\<le>|s2"
schirmer@12854
    84
by (auto simp: gext_def)
schirmer@12854
    85
schirmer@12854
    86
schirmer@12854
    87
lemma gext_lupd1 [simp]: "lupd(vn\<mapsto>v)s1\<le>|s2 = s1\<le>|s2"
schirmer@12854
    88
by (auto simp: gext_def)
schirmer@12854
    89
schirmer@12854
    90
lemma gext_lupd2 [simp]: "s1\<le>|lupd(vn\<mapsto>v)s2 = s1\<le>|s2"
schirmer@12854
    91
by (auto simp: gext_def)
schirmer@12854
    92
schirmer@12854
    93
schirmer@12854
    94
lemma inited_gext: "\<lbrakk>inited C (globs s); s\<le>|s'\<rbrakk> \<Longrightarrow> inited C (globs s')"
schirmer@12854
    95
apply (unfold inited_def)
schirmer@12854
    96
apply (auto dest: gext_objD)
schirmer@12854
    97
done
schirmer@12854
    98
schirmer@12854
    99
schirmer@12854
   100
section "value conformance"
schirmer@12854
   101
schirmer@12854
   102
constdefs
schirmer@12854
   103
schirmer@12854
   104
  conf  :: "prog \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ty \<Rightarrow> bool"    ("_,_\<turnstile>_\<Colon>\<preceq>_"   [71,71,71,71] 70)
wenzelm@32960
   105
           "G,s\<turnstile>v\<Colon>\<preceq>T \<equiv> \<exists>T'\<in>typeof (\<lambda>a. Option.map obj_ty (heap s a)) v:G\<turnstile>T'\<preceq>T"
schirmer@12854
   106
schirmer@12854
   107
lemma conf_cong [simp]: "G,set_locals l s\<turnstile>v\<Colon>\<preceq>T = G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   108
by (auto simp: conf_def)
schirmer@12854
   109
schirmer@12854
   110
lemma conf_lupd [simp]: "G,lupd(vn\<mapsto>va)s\<turnstile>v\<Colon>\<preceq>T = G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   111
by (auto simp: conf_def)
schirmer@12854
   112
schirmer@12854
   113
lemma conf_PrimT [simp]: "\<forall>dt. typeof dt v = Some (PrimT t) \<Longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>PrimT t"
schirmer@12854
   114
apply (simp add: conf_def)
schirmer@12854
   115
done
schirmer@12854
   116
schirmer@13688
   117
lemma conf_Boolean: "G,s\<turnstile>v\<Colon>\<preceq>PrimT Boolean \<Longrightarrow> \<exists> b. v=Bool b"
schirmer@13688
   118
by (cases v)
schirmer@13688
   119
   (auto simp: conf_def obj_ty_def 
schirmer@13688
   120
         dest: widen_Boolean2 
schirmer@13688
   121
        split: obj_tag.splits)
schirmer@13688
   122
schirmer@13688
   123
schirmer@12854
   124
lemma conf_litval [rule_format (no_asm)]: 
schirmer@12854
   125
  "typeof (\<lambda>a. None) v = Some T \<longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   126
apply (unfold conf_def)
schirmer@12854
   127
apply (rule val.induct)
schirmer@12854
   128
apply auto
schirmer@12854
   129
done
schirmer@12854
   130
schirmer@12854
   131
lemma conf_Null [simp]: "G,s\<turnstile>Null\<Colon>\<preceq>T = G\<turnstile>NT\<preceq>T"
schirmer@12854
   132
by (simp add: conf_def)
schirmer@12854
   133
schirmer@12854
   134
lemma conf_Addr: 
schirmer@12854
   135
  "G,s\<turnstile>Addr a\<Colon>\<preceq>T = (\<exists>obj. heap s a = Some obj \<and> G\<turnstile>obj_ty obj\<preceq>T)"
schirmer@12854
   136
by (auto simp: conf_def)
schirmer@12854
   137
schirmer@12854
   138
lemma conf_AddrI:"\<lbrakk>heap s a = Some obj; G\<turnstile>obj_ty obj\<preceq>T\<rbrakk> \<Longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq>T"
schirmer@12854
   139
apply (rule conf_Addr [THEN iffD2])
schirmer@12854
   140
by fast
schirmer@12854
   141
schirmer@12854
   142
lemma defval_conf [rule_format (no_asm), elim]: 
schirmer@12854
   143
  "is_type G T \<longrightarrow> G,s\<turnstile>default_val T\<Colon>\<preceq>T"
schirmer@12854
   144
apply (unfold conf_def)
schirmer@12854
   145
apply (induct "T")
schirmer@12854
   146
apply (auto intro: prim_ty.induct)
schirmer@12854
   147
done
schirmer@12854
   148
schirmer@12854
   149
lemma conf_widen [rule_format (no_asm), elim]: 
schirmer@12854
   150
  "G\<turnstile>T\<preceq>T' \<Longrightarrow> G,s\<turnstile>x\<Colon>\<preceq>T \<longrightarrow> ws_prog G \<longrightarrow> G,s\<turnstile>x\<Colon>\<preceq>T'"
schirmer@12854
   151
apply (unfold conf_def)
schirmer@12854
   152
apply (rule val.induct)
schirmer@12854
   153
apply (auto elim: ws_widen_trans)
schirmer@12854
   154
done
schirmer@12854
   155
schirmer@12854
   156
lemma conf_gext [rule_format (no_asm), elim]: 
schirmer@12854
   157
  "G,s\<turnstile>v\<Colon>\<preceq>T \<longrightarrow> s\<le>|s' \<longrightarrow> G,s'\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   158
apply (unfold gext_def conf_def)
schirmer@12854
   159
apply (rule val.induct)
schirmer@12854
   160
apply force+
schirmer@12854
   161
done
schirmer@12854
   162
schirmer@12854
   163
schirmer@12854
   164
lemma conf_list_widen [rule_format (no_asm)]: 
schirmer@12854
   165
"ws_prog G \<Longrightarrow>  
schirmer@12854
   166
  \<forall>Ts Ts'. list_all2 (conf G s) vs Ts 
schirmer@12854
   167
           \<longrightarrow>   G\<turnstile>Ts[\<preceq>] Ts' \<longrightarrow> list_all2 (conf G s) vs Ts'"
schirmer@12854
   168
apply (unfold widens_def)
schirmer@12854
   169
apply (rule list_all2_trans)
schirmer@12854
   170
apply auto
schirmer@12854
   171
done
schirmer@12854
   172
schirmer@12854
   173
lemma conf_RefTD [rule_format (no_asm)]: 
schirmer@12854
   174
 "G,s\<turnstile>a'\<Colon>\<preceq>RefT T 
schirmer@12854
   175
  \<longrightarrow> a' = Null \<or> (\<exists>a obj T'. a' = Addr a \<and> heap s a = Some obj \<and>  
schirmer@12854
   176
                    obj_ty obj = T' \<and> G\<turnstile>T'\<preceq>RefT T)"
schirmer@12854
   177
apply (unfold conf_def)
schirmer@12854
   178
apply (induct_tac "a'")
schirmer@12854
   179
apply (auto dest: widen_PrimT)
schirmer@12854
   180
done
schirmer@12854
   181
schirmer@12854
   182
schirmer@12854
   183
section "value list conformance"
schirmer@12854
   184
schirmer@12854
   185
constdefs
schirmer@12854
   186
schirmer@12854
   187
  lconf :: "prog \<Rightarrow> st \<Rightarrow> ('a, val) table \<Rightarrow> ('a, ty) table \<Rightarrow> bool"
wenzelm@14674
   188
                                                ("_,_\<turnstile>_[\<Colon>\<preceq>]_" [71,71,71,71] 70)
schirmer@12854
   189
           "G,s\<turnstile>vs[\<Colon>\<preceq>]Ts \<equiv> \<forall>n. \<forall>T\<in>Ts n: \<exists>v\<in>vs n: G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   190
schirmer@12854
   191
lemma lconfD: "\<lbrakk>G,s\<turnstile>vs[\<Colon>\<preceq>]Ts; Ts n = Some T\<rbrakk> \<Longrightarrow> G,s\<turnstile>(the (vs n))\<Colon>\<preceq>T"
schirmer@12854
   192
by (force simp: lconf_def)
schirmer@12854
   193
schirmer@12854
   194
schirmer@12854
   195
lemma lconf_cong [simp]: "\<And>s. G,set_locals x s\<turnstile>l[\<Colon>\<preceq>]L = G,s\<turnstile>l[\<Colon>\<preceq>]L"
schirmer@12854
   196
by (auto simp: lconf_def)
schirmer@12854
   197
schirmer@12854
   198
lemma lconf_lupd [simp]: "G,lupd(vn\<mapsto>v)s\<turnstile>l[\<Colon>\<preceq>]L = G,s\<turnstile>l[\<Colon>\<preceq>]L"
schirmer@12854
   199
by (auto simp: lconf_def)
schirmer@12854
   200
schirmer@12854
   201
(* unused *)
schirmer@12854
   202
lemma lconf_new: "\<lbrakk>L vn = None; G,s\<turnstile>l[\<Colon>\<preceq>]L\<rbrakk> \<Longrightarrow> G,s\<turnstile>l(vn\<mapsto>v)[\<Colon>\<preceq>]L"
schirmer@12854
   203
by (auto simp: lconf_def)
schirmer@12854
   204
schirmer@12854
   205
lemma lconf_upd: "\<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L; G,s\<turnstile>v\<Colon>\<preceq>T; L vn = Some T\<rbrakk> \<Longrightarrow>  
schirmer@12854
   206
  G,s\<turnstile>l(vn\<mapsto>v)[\<Colon>\<preceq>]L"
schirmer@12854
   207
by (auto simp: lconf_def)
schirmer@12854
   208
schirmer@12854
   209
lemma lconf_ext: "\<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L; G,s\<turnstile>v\<Colon>\<preceq>T\<rbrakk> \<Longrightarrow> G,s\<turnstile>l(vn\<mapsto>v)[\<Colon>\<preceq>]L(vn\<mapsto>T)"
schirmer@12854
   210
by (auto simp: lconf_def)
schirmer@12854
   211
schirmer@12854
   212
lemma lconf_map_sum [simp]: 
schirmer@12854
   213
 "G,s\<turnstile>l1 (+) l2[\<Colon>\<preceq>]L1 (+) L2 = (G,s\<turnstile>l1[\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>l2[\<Colon>\<preceq>]L2)"
schirmer@12854
   214
apply (unfold lconf_def)
schirmer@12854
   215
apply safe
schirmer@12854
   216
apply (case_tac [3] "n")
schirmer@12854
   217
apply (force split add: sum.split)+
schirmer@12854
   218
done
schirmer@12854
   219
schirmer@12854
   220
lemma lconf_ext_list [rule_format (no_asm)]: "
schirmer@12854
   221
 \<And>X. \<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L\<rbrakk> \<Longrightarrow> 
wenzelm@12893
   222
      \<forall>vs Ts. distinct vns \<longrightarrow> length Ts = length vns 
schirmer@12854
   223
      \<longrightarrow> list_all2 (conf G s) vs Ts \<longrightarrow> G,s\<turnstile>l(vns[\<mapsto>]vs)[\<Colon>\<preceq>]L(vns[\<mapsto>]Ts)"
schirmer@12854
   224
apply (unfold lconf_def)
schirmer@12854
   225
apply (induct_tac "vns")
schirmer@12854
   226
apply  clarsimp
nipkow@14025
   227
apply clarify
schirmer@12854
   228
apply (frule list_all2_lengthD)
nipkow@14025
   229
apply (clarsimp)
schirmer@12854
   230
done
schirmer@12854
   231
schirmer@12854
   232
schirmer@12854
   233
lemma lconf_deallocL: "\<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L(vn\<mapsto>T); L vn = None\<rbrakk> \<Longrightarrow> G,s\<turnstile>l[\<Colon>\<preceq>]L"
schirmer@12854
   234
apply (simp only: lconf_def)
schirmer@12854
   235
apply safe
schirmer@12854
   236
apply (drule spec)
schirmer@12854
   237
apply (drule ospec)
schirmer@12854
   238
apply auto
schirmer@12854
   239
done 
schirmer@12854
   240
schirmer@12854
   241
schirmer@12854
   242
lemma lconf_gext [elim]: "\<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L; s\<le>|s'\<rbrakk> \<Longrightarrow> G,s'\<turnstile>l[\<Colon>\<preceq>]L"
schirmer@12854
   243
apply (simp only: lconf_def)
schirmer@12854
   244
apply fast
schirmer@12854
   245
done
schirmer@12854
   246
schirmer@12854
   247
lemma lconf_empty [simp, intro!]: "G,s\<turnstile>vs[\<Colon>\<preceq>]empty"
schirmer@12854
   248
apply (unfold lconf_def)
schirmer@12854
   249
apply force
schirmer@12854
   250
done
schirmer@12854
   251
schirmer@12854
   252
lemma lconf_init_vals [intro!]: 
wenzelm@32960
   253
        " \<forall>n. \<forall>T\<in>fs n:is_type G T \<Longrightarrow> G,s\<turnstile>init_vals fs[\<Colon>\<preceq>]fs"
schirmer@12854
   254
apply (unfold lconf_def)
schirmer@12854
   255
apply force
schirmer@12854
   256
done
schirmer@12854
   257
schirmer@13688
   258
section "weak value list conformance"
schirmer@13688
   259
schirmer@13688
   260
text {* Only if the value is defined it has to conform to its type. 
schirmer@13688
   261
        This is the contribution of the definite assignment analysis to 
schirmer@13688
   262
        the notion of conformance. The definite assignment analysis ensures
schirmer@13688
   263
        that the program only attempts to access local variables that 
schirmer@13688
   264
        actually have a defined value in the state. 
schirmer@13688
   265
        So conformance must only ensure that the
schirmer@13688
   266
        defined values are of the right type, and not also that the value
schirmer@13688
   267
        is defined. 
schirmer@13688
   268
*}
schirmer@13688
   269
schirmer@13688
   270
  
schirmer@13688
   271
constdefs
schirmer@13688
   272
schirmer@13688
   273
  wlconf :: "prog \<Rightarrow> st \<Rightarrow> ('a, val) table \<Rightarrow> ('a, ty) table \<Rightarrow> bool"
wenzelm@14674
   274
                                          ("_,_\<turnstile>_[\<sim>\<Colon>\<preceq>]_" [71,71,71,71] 70)
schirmer@13688
   275
           "G,s\<turnstile>vs[\<sim>\<Colon>\<preceq>]Ts \<equiv> \<forall>n. \<forall>T\<in>Ts n: \<forall> v\<in>vs n: G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@13688
   276
schirmer@13688
   277
lemma wlconfD: "\<lbrakk>G,s\<turnstile>vs[\<sim>\<Colon>\<preceq>]Ts; Ts n = Some T; vs n = Some v\<rbrakk> \<Longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@13688
   278
by (auto simp: wlconf_def)
schirmer@13688
   279
schirmer@13688
   280
schirmer@13688
   281
lemma wlconf_cong [simp]: "\<And>s. G,set_locals x s\<turnstile>l[\<sim>\<Colon>\<preceq>]L = G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   282
by (auto simp: wlconf_def)
schirmer@13688
   283
schirmer@13688
   284
lemma wlconf_lupd [simp]: "G,lupd(vn\<mapsto>v)s\<turnstile>l[\<sim>\<Colon>\<preceq>]L = G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   285
by (auto simp: wlconf_def)
schirmer@13688
   286
schirmer@13688
   287
schirmer@13688
   288
lemma wlconf_upd: "\<lbrakk>G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L; G,s\<turnstile>v\<Colon>\<preceq>T; L vn = Some T\<rbrakk> \<Longrightarrow>  
schirmer@13688
   289
  G,s\<turnstile>l(vn\<mapsto>v)[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   290
by (auto simp: wlconf_def)
schirmer@13688
   291
schirmer@13688
   292
lemma wlconf_ext: "\<lbrakk>G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L; G,s\<turnstile>v\<Colon>\<preceq>T\<rbrakk> \<Longrightarrow> G,s\<turnstile>l(vn\<mapsto>v)[\<sim>\<Colon>\<preceq>]L(vn\<mapsto>T)"
schirmer@13688
   293
by (auto simp: wlconf_def)
schirmer@13688
   294
schirmer@13688
   295
lemma wlconf_map_sum [simp]: 
schirmer@13688
   296
 "G,s\<turnstile>l1 (+) l2[\<sim>\<Colon>\<preceq>]L1 (+) L2 = (G,s\<turnstile>l1[\<sim>\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>l2[\<sim>\<Colon>\<preceq>]L2)"
schirmer@13688
   297
apply (unfold wlconf_def)
schirmer@13688
   298
apply safe
schirmer@13688
   299
apply (case_tac [3] "n")
schirmer@13688
   300
apply (force split add: sum.split)+
schirmer@13688
   301
done
schirmer@13688
   302
schirmer@13688
   303
lemma wlconf_ext_list [rule_format (no_asm)]: "
schirmer@13688
   304
 \<And>X. \<lbrakk>G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L\<rbrakk> \<Longrightarrow> 
schirmer@13688
   305
      \<forall>vs Ts. distinct vns \<longrightarrow> length Ts = length vns 
schirmer@13688
   306
      \<longrightarrow> list_all2 (conf G s) vs Ts \<longrightarrow> G,s\<turnstile>l(vns[\<mapsto>]vs)[\<sim>\<Colon>\<preceq>]L(vns[\<mapsto>]Ts)"
schirmer@13688
   307
apply (unfold wlconf_def)
schirmer@13688
   308
apply (induct_tac "vns")
schirmer@13688
   309
apply  clarsimp
nipkow@14025
   310
apply clarify
schirmer@13688
   311
apply (frule list_all2_lengthD)
schirmer@13688
   312
apply clarsimp
schirmer@13688
   313
done
schirmer@13688
   314
schirmer@13688
   315
schirmer@13688
   316
lemma wlconf_deallocL: "\<lbrakk>G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L(vn\<mapsto>T); L vn = None\<rbrakk> \<Longrightarrow> G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   317
apply (simp only: wlconf_def)
schirmer@13688
   318
apply safe
schirmer@13688
   319
apply (drule spec)
schirmer@13688
   320
apply (drule ospec)
schirmer@13688
   321
defer
schirmer@13688
   322
apply (drule ospec )
schirmer@13688
   323
apply auto
schirmer@13688
   324
done 
schirmer@13688
   325
schirmer@13688
   326
schirmer@13688
   327
lemma wlconf_gext [elim]: "\<lbrakk>G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L; s\<le>|s'\<rbrakk> \<Longrightarrow> G,s'\<turnstile>l[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   328
apply (simp only: wlconf_def)
schirmer@13688
   329
apply fast
schirmer@13688
   330
done
schirmer@13688
   331
schirmer@13688
   332
lemma wlconf_empty [simp, intro!]: "G,s\<turnstile>vs[\<sim>\<Colon>\<preceq>]empty"
schirmer@13688
   333
apply (unfold wlconf_def)
schirmer@13688
   334
apply force
schirmer@13688
   335
done
schirmer@13688
   336
schirmer@13688
   337
lemma wlconf_empty_vals: "G,s\<turnstile>empty[\<sim>\<Colon>\<preceq>]ts"
schirmer@13688
   338
  by (simp add: wlconf_def)
schirmer@13688
   339
schirmer@13688
   340
lemma wlconf_init_vals [intro!]: 
wenzelm@32960
   341
        " \<forall>n. \<forall>T\<in>fs n:is_type G T \<Longrightarrow> G,s\<turnstile>init_vals fs[\<sim>\<Colon>\<preceq>]fs"
schirmer@13688
   342
apply (unfold wlconf_def)
schirmer@13688
   343
apply force
schirmer@13688
   344
done
schirmer@13688
   345
schirmer@13688
   346
lemma lconf_wlconf:
schirmer@13688
   347
 "G,s\<turnstile>l[\<Colon>\<preceq>]L \<Longrightarrow> G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L"
schirmer@13688
   348
by (force simp add: lconf_def wlconf_def)
schirmer@12854
   349
schirmer@12854
   350
section "object conformance"
schirmer@12854
   351
schirmer@12854
   352
constdefs
schirmer@12854
   353
schirmer@12854
   354
  oconf :: "prog \<Rightarrow> st \<Rightarrow> obj \<Rightarrow> oref \<Rightarrow> bool"  ("_,_\<turnstile>_\<Colon>\<preceq>\<surd>_"  [71,71,71,71] 70)
wenzelm@32960
   355
           "G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r \<equiv> G,s\<turnstile>values obj[\<Colon>\<preceq>]var_tys G (tag obj) r \<and> 
schirmer@12854
   356
                           (case r of 
wenzelm@32960
   357
                              Heap a \<Rightarrow> is_type G (obj_ty obj) 
schirmer@12854
   358
                            | Stat C \<Rightarrow> True)"
schirmer@13688
   359
schirmer@13688
   360
schirmer@12854
   361
lemma oconf_is_type: "G,s\<turnstile>obj\<Colon>\<preceq>\<surd>Heap a \<Longrightarrow> is_type G (obj_ty obj)"
schirmer@12854
   362
by (auto simp: oconf_def Let_def)
schirmer@12854
   363
schirmer@12854
   364
lemma oconf_lconf: "G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r \<Longrightarrow> G,s\<turnstile>values obj[\<Colon>\<preceq>]var_tys G (tag obj) r"
schirmer@12854
   365
by (simp add: oconf_def) 
schirmer@12854
   366
schirmer@12854
   367
lemma oconf_cong [simp]: "G,set_locals l s\<turnstile>obj\<Colon>\<preceq>\<surd>r = G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r"
schirmer@12854
   368
by (auto simp: oconf_def Let_def)
schirmer@12854
   369
schirmer@12854
   370
lemma oconf_init_obj_lemma: 
schirmer@12854
   371
"\<lbrakk>\<And>C c. class G C = Some c \<Longrightarrow> unique (DeclConcepts.fields G C);  
schirmer@12854
   372
  \<And>C c f fld. \<lbrakk>class G C = Some c; 
schirmer@12854
   373
                table_of (DeclConcepts.fields G C) f = Some fld \<rbrakk> 
schirmer@12854
   374
            \<Longrightarrow> is_type G (type fld);  
schirmer@12854
   375
  (case r of 
schirmer@12854
   376
     Heap a \<Rightarrow> is_type G (obj_ty obj) 
schirmer@12854
   377
  | Stat C \<Rightarrow> is_class G C)
schirmer@12854
   378
\<rbrakk> \<Longrightarrow>  G,s\<turnstile>obj \<lparr>values:=init_vals (var_tys G (tag obj) r)\<rparr>\<Colon>\<preceq>\<surd>r"
schirmer@12854
   379
apply (auto simp add: oconf_def)
schirmer@12854
   380
apply (drule_tac var_tys_Some_eq [THEN iffD1]) 
schirmer@12854
   381
defer
schirmer@12854
   382
apply (subst obj_ty_cong)
schirmer@12854
   383
apply(auto dest!: fields_table_SomeD obj_ty_CInst1 obj_ty_Arr1
schirmer@12854
   384
           split add: sum.split_asm obj_tag.split_asm)
schirmer@12854
   385
done
schirmer@12854
   386
schirmer@12854
   387
section "state conformance"
schirmer@12854
   388
schirmer@12854
   389
constdefs
schirmer@12854
   390
wenzelm@24783
   391
  conforms :: "state \<Rightarrow> env' \<Rightarrow> bool"          (     "_\<Colon>\<preceq>_"   [71,71]      70)
schirmer@12854
   392
   "xs\<Colon>\<preceq>E \<equiv> let (G, L) = E; s = snd xs; l = locals s in
schirmer@13688
   393
    (\<forall>r. \<forall>obj\<in>globs s r:           G,s\<turnstile>obj   \<Colon>\<preceq>\<surd>r) \<and>
schirmer@13688
   394
                \<spacespace>                   G,s\<turnstile>l    [\<sim>\<Colon>\<preceq>]L\<spacespace> \<and>
schirmer@13688
   395
    (\<forall>a. fst xs=Some(Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)) \<and>
schirmer@13688
   396
         (fst xs=Some(Jump Ret) \<longrightarrow> l Result \<noteq> None)"
schirmer@12854
   397
schirmer@12854
   398
section "conforms"
schirmer@12854
   399
schirmer@12854
   400
lemma conforms_globsD: 
schirmer@12854
   401
"\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); globs s r = Some obj\<rbrakk> \<Longrightarrow> G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r"
schirmer@12854
   402
by (auto simp: conforms_def Let_def)
schirmer@12854
   403
schirmer@13688
   404
lemma conforms_localD: "(x, s)\<Colon>\<preceq>(G, L) \<Longrightarrow> G,s\<turnstile>locals s[\<sim>\<Colon>\<preceq>]L"
schirmer@12854
   405
by (auto simp: conforms_def Let_def)
schirmer@12854
   406
schirmer@12854
   407
lemma conforms_XcptLocD: "\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); x = Some (Xcpt (Loc a))\<rbrakk> \<Longrightarrow>  
wenzelm@32960
   408
          G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)"
schirmer@12854
   409
by (auto simp: conforms_def Let_def)
schirmer@12854
   410
schirmer@13688
   411
lemma conforms_RetD: "\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); x = Some (Jump Ret)\<rbrakk> \<Longrightarrow>  
wenzelm@32960
   412
          (locals s) Result \<noteq> None"
schirmer@13688
   413
by (auto simp: conforms_def Let_def)
schirmer@13688
   414
schirmer@12854
   415
lemma conforms_RefTD: 
schirmer@12854
   416
 "\<lbrakk>G,s\<turnstile>a'\<Colon>\<preceq>RefT t; a' \<noteq> Null; (x,s) \<Colon>\<preceq>(G, L)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   417
   \<exists>a obj. a' = Addr a \<and> globs s (Inl a) = Some obj \<and>  
schirmer@12854
   418
   G\<turnstile>obj_ty obj\<preceq>RefT t \<and> is_type G (obj_ty obj)"
schirmer@12854
   419
apply (drule_tac conf_RefTD)
schirmer@12854
   420
apply clarsimp
schirmer@12854
   421
apply (rule conforms_globsD [THEN oconf_is_type])
schirmer@12854
   422
apply auto
schirmer@12854
   423
done
schirmer@12854
   424
schirmer@12854
   425
lemma conforms_Jump [iff]:
schirmer@13688
   426
  "j=Ret \<longrightarrow> locals s Result \<noteq> None 
schirmer@13688
   427
   \<Longrightarrow> ((Some (Jump j), s)\<Colon>\<preceq>(G, L)) = (Norm s\<Colon>\<preceq>(G, L))"
schirmer@13688
   428
by (auto simp: conforms_def Let_def)
schirmer@12854
   429
schirmer@12854
   430
lemma conforms_StdXcpt [iff]: 
schirmer@12854
   431
  "((Some (Xcpt (Std xn)), s)\<Colon>\<preceq>(G, L)) = (Norm s\<Colon>\<preceq>(G, L))"
schirmer@12854
   432
by (auto simp: conforms_def)
schirmer@12854
   433
schirmer@12925
   434
lemma conforms_Err [iff]:
schirmer@12925
   435
   "((Some (Error e), s)\<Colon>\<preceq>(G, L)) = (Norm s\<Colon>\<preceq>(G, L))"
schirmer@12925
   436
  by (auto simp: conforms_def)  
schirmer@12925
   437
schirmer@12854
   438
lemma conforms_raise_if [iff]: 
schirmer@12854
   439
  "((raise_if c xn x, s)\<Colon>\<preceq>(G, L)) = ((x, s)\<Colon>\<preceq>(G, L))"
schirmer@12854
   440
by (auto simp: abrupt_if_def)
schirmer@12854
   441
schirmer@12925
   442
lemma conforms_error_if [iff]: 
schirmer@12925
   443
  "((error_if c err x, s)\<Colon>\<preceq>(G, L)) = ((x, s)\<Colon>\<preceq>(G, L))"
schirmer@12925
   444
by (auto simp: abrupt_if_def split: split_if)
schirmer@12854
   445
schirmer@12854
   446
lemma conforms_NormI: "(x, s)\<Colon>\<preceq>(G, L) \<Longrightarrow> Norm s\<Colon>\<preceq>(G, L)"
schirmer@12854
   447
by (auto simp: conforms_def Let_def)
schirmer@12854
   448
schirmer@12854
   449
lemma conforms_absorb [rule_format]:
schirmer@12854
   450
  "(a, b)\<Colon>\<preceq>(G, L) \<longrightarrow> (absorb j a, b)\<Colon>\<preceq>(G, L)"
schirmer@12854
   451
apply (rule impI)
schirmer@12854
   452
apply ( case_tac a)
schirmer@12854
   453
apply (case_tac "absorb j a")
schirmer@12854
   454
apply auto
schirmer@12854
   455
apply (case_tac "absorb j (Some a)",auto)
schirmer@12854
   456
apply (erule conforms_NormI)
schirmer@12854
   457
done
schirmer@12854
   458
schirmer@12854
   459
lemma conformsI: "\<lbrakk>\<forall>r. \<forall>obj\<in>globs s r: G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r;  
schirmer@13688
   460
     G,s\<turnstile>locals s[\<sim>\<Colon>\<preceq>]L;  
schirmer@13688
   461
     \<forall>a. x = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable);
schirmer@13688
   462
     x = Some (Jump Ret)\<longrightarrow> locals s Result \<noteq> None\<rbrakk> \<Longrightarrow> 
schirmer@12854
   463
  (x, s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   464
by (auto simp: conforms_def Let_def)
schirmer@12854
   465
schirmer@12854
   466
lemma conforms_xconf: "\<lbrakk>(x, s)\<Colon>\<preceq>(G,L);   
schirmer@13688
   467
 \<forall>a. x' = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable);
schirmer@13688
   468
     x' = Some (Jump Ret) \<longrightarrow> locals s Result \<noteq> None\<rbrakk> \<Longrightarrow> 
schirmer@12854
   469
 (x',s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   470
by (fast intro: conformsI elim: conforms_globsD conforms_localD)
schirmer@12854
   471
schirmer@12854
   472
lemma conforms_lupd: 
schirmer@12854
   473
 "\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); L vn = Some T; G,s\<turnstile>v\<Colon>\<preceq>T\<rbrakk> \<Longrightarrow> (x, lupd(vn\<mapsto>v)s)\<Colon>\<preceq>(G, L)"
schirmer@13688
   474
by (force intro: conformsI wlconf_upd dest: conforms_globsD conforms_localD 
schirmer@13688
   475
                                           conforms_XcptLocD conforms_RetD 
schirmer@13688
   476
          simp: oconf_def)
schirmer@12854
   477
schirmer@12854
   478
schirmer@13688
   479
lemmas conforms_allocL_aux = conforms_localD [THEN wlconf_ext]
schirmer@12854
   480
schirmer@12854
   481
lemma conforms_allocL: 
schirmer@12854
   482
  "\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); G,s\<turnstile>v\<Colon>\<preceq>T\<rbrakk> \<Longrightarrow> (x, lupd(vn\<mapsto>v)s)\<Colon>\<preceq>(G, L(vn\<mapsto>T))"
schirmer@13688
   483
by (force intro: conformsI dest: conforms_globsD conforms_RetD 
schirmer@13688
   484
          elim: conforms_XcptLocD  conforms_allocL_aux 
schirmer@13688
   485
          simp: oconf_def)
schirmer@12854
   486
schirmer@13688
   487
lemmas conforms_deallocL_aux = conforms_localD [THEN wlconf_deallocL]
schirmer@12854
   488
schirmer@12854
   489
lemma conforms_deallocL: "\<And>s.\<lbrakk>s\<Colon>\<preceq>(G, L(vn\<mapsto>T)); L vn = None\<rbrakk> \<Longrightarrow> s\<Colon>\<preceq>(G,L)"
schirmer@13688
   490
by (fast intro: conformsI dest: conforms_globsD conforms_RetD
schirmer@12854
   491
         elim: conforms_XcptLocD conforms_deallocL_aux)
schirmer@12854
   492
schirmer@12854
   493
lemma conforms_gext: "\<lbrakk>(x, s)\<Colon>\<preceq>(G,L); s\<le>|s';  
schirmer@12854
   494
  \<forall>r. \<forall>obj\<in>globs s' r: G,s'\<turnstile>obj\<Colon>\<preceq>\<surd>r;  
schirmer@12854
   495
   locals s'=locals s\<rbrakk> \<Longrightarrow> (x,s')\<Colon>\<preceq>(G,L)"
schirmer@13688
   496
apply (rule conformsI)
schirmer@13688
   497
apply     assumption
schirmer@13688
   498
apply    (drule conforms_localD) apply force
schirmer@13688
   499
apply   (intro strip)
schirmer@13688
   500
apply  (drule (1) conforms_XcptLocD) apply force 
schirmer@13688
   501
apply (intro strip)
schirmer@13688
   502
apply (drule (1) conforms_RetD) apply force
schirmer@13688
   503
done
schirmer@13688
   504
schirmer@12854
   505
schirmer@12854
   506
schirmer@12854
   507
lemma conforms_xgext: 
schirmer@13688
   508
  "\<lbrakk>(x ,s)\<Colon>\<preceq>(G,L); (x', s')\<Colon>\<preceq>(G, L); s'\<le>|s;dom (locals s') \<subseteq> dom (locals s)\<rbrakk> 
schirmer@13688
   509
   \<Longrightarrow> (x',s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   510
apply (erule_tac conforms_xconf)
schirmer@13688
   511
apply  (fast dest: conforms_XcptLocD)
schirmer@13688
   512
apply (intro strip)
schirmer@13688
   513
apply (drule (1) conforms_RetD) 
schirmer@13688
   514
apply (auto dest: domI)
schirmer@12854
   515
done
schirmer@12854
   516
schirmer@12854
   517
lemma conforms_gupd: "\<And>obj. \<lbrakk>(x, s)\<Colon>\<preceq>(G, L); G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r; s\<le>|gupd(r\<mapsto>obj)s\<rbrakk> 
schirmer@12854
   518
\<Longrightarrow>  (x, gupd(r\<mapsto>obj)s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   519
apply (rule conforms_gext)
schirmer@12854
   520
apply    auto
schirmer@12854
   521
apply (force dest: conforms_globsD simp add: oconf_def)+
schirmer@12854
   522
done
schirmer@12854
   523
schirmer@12854
   524
lemma conforms_upd_gobj: "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L); globs s r = Some obj; 
schirmer@12854
   525
  var_tys G (tag obj) r n = Some T; G,s\<turnstile>v\<Colon>\<preceq>T\<rbrakk> \<Longrightarrow> (x,upd_gobj r n v s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   526
apply (rule conforms_gext)
schirmer@12854
   527
apply auto
schirmer@12854
   528
apply (drule (1) conforms_globsD)
schirmer@12854
   529
apply (simp add: oconf_def)
schirmer@12854
   530
apply safe
schirmer@12854
   531
apply (rule lconf_upd)
schirmer@12854
   532
apply auto
schirmer@12854
   533
apply (simp only: obj_ty_cong) 
schirmer@12854
   534
apply (force dest: conforms_globsD intro!: lconf_upd 
schirmer@12854
   535
       simp add: oconf_def cong del: sum.weak_case_cong)
schirmer@12854
   536
done
schirmer@12854
   537
schirmer@12854
   538
lemma conforms_set_locals: 
schirmer@13688
   539
  "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L'); G,s\<turnstile>l[\<sim>\<Colon>\<preceq>]L; x=Some (Jump Ret) \<longrightarrow> l Result \<noteq> None\<rbrakk> 
schirmer@13688
   540
   \<Longrightarrow> (x,set_locals l s)\<Colon>\<preceq>(G,L)"
schirmer@13688
   541
apply (rule conformsI)
schirmer@13688
   542
apply     (intro strip)
schirmer@13688
   543
apply     simp
schirmer@13688
   544
apply     (drule (2) conforms_globsD)
schirmer@13688
   545
apply    simp
schirmer@13688
   546
apply   (intro strip)
schirmer@13688
   547
apply   (drule (1) conforms_XcptLocD)
schirmer@13688
   548
apply   simp
schirmer@13688
   549
apply (intro strip)
schirmer@13688
   550
apply (drule (1) conforms_RetD)
schirmer@13688
   551
apply simp
schirmer@12854
   552
done
schirmer@12854
   553
schirmer@13688
   554
lemma conforms_locals: 
schirmer@13688
   555
  "\<lbrakk>(a,b)\<Colon>\<preceq>(G, L); L x = Some T;locals b x \<noteq>None\<rbrakk>
schirmer@13688
   556
   \<Longrightarrow> G,b\<turnstile>the (locals b x)\<Colon>\<preceq>T"
schirmer@13688
   557
apply (force simp: conforms_def Let_def wlconf_def)
schirmer@12925
   558
done
schirmer@12925
   559
schirmer@13688
   560
lemma conforms_return: 
schirmer@13688
   561
"\<And>s'. \<lbrakk>(x,s)\<Colon>\<preceq>(G, L); (x',s')\<Colon>\<preceq>(G, L'); s\<le>|s';x'\<noteq>Some (Jump Ret)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   562
  (x',set_locals (locals s) s')\<Colon>\<preceq>(G, L)"
schirmer@12854
   563
apply (rule conforms_xconf)
schirmer@12854
   564
prefer 2 apply (force dest: conforms_XcptLocD)
schirmer@12854
   565
apply (erule conforms_gext)
schirmer@12854
   566
apply (force dest: conforms_globsD)+
schirmer@12854
   567
done
schirmer@12854
   568
schirmer@12925
   569
schirmer@12854
   570
end