src/HOL/Bali/Conform.thy
author schirmer
Mon Jan 28 17:00:19 2002 +0100 (2002-01-28)
changeset 12854 00d4a435777f
child 12857 a4386cc9b1c3
permissions -rw-r--r--
Isabelle/Bali sources;
schirmer@12854
     1
(*  Title:      isabelle/Bali/Conform.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
schirmer@12854
     4
    Copyright   1997 Technische Universitaet Muenchen
schirmer@12854
     5
*)
schirmer@12854
     6
schirmer@12854
     7
header {* Conformance notions for the type soundness proof for Java *}
schirmer@12854
     8
schirmer@12854
     9
theory Conform = State:
schirmer@12854
    10
schirmer@12854
    11
text {*
schirmer@12854
    12
design issues:
schirmer@12854
    13
\begin{itemize}
schirmer@12854
    14
\item lconf allows for (arbitrary) inaccessible values
schirmer@12854
    15
\item ''conforms'' does not directly imply that the dynamic types of all 
schirmer@12854
    16
      objects on the heap are indeed existing classes. Yet this can be 
schirmer@12854
    17
      inferred for all referenced objs.
schirmer@12854
    18
\end{itemize}
schirmer@12854
    19
*}
schirmer@12854
    20
schirmer@12854
    21
types	env_ = "prog \<times> (lname, ty) table" (* same as env of WellType.thy *)
schirmer@12854
    22
schirmer@12854
    23
schirmer@12854
    24
section "extension of global store"
schirmer@12854
    25
schirmer@12854
    26
constdefs
schirmer@12854
    27
schirmer@12854
    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@12854
    31
lemma gext_objD: 
schirmer@12854
    32
"\<lbrakk>s\<le>|s'; globs s r = Some obj\<rbrakk> 
schirmer@12854
    33
\<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj"
schirmer@12854
    34
apply (simp only: gext_def)
schirmer@12854
    35
by force
schirmer@12854
    36
schirmer@12854
    37
lemma rev_gext_objD: 
schirmer@12854
    38
"\<lbrakk>globs s r = Some obj; s\<le>|s'\<rbrakk> 
schirmer@12854
    39
 \<Longrightarrow> \<exists>obj'. globs s' r = Some obj' \<and> tag obj' = tag obj"
schirmer@12854
    40
by (auto elim: gext_objD)
schirmer@12854
    41
schirmer@12854
    42
lemma init_class_obj_inited: 
schirmer@12854
    43
   "init_class_obj G C s1\<le>|s2 \<Longrightarrow> inited C (globs s2)"
schirmer@12854
    44
apply (unfold inited_def init_obj_def)
schirmer@12854
    45
apply (auto dest!: gext_objD)
schirmer@12854
    46
done
schirmer@12854
    47
schirmer@12854
    48
lemma gext_refl [intro!, simp]: "s\<le>|s"
schirmer@12854
    49
apply (unfold gext_def)
schirmer@12854
    50
apply (fast del: fst_splitE)
schirmer@12854
    51
done
schirmer@12854
    52
schirmer@12854
    53
lemma gext_gupd [simp, elim!]: "\<And>s. globs s r = None \<Longrightarrow> s\<le>|gupd(r\<mapsto>x)s"
schirmer@12854
    54
by (auto simp: gext_def)
schirmer@12854
    55
schirmer@12854
    56
lemma gext_new [simp, elim!]: "\<And>s. globs s r = None \<Longrightarrow> s\<le>|init_obj G oi r s"
schirmer@12854
    57
apply (simp only: init_obj_def)
schirmer@12854
    58
apply (erule_tac gext_gupd)
schirmer@12854
    59
done
schirmer@12854
    60
schirmer@12854
    61
lemma gext_trans [elim]: "\<And>X. \<lbrakk>s\<le>|s'; s'\<le>|s''\<rbrakk> \<Longrightarrow> s\<le>|s''" 
schirmer@12854
    62
