CG_stack.v 16.5 KB
Newer Older
1 2
From iris.proofmode Require Import tactics.
From iris.base_logic Require Import namespaces.
3
From iris_logrel.F_mu_ref_conc Require Import tactics examples.lock.
4 5
Import uPred.

6 7
(* Stack τ = μ x. Unit + (τ * x), essentially a type of lists *)
(* writing nil and cons for "constructors" *)
8 9 10 11
Definition CG_StackType τ :=
  TRec (TSum TUnit (TProd τ.[ren (+1)] (TVar 0))).

(* Coarse-grained push *)
12 13
(* push s = λ x. s <- fold (injr (x, load st)) *)
(* push s = λ x. s <- cons (x, load st) *)
14
Definition CG_push (st : expr) : expr :=
15
  Rec (Store
16 17 18 19 20
         (st.[ren (+2)]) (Fold (InjR (Pair (Var 1) (Load st.[ren (+ 2)]))))).

Definition CG_locked_push (st l : expr) := with_lock (CG_push st) l.
Definition CG_locked_pushV (st l : expr) : val := with_lockV (CG_push st) l.

21 22 23 24
(* pop s = λ x. match (load s) with
                | nil => InjL ()
                | cons y ys => s <- ys ;; InjR y 
                end *)
25
Definition CG_pop (st : expr) : expr :=
26
  Rec (Case (Unfold (Load st.[ren (+ 2)]))
27 28
            (InjL Unit)
            (
29
              App (Rec (InjR (Fst (Var 2))))
30 31 32 33 34 35 36
                  (Store st.[ren (+ 3)] (Snd (Var 0)))
            )
      ).

Definition CG_locked_pop (st l : expr) := with_lock (CG_pop st) l.
Definition CG_locked_popV (st l : expr) : val := with_lockV (CG_pop st) l.

37
(* snap st l = with_lock (λ _, load st) l *)
38 39
Definition CG_snap (st l : expr) :=  with_lock (Rec (Load st.[ren (+2)])) l.
Definition CG_snapV (st l : expr) : val := with_lockV (Rec (Load st.[ren (+2)])) l.
40

41 42 43 44
(* iter f = λ s. match s with
                 | nil => Unit
                 | cons x xs => (f x) ;; iter f xs
                 end *)
45
Definition CG_iter (f : expr) : expr :=
46
  Rec (Case (Unfold (Var 1))
47 48
            Unit
            (
49
              App (Rec (App (Var 3) (Snd (Var 2))))
50 51 52 53 54
                  (App f.[ren (+3)] (Fst (Var 0)))
            )
      ).

Definition CG_iterV (f : expr) : val :=
55
  RecV (Case (Unfold (Var 1))
56 57
            Unit
            (
58
              App (Rec (App (Var 3) (Snd (Var 2))))
59 60 61 62
                  (App f.[ren (+3)] (Fst (Var 0)))
            )
      ).

