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