by (force simp: gext_def)
schirmer@12854
    63
schirmer@12854
    64
lemma gext_upd_gobj [intro!]: "s\<le>|upd_gobj r n v s"
schirmer@12854
    65
apply (simp only: gext_def)
schirmer@12854
    66
apply auto
schirmer@12854
    67
apply (case_tac "ra = r")
schirmer@12854
    68
apply auto
schirmer@12854
    69
apply (case_tac "globs s r = None")
schirmer@12854
    70
apply auto
schirmer@12854
    71
done
schirmer@12854
    72
schirmer@12854
    73
lemma gext_cong1 [simp]: "set_locals l s1\<le>|s2 = s1\<le>|s2"
schirmer@12854
    74
by (auto simp: gext_def)
schirmer@12854
    75
schirmer@12854
    76
lemma gext_cong2 [simp]: "s1\<le>|set_locals l s2 = s1\<le>|s2"
schirmer@12854
    77
by (auto simp: gext_def)
schirmer@12854
    78
schirmer@12854
    79
schirmer@12854
    80
lemma gext_lupd1 [simp]: "lupd(vn\<mapsto>v)s1\<le>|s2 = s1\<le>|s2"
schirmer@12854
    81
by (auto simp: gext_def)
schirmer@12854
    82
schirmer@12854
    83
lemma gext_lupd2 [simp]: "s1\<le>|lupd(vn\<mapsto>v)s2 = s1\<le>|s2"
schirmer@12854
    84
by (auto simp: gext_def)
schirmer@12854
    85
schirmer@12854
    86
schirmer@12854
    87
lemma inited_gext: "\<lbrakk>inited C (globs s); s\<le>|s'\<rbrakk> \<Longrightarrow> inited C (globs s')"
schirmer@12854
    88
apply (unfold inited_def)
schirmer@12854
    89
apply (auto dest: gext_objD)
schirmer@12854
    90
done
schirmer@12854
    91
schirmer@12854
    92
schirmer@12854
    93
section "value conformance"
schirmer@12854
    94
schirmer@12854
    95
constdefs
schirmer@12854
    96
schirmer@12854
    97
  conf  :: "prog \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ty \<Rightarrow> bool"    ("_,_\<turnstile>_\<Colon>\<preceq>_"   [71,71,71,71] 70)
schirmer@12854
    98
	   "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
    99
schirmer@12854
   100
lemma conf_cong [simp]: "G,set_locals l s\<turnstile>v\<Colon>\<preceq>T = G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   101
by (auto simp: conf_def)
schirmer@12854
   102
schirmer@12854
   103
lemma conf_lupd [simp]: "G,lupd(vn\<mapsto>va)s\<turnstile>v\<Colon>\<preceq>T = G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   104
by (auto simp: conf_def)
schirmer@12854
   105
schirmer@12854
   106
lemma conf_PrimT [simp]: "\<forall>dt. typeof dt v = Some (PrimT t) \<Longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>PrimT t"
schirmer@12854
   107
apply (simp add: conf_def)
schirmer@12854
   108
done
schirmer@12854
   109
schirmer@12854
   110
lemma conf_litval [rule_format (no_asm)]: 
schirmer@12854
   111
  "typeof (\<lambda>a. None) v = Some T \<longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   112
apply (unfold conf_def)
schirmer@12854
   113
apply (rule val.induct)
schirmer@12854
   114
apply auto
schirmer@12854
   115
done
schirmer@12854
   116
schirmer@12854
   117
lemma conf_Null [simp]: "G,s\<turnstile>Null\<Colon>\<preceq>T = G\<turnstile>NT\<preceq>T"
schirmer@12854
   118
by (simp add: conf_def)
schirmer@12854
   119
schirmer@12854
   120
lemma conf_Addr: 
schirmer@12854
   121
  "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
   122
by (auto simp: conf_def)
schirmer@12854
   123
