Commit d7107cb8 authored by Ralf Jung's avatar Ralf Jung
Browse files

adjust solutions file syntax to be easier to use

parent b2b410d9
...@@ -111,12 +111,13 @@ macOS). ...@@ -111,12 +111,13 @@ macOS).
The syntax for the solution files is as follows: The syntax for the solution files is as follows:
``` ```
(* BEGIN SOLUTION *) (* SOLUTION *) Proof.
solution here. solution here.
(* END SOLUTION *) Qed.
``` ```
is replaced by is replaced by
``` ```
Proof.
(* exercise *) (* exercise *)
Admitted. Admitted.
``` ```
......
...@@ -2,12 +2,15 @@ BEGIN { ...@@ -2,12 +2,15 @@ BEGIN {
in_solution = 0; in_solution = 0;
} }
{ # on every line of the input { # on every line of the input
if (match($0, /^( *)\(\* *BEGIN SOLUTION *\*\)$/, groups)) { if (match($0, /^( *)\(\* *SOLUTION *\*\) *Proof.$/, groups)) {
print groups[1] "Proof."
in_solution = 1 in_solution = 1
} else if (match($0, /^( *)\(\* *END SOLUTION *\*\)$/, groups)) { } else if (in_solution == 1 && match($0, /^( *)Qed.$/, groups)) {
print groups[1] " (* exercise *)" print groups[1] " (* exercise *)"
print groups[1] "Admitted." print groups[1] "Admitted."
in_solution = 0 in_solution = 0
} else if (match($0, /^( *)\(\* *BEGIN SOLUTION *\*\)$/, groups)) {
in_solution = 1
} else if (match($0, /^( *)\(\* *END SOLUTION BEGIN TEMPLATE *$/, groups)) { } else if (match($0, /^( *)\(\* *END SOLUTION BEGIN TEMPLATE *$/, groups)) {
in_solution = 0 in_solution = 0
} else if (match($0, /^( *)END TEMPLATE *\*\)$/, groups)) { } else if (match($0, /^( *)END TEMPLATE *\*\)$/, groups)) {
......
...@@ -58,35 +58,28 @@ Section compatibility. ...@@ -58,35 +58,28 @@ Section compatibility.
iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures. iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures.
Qed. Qed.
Lemma Snd_sem_typed Γ e A1 A2 : Γ e : A1 * A2 - Γ Snd e : A2. Lemma Snd_sem_typed Γ e A1 A2 : Γ e : A1 * A2 - Γ Snd e : A2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H" (vs) "!# #HΓ /=". iIntros "#H" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H [//])"); iIntros (w). wp_apply (wp_wand with "(H [//])"); iIntros (w).
iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures. iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures.
Qed. Qed.
(* END SOLUTION *)
Lemma InjL_sem_typed Γ e A1 A2 : Γ e : A1 - Γ InjL e : A1 + A2. Lemma InjL_sem_typed Γ e A1 A2 : Γ e : A1 - Γ InjL e : A1 + A2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H" (vs) "!# #HΓ /=". iIntros "#H" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA".
wp_pures. iLeft. iExists w. auto. wp_pures. iLeft. iExists w. auto.
Qed. Qed.
(* END SOLUTION *)
Lemma InjR_sem_typed Γ e A1 A2 : Γ e : A2 - Γ InjR e : A1 + A2. Lemma InjR_sem_typed Γ e A1 A2 : Γ e : A2 - Γ InjR e : A1 + A2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H" (vs) "!# #HΓ /=". iIntros "#H" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA".
wp_pures. iRight. iExists w. auto. wp_pures. iRight. iExists w. auto.
Qed. Qed.
(* END SOLUTION *)
Lemma Case_sem_typed Γ e e1 e2 A1 A2 B : Lemma Case_sem_typed Γ e e1 e2 A1 A2 B :
Γ e : A1 + A2 - Γ e1 : (A1 B) - Γ e2 : (A2 B) - Γ e : A1 + A2 - Γ e1 : (A1 B) - Γ e2 : (A2 B) -
Γ Case e e1 e2 : B. Γ Case e e1 e2 : B.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H #H1 #H2" (vs) "!# #HΓ /=". iIntros "#H #H1 #H2" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H [//])"); iIntros (w) "#[HA|HA]". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#[HA|HA]".
- iDestruct "HA" as (w1 ->) "HA". wp_pures. - iDestruct "HA" as (w1 ->) "HA". wp_pures.
...@@ -94,7 +87,6 @@ Section compatibility. ...@@ -94,7 +87,6 @@ Section compatibility.
- iDestruct "HA" as (w2 ->) "HA". wp_pures. - iDestruct "HA" as (w2 ->) "HA". wp_pures.
wp_apply (wp_wand with "(H2 [//])"); iIntros (v) "#HAB". by iApply "HAB". wp_apply (wp_wand with "(H2 [//])"); iIntros (v) "#HAB". by iApply "HAB".
Qed. Qed.
(* END SOLUTION *)
(** * Functions *) (** * Functions *)
Lemma Rec_sem_typed Γ f x e A1 A2 : Lemma Rec_sem_typed Γ f x e A1 A2 :
...@@ -128,18 +120,15 @@ Section compatibility. ...@@ -128,18 +120,15 @@ Section compatibility.
Qed. Qed.
Lemma Pack_sem_typed Γ e C A : Γ e : C A - Γ (pack: e) : A, C A. Lemma Pack_sem_typed Γ e C A : Γ e : C A - Γ (pack: e) : A, C A.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H" (vs) "!# #HΓ /=". iIntros "#H" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HB". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HB".
wp_lam. by iExists A. wp_lam. by iExists A.
Qed. Qed.
(* END SOLUTION *)
Lemma Unpack_sem_typed Γ x e1 e2 C B : Lemma Unpack_sem_typed Γ x e1 e2 C B :
(Γ e1 : A, C A) - ( A, binder_insert x (C A) Γ e2 : B) - (Γ e1 : A, C A) - ( A, binder_insert x (C A) Γ e2 : B) -
Γ (unpack: x := e1 in e2) : B. Γ (unpack: x := e1 in e2) : B.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H1 #H2" (vs) "!# #HΓ /=". iIntros "#H1 #H2" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H1 [//])"); iIntros (v); iDestruct 1 as (A) "#HC". wp_apply (wp_wand with "(H1 [//])"); iIntros (v); iDestruct 1 as (A) "#HC".
rewrite /exist_unpack; wp_pures. rewrite -subst_map_binder_insert. rewrite /exist_unpack; wp_pures. rewrite -subst_map_binder_insert.
...@@ -147,7 +136,6 @@ Section compatibility. ...@@ -147,7 +136,6 @@ Section compatibility.
{ by iApply env_sem_typed_insert. } { by iApply env_sem_typed_insert. }
auto. auto.
Qed. Qed.
(* END SOLUTION *)
(** ** Heap operations *) (** ** Heap operations *)
Lemma Alloc_sem_typed Γ e A : Γ e : A - Γ ref e : ref A. Lemma Alloc_sem_typed Γ e A : Γ e : A - Γ ref e : ref A.
...@@ -168,31 +156,26 @@ Section compatibility. ...@@ -168,31 +156,26 @@ Section compatibility.
Qed. Qed.
Lemma Store_sem_typed Γ e1 e2 A : Lemma Store_sem_typed Γ e1 e2 A :
Γ e1 : ref A - Γ e2 : A - Γ (e1 <- e2) : (). Γ e1 : ref A - Γ e2 : A - Γ (e1 <- e2) : ().
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H1 #H2" (vs) "!# #HΓ /=". iIntros "#H1 #H2" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "#HA". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "#HA".
wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?". wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?".
iInv (tyN.@l) as (v) "[>Hl _]". wp_store. eauto 10. iInv (tyN.@l) as (v) "[>Hl _]". wp_store. eauto 10.
Qed. Qed.
(* END SOLUTION *)
Lemma FAA_sem_typed Γ e1 e2 : Lemma FAA_sem_typed Γ e1 e2 :
Γ e1 : ref sem_ty_int - Γ e2 : sem_ty_int - Γ FAA e1 e2 : sem_ty_int. Γ e1 : ref sem_ty_int - Γ e2 : sem_ty_int - Γ FAA e1 e2 : sem_ty_int.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H1 #H2" (vs) "!# #HΓ /=". iIntros "#H1 #H2" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H2 [//])"); iIntros (w2); iDestruct 1 as (n) "->". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2); iDestruct 1 as (n) "->".
wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?". wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?".
iInv (tyN.@l) as (v) "[>Hl Hv]"; iDestruct "Hv" as (n') "> ->". iInv (tyN.@l) as (v) "[>Hl Hv]"; iDestruct "Hv" as (n') "> ->".
wp_faa. iModIntro. eauto 10. wp_faa. iModIntro. eauto 10.
Qed. Qed.
(* END SOLUTION *)
Lemma CmpXchg_sem_typed Γ A e1 e2 e3 : Lemma CmpXchg_sem_typed Γ A e1 e2 e3 :
SemTyUnboxed A SemTyUnboxed A
Γ e1 : ref A - Γ e2 : A - Γ e3 : A - Γ e1 : ref A - Γ e2 : A - Γ e3 : A -
Γ CmpXchg e1 e2 e3 : A * sem_ty_bool. Γ CmpXchg e1 e2 e3 : A * sem_ty_bool.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros. iIntros "#H1 #H2 #H3" (vs) "!# #HΓ /=". intros. iIntros "#H1 #H2 #H3" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H3 [//])"); iIntros (w3) "HA3". wp_apply (wp_wand with "(H3 [//])"); iIntros (w3) "HA3".
wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "HA2". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "HA2".
...@@ -201,7 +184,6 @@ Section compatibility. ...@@ -201,7 +184,6 @@ Section compatibility.
iInv (tyN.@l) as (v) "[>Hl #Hv]". wp_cmpxchg as ?|?; iModIntro; iInv (tyN.@l) as (v) "[>Hl #Hv]". wp_cmpxchg as ?|?; iModIntro;
(iSplitL; [by eauto 12 with iFrame | iExists _, _; eauto]). (iSplitL; [by eauto 12 with iFrame | iExists _, _; eauto]).
Qed. Qed.
(* END SOLUTION *)
(** ** Operators *) (** ** Operators *)
Lemma UnOp_sem_typed Γ e op A B : Lemma UnOp_sem_typed Γ e op A B :
...@@ -213,34 +195,28 @@ Section compatibility. ...@@ -213,34 +195,28 @@ Section compatibility.
Qed. Qed.
Lemma BinOp_sem_typed Γ e1 e2 op A1 A2 B : Lemma BinOp_sem_typed Γ e1 e2 op A1 A2 B :
SemTyBinOp op A1 A2 B Γ e1 : A1 - Γ e2 : A2 - Γ BinOp op e1 e2 : B. SemTyBinOp op A1 A2 B Γ e1 : A1 - Γ e2 : A2 - Γ BinOp op e1 e2 : B.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros. iIntros "#H1 #H2" (vs) "!# #HΓ /=". intros. iIntros "#H1 #H2" (vs) "!# #HΓ /=".
wp_apply (wp_wand with "(H2 [//])"); iIntros (v2) "#HA2". wp_apply (wp_wand with "(H2 [//])"); iIntros (v2) "#HA2".
wp_apply (wp_wand with "(H1 [//])"); iIntros (v1) "#HA1". wp_apply (wp_wand with "(H1 [//])"); iIntros (v1) "#HA1".
iDestruct (sem_ty_bin_op with "HA1 HA2") as (w ?) "#HB". by wp_binop. iDestruct (sem_ty_bin_op with "HA1 HA2") as (w ?) "#HB". by wp_binop.
Qed. Qed.
(* END SOLUTION *)
Lemma If_sem_typed Γ e e1 e2 B : Lemma If_sem_typed Γ e e1 e2 B :
Γ e : sem_ty_bool - Γ e1 : B - Γ e2 : B - Γ e : sem_ty_bool - Γ e1 : B - Γ e2 : B -
Γ (if: e then e1 else e2) : B. Γ (if: e then e1 else e2) : B.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H #H1 #H2" (vs) "!# #HΓ /=". iIntros "#H #H1 #H2" (vs) "!# #HΓ /=".
iSpecialize ("H1" with "HΓ"). iSpecialize ("H2" with "HΓ"). iSpecialize ("H1" with "HΓ"). iSpecialize ("H2" with "HΓ").
wp_apply (wp_wand with "(H [//])"); iIntros (w). iDestruct 1 as ([]) "->"; by wp_if. wp_apply (wp_wand with "(H [//])"); iIntros (w). iDestruct 1 as ([]) "->"; by wp_if.
Qed. Qed.
(* END SOLUTION *)
(** ** Fork *) (** ** Fork *)
Lemma Fork_sem_typed Γ e : Γ e : () - Γ Fork e : (). Lemma Fork_sem_typed Γ e : Γ e : () - Γ Fork e : ().
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "#H" (vs) "!# #HΓ /=". iIntros "#H" (vs) "!# #HΓ /=".
wp_apply wp_fork; last done. by iApply (wp_wand with "(H [//])"). wp_apply wp_fork; last done. by iApply (wp_wand with "(H [//])").
Qed. Qed.
(* END SOLUTION *)
(** * Compatibility rules for value typing *) (** * Compatibility rules for value typing *)
(** ** Base types *) (** ** Base types *)
...@@ -249,11 +225,9 @@ Section compatibility. ...@@ -249,11 +225,9 @@ Section compatibility.
Lemma BoolV_sem_typed (b : bool) : #b : sem_ty_bool. Lemma BoolV_sem_typed (b : bool) : #b : sem_ty_bool.
Proof. by iExists b. Qed. Proof. by iExists b. Qed.
Lemma IntV_sem_typed (n : Z) : #n : sem_ty_int. Lemma IntV_sem_typed (n : Z) : #n : sem_ty_int.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
by iExists n. by iExists n.
Qed. Qed.
(* END SOLUTION *)
(** ** Products and sums *) (** ** Products and sums *)
Lemma PairV_sem_typed v1 v2 τ1 τ2 : Lemma PairV_sem_typed v1 v2 τ1 τ2 :
......
...@@ -233,11 +233,9 @@ You should prove this lemma. ...@@ -233,11 +233,9 @@ You should prove this lemma.
Hint: [wp_pures] also executes the [+] operator. Carefully check how it affects Hint: [wp_pures] also executes the [+] operator. Carefully check how it affects
the embedded [#] and convince yourself why that makes sense. *) the embedded [#] and convince yourself why that makes sense. *)
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros. rewrite /swap_and_add. do 2 wp_load. do 2 wp_store. by iFrame. iIntros. rewrite /swap_and_add. do 2 wp_load. do 2 wp_store. by iFrame.
Qed. Qed.
(* END SOLUTION *)
(** ** Reasoning about higher-order functions *) (** ** Reasoning about higher-order functions *)
(** For the next example, let us consider the higher-order function [twice]. (** For the next example, let us consider the higher-order function [twice].
...@@ -340,8 +338,7 @@ Lemma wp_add_two_ref `{!heapG Σ} l (x : Z) : ...@@ -340,8 +338,7 @@ Lemma wp_add_two_ref `{!heapG Σ} l (x : Z) :
about addition on [Z] (or the [replace] or [rewrite (_ : x = y)] tactic with about addition on [Z] (or the [replace] or [rewrite (_ : x = y)] tactic with
[lia]) to turn [2 + x] into [1 + (1 + x)]. Tactics like [replace] and [rewrite] [lia]) to turn [2 + x] into [1 + (1 + x)]. Tactics like [replace] and [rewrite]
work operate both on the MoSeL proof goal and the MoSeL proof context. *) work operate both on the MoSeL proof goal and the MoSeL proof context. *)
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "Hl". iIntros "Hl".
rewrite /add_two_ref. wp_pures. rewrite /add_two_ref. wp_pures.
iApply wp_twice. iApply wp_twice.
...@@ -351,7 +348,6 @@ Proof. ...@@ -351,7 +348,6 @@ Proof.
iFrame. iFrame.
auto. auto.
Qed. Qed.
(* END SOLUTION *)
(** ** Reasoning about higher-order state *) (** ** Reasoning about higher-order state *)
(** To see how Iris can be used to reason about higher-order state---that is, (** To see how Iris can be used to reason about higher-order state---that is,
...@@ -422,8 +418,7 @@ Definition add_two_fancy : val := λ: "x", ...@@ -422,8 +418,7 @@ Definition add_two_fancy : val := λ: "x",
Lemma wp_add_two_fancy `{!heapG Σ} (x : Z) : Lemma wp_add_two_fancy `{!heapG Σ} (x : Z) :
WP add_two_fancy #x {{ w, w = #(2 + x) }}. WP add_two_fancy #x {{ w, w = #(2 + x) }}.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
rewrite /add_two_fancy. wp_pures. rewrite /add_two_fancy. wp_pures.
wp_alloc lf as "Hlf". wp_alloc lf as "Hlf".
wp_alloc lx as "Hlx". wp_alloc lx as "Hlx".
...@@ -435,7 +430,6 @@ Proof. ...@@ -435,7 +430,6 @@ Proof.
wp_load. wp_load.
auto with f_equal lia. auto with f_equal lia.
Qed. Qed.
(* END SOLUTION *)
(** * Reasoning about "unsafe" programs *) (** * Reasoning about "unsafe" programs *)
(** Since HeapLang is an untyped language, we can write down arbitrary (** Since HeapLang is an untyped language, we can write down arbitrary
...@@ -466,12 +460,10 @@ Definition unsafe_ref : val := λ: <>, ...@@ -466,12 +460,10 @@ Definition unsafe_ref : val := λ: <>,
Lemma wp_unsafe_ref `{!heapG Σ} : Lemma wp_unsafe_ref `{!heapG Σ} :
WP unsafe_ref #() {{ v, v = #true }}. WP unsafe_ref #() {{ v, v = #true }}.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
rewrite /unsafe_ref. wp_pures. rewrite /unsafe_ref. wp_pures.
wp_alloc l. wp_alloc l.
wp_store. wp_store.
wp_load. wp_load.
auto. auto.
Qed. Qed.
(* END SOLUTION *)
...@@ -27,8 +27,7 @@ Section parametricity. ...@@ -27,8 +27,7 @@ Section parametricity.
( `{!heapG Σ}, e : A, A) ( `{!heapG Σ}, e : A, A)
rtc erased_step ([e <_>]%E, σ) (of_val w :: es, σ') rtc erased_step ([e <_>]%E, σ) (of_val w :: es, σ')
False. False.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
change False with ((λ _, False) w). change False with ((λ _, False) w).
apply sem_gen_type_safety with (φ := λ _, False)=> ?. apply sem_gen_type_safety with (φ := λ _, False)=> ?.
...@@ -41,14 +40,12 @@ Section parametricity. ...@@ -41,14 +40,12 @@ Section parametricity.
iIntros (u) "#Hu". iIntros (u) "#Hu".
iApply ("Hu" $! T). iApply ("Hu" $! T).
Qed. Qed.
(* END SOLUTION *)
(** * Exercise (boolean_param, moderate) *) (** * Exercise (boolean_param, moderate) *)
Lemma boolean_param `{!heapPreG Σ} e (v1 v2 : val) σ w es σ' : Lemma boolean_param `{!heapPreG Σ} e (v1 v2 : val) σ w es σ' :
( `{!heapG Σ}, e : A, A A A) ( `{!heapG Σ}, e : A, A A A)
rtc erased_step ([e <_> v1 v2]%E, σ) (of_val w :: es, σ') w = v1 w = v2. rtc erased_step ([e <_> v1 v2]%E, σ) (of_val w :: es, σ') w = v1 w = v2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
apply sem_gen_type_safety with (φ := λ w, w = v1 w = v2)=> ?. apply sem_gen_type_safety with (φ := λ w, w = v1 w = v2)=> ?.
pose (T := SemTy (λ w, w = v1 w = v2)%I : sem_ty Σ). pose (T := SemTy (λ w, w = v1 w = v2)%I : sem_ty Σ).
...@@ -65,15 +62,13 @@ Section parametricity. ...@@ -65,15 +62,13 @@ Section parametricity.
iIntros (w'') "#Hw''". iIntros (w'') "#Hw''".
iApply ("Hw''" $! v2). by iRight. iApply ("Hw''" $! v2). by iRight.
Qed. Qed.
(* END SOLUTION *)
(** * Exercise (nat_param, hard) *) (** * Exercise (nat_param, hard) *)
Lemma nat_param `{!heapPreG Σ} e σ w es σ' : Lemma nat_param `{!heapPreG Σ} e σ w es σ' :
( `{!heapG Σ}, e : A, (A A) A A) ( `{!heapG Σ}, e : A, (A A) A A)
rtc erased_step ([e <_> (λ: "n", "n" + #1)%V #0]%E, σ) rtc erased_step ([e <_> (λ: "n", "n" + #1)%V #0]%E, σ)
(of_val w :: es, σ') n : nat, w = #n. (of_val w :: es, σ') n : nat, w = #n.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
apply sem_gen_type_safety with (φ := λ w, n : nat, w = #n)=> ?. apply sem_gen_type_safety with (φ := λ w, n : nat, w = #n)=> ?.
set (T := SemTy (λ w, n : nat, w = #n)%I : sem_ty Σ). set (T := SemTy (λ w, n : nat, w = #n)%I : sem_ty Σ).
...@@ -94,7 +89,6 @@ Section parametricity. ...@@ -94,7 +89,6 @@ Section parametricity.
iApply ("Hw''" $! #0). iApply ("Hw''" $! #0).
by iExists 0%nat. by iExists 0%nat.
Qed. Qed.
(* END SOLUTION *)
(** * Exercise (strong_nat_param, hard) *) (** * Exercise (strong_nat_param, hard) *)
Lemma strong_nat_param `{!heapPreG Σ} e σ w es σ' (vf vz : val) φ : Lemma strong_nat_param `{!heapPreG Σ} e σ w es σ' (vf vz : val) φ :
...@@ -104,8 +98,7 @@ Section parametricity. ...@@ -104,8 +98,7 @@ Section parametricity.
( Φ vz) ( Φ vz)
( w, Φ w - ⌜φ w)) ( w, Φ w - ⌜φ w))
rtc erased_step ([e <_> vf vz]%E, σ) (of_val w :: es, σ') φ w. rtc erased_step ([e <_> vf vz]%E, σ) (of_val w :: es, σ') φ w.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
apply sem_gen_type_safety with (φ0 := φ)=> ?. apply sem_gen_type_safety with (φ0 := φ)=> ?.
set (T := SemTy (λ w, φ w )%I : sem_ty Σ). set (T := SemTy (λ w, φ w )%I : sem_ty Σ).
...@@ -126,5 +119,4 @@ Section parametricity. ...@@ -126,5 +119,4 @@ Section parametricity.
{ iApply "Hw''". iApply Hvz. } { iApply "Hw''". iApply Hvz. }
iIntros (v). by iApply Hφ. iIntros (v). by iApply Hφ.
Qed. Qed.
(* END SOLUTION *)
End parametricity. End parametricity.
...@@ -44,12 +44,10 @@ Lemma wp_swap_poly `{!heapG Σ} l1 l2 v1 v2 : ...@@ -44,12 +44,10 @@ Lemma wp_swap_poly `{!heapG Σ} l1 l2 v1 v2 :
l1 v1 - l1 v1 -
l2 v2 - l2 v2 -
WP swap_poly <_> #l1 #l2 {{ v, v = #() l1 v2 l2 v1 }}. WP swap_poly <_> #l1 #l2 {{ v, v = #() l1 v2 l2 v1 }}.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
iIntros "Hl1 Hl2". iIntros "Hl1 Hl2".
rewrite /swap_poly. rewrite /swap_poly.
do 2 wp_load. do 2 wp_load.
do 2 wp_store. do 2 wp_store.
by iFrame. by iFrame.
Qed. Qed.
(* END SOLUTION *)
...@@ -267,68 +267,57 @@ of them for both the expression construct and their value counterpart. *) ...@@ -267,68 +267,57 @@ of them for both the expression construct and their value counterpart. *)
Lemma Lam_typed Γ x e τ1 τ2 : Lemma Lam_typed Γ x e τ1 τ2 :
binder_insert x τ1 Γ e : τ2 binder_insert x τ1 Γ e : τ2
Γ (λ: x, e) : TArr τ1 τ2. Γ (λ: x, e) : TArr τ1 τ2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
apply Rec_typed. apply Rec_typed.
simpl. simpl.
done. done.
Qed. Qed.
(* END SOLUTION *)
Lemma LamV_typed x e τ1 τ2 : Lemma LamV_typed x e τ1 τ2 :
binder_insert x τ1 e : τ2 binder_insert x τ1 e : τ2
(λ: x, e) : TArr τ1 τ2. (λ: x, e) : TArr τ1 τ2.
Proof. (* SOLUTION *) Proof.
(* BEGIN SOLUTION *)
intros He. intros He.
apply RecV_typed. apply RecV_typed.
simpl.