63
(* snap_iter st l := λ f. iter f (snap st l #()) *)
64
Definition CG_snap_iter (st l : expr) : expr :=
65
  Rec (App (CG_iter (Var 1)) (App (CG_snap st.[ren (+2)] l.[ren (+2)]) Unit)).
66 67 68

(* stack_body st l :=
   locked_push st l, locked_pop st l, snap_iter st l *)
69 70 71 72
Definition CG_stack_body (st l : expr) : expr :=
  Pair (Pair (CG_locked_push st l) (CG_locked_pop st l))
       (CG_snap_iter st l).

73 74
(* stack :=
   Λα. (λ(l : lock) (s : stack α). stack_body s l) (ref nil) newlock *)
75
Definition CG_stack : expr :=
76
  TLam (App (Rec (App (Rec (CG_stack_body (Var 1) (Var 3)))
77 78
                (Alloc (Fold (InjL Unit))))) newlock).

79
Section CG_Stack.
Robbert Krebbers's avatar
Robbert Krebbers committed
80
  Context `{heapIG Σ, cfgSG Σ}.
81 82 83 84 85 86

  Lemma CG_push_type st Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ (CG_push st) (TArrow τ TUnit).
  Proof.
    intros H1. repeat econstructor.
87 88
    eapply (context_weakening [_; _]); eauto.
    repeat constructor; asimpl; trivial.
89 90 91 92 93
    eapply (context_weakening [_; _]); eauto.
  Qed.

  Lemma CG_push_closed (st : expr) :
    ( f, st.[f] = st)   f, (CG_push st).[f] = CG_push st.
94
  Proof. intros Hst f. unfold CG_push. asimpl. rewrite ?Hst; trivial. Qed.
95

Robbert Krebbers's avatar
Robbert Krebbers committed
96
  Lemma CG_push_subst (st : expr) f : (CG_push st).[f] = CG_push st.[f].
97 98
  Proof. unfold CG_push; asimpl; trivial. Qed.

99 100
  Lemma steps_CG_push E ρ j K st v w :
    nclose specN  E 
101 102
    spec_ctx ρ  st ↦ₛ v  j  fill K (App (CG_push (Loc st)) (of_val w))
     |={E}=> j  fill K Unit  st ↦ₛ FoldV (InjRV (PairV w v)).
103 104
  Proof.
    intros HNE. iIntros "[#Hspec [Hx Hj]]". unfold CG_push.
105 106 107 108 109
    tp_rec j; eauto using to_of_val.
    tp_normalise j.
    tp_load j. tp_normalise j.
    tp_store j. simpl. by rewrite ?to_of_val /=. 
    tp_normalise j. by iFrame.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  Qed.

  Global Opaque CG_push.

  Lemma CG_locked_push_to_val st l :
    to_val (CG_locked_push st l) = Some (CG_locked_pushV st l).
  Proof. trivial. Qed.

  Lemma CG_locked_push_of_val st l :
    of_val (CG_locked_pushV st l) = CG_locked_push st l.
  Proof. trivial. Qed.

  Global Opaque CG_locked_pushV.

  Lemma CG_locked_push_type st l Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ l LockType 
    typed Γ (CG_locked_push st l) (TArrow τ TUnit).
  Proof.
    intros H1 H2. repeat econstructor.
    eapply with_lock_type; auto using CG_push_type.
  Qed.

  Lemma CG_locked_push_closed (st l : expr) :
    ( f, st.[f] = st)  ( f, l.[f] = l) 
     f, (CG_locked_push st l).[f] = CG_locked_push st l.
  Proof.
    intros H1 H2 f. asimpl. unfold CG_locked_push.
    rewrite with_lock_closed; trivial. apply CG_push_closed; trivial.
  Qed.

  Lemma CG_locked_push_subst (st l : expr) f :
Robbert Krebbers's avatar
Robbert Krebbers committed
142
    (CG_locked_push st l).[f] = CG_locked_push st.[f] l.[f].
143 144
  Proof. by rewrite with_lock_subst CG_push_subst. Qed.

145 146
  Lemma steps_CG_locked_push E ρ j K st w v l :
    nclose specN  E 
147 148 149
    spec_ctx ρ  st ↦ₛ v  l ↦ₛ (#v false)
       j  fill K (App (CG_locked_push (Loc st) (Loc l)) (of_val w))
     |={E}=> j  fill K Unit  st ↦ₛ FoldV (InjRV (PairV w v))  l ↦ₛ (#v false).
150
  Proof.
151 152 153 154 155 156 157 158
    iIntros (?) "(#Hspec & Hst & Hl & Hj)".
    unfold CG_locked_push.
    (* TODO would be nice to be able to determine that e := Loc l for instance *)
    iMod (steps_with_lock _ _ j K (CG_push (Loc st)) l _ _ UnitV _ _ _ with "[Hspec Hst Hj Hl]") as "Hj"; last done. 
    - iIntros (K') "(#Hspec & HQ & Hj)".
      iApply steps_CG_push; first eauto.
      iFrame "Hspec Hj". iFrame "HQ".
    - by iFrame. 
159 160 161 162 163
      Unshelve. all: trivial.
  Qed.

  Global Opaque CG_locked_push.

164
  (* Coarse-grained pop *)
165 166 167 168 169
  Lemma CG_pop_type st Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ (CG_pop st) (TArrow TUnit (TSum TUnit τ)).
  Proof.
    intros H1.
170 171 172 173 174 175 176 177 178
    econstructor.
    eapply (Case_typed _ _ _ _ TUnit);
      [| repeat constructor
       | repeat econstructor; eapply (context_weakening [_; _; _]); eauto].
    replace (TSum TUnit (TProd τ (CG_StackType τ))) with
    ((TSum TUnit (TProd τ.[ren (+1)] (TVar 0))).[(CG_StackType τ)/])
      by (by asimpl).
    repeat econstructor.
    eapply (context_weakening [_; _]); eauto.
179 180 181 182
  Qed.

  Lemma CG_pop_closed (st : expr) :
    ( f, st.[f] = st)   f, (CG_pop st).[f] = CG_pop st.
183
  Proof. intros Hst f. unfold CG_pop. asimpl. rewrite ?Hst; trivial. Qed.
184

185
  Lemma CG_pop_subst (st : expr) f : (CG_pop st).[f] = CG_pop st.[f].
186 187
  Proof. unfold CG_pop; asimpl; trivial. Qed.

188 189
  Lemma steps_CG_pop_suc E ρ j K st v w :
    nclose specN  E 
190
    spec_ctx ρ  st ↦ₛ FoldV (InjRV (PairV w v)) 
191
               j  fill K (App (CG_pop (Loc st)) Unit)
192
       |={E}=> j  fill K (InjR (of_val w))  st ↦ₛ v.
193 194
  Proof.
    intros HNE. iIntros "[#Hspec [Hx Hj]]". unfold CG_pop.
195 196 197 198 199 200 201 202 203 204
    tp_rec j. asimpl.
    tp_load j. tp_normalise j.
    tp_fold j; simpl; first by rewrite ?to_of_val /=.
    tp_normalise j.
    tp_case_inr j; simpl; first by rewrite ?to_of_val.
    tp_snd j; eauto using to_of_val.    
    tp_store j; eauto using to_of_val. tp_normalise j.
    tp_rec j. asimpl.
    tp_fst j; eauto using to_of_val. tp_normalise j.
    by iFrame.
205 206
  Qed.

207 208
  Lemma steps_CG_pop_fail E ρ j K st :
    nclose specN  E 
209
    spec_ctx ρ  st ↦ₛ FoldV (InjLV UnitV) 
210
               j  fill K (App (CG_pop (Loc st)) Unit)
211
       |={E}=> j  fill K (InjL Unit)  st ↦ₛ FoldV (InjLV UnitV).
212
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
213
    iIntros (HNE) "[#Hspec [Hx Hj]]". unfold CG_pop.
214 215 216 217 218
    tp_rec j.
    tp_load j. asimpl. tp_normalise j.
    tp_fold j.
    tp_case_inl j. asimpl. tp_normalise j.
    by iFrame.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
  Qed.

  Global Opaque CG_pop.

  Lemma CG_locked_pop_to_val st l :
    to_val (CG_locked_pop st l) = Some (CG_locked_popV st l).
  Proof. trivial. Qed.

  Lemma CG_locked_pop_of_val st l :
    of_val (CG_locked_popV st l) = CG_locked_pop st l.
  Proof. trivial. Qed.

  Global Opaque CG_locked_popV.

  Lemma CG_locked_pop_type st l Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ l LockType 
    typed Γ (CG_locked_pop st l) (TArrow TUnit (TSum TUnit τ)).
  Proof.
    intros H1 H2. repeat econstructor.
    eapply with_lock_type; auto using CG_pop_type.
  Qed.

  Lemma CG_locked_pop_closed (st l : expr) :
    ( f, st.[f] = st)  ( f, l.[f] = l) 
     f, (CG_locked_pop st l).[f] = CG_locked_pop st l.
  Proof.
    intros H1 H2 f. asimpl. unfold CG_locked_pop.
    rewrite with_lock_closed; trivial. apply CG_pop_closed; trivial.
  Qed.

  Lemma CG_locked_pop_subst (st l : expr) f :
  (CG_locked_pop st l).[f] = CG_locked_pop st.[f] l.[f].
  Proof. by rewrite with_lock_subst CG_pop_subst. Qed.

254 255
  Lemma steps_CG_locked_pop_suc E ρ j K st v w l :
    nclose specN  E 
256 257 258
    spec_ctx ρ  st ↦ₛ FoldV (InjRV (PairV w v))  l ↦ₛ (#v false)
                j  fill K (App (CG_locked_pop (Loc st) (Loc l)) Unit)
       |={E}=> j  fill K (InjR (of_val w))  st ↦ₛ v  l ↦ₛ (#v false).
259
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
260
    iIntros (HNE) "[#Hspec [Hx [Hl Hj]]]". unfold CG_locked_pop.
261
    iMod (steps_with_lock _ _ j K _ _ _ _ (InjRV w) UnitV _ _
262
          with "[Hj Hx Hl]") as "Hj"; last done.
Robbert Krebbers's avatar
Robbert Krebbers committed
263
    - iIntros (K') "[#Hspec [Hx Hj]]".
264
      iApply steps_CG_pop_suc; first done. iFrame "Hspec Hj Hx"; trivial.
265 266 267 268
    - iFrame "Hspec Hj Hx"; trivial.
      Unshelve. all: trivial.
  Qed.

269 270
  Lemma steps_CG_locked_pop_fail E ρ j K st l :
    nclose specN  E 
271 272 273
    spec_ctx ρ  st ↦ₛ FoldV (InjLV UnitV)  l ↦ₛ (#v false)
                j  fill K (App (CG_locked_pop (Loc st) (Loc l)) Unit)
       |={E}=> j  fill K (InjL Unit)  st ↦ₛ FoldV (InjLV UnitV)  l ↦ₛ (#v false).
274
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
275
    iIntros (HNE) "[#Hspec [Hx [Hl Hj]]]". unfold CG_locked_pop.
276
    iMod (steps_with_lock _ _ j K _ _ _ _ (InjLV UnitV) UnitV _ _
277
          with "[Hj Hx Hl]") as "Hj"; last done.
Robbert Krebbers's avatar
Robbert Krebbers committed
278
    - iIntros (K') "[#Hspec [Hx Hj]] /=".
279
      iApply steps_CG_pop_fail; first done. iFrame "Hspec Hj Hx"; trivial.
280 281 282 283 284 285
    - iFrame "Hspec Hj Hx"; trivial.
      Unshelve. all: trivial.
  Qed.

  Global Opaque CG_locked_pop.

Robbert Krebbers's avatar
Robbert Krebbers committed
286
  Lemma CG_snap_to_val st l : to_val (CG_snap st l) = Some (CG_snapV st l).
287 288
  Proof. trivial. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
289
  Lemma CG_snap_of_val st l : of_val (CG_snapV st l) = CG_snap st l.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  Proof. trivial. Qed.

  Global Opaque CG_snapV.

  Lemma CG_snap_type st l Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ l LockType 
    typed Γ (CG_snap st l) (TArrow TUnit (CG_StackType τ)).
  Proof.
    intros H1 H2. repeat econstructor.
    eapply with_lock_type; trivial. do 2 constructor.
    eapply (context_weakening [_; _]); eauto.
  Qed.

  Lemma CG_snap_closed (st l : expr) :
    ( f, st.[f] = st)  ( f, l.[f] = l) 
     f, (CG_snap st l).[f] = CG_snap st l.
  Proof.
    intros H1 H2 f. asimpl. unfold CG_snap.
    rewrite with_lock_closed; trivial.
    intros f'. by asimpl; rewrite ?H1.
  Qed.

  Lemma CG_snap_subst (st l : expr) f :
314
    (CG_snap st l).[f] = CG_snap st.[f] l.[f].
315 316
  Proof. unfold CG_snap; rewrite ?with_lock_subst. by asimpl. Qed.

317 318
  Lemma steps_CG_snap E ρ j K st v l :
    nclose specN  E 
319 320 321
    spec_ctx ρ  st ↦ₛ v  l ↦ₛ (#v false)
                j  fill K (App (CG_snap (Loc st) (Loc l)) Unit)
       |={E}=> j  (fill K (of_val v))  st ↦ₛ v  l ↦ₛ (#v false).
322
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
323
    iIntros (HNE) "[#Hspec [Hx [Hl Hj]]]". unfold CG_snap.
324
    iMod (steps_with_lock _ _ j K _ _ _ _ v UnitV _ _
325
          with "[Hj Hx Hl]") as "Hj"; last done; [|by iFrame "Hspec Hx Hl Hj"].
Robbert Krebbers's avatar
Robbert Krebbers committed
326
    iIntros (K') "[#Hspec [Hx Hj]]".
327 328 329 330
    tp_rec j.
    tp_load j. tp_normalise j.
    by iFrame.
    Unshelve. all: trivial.
331 332 333 334 335 336 337
  Qed.

  Global Opaque CG_snap.

  (* Coarse-grained iter *)
  Lemma CG_iter_folding (f : expr) :
    CG_iter f =
338
    Rec (Case (Unfold (Var 1))
339 340
              Unit
              (
341
                App (Rec (App (Var 3) (Snd (Var 2))))
342
                    (App f.[ren (+3)] (Fst (Var 0)))
343
              )
344
        ).
345 346 347 348 349 350 351
  Proof. trivial. Qed.

  Lemma CG_iter_type f Γ τ :
    typed Γ f (TArrow τ TUnit) 
    typed Γ (CG_iter f) (TArrow (CG_StackType τ) TUnit).
  Proof.
    intros H1.
352 353 354 355 356 357 358
    econstructor.
    eapply (Case_typed _ _ _ _ TUnit);
      [| repeat constructor
       | repeat econstructor; eapply (context_weakening [_; _; _]); eauto].
    replace (TSum TUnit (TProd τ (CG_StackType τ))) with
    ((TSum TUnit (TProd τ.[ren (+1)] (TVar 0))).[(CG_StackType τ)/])
      by (by asimpl).
359 360 361
    repeat econstructor.
  Qed.

362 363 364 365 366 367 368 369
  Lemma CG_iter_to_val f : to_val (CG_iter f) = Some (CG_iterV f).
  Proof. trivial. Qed.

  Lemma CG_iter_of_val f : of_val (CG_iterV f) = CG_iter f.
  Proof. trivial. Qed.

  Global Opaque CG_iterV.

370 371
  Lemma CG_iter_closed (f : expr) :
    ( g, f.[g] = f)   g, (CG_iter f).[g] = CG_iter f.
372
  Proof. intros Hf g. unfold CG_iter. asimpl. rewrite ?Hf; trivial. Qed.
373

Robbert Krebbers's avatar
Robbert Krebbers committed
374
  Lemma CG_iter_subst (f : expr) g : (CG_iter f).[g] = CG_iter f.[g].
375 376
  Proof. unfold CG_iter; asimpl; trivial. Qed.

377 378 379
  Lemma steps_CG_iter E ρ j K f v w :
    nclose specN  E 
    spec_ctx ρ
380
              j  fill K (App (CG_iter (of_val f))
Amin Timany's avatar
Amin Timany committed
381
                               (Fold (InjR (Pair (of_val w) (of_val v)))))
382
       |={E}=>
383
    j  fill K
384
          (App
385
             (Rec
Amin Timany's avatar
Amin Timany committed
386 387 388
                (App ((CG_iter (of_val f)).[ren (+2)])
                     (Snd (Pair ((of_val w).[ren (+2)]) (of_val v).[ren (+2)]))))
             (App (of_val f) (of_val w))).
389
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
390
    iIntros (HNE) "[#Hspec Hj]". unfold CG_iter.
391 392 393 394
    tp_rec j; first by (rewrite /= ?to_of_val /=).
    rewrite -CG_iter_folding. Opaque CG_iter.
    tp_fold j; first by (rewrite /= ?to_of_val /=). 
    tp_case_inr j; first by (rewrite /= ?to_of_val /=). 
395
    asimpl.
396 397 398 399
    tp_fst j; auto using to_of_val.
    tp_normalise j.
    done.
  Qed. 
400 401 402

  Transparent CG_iter.

403 404
  Lemma steps_CG_iter_end E ρ j K f :
    nclose specN  E 
405
    spec_ctx ρ  j  fill K (App (CG_iter (of_val f)) (Fold (InjL Unit)))
406
       |={E}=> j  fill K Unit.
407
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
408
    iIntros (HNE) "[#Hspec Hj]". unfold CG_iter.
409 410 411 412
    tp_rec j. 
    tp_fold j.
    tp_case_inl j. tp_normalise j. 
    by iFrame.
413 414 415 416 417 418 419
  Qed.

  Global Opaque CG_iter.

  Lemma CG_snap_iter_type st l Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ l LockType 
Robbert Krebbers's avatar
Robbert Krebbers committed
420
    typed Γ (CG_snap_iter st l) (TArrow (TArrow τ TUnit) TUnit).
421 422 423 424 425 426 427
  Proof.
    intros H1 H2; repeat econstructor.
    - eapply CG_iter_type; by constructor.
    - eapply CG_snap_type; by eapply (context_weakening [_;_]).
  Qed.

  Lemma CG_snap_iter_closed (st l : expr) :
Robbert Krebbers's avatar
Robbert Krebbers committed
428
    ( f, st.[f] = st)  ( f, l.[f] = l) 
429 430 431 432 433 434 435
     f, (CG_snap_iter st l).[f] = CG_snap_iter st l.
  Proof.
    intros H1 H2 f. unfold CG_snap_iter. asimpl. rewrite H1 H2.
    rewrite CG_snap_closed; auto.
  Qed.

  Lemma CG_snap_iter_subst (st l : expr) g :
Robbert Krebbers's avatar
Robbert Krebbers committed
436
    (CG_snap_iter st l).[g] = CG_snap_iter st.[g] l.[g].
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
  Proof.
    unfold CG_snap_iter; asimpl.
    rewrite CG_snap_subst CG_iter_subst. by asimpl.
  Qed.

  Lemma CG_stack_body_type st l Γ τ :
    typed Γ st (Tref (CG_StackType τ)) 
    typed Γ l LockType 
    typed Γ (CG_stack_body st l)
          (TProd
             (TProd (TArrow τ TUnit) (TArrow TUnit (TSum TUnit τ)))
             (TArrow (TArrow τ TUnit) TUnit)
          ).
  Proof.
    intros H1 H2.
    repeat (econstructor; eauto using CG_locked_push_type,
                          CG_locked_pop_type, CG_snap_iter_type).
  Qed.

  Opaque CG_snap_iter.

  Lemma CG_stack_body_closed (st l : expr) :
Robbert Krebbers's avatar
Robbert Krebbers committed
459
    ( f, st.[f] = st)  ( f, l.[f] = l) 
460 461 462 463 464 465 466 467
     f, (CG_stack_body st l).[f] = CG_stack_body st l.
  Proof.
    intros H1 H2 f. unfold CG_stack_body. asimpl.
    rewrite CG_locked_push_closed; trivial.
    rewrite CG_locked_pop_closed; trivial.
    by rewrite CG_snap_iter_closed.
  Qed.

468 469
  (* CG_stack 
    :  α. ((α  Unit) * (Unit  Unit + α) * ((α  Unit)  Unit))  *)
470
  Lemma CG_stack_type Γ :
471
    typed Γ CG_stack
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
          (TForall
             (TProd
                (TProd
                   (TArrow (TVar 0) TUnit)
                   (TArrow TUnit (TSum TUnit (TVar 0)))
                )
                (TArrow (TArrow (TVar 0) TUnit) TUnit)
          )).
  Proof.
    repeat econstructor.
    - eapply CG_locked_push_type; constructor; simpl; eauto.
    - eapply CG_locked_pop_type; constructor; simpl; eauto.
    - eapply CG_snap_iter_type; constructor; by simpl.
    - asimpl. repeat constructor.
    - eapply newlock_type.
  Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
489
  Lemma CG_stack_closed f : CG_stack.[f] = CG_stack.
490 491 492 493 494
  Proof.
    unfold CG_stack.
    asimpl; rewrite ?CG_locked_push_subst ?CG_locked_pop_subst.
    asimpl. rewrite ?CG_snap_iter_subst. by asimpl.
  Qed.
495
End CG_Stack.