schirmer@12854
   124
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
   125
apply (rule conf_Addr [THEN iffD2])
schirmer@12854
   126
by fast
schirmer@12854
   127
schirmer@12854
   128
lemma defval_conf [rule_format (no_asm), elim]: 
schirmer@12854
   129
  "is_type G T \<longrightarrow> G,s\<turnstile>default_val T\<Colon>\<preceq>T"
schirmer@12854
   130
apply (unfold conf_def)
schirmer@12854
   131
apply (induct "T")
schirmer@12854
   132
apply (auto intro: prim_ty.induct)
schirmer@12854
   133
done
schirmer@12854
   134
schirmer@12854
   135
lemma conf_widen [rule_format (no_asm), elim]: 
schirmer@12854
   136
  "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
   137
apply (unfold conf_def)
schirmer@12854
   138
apply (rule val.induct)
schirmer@12854
   139
apply (auto elim: ws_widen_trans)
schirmer@12854
   140
done
schirmer@12854
   141
schirmer@12854
   142
lemma conf_gext [rule_format (no_asm), elim]: 
schirmer@12854
   143
  "G,s\<turnstile>v\<Colon>\<preceq>T \<longrightarrow> s\<le>|s' \<longrightarrow> G,s'\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   144
apply (unfold gext_def conf_def)
schirmer@12854
   145
apply (rule val.induct)
schirmer@12854
   146
apply force+
schirmer@12854
   147
done
schirmer@12854
   148
schirmer@12854
   149
schirmer@12854
   150
lemma conf_list_widen [rule_format (no_asm)]: 
schirmer@12854
   151
"ws_prog G \<Longrightarrow>  
schirmer@12854
   152
  \<forall>Ts Ts'. list_all2 (conf G s) vs Ts 
schirmer@12854
   153
           \<longrightarrow>   G\<turnstile>Ts[\<preceq>] Ts' \<longrightarrow> list_all2 (conf G s) vs Ts'"
schirmer@12854
   154
apply (unfold widens_def)
schirmer@12854
   155
apply (rule list_all2_trans)
schirmer@12854
   156
apply auto
schirmer@12854
   157
done
schirmer@12854
   158
schirmer@12854
   159
lemma conf_RefTD [rule_format (no_asm)]: 
schirmer@12854
   160
 "G,s\<turnstile>a'\<Colon>\<preceq>RefT T 
schirmer@12854
   161
  \<longrightarrow> a' = Null \<or> (\<exists>a obj T'. a' = Addr a \<and> heap s a = Some obj \<and>  
schirmer@12854
   162
                    obj_ty obj = T' \<and> G\<turnstile>T'\<preceq>RefT T)"
schirmer@12854
   163
apply (unfold conf_def)
schirmer@12854
   164
apply (induct_tac "a'")
schirmer@12854
   165
apply (auto dest: widen_PrimT)
schirmer@12854
   166
done
schirmer@12854
   167
schirmer@12854
   168
schirmer@12854
   169
section "value list conformance"
schirmer@12854
   170
schirmer@12854
   171
constdefs
schirmer@12854
   172
schirmer@12854
   173
  lconf :: "prog \<Rightarrow> st \<Rightarrow> ('a, val) table \<Rightarrow> ('a, ty) table \<Rightarrow> bool"
schirmer@12854
   174
                                                ("_,_\<turnstile>_[\<Colon>\<preceq>]_" [71,71,71,71] 70)
schirmer@12854
   175
           "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
   176
schirmer@12854
   177
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
   178
by (force simp: lconf_def)
schirmer@12854
   179
schirmer@12854
   180
schirmer@12854
   181
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
   182
by (auto simp: lconf_def)
schirmer@12854
   183
schirmer@12854
   184
lemma lconf_lupd [simp]: "G,lupd(vn\<mapsto>v)s\<turnstile>l[\<Colon>\<preceq>]L = G,s\<turnstile>l[\<Colon>\<preceq>]L"
schirmer@12854
   185
