@@ -2,20 +2,23 @@ From iris.heap_lang Require Export adequacy.
Fromtutorial_popl20RequireExportfundamental.
(** * Semantic and syntactic type safety *)
(** We prove that any _closed_ expression that is semantically typed is safe,
i.e., it does not crash. Based on this theorem we then prove _syntactic type
safety_, i.e., any _closed_ syntactically well-typed program is safe. Semantic
type safety is a consequence of Iris's adequacy theorem, and syntactic type
safety is a consequence of the fundamental theorem of logical relations together
with the safety for semantic typing. *)
(** We prove *semantic type safety*, which says that any _closed_ expression
that is semantically typed is safe, i.e., it does not crash. Based on this
theorem we then prove *syntactic type safety* as a corollary, i.e., any _closed_ syntactically well-typed program is safe. Semantic type safety is a consequence
of Iris's adequacy theorem, and syntactic type safety is a consequence of the
fundamental theorem together and semantic type safety. *)
(** ** Semantic type safety *)
(** The following lemma states that given a closed program [e], heap [σ], and
(** ** Semantic type safety *)
(** Before proving semantic type safety, we first prove a stronger lemma. We
use this lemma in the file [parametricity.v] to prove parametricity properties.
This stronger lemma states that given a closed program [e], heap [σ], and a
_Coq_ predicate [φ : val → Prop], if there is a semantic type [A] such that [A]
implies [φ], and [e] is semantically typed at type [A], then we have
[adequate NotStuck e σ (λ v σ, φ v)]. The proposition
[adequate NotStuck e σ (λ v σ, φ v)] means that [e], starting in heap [σ] does
not get stuck, and if [e] reduces to a value [v], we have [φ v]. *)
[adequate NotStuck e σ (λ v σ, φ v)].
The proposition [adequate NotStuck e σ (λ v σ, φ v)] (which is defined in the
Iris library) means that [e], starting in heap [σ] does not get stuck, and if
[e] reduces to a value [v], we have [φ v]. *)
Lemmasem_gen_type_safety`{!heapPreGΣ}eσφ:
(∀`{!heapGΣ},∃A:sem_tyΣ,(∀v,Av-∗⌜φv⌝)∧(∅⊨e:A)%I)→
adequateNotStuckeσ(λvσ,φv).
...
...
@@ -28,9 +31,9 @@ Proof.
byiIntros;iApplyHA.
Qed.
(** This lemma states that semantically typed closed programs do not get stuck.
It is a simple consequence of the lemma [sem_gen_type_safety] above. *)
Lemmasem_type_safety`{!heapPreGΣ}eσesσ'e':
(** The actual theorem for semantic type safety lemma states that semantically
typed closed programs do not get stuck. It is a simple consequence of the lemma [sem_gen_type_safety] above. *)
Theoremsem_type_safety`{!heapPreGΣ}eσesσ'e':
(∀`{!heapGΣ},∃A,(∅⊨e:A)%I)→
rtcerased_step([e],σ)(es,σ')→e'∈es→
is_Some(to_vale')∨reduciblee'σ'.
...
...
@@ -41,7 +44,9 @@ Proof.
Qed.
(** ** Syntactic type safety *)
Lemmatype_safetyeσesσ'e'τ:
(** Syntactic type safety is a consequence of the fundamental theorem together