Translation.v 19.9 KB
Newer Older
1
From stdpp Require Import fin_maps.
MEVEL Glen's avatar
MEVEL Glen committed
2
From iris_time.heap_lang Require Export notation proofmode.
3
From iris_time Require Import Reduction.
4 5 6 7 8 9 10 11 12 13 14 15 16 17

Implicit Type e : expr.
Implicit Type v : val.
Implicit Type σ : state.
Implicit Type t : list expr.
Implicit Type K : ectx heap_ectx_lang.
Implicit Type m n : nat.



(*
 * Translation with any arbitrary expression for [tick]
 *)

MEVEL Glen's avatar
MEVEL Glen committed
18
(* “tick” is a typeclass so that it can be made an implicit argument of the
19 20 21
 * translation and be inferred automatically from the context.
   This also make it possible to share notations. *)
Class Tick := tick : val.
22

23 24
Section Translation.

25 26
  Context {Htick : Tick}.

MEVEL Glen's avatar
MEVEL Glen committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40
  (* Unfortunately, the operational semantics of [match] in our language is
   * ad-hoc somehow, as the rule is:
   *     Case (InjL v) e1 e2  →  e1 v
   * Instead of the more canonical rule:
   *     Case (InjL v) (x1. e1) (x2. e2)  →  e1 [x1 := v]
   * This means that the reduction of a match construct really takes two steps,
   * since we still have to reduce the application; hence, in our time credit
   * model, a match construct will cost two credits.
   * It also means that the “branch” [e1] is not constrained be a λ-abstraction,
   * and can reduce after the reduction of the [match] but before it is applied
   * to [v]!
   * This ad-hoc semantics calls for an ad-hoc definition of the translation in
   * that case because, to observe the simulation lemma, the translation of
   * [Case (InjL v) e1 e2] must reduce to the translation of [e1 v], which is
41
   * [(tick «e1») «v»]. To do so --which means preserving the weird evaluation
MEVEL Glen's avatar
MEVEL Glen committed
42 43
   * order--, we use the helper term below: *)
  Definition tick_case_branch : val :=