by (auto simp: lconf_def)
schirmer@12854
   186
schirmer@12854
   187
(* unused *)
schirmer@12854
   188
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
   189
by (auto simp: lconf_def)
schirmer@12854
   190
schirmer@12854
   191
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
   192
  G,s\<turnstile>l(vn\<mapsto>v)[\<Colon>\<preceq>]L"
schirmer@12854
   193
by (auto simp: lconf_def)
schirmer@12854
   194
schirmer@12854
   195
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
   196
by (auto simp: lconf_def)
schirmer@12854
   197
schirmer@12854
   198
lemma lconf_map_sum [simp]: 
schirmer@12854
   199
 "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
   200
apply (unfold lconf_def)
schirmer@12854
   201
apply safe
schirmer@12854
   202
apply (case_tac [3] "n")
schirmer@12854
   203
apply (force split add: sum.split)+
schirmer@12854
   204
done
schirmer@12854
   205
schirmer@12854
   206
lemma lconf_ext_list [rule_format (no_asm)]: "
schirmer@12854
   207
 \<And>X. \<lbrakk>G,s\<turnstile>l[\<Colon>\<preceq>]L\<rbrakk> \<Longrightarrow> 
schirmer@12854
   208
      \<forall>vs Ts. nodups vns \<longrightarrow> length Ts = length vns 
schirmer@12854
   209
      \<longrightarrow> list_all2 (conf G s) vs Ts \<longrightarrow> G,s\<turnstile>l(vns[\<mapsto>]vs)[\<Colon>\<preceq>]L(vns[\<mapsto>]Ts)"
schirmer@12854
   210
apply (unfold lconf_def)
schirmer@12854
   211
apply (induct_tac "vns")
schirmer@12854
   212
apply  clarsimp
schirmer@12854
   213
apply clarsimp
schirmer@12854
   214
apply (frule list_all2_lengthD)
schirmer@12854
   215
apply clarsimp
schirmer@12854
   216
done
schirmer@12854
   217
schirmer@12854
   218
schirmer@12854
   219
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
   220
apply (simp only: lconf_def)
schirmer@12854
   221
apply safe
schirmer@12854
   222
apply (drule spec)
schirmer@12854
   223
apply (drule ospec)
schirmer@12854
   224
apply auto
schirmer@12854
   225
done 
schirmer@12854
   226
schirmer@12854
   227
schirmer@12854
   228
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
   229
apply (simp only: lconf_def)
schirmer@12854
   230
apply fast
schirmer@12854
   231
done
schirmer@12854
   232
schirmer@12854
   233
lemma lconf_empty [simp, intro!]: "G,s\<turnstile>vs[\<Colon>\<preceq>]empty"
schirmer@12854
   234
apply (unfold lconf_def)
schirmer@12854
   235
apply force
schirmer@12854
   236
done
schirmer@12854
   237
schirmer@12854
   238
lemma lconf_init_vals [intro!]: 
schirmer@12854
   239
	" \<forall>n. \<forall>T\<in>fs n:is_type G T \<Longrightarrow> G,s\<turnstile>init_vals fs[\<Colon>\<preceq>]fs"
schirmer@12854
   240
apply (unfold lconf_def)
schirmer@12854
   241
apply force
schirmer@12854
   242
done
schirmer@12854
   243
schirmer@12854
   244
schirmer@12854
   245
section "object conformance"
schirmer@12854
   246
schirmer@12854
   247
constdefs
schirmer@12854
   248
schirmer@12854
   249
  oconf :: "prog \<Rightarrow> st \<Rightarrow> obj \<Rightarrow> oref \<Rightarrow> bool"  ("_,_\<turnstile>_\<Colon>\<preceq>\<surd>_"  [71,71,71,71] 70)
