par.v 1.65 KB
Newer Older
1
From iris.heap_lang Require Export heap spawn.
Robbert Krebbers's avatar
Robbert Krebbers committed
2
From iris.heap_lang Require Import proofmode notation.
Ralf Jung's avatar
Ralf Jung committed
3
Import uPred.
4 5

Definition par : val :=
Robbert Krebbers's avatar
Robbert Krebbers committed
6 7
  λ: "fs",
    let: "handle" := ^spawn (Fst '"fs") in
8
    let: "v2" := Snd '"fs" #() in
Robbert Krebbers's avatar
Robbert Krebbers committed
9 10
    let: "v1" := ^join '"handle" in
    Pair '"v1" '"v2".
11 12
Notation Par e1 e2 := (^par (Pair (λ: <>, e1) (λ: <>, e2)))%E.
Notation ParV e1 e2 := (par (Pair (λ: <>, e1) (λ: <>, e2)))%E.
13 14
(* We want both par and par^ to print like this. *)
Infix "||" := ParV : expr_scope.
Ralf Jung's avatar
Ralf Jung committed
15
Infix "||" := Par : expr_scope.
16 17

Section proof.
18
Context {Σ : gFunctors} `{!heapG Σ, !spawnG Σ}.
19 20 21
Context (heapN N : namespace).
Local Notation iProp := (iPropG heap_lang Σ).

22
Lemma par_spec (Ψ1 Ψ2 : val  iProp) e (f1 f2 : val) (Φ : val  iProp) :
Robbert Krebbers's avatar
Robbert Krebbers committed
23
  heapN  N  to_val e = Some (f1,f2)%V 
24
  (heap_ctx heapN  WP f1 #() {{ Ψ1 }}  WP f2 #() {{ Ψ2 }} 
25
    v1 v2, Ψ1 v1  Ψ2 v2 -  Φ (v1,v2)%V)
26
   WP par e {{ Φ }}.
27
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
28 29 30 31 32 33
  iIntros {??} "(#Hh&Hf1&Hf2&HΦ)". wp_value. wp_let. wp_proj.
  wp_apply spawn_spec; try wp_done. iFrame "Hf1 Hh".
  iIntros {l} "Hl". wp_let. wp_proj. wp_focus (f2 _).
  iApply wp_wand_l; iFrame "Hf2"; iIntros {v} "H2". wp_let.
  wp_apply join_spec; iFrame "Hl". iIntros {w} "H1".
  iSpecialize "HΦ" "-"; first by iSplitL "H1". wp_let. by iPvsIntro.
Ralf Jung's avatar
Ralf Jung committed
34
Qed.
35

Ralf Jung's avatar
Ralf Jung committed
36 37
Lemma wp_par (Ψ1 Ψ2 : val  iProp) (e1 e2 : expr []) (Φ : val  iProp) :
  heapN  N 
38
  (heap_ctx heapN  WP e1 {{ Ψ1 }}  WP e2 {{ Ψ2 }} 
39
    v1 v2, Ψ1 v1  Ψ2 v2 -  Φ (v1,v2)%V)
40
   WP ParV e1 e2 {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
41
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
42 43
  iIntros {?} "(#Hh&H1&H2&H)". iApply par_spec; auto.
  iFrame "Hh H". iSplitL "H1"; by wp_let.
Ralf Jung's avatar
Ralf Jung committed
44 45
Qed.
End proof.