wp_tactics.v 3.05 KB
Newer Older
1
From algebra Require Export upred_tactics.
2
3
4
From heap_lang Require Export tactics substitution.
Import uPred.

5
(** wp-specific helper tactics *)
6
7
8
Ltac wp_bind K :=
  lazymatch eval hnf in K with
  | [] => idtac
9
  | _ => etrans; [|solve [ apply (wp_bind K) ]]; simpl
10
  end.
11
12
13
Ltac wp_finish :=
  let rec go :=
  match goal with
14
  | |- _   _ => etrans; [|apply later_mono; go; reflexivity]
15
  | |- _  wp _ _ _ =>
16
17
18
19
20
    etrans; [|eapply wp_value_pvs; reflexivity];
    (* sometimes, we will have to do a final view shift, so only apply
    pvs_intro if we obtain a consecutive wp *)
    try (eapply pvs_intro;
         match goal with |- _  wp _ _ _ => simpl | _ => fail end)
21
  | _ => idtac
22
  end in simpl; intros_revert go.
23

24
Tactic Notation "wp_rec" ">" :=
25
26
27
28
29
30
31
32
33
34
  löb ltac:(
    (* Find the redex and apply wp_rec *)
    idtac; (* <https://coq.inria.fr/bugs/show_bug.cgi?id=4584> *)
    lazymatch goal with
    | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
      match eval cbv in e' with
      | App (Rec _ _ _) _ =>
         wp_bind K; etrans; [|eapply wp_rec; reflexivity]; wp_finish
      end)
     end).
35
Tactic Notation "wp_rec" := wp_rec>; try strip_later.
36

37
38
39
40
41
Tactic Notation "wp_lam" ">" :=
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | App (Rec "" _ _) _ =>
42
       wp_bind K; etrans; [|eapply wp_lam; reflexivity]; wp_finish
43
44
    end)
  end.
45
Tactic Notation "wp_lam" := wp_lam>; try strip_later.
46
47
48
49
50
51

Tactic Notation "wp_let" ">" := wp_lam>.
Tactic Notation "wp_let" := wp_lam.
Tactic Notation "wp_seq" ">" := wp_let>.
Tactic Notation "wp_seq" := wp_let.

52
Tactic Notation "wp_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
58
59
    | 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 _ _ _ =>
60
       wp_bind K; etrans; [|eapply wp_bin_op; reflexivity]; wp_finish
61
    | UnOp _ _ =>
62
       wp_bind K; etrans; [|eapply wp_un_op; reflexivity]; wp_finish
63
64
    end)
  end.
65
Tactic Notation "wp_op" := wp_op>; try strip_later.
66

67
Tactic Notation "wp_if" ">" :=
68
69
70
71
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | If _ _ _ =>
72
       wp_bind K;
73
       etrans; [|apply wp_if_true || apply wp_if_false]; wp_finish
74
75
    end)
  end.
76
Tactic Notation "wp_if" := wp_if>; try strip_later.
77

78
79
80
81
82
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.
83

84
Tactic Notation "wp" ">" tactic(tac) :=
85
86
87
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' => wp_bind K; tac)
  end.
88
Tactic Notation "wp" tactic(tac) := (wp> tac); [try strip_later|..].
89

Ralf Jung's avatar
Ralf Jung committed
90
91
(* In case the precondition does not match.
   TODO: Have one tactic unifying wp and ewp. *)
92
93
Tactic Notation "ewp" tactic(tac) := wp (etrans; [|tac]).
Tactic Notation "ewp" ">" tactic(tac) := wp> (etrans; [|tac]).