schirmer@12854
   250
	   "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
   251
                           (case r of 
schirmer@12854
   252
		              Heap a \<Rightarrow> is_type G (obj_ty obj) 
schirmer@12854
   253
                            | Stat C \<Rightarrow> True)"
schirmer@12854
   254
(*
schirmer@12854
   255
lemma oconf_def2:  "G,s\<turnstile>\<lparr>tag=oi,values=fs\<rparr>\<Colon>\<preceq>\<surd>r =  
schirmer@12854
   256
  (G,s\<turnstile>fs[\<Colon>\<preceq>]var_tys G oi r \<and> 
schirmer@12854
   257
  (case r of Heap a \<Rightarrow> is_type G (obj_ty \<lparr>tag=oi,values=fs\<rparr>) | Stat C \<Rightarrow> True))"
schirmer@12854
   258
by (simp add: oconf_def Let_def)
schirmer@12854
   259
*)
schirmer@12854
   260
(*
schirmer@12854
   261
lemma oconf_def2:  "G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r =  
schirmer@12854
   262
  (G,s\<turnstile>values obj[\<Colon>\<preceq>]var_tys G (tag obj) r \<and> 
schirmer@12854
   263
  (case r of Heap a \<Rightarrow> is_type G (obj_ty obj) | Stat C \<Rightarrow> True))"
schirmer@12854
   264
by (simp add: oconf_def Let_def)
schirmer@12854
   265
*)
schirmer@12854
   266
lemma oconf_is_type: "G,s\<turnstile>obj\<Colon>\<preceq>\<surd>Heap a \<Longrightarrow> is_type G (obj_ty obj)"
schirmer@12854
   267
by (auto simp: oconf_def Let_def)
schirmer@12854
   268
schirmer@12854
   269
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
   270
by (simp add: oconf_def) 
schirmer@12854
   271
schirmer@12854
   272
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
   273
by (auto simp: oconf_def Let_def)
schirmer@12854
   274
schirmer@12854
   275
lemma oconf_init_obj_lemma: 
schirmer@12854
   276
"\<lbrakk>\<And>C c. class G C = Some c \<Longrightarrow> unique (DeclConcepts.fields G C);  
schirmer@12854
   277
  \<And>C c f fld. \<lbrakk>class G C = Some c; 
schirmer@12854
   278
                table_of (DeclConcepts.fields G C) f = Some fld \<rbrakk> 
schirmer@12854
   279
            \<Longrightarrow> is_type G (type fld);  
schirmer@12854
   280
  (case r of 
schirmer@12854
   281
     Heap a \<Rightarrow> is_type G (obj_ty obj) 
schirmer@12854
   282
  | Stat C \<Rightarrow> is_class G C)
schirmer@12854
   283
\<rbrakk> \<Longrightarrow>  G,s\<turnstile>obj \<lparr>values:=init_vals (var_tys G (tag obj) r)\<rparr>\<Colon>\<preceq>\<surd>r"
schirmer@12854
   284
apply (auto simp add: oconf_def)
schirmer@12854
   285
apply (drule_tac var_tys_Some_eq [THEN iffD1]) 
schirmer@12854
   286
defer
schirmer@12854
   287
apply (subst obj_ty_cong)
schirmer@12854
   288
apply(auto dest!: fields_table_SomeD obj_ty_CInst1 obj_ty_Arr1
schirmer@12854
   289
           split add: sum.split_asm obj_tag.split_asm)
schirmer@12854
   290
done
schirmer@12854
   291
schirmer@12854
   292
