Commit d7107cb8 by Ralf Jung

### adjust solutions file syntax to be easier to use

parent b2b410d9
 ... ... @@ -111,12 +111,13 @@ macOS). The syntax for the solution files is as follows: ``` (* BEGIN SOLUTION *) (* SOLUTION *) Proof. solution here. (* END SOLUTION *) Qed. ``` is replaced by ``` Proof. (* exercise *) Admitted. ``` ... ...
 ... ... @@ -2,12 +2,15 @@ BEGIN { in_solution = 0; } { # 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 } else if (match(\$0, /^( *)\(\* *END SOLUTION *\*\)\$/, groups)) { } else if (in_solution == 1 && match(\$0, /^( *)Qed.\$/, groups)) { print groups[1] " (* exercise *)" print groups[1] "Admitted." in_solution = 0 } else if (match(\$0, /^( *)\(\* *BEGIN SOLUTION *\*\)\$/, groups)) { in_solution = 1 } else if (match(\$0, /^( *)\(\* *END SOLUTION BEGIN TEMPLATE *\$/, groups)) { in_solution = 0 } else if (match(\$0, /^( *)END TEMPLATE *\*\)\$/, groups)) { ... ...
 ... ... @@ -58,35 +58,28 @@ Section compatibility. iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures. Qed. Lemma Snd_sem_typed Γ e A1 A2 : Γ ⊨ e : A1 * A2 -∗ Γ ⊨ Snd e : A2. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H [//])"); iIntros (w). iDestruct 1 as (w1 w2 ->) "[??]". by wp_pures. Qed. (* END SOLUTION *) Lemma InjL_sem_typed Γ e A1 A2 : Γ ⊨ e : A1 -∗ Γ ⊨ InjL e : A1 + A2. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA". wp_pures. iLeft. iExists w. auto. Qed. (* END SOLUTION *) Lemma InjR_sem_typed Γ e A1 A2 : Γ ⊨ e : A2 -∗ Γ ⊨ InjR e : A1 + A2. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HA". wp_pures. iRight. iExists w. auto. Qed. (* END SOLUTION *) Lemma Case_sem_typed Γ e e1 e2 A1 A2 B : Γ ⊨ e : A1 + A2 -∗ Γ ⊨ e1 : (A1 → B) -∗ Γ ⊨ e2 : (A2 → B) -∗ Γ ⊨ Case e e1 e2 : B. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H #H1 #H2" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#[HA|HA]". - iDestruct "HA" as (w1 ->) "HA". wp_pures. ... ... @@ -94,7 +87,6 @@ Section compatibility. - iDestruct "HA" as (w2 ->) "HA". wp_pures. wp_apply (wp_wand with "(H2 [//])"); iIntros (v) "#HAB". by iApply "HAB". Qed. (* END SOLUTION *) (** * Functions *) Lemma Rec_sem_typed Γ f x e A1 A2 : ... ... @@ -128,18 +120,15 @@ Section compatibility. Qed. Lemma Pack_sem_typed Γ e C A : Γ ⊨ e : C A -∗ Γ ⊨ (pack: e) : ∃ A, C A. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H [//])"); iIntros (w) "#HB". wp_lam. by iExists A. Qed. (* END SOLUTION *) Lemma Unpack_sem_typed Γ x e1 e2 C B : (Γ ⊨ e1 : ∃ A, C A) -∗ (∀ A, binder_insert x (C A) Γ ⊨ e2 : B) -∗ Γ ⊨ (unpack: x := e1 in e2) : B. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H1 #H2" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H1 [//])"); iIntros (v); iDestruct 1 as (A) "#HC". rewrite /exist_unpack; wp_pures. rewrite -subst_map_binder_insert. ... ... @@ -147,7 +136,6 @@ Section compatibility. { by iApply env_sem_typed_insert. } auto. Qed. (* END SOLUTION *) (** ** Heap operations *) Lemma Alloc_sem_typed Γ e A : Γ ⊨ e : A -∗ Γ ⊨ ref e : ref A. ... ... @@ -168,31 +156,26 @@ Section compatibility. Qed. Lemma Store_sem_typed Γ e1 e2 A : Γ ⊨ e1 : ref A -∗ Γ ⊨ e2 : A -∗ Γ ⊨ (e1 <- e2) : (). Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H1 #H2" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "#HA". wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?". iInv (tyN.@l) as (v) "[>Hl _]". wp_store. eauto 10. Qed. (* END SOLUTION *) Lemma FAA_sem_typed Γ e1 e2 : Γ ⊨ e1 : ref sem_ty_int -∗ Γ ⊨ e2 : sem_ty_int -∗ Γ ⊨ FAA e1 e2 : sem_ty_int. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H1 #H2" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2); iDestruct 1 as (n) "->". wp_apply (wp_wand with "(H1 [//])"); iIntros (w1); iDestruct 1 as (l ->) "#?". iInv (tyN.@l) as (v) "[>Hl Hv]"; iDestruct "Hv" as (n') "> ->". wp_faa. iModIntro. eauto 10. Qed. (* END SOLUTION *) Lemma CmpXchg_sem_typed Γ A e1 e2 e3 : SemTyUnboxed A → Γ ⊨ e1 : ref A -∗ Γ ⊨ e2 : A -∗ Γ ⊨ e3 : A -∗ Γ ⊨ CmpXchg e1 e2 e3 : A * sem_ty_bool. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. intros. iIntros "#H1 #H2 #H3" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H3 [//])"); iIntros (w3) "HA3". wp_apply (wp_wand with "(H2 [//])"); iIntros (w2) "HA2". ... ... @@ -201,7 +184,6 @@ Section compatibility. iInv (tyN.@l) as (v) "[>Hl #Hv]". wp_cmpxchg as ?|?; iModIntro; (iSplitL; [by eauto 12 with iFrame | iExists _, _; eauto]). Qed. (* END SOLUTION *) (** ** Operators *) Lemma UnOp_sem_typed Γ e op A B : ... ... @@ -213,34 +195,28 @@ Section compatibility. Qed. Lemma BinOp_sem_typed Γ e1 e2 op A1 A2 B : SemTyBinOp op A1 A2 B → Γ ⊨ e1 : A1 -∗ Γ ⊨ e2 : A2 -∗ Γ ⊨ BinOp op e1 e2 : B. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. intros. iIntros "#H1 #H2" (vs) "!# #HΓ /=". wp_apply (wp_wand with "(H2 [//])"); iIntros (v2) "#HA2". wp_apply (wp_wand with "(H1 [//])"); iIntros (v1) "#HA1". iDestruct (sem_ty_bin_op with "HA1 HA2") as (w ?) "#HB". by wp_binop. Qed. (* END SOLUTION *) Lemma If_sem_typed Γ e e1 e2 B : Γ ⊨ e : sem_ty_bool -∗ Γ ⊨ e1 : B -∗ Γ ⊨ e2 : B -∗ Γ ⊨ (if: e then e1 else e2) : B. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H #H1 #H2" (vs) "!# #HΓ /=". iSpecialize ("H1" with "HΓ"). iSpecialize ("H2" with "HΓ"). wp_apply (wp_wand with "(H [//])"); iIntros (w). iDestruct 1 as ([]) "->"; by wp_if. Qed. (* END SOLUTION *) (** ** Fork *) Lemma Fork_sem_typed Γ e : Γ ⊨ e : () -∗ Γ ⊨ Fork e : (). Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. iIntros "#H" (vs) "!# #HΓ /=". wp_apply wp_fork; last done. by iApply (wp_wand with "(H [//])"). Qed. (* END SOLUTION *) (** * Compatibility rules for value typing *) (** ** Base types *) ... ... @@ -249,11 +225,9 @@ Section compatibility. Lemma BoolV_sem_typed (b : bool) : ⊢ ⊨ᵥ #b : sem_ty_bool. Proof. by iExists b. Qed. Lemma IntV_sem_typed (n : Z) : ⊢ ⊨ᵥ #n : sem_ty_int. Proof. (* BEGIN SOLUTION *) (* SOLUTION *) Proof. by iExists n. Qed. (* END SOLUTION *) (** ** Products and sums *) Lemma PairV_sem_typed v1 v2 τ1 τ2 : ... ...