44
    (λ: "f" "x", tick ("f" #()) "x")%V.
45 46 47 48 49

  Fixpoint translation (e : expr) : expr :=
    match e with
    (* Base lambda calculus *)
    | Var _           => e
50
    | Rec f x e       => tick $ Rec f x (translation e)
51
    | App e1 e2       => (tick $ translation e1) (translation e2)
52
    | Val v           => Val $ translationV v
53 54
    (* Base types and their operations *)
    | UnOp op e       => UnOp op (tick $ translation e)
55
    | BinOp op e1 e2  => BinOp op (tick $ translation e1) (translation e2)
56 57
    | If e0 e1 e2     => If (tick $ translation e0) (translation e1) (translation e2)
    (* Products *)
58
    | Pair e1 e2      => Pair (tick $ translation e1) (translation e2)
59 60 61
    | Fst e           => Fst (tick $ translation e)
    | Snd e           => Snd (tick $ translation e)
    (* Sums *)
62 63
    | InjL e          => InjL (tick $ translation e)
    | InjR e          => InjR (tick $ translation e)
64 65
    | Case e0 e1 e2   =>
        Case (tick $ translation e0)
MEVEL Glen's avatar
MEVEL Glen committed
66 67
          (tick_case_branch (λ: <>, translation e1))
          (tick_case_branch (λ: <>, translation e2))
68 69 70 71 72
    (* Concurrency *)
    | Fork e          => tick $ Fork (translation e)
    (* Heap *)
    | Alloc e         => Alloc (tick $ translation e)
    | Load e          => Load (tick $ translation e)
73 74 75
    | Store e1 e2     => Store (tick $ translation e1) (translation e2)
    | CAS e0 e1 e2    => CAS (tick $ translation e0) (translation e1) (translation e2)
    | FAA e1 e2       => FAA (tick $ translation e1) (translation e2)
76 77
    end %E
  with translationV (v : val) : val :=
78
    match v with
79
    | RecV f x e    => RecV f x (translation e)
80 81 82 83 84 85 86 87 88 89 90 91 92
    | LitV _        => v
    | PairV v1 v2   => PairV (translationV v1) (translationV v2)
    | InjLV v       => InjLV (translationV v)
    | InjRV v       => InjRV (translationV v)
    end.

  Definition translationS (σ : state) : state :=
    translationV <$> σ.

  Let tickCtx : ectx_item := AppRCtx tick.

  Definition translationKi (Ki : ectx_item) : ectx_item :=
    match Ki with
93 94
    | AppLCtx v2      => AppLCtx (translationV v2)
    | AppRCtx e1      => AppRCtx (tick $ translation e1)
95
    | UnOpCtx op      => UnOpCtx op
96 97
    | BinOpLCtx op v2 => BinOpLCtx op (translationV v2)
    | BinOpRCtx op e1 => BinOpRCtx op (tick $ translation e1)
98
    | IfCtx e1 e2     => IfCtx (translation e1) (translation e2)
99
    | PairLCtx v2     => PairLCtx (translationV v2)
100
    | PairRCtx e1     => PairRCtx (tick $ translation e1)
101 102 103 104 105 106
    | FstCtx          => FstCtx
    | SndCtx          => SndCtx
    | InjLCtx         => InjLCtx
    | InjRCtx         => InjRCtx
    | CaseCtx e1 e2   =>
        CaseCtx
MEVEL Glen's avatar
MEVEL Glen committed
107 108
          (tick_case_branch (λ: <>, translation e1))%E
          (tick_case_branch (λ: <>, translation e2))%E
109 110
    | AllocCtx        => AllocCtx
    | LoadCtx         => LoadCtx
111 112 113 114 115 116 117
    | StoreLCtx v2    => StoreLCtx (translationV v2)
    | StoreRCtx e1    => StoreRCtx (tick $ translation e1)
    | CasLCtx v0 v1   => CasLCtx (translationV v0) (translationV v1)
    | CasMCtx e1 v1   => CasMCtx (tick $ translation e1) (translationV v1)
    | CasRCtx e1 e2   => CasRCtx (tick $ translation e1) (translation e2)
    | FaaLCtx v2      => FaaLCtx (translationV v2)
    | FaaRCtx e1      => FaaRCtx (tick $ translation e1)
118 119 120 121 122 123 124 125 126
    end.

  Definition translationKi_aux (Ki : ectx_item) : ectx _ :=
    if ectx_item_is_active Ki then
      [ tickCtx ; translationKi Ki ]
    else
      [ translationKi Ki ].

  Definition translationK (K : ectx heap_ectx_lang) : ectx _ :=
MEVEL Glen's avatar
MEVEL Glen committed
127
    List.concat (translationKi_aux <$> K).
128 129 130 131 132

(*
 * Lemmas about translation
 *)

133 134
  Lemma translation_subst x e v :
    translation (subst x v e) = subst x (translationV v) (translation e).
135
  Proof.
136
    induction e ;
137 138 139
    unfold subst ; simpl ; fold subst ;
    try case_match ; (* ← this handles the cases of Var and Rec *)
    repeat f_equal ;
140
    assumption.
141 142
  Qed.

143 144
  Lemma translation_subst' x e v :
    translation (subst' x v e) = subst' x (translationV v) (translation e).
145 146 147 148 149 150
  Proof.
    destruct x.
    - reflexivity.
    - apply translation_subst.
  Qed.

151 152 153 154 155 156 157 158
  Lemma translation_injective :
     e1 e2,
      translation e1 = translation e2 
      e1 = e2
  with translationV_injective :
     v1 v2,
      translationV v1 = translationV v2 
      v1 = v2.
159
  Proof.
160 161 162 163
    destruct e1, e2; try discriminate; intros [=]; subst; f_equal;
      by (apply translation_injective || apply translationV_injective).
    destruct v1, v2; try discriminate; intros [=]; subst; f_equal;
      by (apply translation_injective || apply translationV_injective).
164 165 166 167 168
  Qed.

  Lemma translation_fill_item Ki e :
    translation (fill_item Ki e) = fill (translationKi_aux Ki) (translation e).
  Proof.
169
    destruct Ki ; reflexivity.
170 171 172 173 174 175
  Qed.

  Lemma translation_fill_item_active (ki : ectx_item) v :
    ectx_item_is_active ki 
    translation (fill_item ki v) = fill_item (translationKi ki) (tick (translationV v)).
  Proof.
176
    rewrite translation_fill_item.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 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 254
    unfold translationKi_aux ; destruct (ectx_item_is_active ki) ; last contradiction.
    reflexivity.
  Qed.

  Lemma is_active_translationKi ki :
    ectx_item_is_active ki 
    ectx_item_is_active (translationKi ki).
  Proof.
    by destruct ki.
  Qed.

  Lemma translation_fill K e :
    translation (fill K e) = fill (translationK K) (translation e).
  Proof.
    revert e ; induction K ; intros e.
    - done.
    - rewrite /= fill_app - translation_fill_item //.
  Qed.

  Lemma lookup_translationS_None σ l :
    σ !! l = None 
    translationS σ !! l = None.
  Proof.
    intros H. by rewrite lookup_fmap H.
  Qed.

  Lemma lookup_translationS_Some σ l v :
    σ !! l = Some v 
    translationS σ !! l = Some (translationV v).
  Proof.
    intros H. by rewrite lookup_fmap H.
  Qed.

  Lemma lookup_translationS_is_Some σ l :
    is_Some (σ !! l) 
    is_Some (translationS σ !! l).
  Proof.
    destruct 1. eauto using lookup_translationS_Some.
  Qed.

  Lemma lookup_translationS_None_inv σ l :
    translationS σ !! l = None 
    σ !! l = None.
  Proof.
    unfold translationS ; rewrite lookup_fmap.
    destruct (σ !! l) eqn:E ; rewrite E ; first discriminate.
    done.
  Qed.

  Lemma lookup_translationS_Some_inv σ l v' :
    translationS σ !! l = Some v' 
     v,  σ !! l = Some v    v' = translationV v.
  Proof.
    rewrite lookup_fmap.
    destruct (σ !! l) eqn:E ; rewrite E ; last discriminate.
    intros ? % Some_inj ; eauto.
  Qed.

  Lemma lookup_translationS_is_Some_inv σ l :
    is_Some (translationS σ !! l) 
    is_Some (σ !! l).
  Proof.
    intros [_ (? & ? & _) % lookup_translationS_Some_inv]. eauto.
  Qed.

  Lemma translationS_insert l v σ :
    translationS (<[l := v]> σ) = <[l := translationV v]> (translationS σ).
  Proof.
    apply fmap_insert.
  Qed.

  Lemma un_op_eval_translation op v v' :
    un_op_eval op v = Some v' 
    un_op_eval op (translationV v) = Some (translationV v').
  Proof.
    intros H.
    destruct op ;
    destruct v ; try discriminate H ;
255 256 257 258 259
    simpl ; case_match ; simpl in *;
      try discriminate H;
      try match goal with
          |- context [to_mach_int ?x] => destruct (to_mach_int x); [|discriminate] end;
      try by injection H as <-.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
  Qed.

  Local Lemma _eval_EqOp_bool_decide v1 v2 :
    bin_op_eval EqOp v1 v2 = Some $ LitV $ LitBool $ bool_decide (v1 = v2).
  Proof.
    destruct v1, v2 ; try done ;
    simpl ; case_match ; try done ;
    simpl ; case_match ; try done ;
    repeat f_equal ; apply bool_decide_iff ; naive_solver.
  Qed.

  Local Lemma _bool_decide_eq_translationV v1 v2 :
    bool_decide (v1 = v2) = bool_decide (translationV v1 = translationV v2).
  Proof.
    apply bool_decide_iff ; split ; intros H.
    - by rewrite H.
    - by eapply translationV_injective.
  Qed.

  Lemma bin_op_eval_translation op v1 v2 v' :
    bin_op_eval op v1 v2 = Some v' 
    bin_op_eval op (translationV v1) (translationV v2) = Some (translationV v').
  Proof.
    intros H.
    destruct op ; try (
      destruct v1, v2 ; try discriminate H ;
286 287
      unfold bin_op_eval in * ;
      do 3 try (case_match ; try discriminate H) ;
288 289 290
      simpl in *;
      try match goal with
          |- context [to_mach_int ?x] => destruct (to_mach_int x); [|discriminate] end;
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
      by injection H as <-
    ).
    (* Remaining case: op = EqOp *)
    rewrite _eval_EqOp_bool_decide in H ; injection H as <-.
    by rewrite _eval_EqOp_bool_decide - _bool_decide_eq_translationV.
  Qed.

  Lemma un_op_eval_translation_inv op v v' :
    un_op_eval op (translationV v) = Some v' 
    un_op_eval op v = Some v'.
  Proof.
    intros H.
    destruct op ;
    destruct v ; try discriminate H ;
    done.
  Qed.

  Lemma bin_op_eval_translation_inv op v1 v2 v' :
    bin_op_eval op (translationV v1) (translationV v2) = Some v' 
    bin_op_eval op v1 v2 = Some v'.
  Proof.
    intros H.
    destruct op ; try (
      destruct v1, v2 ; try discriminate H ;
      done
    ).
    (* Remaining case: op = EqOp *)
    rewrite -> _eval_EqOp_bool_decide in *. injection H as <-.
    by rewrite - _bool_decide_eq_translationV.
  Qed.

  Lemma translationV_lit lit :
    translationV #lit = #lit.
  Proof.
    done.
  Qed.

  Lemma translationV_lit_inv v lit :
    translationV v = #lit 
    v = #lit.
  Proof.
    destruct v ; try discriminate. done.
  Qed.

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  Lemma vals_cas_compare_safe_translationV v1 v2 :
    vals_cas_compare_safe v1 v2 
    vals_cas_compare_safe (translationV v1) (translationV v2).
  Proof.
    intros [].
    - left. by destruct v1 as [| | |[]|[]].
    - right. by destruct v2 as [| | |[]|[]].
  Qed.
  Lemma vals_cas_compare_safe_translationV_inv v1 v2 :
    vals_cas_compare_safe (translationV v1) (translationV v2) 
    vals_cas_compare_safe v1 v2.
  Proof.
    intros [].
    - left. by destruct v1 as [| | |[]|[]].
    - right. by destruct v2 as [| | |[]|[]].
  Qed.

352 353
End Translation.

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
(*
 * Notations
 *)

Notation "E« e »" := (translation e%E).
Notation "V« v »" := (translationV v%V).
Notation "Ki« ki »" := (translationKi ki).
Notation "K« K »" := (translationK K).
Notation "S« σ »" := (translationS σ%V).
Notation "T« t »" := (translation <$> t%E).

Notation "« e »" := (translation e%E).
Notation "« e »" := (translation e%E) : expr_scope.
Notation "« v »" := (translationV v%V) : val_scope.

(* for some reason, these notations make parsing fail,
 * even if they only regard printing… *)
(*
Notation "« e »" := (translation e%E) (only printing).
Notation "« v »" := (translationV v%V) (only printing).
Notation "« ki »" := (translationKi ki) (only printing).
Notation "« K »" := (translationK K) (only printing).
Notation "« σ »" := (translationS σ%V) (only printing).
Notation "« t »" := (translation <$> t%E) (only printing).
*)

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
(* FIXME : the way coercions should or should not be included in
   notations so that notations are pretty-printed back is completely
   non-predictible. *)

Notation "'tickrec:' f x y .. z := e" :=
  (tick (Rec f%bind x%bind (tick (Lam y%bind .. (tick (Lam z%bind e%E)) ..))))
  (at level 200, f, x, y, z at level 1, e at level 200,
   format "'[' 'tickrec:'  f  x  y  ..  z  :=  '/  ' e ']'") : expr_scope.

Notation "tickλ: x , e" := (tick (Lam x%bind e%E))
  (at level 200, x at level 1, e at level 200,
   format "'[' 'tickλ:'  x ,  '/  ' e ']'") : expr_scope.
Notation "tickλ: x y .. z , e" :=
  (tick (Lam x%bind (tick (Lam y%bind .. (tick (Lam z%bind e%E)) ..))))
  (at level 200, x, y, z at level 1, e at level 200,
   format "'[' 'tickλ:'  x  y  ..  z ,  '/  ' e ']'") : expr_scope.

397
Notation "'lettick:' x := e1 'in' e2" :=
398
  ((tick (App (Val tick) (Lam x%bind e2%E))) e1%E)
399 400 401 402
  (at level 200, x at level 1, e1, e2 at level 200,
   format "'[' 'lettick:'  x  :=  '[' e1 ']'  'in'  '/' e2 ']'") : expr_scope.

Notation "e1 ;tick; e2" :=
403
  ((tick (App (Val tick) (Lam BAnon e2%E))) e1%E)
404 405 406 407
  (at level 100, e2 at level 200,
   format "'[' '[hv' '[' e1 ']'  ;tick;  ']' '/' e2 ']'") : expr_scope.

Notation "'tickmatch:' e0 'with' 'InjL' x1 => e1 | 'InjR' x2 => e2 'end'" :=
408 409
  (Case (App (Val tick) e0) (App (Val tick_case_branch) (λ: <>, App (Val tick) (λ: x1, e1))%E)
                            (App (Val tick_case_branch) (λ: <>, App (Val tick) (λ: x2, e2))%E))
410 411 412
  (e0, x1, e1, x2, e2 at level 200,
   format "'[hv' 'tickmatch:'  e0  'with'  '/  ' '[' 'InjL'  x1  =>  '/  ' e1 ']'  '/' '[' |  'InjR'  x2  =>  '/  ' e2 ']'  '/' 'end' ']'") : expr_scope.

413 414 415 416 417 418 419 420 421 422 423 424
(*
  Typeclass instance for the proofmode
 *)

Instance AsRecV_translationV `{Tick} v f x e :
  AsRecV v f x e 
  AsRecV « v » f x « e ».
Proof. by intros ->. Qed.

(*
 * Simplification tactic
 *)
425

426 427 428
(* simpl and cbn do not work well with mutual fixpoints... *)
Ltac simpl_trans :=
  cbn [translation translationV]; fold translation translationV.
429

430 431 432 433 434 435 436 437
(*
 * (Partial) Inverse translation
 *)

Section InvTranslation.

  Fixpoint invtranslation (e : expr) : expr :=
    match e with
438 439 440
    (* Concurrency -- This pattern has to appear before the pattern of
      App, since it conflicts with it. *)
    | App tick (Fork e)          => Fork (invtranslation e)
441 442
    (* Base lambda calculus *)
    | Var _                      => e
443
    | App tick (Rec f x e)       => Rec f x (invtranslation e)
444
    | App (App tick e1) e2       => (invtranslation e1) (invtranslation e2)
445
    | Val v                      => Val (invtranslationV v)
446 447
    (* Base types and their operations *)
    | UnOp op (App tick e)       => UnOp op (invtranslation e)
448
    | BinOp op (App tick e1) e2  => BinOp op (invtranslation e1) (invtranslation e2)
449 450
    | If (App tick e0) e1 e2     => If (invtranslation e0) (invtranslation e1) (invtranslation e2)
    (* Products *)
451
    | Pair (App tick e1) e2      => Pair (invtranslation e1) (invtranslation e2)
452 453 454
    | Fst (App tick e)           => Fst (invtranslation e)
    | Snd (App tick e)           => Snd (invtranslation e)
    (* Sums *)
455 456
    | InjL (App tick e)          => InjL (invtranslation e)
    | InjR (App tick e)          => InjR (invtranslation e)
457
    | Case (App tick e0) (App tickaux1 (Rec BAnon BAnon e1)) (App tickaux2 (Rec BAnon BAnon e2)) =>
458 459 460 461
        Case (invtranslation e0) (invtranslation e1) (invtranslation e2)
    (* Heap *)
    | Alloc (App tick e)         => Alloc (invtranslation e)
    | Load (App tick e)          => Load (invtranslation e)
462 463 464
    | Store (App tick e1) e2     => Store (invtranslation e1) (invtranslation e2)
    | CAS (App tick e0) e1 e2    => CAS (invtranslation e0) (invtranslation e1) (invtranslation e2)
    | FAA (App tick e1) e2       => FAA (invtranslation e1) (invtranslation e2)
465
    | _ => #42
466 467
    end %E
  with invtranslationV v :=
468
    match v with
469
    | RecV f x e    => RecV f x (invtranslation e)
470 471 472 473 474 475
    | LitV _        => v
    | PairV v1 v2   => PairV (invtranslationV v1) (invtranslationV v2)
    | InjLV v       => InjLV (invtranslationV v)
    | InjRV v       => InjRV (invtranslationV v)
    end.

476
  Lemma invtranslation_translation {Htick : Tick} e :
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
    invtranslation (translation e) = e
  with invtranslationV_translationV {Htick : Tick} v :
    invtranslationV (translationV v) = v.
  Proof.
    - specialize (invtranslation_translation Htick).
      specialize (invtranslationV_translationV Htick).
      destruct e;
        try by rewrite /= ?invtranslation_translation ?invtranslationV_translationV.
      (* Handle the App case by hand. *)
      { simpl. rewrite !invtranslation_translation. case_match=>//.
          by destruct e2. by destruct e2. }

    - specialize (invtranslation_translation Htick).
      specialize (invtranslationV_translationV Htick).
      destruct v;
        try by rewrite /= ?invtranslation_translation ?invtranslationV_translationV.
493 494 495 496 497 498 499 500 501 502 503 504 505
  Qed.
End InvTranslation.



(*
 * Characterizing expressions that are left invariant by translation
 *)

Section ClosureFree.

  Fixpoint closure_free (v : val) : bool :=
    match v with
506
    | RecV _ _ _ => false
507 508 509 510 511 512
    | LitV _ => true
    | PairV v1 v2 => closure_free v1 && closure_free v2
    | InjLV v1 => closure_free v1
    | InjRV v1 => closure_free v1
    end.

513
  Lemma closure_free_is_translationV_invariant {Htick : Tick} v :
514
    closure_free v 
515
    translationV v = v.
516 517 518
  Proof.
    intros ?.
    induction v as
519 520
      [ (* LitV *) lit
      | (* RecV *) f x e1
521 522 523
      | (* PairV *) v1 IH1 v2 IH2
      | (* InjLV *) v1 IH1
      | (* InjRV *) v1 IH1
524
      ] ; cbn in *.
525
    - done.
526 527
    - contradiction.
    - rewrite IH1 ?IH2; naive_solver.
528 529 530 531 532 533 534 535 536 537
    - rewrite IH1 ; naive_solver.
    - rewrite IH1 ; naive_solver.
  Qed.

  Lemma closure_free_is_invtranslationV_invariant v :
    closure_free v 
    invtranslationV v = v.
  Proof.
    intros ?.
    induction v as
538 539
      [ (* LitV *) lit
      | (* RecV *) f x e1
540 541 542
      | (* PairV *) v1 IH1 v2 IH2
      | (* InjLV *) v1 IH1
      | (* InjRV *) v1 IH1
543
      ] ; cbn.
544
    - done.
545
    - contradiction.
546 547 548 549 550
    - rewrite -> IH1, IH2 ; naive_solver.
    - rewrite IH1 ; naive_solver.
    - rewrite IH1 ; naive_solver.
  Qed.

551
  Lemma closure_free_translationV {Htick : Tick} v :
552
    closure_free v 
553
    closure_free (translationV v).
554
  Proof.
555
    intros Hv. by rewrite (closure_free_is_translationV_invariant v Hv).
556 557 558 559 560 561 562 563 564
  Qed.

  Lemma closure_free_invtranslationV v :
    closure_free v 
    closure_free (invtranslationV v).
  Proof.
    intros Hv. by rewrite (closure_free_is_invtranslationV_invariant v Hv).
  Qed.

565 566
  Lemma closure_free_translationV_iff  {Htick : Tick} v :
    closure_free v    closure_free (translationV v).
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
  Proof.
    split.
    - apply closure_free_translationV.
    - intros H % closure_free_invtranslationV. by rewrite invtranslationV_translationV in H.
  Qed.

  Lemma closure_free_predicate (φ : val  Prop) :
    ( (v : val), φ v  closure_free v) 
     (v : val),
      φ v  φ (invtranslationV v).
  Proof.
    intros Hφ v H.
    by specialize (Hφ _ H) as -> % closure_free_is_invtranslationV_invariant.
  Qed.

End ClosureFree.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

(*
 *  Proofmode wp_* tactics.
 *)

(* wp_tick is a stub to be redefined for each particular definition of
   the tick function. *)
Ltac wp_tick := idtac.

Ltac wp_tick_closure := wp_closure; wp_tick.
Ltac wp_tick_pair := wp_tick; wp_pair.
Ltac wp_tick_inj := wp_tick; wp_inj.

Ltac wp_tick_rec := wp_tick ; wp_rec; simpl_trans.
Ltac wp_tick_lam := wp_tick_rec.
Ltac wp_tick_let := wp_tick_closure; wp_tick_lam.
Ltac wp_tick_seq := wp_tick_let.
Ltac wp_tick_op := wp_tick ; wp_op.
Ltac wp_tick_if := wp_tick ; wp_if.
Ltac wp_tick_match :=
  wp_tick; wp_match; (wp_let || wp_seq); wp_lam;
  wp_closure; wp_tick; wp_tick; wp_lam.
Ltac wp_tick_proj := wp_tick ; wp_proj.
Ltac wp_tick_alloc loc := wp_tick ; wp_alloc loc.
Ltac wp_tick_load := wp_tick ; wp_load.
Ltac wp_tick_store := wp_tick ; wp_store.