(*
schirmer@12854
   293
lemma oconf_init_obj_lemma: 
schirmer@12854
   294
"\<lbrakk>\<And>C c. class G C = Some c \<Longrightarrow> unique (fields G C);  
schirmer@12854
   295
  \<And>C c f fld. \<lbrakk>class G C = Some c; table_of (fields G C) f = Some fld \<rbrakk> 
schirmer@12854
   296
            \<Longrightarrow> is_type G (type fld);  
schirmer@12854
   297
  (case r of 
schirmer@12854
   298
     Heap a \<Rightarrow> is_type G (obj_ty \<lparr>tag=oi,values=fs\<rparr>) 
schirmer@12854
   299
  | Stat C \<Rightarrow> is_class G C)
schirmer@12854
   300
\<rbrakk> \<Longrightarrow>  G,s\<turnstile>\<lparr>tag=oi, values=init_vals (var_tys G oi r)\<rparr>\<Colon>\<preceq>\<surd>r"
schirmer@12854
   301
apply (auto simp add: oconf_def)
schirmer@12854
   302
apply (drule_tac var_tys_Some_eq [THEN iffD1]) 
schirmer@12854
   303
defer
schirmer@12854
   304
apply (subst obj_ty_eq)
schirmer@12854
   305
apply(auto dest!: fields_table_SomeD split add: sum.split_asm obj_tag.split_asm)
schirmer@12854
   306
done
schirmer@12854
   307
*)
schirmer@12854
   308
schirmer@12854
   309
schirmer@12854
   310
section "state conformance"
schirmer@12854
   311
schirmer@12854
   312
constdefs
schirmer@12854
   313
schirmer@12854
   314
  conforms :: "state \<Rightarrow> env_ \<Rightarrow> bool"          (     "_\<Colon>\<preceq>_"   [71,71]      70)
schirmer@12854
   315
   "xs\<Colon>\<preceq>E \<equiv> let (G, L) = E; s = snd xs; l = locals s in
schirmer@12854
   316
      (\<forall>r. \<forall>obj\<in>globs s r:           G,s\<turnstile>obj   \<Colon>\<preceq>\<surd>r) \<and>
schirmer@12854
   317
                  \<spacespace>                   G,s\<turnstile>l    [\<Colon>\<preceq>]L\<spacespace> \<and>
schirmer@12854
   318
      (\<forall>a. fst xs=Some(Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable))"
schirmer@12854
   319
schirmer@12854
   320
section "conforms"
schirmer@12854
   321
schirmer@12854
   322
lemma conforms_globsD: 
schirmer@12854
   323
"\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); globs s r = Some obj\<rbrakk> \<Longrightarrow> G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r"
schirmer@12854
   324
by (auto simp: conforms_def Let_def)
schirmer@12854
   325
schirmer@12854
   326
lemma conforms_localD: "(x, s)\<Colon>\<preceq>(G, L) \<Longrightarrow> G,s\<turnstile>locals s[\<Colon>\<preceq>]L"
schirmer@12854
   327
by (auto simp: conforms_def Let_def)
schirmer@12854
   328
schirmer@12854
   329
lemma conforms_XcptLocD: "\<lbrakk>(x, s)\<Colon>\<preceq>(G, L); x = Some (Xcpt (Loc a))\<rbrakk> \<Longrightarrow>  
schirmer@12854
   330
	  G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)"
schirmer@12854
   331
by (auto simp: conforms_def Let_def)
schirmer@12854
   332
schirmer@12854
   333
lemma conforms_RefTD: 
schirmer@12854
   334
 "\<lbrakk>G,s\<turnstile>a'\<Colon>\<preceq>RefT t; a' \<noteq> Null; (x,s) \<Colon>\<preceq>(G, L)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   335
   \<exists>a obj. a' = Addr a \<and> globs s (Inl a) = Some obj \<and>  
schirmer@12854
   336
   G\<turnstile>obj_ty obj\<preceq>RefT t \<and> is_type G (obj_ty obj)"
schirmer@12854
   337
apply (drule_tac conf_RefTD)
schirmer@12854
   338
apply clarsimp
schirmer@12854
   339
apply (rule conforms_globsD [THEN oconf_is_type])
schirmer@12854
   340
apply auto
schirmer@12854
   341
done
schirmer@12854
   342
schirmer@12854
   343
