wp_tactics.v 2.55 KB
Newer Older
1 2 3 4 5 6
From heap_lang Require Export tactics substitution.
Import uPred.

Ltac wp_strip_later :=
  match goal with
  | |-  _, _ => let H := fresh in intro H; wp_strip_later; revert H
7
  | |- _   _ => etransitivity; [|by apply later_intro]
8 9 10 11
  end.
Ltac wp_bind K :=
  lazymatch eval hnf in K with
  | [] => idtac
12
  | _ => etransitivity; [|by apply (wp_bind K)]; simpl
13
  end.
14 15 16 17 18
Ltac wp_finish :=
  let rec go :=
  match goal with
  | |-  _, _ => let H := fresh in intro H; go; revert H
  | |- _   _ => etransitivity; [|apply later_mono; go; reflexivity]
19 20 21 22 23
  | |- _  wp _ _ _ =>
     etransitivity; [|eapply wp_value; reflexivity];
     (* sometimes, we will have to do a final view shift, so only apply
     wp_value if we obtain a consecutive wp *)
     match goal with |- _  wp _ _ _ => simpl | _ => fail end
24 25
  | _ => idtac
  end in simpl; go.
26 27 28

Tactic Notation "wp_value" :=
  match goal with
29
  | |- _  wp ?E ?e ?Q => etransitivity; [|eapply wp_value; reflexivity]; simpl
30
  end.
31
Tactic Notation "wp_rec" ">" :=
32 33 34
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
35 36
    | App (Rec _ _ _) _ =>
       wp_bind K; etransitivity; [|eapply wp_rec; reflexivity]; wp_finish
37 38
    end)
  end.
39 40
Tactic Notation "wp_rec" := wp_rec>; wp_strip_later.
Tactic Notation "wp_bin_op" ">" :=
41 42 43
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
44 45 46 47 48
    | BinOp LtOp _ _ => wp_bind K; apply wp_lt; wp_finish
    | BinOp LeOp _ _ => wp_bind K; apply wp_le; wp_finish
    | BinOp EqOp _ _ => wp_bind K; apply wp_eq; wp_finish
    | BinOp _ _ _ =>
       wp_bind K; etransitivity; [|eapply wp_bin_op; reflexivity]; wp_finish
49 50
    end)
  end.
51 52
Tactic Notation "wp_bin_op" := wp_bin_op>; wp_strip_later.
Tactic Notation "wp_un_op" ">" :=
53 54 55
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
56 57
    | UnOp _ _ =>
       wp_bind K; etransitivity; [|eapply wp_un_op; reflexivity]; wp_finish
58 59
    end)
  end.
60 61
Tactic Notation "wp_un_op" := wp_un_op>; wp_strip_later.
Tactic Notation "wp_if" ">" :=
62 63 64 65
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | If _ _ _ =>
66 67
       wp_bind K;
       etransitivity; [|apply wp_if_true || apply wp_if_false]; wp_finish
68 69
    end)
  end.
70
Tactic Notation "wp_if" := wp_if>; wp_strip_later.
71 72 73 74 75
Tactic Notation "wp_focus" open_constr(efoc) :=
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match e' with efoc => unify e' efoc; wp_bind K end)
  end.