wp_tactics.v 2.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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
  | |- _   _ => etransitivity; [|apply later_intro]
  end.
Ltac wp_bind K :=
  lazymatch eval hnf in K with
  | [] => idtac
  | _ => etransitivity; [|apply (wp_bind K)]; simpl
  end.
14
15
16
17
18
19
20
21
Ltac wp_finish :=
  let rec go :=
  match goal with
  | |-  _, _ => let H := fresh in intro H; go; revert H
  | |- _   _ => etransitivity; [|apply later_mono; go; reflexivity]
  | |- _  wp _ _ _ => etransitivity; [|eapply wp_value; reflexivity]; simpl
  | _ => idtac
  end in simpl; go.
22
23
24

Tactic Notation "wp_value" :=
  match goal with
25
  | |- _  wp ?E ?e ?Q => etransitivity; [|eapply wp_value; reflexivity]; simpl
26
  end.
27
Tactic Notation "wp_rec" ">" :=
28
29
30
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
31
32
    | App (Rec _ _ _) _ =>
       wp_bind K; etransitivity; [|eapply wp_rec; reflexivity]; wp_finish
33
34
    end)
  end.
35
36
Tactic Notation "wp_rec" := wp_rec>; wp_strip_later.
Tactic Notation "wp_bin_op" ">" :=
37
38
39
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
40
41
42
43
44
    | 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
45
46
47
    end)
  end.

48
49
Tactic Notation "wp_bin_op" := wp_bin_op>; wp_strip_later.
Tactic Notation "wp_un_op" ">" :=
50
51
52
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
53
54
    | UnOp _ _ =>
       wp_bind K; etransitivity; [|eapply wp_un_op; reflexivity]; wp_finish
55
56
    end)
  end.
57
58
Tactic Notation "wp_un_op" := wp_un_op>; wp_strip_later.
Tactic Notation "wp_if" ">" :=
59
  try wp_value;
60
61
62
63
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | If _ _ _ =>
64
65
       wp_bind K;
       etransitivity; [|apply wp_if_true || apply wp_if_false]; wp_finish
66
67
    end)
  end.
68
Tactic Notation "wp_if" := wp_if>; wp_strip_later.
69
70
71
72
73
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.