lemma conforms_Jump [iff]:
schirmer@12854
   344
  "((Some (Jump j), s)\<Colon>\<preceq>(G, L)) = (Norm s\<Colon>\<preceq>(G, L))"
schirmer@12854
   345
by (auto simp: conforms_def)
schirmer@12854
   346
schirmer@12854
   347
lemma conforms_StdXcpt [iff]: 
schirmer@12854
   348
  "((Some (Xcpt (Std xn)), s)\<Colon>\<preceq>(G, L)) = (Norm s\<Colon>\<preceq>(G, L))"
schirmer@12854
   349
by (auto simp: conforms_def)
schirmer@12854
   350
schirmer@12854
   351
lemma conforms_raise_if [iff]: 
schirmer@12854
   352
  "((raise_if c xn x, s)\<Colon>\<preceq>(G, L)) = ((x, s)\<Colon>\<preceq>(G, L))"
schirmer@12854
   353
by (auto simp: abrupt_if_def)
schirmer@12854
   354
schirmer@12854
   355
schirmer@12854
   356
lemma conforms_NormI: "(x, s)\<Colon>\<preceq>(G, L) \<Longrightarrow> Norm s\<Colon>\<preceq>(G, L)"
schirmer@12854
   357
by (auto simp: conforms_def Let_def)
schirmer@12854
   358
schirmer@12854
   359
schirmer@12854
   360
lemma conforms_absorb [rule_format]:
schirmer@12854
   361
  "(a, b)\<Colon>\<preceq>(G, L) \<longrightarrow> (absorb j a, b)\<Colon>\<preceq>(G, L)"
schirmer@12854
   362
apply (rule impI)
schirmer@12854
   363
apply ( case_tac a)
schirmer@12854
   364
apply (case_tac "absorb j a")
schirmer@12854
   365
apply auto
schirmer@12854
   366
apply (case_tac "absorb j (Some a)",auto)
schirmer@12854
   367
apply (erule conforms_NormI)
schirmer@12854
   368
done
schirmer@12854
   369
schirmer@12854
   370
lemma conformsI: "\<lbrakk>\<forall>r. \<forall>obj\<in>globs s r: G,s\<turnstile>obj\<Colon>\<preceq>\<surd>r;  
schirmer@12854
   371
     G,s\<turnstile>locals s[\<Colon>\<preceq>]L;  
schirmer@12854
   372
     \<forall>a. x = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)\<rbrakk> \<Longrightarrow> 
schirmer@12854
   373
  (x, s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   374
by (auto simp: conforms_def Let_def)
schirmer@12854
   375
schirmer@12854
   376
lemma conforms_xconf: "\<lbrakk>(x, s)\<Colon>\<preceq>(G,L);   
schirmer@12854
   377
 \<forall>a. x' = Some (Xcpt (Loc a)) \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq> Class (SXcpt Throwable)\<rbrakk> \<Longrightarrow> 
schirmer@12854
   378
 (x',s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   379
by (fast intro: conformsI elim: conforms_globsD conforms_localD)
schirmer@12854
   380
schirmer@12854
   381
lemma conforms_lupd: 
schirmer@12854
   382
 "\<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@12854
   383
by (force intro: conformsI lconf_upd dest: conforms_globsD conforms_localD 
schirmer@12854
   384
                                           conforms_XcptLocD simp: oconf_def)
schirmer@12854
   385
schirmer@12854
   386
schirmer@12854
   387
lemmas conforms_allocL_aux = conforms_localD [THEN lconf_ext]
schirmer@12854
   388
schirmer@12854
   389
lemma conforms_allocL: 
schirmer@12854
   390
  "\<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@12854
   391
by (force intro: conformsI dest: conforms_globsD 
schirmer@12854
   392
          elim: conforms_XcptLocD conforms_allocL_aux simp: oconf_def)
schirmer@12854
   393
schirmer@12854
   394
lemmas conforms_deallocL_aux = conforms_localD [THEN lconf_deallocL]
schirmer@12854
   395
schirmer@12854
   396
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@12854
   397
by (fast intro: conformsI dest: conforms_globsD 
schirmer@12854
   398
         elim: conforms_XcptLocD conforms_deallocL_aux)
schirmer@12854
   399
schirmer@12854
   400
lemma conforms_gext: "\<lbrakk>(x, s)\<Colon>\<preceq>(G,L); s\<le>|s';  
schirmer@12854
   401
  \<forall>r. \<forall>obj\<in>globs s' r: G,s'\<turnstile>obj\<Colon>\<preceq>\<surd>r;  
schirmer@12854
   402
   locals s'=locals s\<rbrakk> \<Longrightarrow> (x,s')\<Colon>\<preceq>(G,L)"
schirmer@12854
   403
by (force intro!: conformsI dest: conforms_localD conforms_XcptLocD)
schirmer@12854
   404
schirmer@12854
   405
schirmer@12854
   406
lemma conforms_xgext: 
schirmer@12854
   407
  "\<lbrakk>(x ,s)\<Colon>\<preceq>(G,L); (x', s')\<Colon>\<preceq>(G, L); s'\<le>|s\<rbrakk> \<Longrightarrow> (x',s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   408
apply (erule_tac conforms_xconf)
schirmer@12854
   409
apply (fast dest: conforms_XcptLocD)
schirmer@12854
   410
done
schirmer@12854
   411
schirmer@12854
   412
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
   413
\<Longrightarrow>  (x, gupd(r\<mapsto>obj)s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   414
apply (rule conforms_gext)
schirmer@12854
   415
apply    auto
schirmer@12854
   416
apply (force dest: conforms_globsD simp add: oconf_def)+
schirmer@12854
   417
done
schirmer@12854
   418
schirmer@12854
   419
lemma conforms_upd_gobj: "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L); globs s r = Some obj; 
schirmer@12854
   420
  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
   421
apply (rule conforms_gext)
schirmer@12854
   422
apply auto
schirmer@12854
   423
apply (drule (1) conforms_globsD)
schirmer@12854
   424
apply (simp add: oconf_def)
schirmer@12854
   425
apply safe
schirmer@12854
   426
apply (rule lconf_upd)
schirmer@12854
   427
apply auto
schirmer@12854
   428
apply (simp only: obj_ty_cong) 
schirmer@12854
   429
apply (force dest: conforms_globsD intro!: lconf_upd 
schirmer@12854
   430
       simp add: oconf_def cong del: sum.weak_case_cong)
schirmer@12854
   431
done
schirmer@12854
   432
schirmer@12854
   433
lemma conforms_set_locals: 
schirmer@12854
   434
  "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L'); G,s\<turnstile>l[\<Colon>\<preceq>]L\<rbrakk> \<Longrightarrow> (x,set_locals l s)\<Colon>\<preceq>(G,L)"
schirmer@12854
   435
apply (auto intro!: conformsI dest: conforms_globsD 
schirmer@12854
   436
            elim!: conforms_XcptLocD simp add: oconf_def)
schirmer@12854
   437
done
schirmer@12854
   438
schirmer@12854
   439
lemma conforms_return: "\<And>s'. \<lbrakk>(x,s)\<Colon>\<preceq>(G, L); (x',s')\<Colon>\<preceq>(G, L'); s\<le>|s'\<rbrakk> \<Longrightarrow>  
schirmer@12854
   440
  (x',set_locals (locals s) s')\<Colon>\<preceq>(G, L)"
schirmer@12854
   441
apply (rule conforms_xconf)
schirmer@12854
   442
prefer 2 apply (force dest: conforms_XcptLocD)
schirmer@12854
   443
apply (erule conforms_gext)
schirmer@12854
   444
apply (force dest: conforms_globsD)+
schirmer@12854
   445
done
schirmer@12854
   446
schirmer@12854
   447
end