wp_tactics.v 3.31 KB
 Ralf Jung committed Feb 24, 2016 1 ``````From algebra Require Export upred_tactics. `````` Robbert Krebbers committed Feb 16, 2016 2 3 4 ``````From heap_lang Require Export tactics substitution. Import uPred. `````` Ralf Jung committed Feb 20, 2016 5 6 7 ``````(** wp-specific helper tactics *) (* First try to productively strip off laters; if that fails, at least cosmetically get rid of laters in the conclusion. *) `````` Robbert Krebbers committed Feb 16, 2016 8 9 10 ``````Ltac wp_bind K := lazymatch eval hnf in K with | [] => idtac `````` Ralf Jung committed Feb 20, 2016 11 `````` | _ => etrans; [|solve [ apply (wp_bind K) ]]; simpl `````` Robbert Krebbers committed Feb 16, 2016 12 `````` end. `````` Robbert Krebbers committed Feb 16, 2016 13 14 15 ``````Ltac wp_finish := let rec go := match goal with `````` Ralf Jung committed Feb 20, 2016 16 `````` | |- _ ⊑ ▷ _ => etrans; [|apply later_mono; go; reflexivity] `````` Robbert Krebbers committed Feb 16, 2016 17 `````` | |- _ ⊑ wp _ _ _ => `````` Ralf Jung committed Feb 20, 2016 18 `````` etrans; [|eapply wp_value_pvs; reflexivity]; `````` Robbert Krebbers committed Feb 16, 2016 19 `````` (* sometimes, we will have to do a final view shift, so only apply `````` Robbert Krebbers committed Feb 25, 2016 20 `````` pvs_intro if we obtain a consecutive wp *) `````` Ralf Jung committed Feb 20, 2016 21 22 `````` try (eapply pvs_intro; match goal with |- _ ⊑ wp _ _ _ => simpl | _ => fail end) `````` Robbert Krebbers committed Feb 16, 2016 23 `````` | _ => idtac `````` Robbert Krebbers committed Feb 25, 2016 24 `````` end in simpl; intros_revert go. `````` Robbert Krebbers committed Feb 16, 2016 25 `````` `````` Ralf Jung committed Feb 20, 2016 26 ``````Tactic Notation "wp_rec" ">" := `````` Robbert Krebbers committed Feb 25, 2016 27 `````` löb ltac:((* Find the redex and apply wp_rec *) `````` Ralf Jung committed Feb 20, 2016 28 `````` idtac; (* *) `````` Ralf Jung committed Feb 20, 2016 29 `````` lazymatch goal with `````` Ralf Jung committed Feb 20, 2016 30 31 32 `````` | |- _ ⊑ wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' => match eval cbv in e' with | App (Rec _ _ _) _ => `````` Ralf Jung committed Feb 20, 2016 33 34 `````` wp_bind K; etrans; [|eapply wp_rec; reflexivity]; wp_finish `````` Ralf Jung committed Feb 20, 2016 35 `````` end) `````` Ralf Jung committed Feb 20, 2016 36 `````` end). `````` Robbert Krebbers committed Feb 25, 2016 37 ``````Tactic Notation "wp_rec" := wp_rec>; try strip_later. `````` Ralf Jung committed Feb 20, 2016 38 `````` `````` 39 40 41 42 43 ``````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 "" _ _) _ => `````` Ralf Jung committed Feb 20, 2016 44 `````` wp_bind K; etrans; [|eapply wp_lam; reflexivity]; wp_finish `````` 45 46 `````` end) end. `````` Robbert Krebbers committed Feb 25, 2016 47 ``````Tactic Notation "wp_lam" := wp_lam>; try strip_later. `````` 48 49 50 51 52 53 `````` Tactic Notation "wp_let" ">" := wp_lam>. Tactic Notation "wp_let" := wp_lam. Tactic Notation "wp_seq" ">" := wp_let>. Tactic Notation "wp_seq" := wp_let. `````` Ralf Jung committed Feb 20, 2016 54 ``````Tactic Notation "wp_op" ">" := `````` Robbert Krebbers committed Feb 16, 2016 55 56 57 `````` match goal with | |- _ ⊑ wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' => match eval cbv in e' with `````` Robbert Krebbers committed Feb 16, 2016 58 59 60 61 `````` | 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 _ _ _ => `````` Ralf Jung committed Feb 20, 2016 62 `````` wp_bind K; etrans; [|eapply wp_bin_op; reflexivity]; wp_finish `````` Robbert Krebbers committed Feb 16, 2016 63 `````` | UnOp _ _ => `````` Ralf Jung committed Feb 20, 2016 64 `````` wp_bind K; etrans; [|eapply wp_un_op; reflexivity]; wp_finish `````` Robbert Krebbers committed Feb 16, 2016 65 66 `````` end) end. `````` Robbert Krebbers committed Feb 25, 2016 67 ``````Tactic Notation "wp_op" := wp_op>; try strip_later. `````` Ralf Jung committed Feb 20, 2016 68 `````` `````` Robbert Krebbers committed Feb 16, 2016 69 ``````Tactic Notation "wp_if" ">" := `````` Robbert Krebbers committed Feb 16, 2016 70 71 72 73 `````` match goal with | |- _ ⊑ wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' => match eval cbv in e' with | If _ _ _ => `````` Robbert Krebbers committed Feb 16, 2016 74 `````` wp_bind K; `````` Ralf Jung committed Feb 20, 2016 75 `````` etrans; [|apply wp_if_true || apply wp_if_false]; wp_finish `````` Robbert Krebbers committed Feb 16, 2016 76 77 `````` end) end. `````` Robbert Krebbers committed Feb 25, 2016 78 ``````Tactic Notation "wp_if" := wp_if>; try strip_later. `````` Ralf Jung committed Feb 20, 2016 79 `````` `````` Robbert Krebbers committed Feb 16, 2016 80 81 82 83 84 ``````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. `````` Robbert Krebbers committed Feb 17, 2016 85 `````` `````` 86 ``````Tactic Notation "wp" ">" tactic(tac) := `````` Robbert Krebbers committed Feb 17, 2016 87 88 89 `````` match goal with | |- _ ⊑ wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' => wp_bind K; tac) end. `````` Robbert Krebbers committed Feb 25, 2016 90 ``````Tactic Notation "wp" tactic(tac) := (wp> tac); [try strip_later|..]. `````` Robbert Krebbers committed Feb 17, 2016 91 `````` `````` Ralf Jung committed Feb 22, 2016 92 93 ``````(* In case the precondition does not match. TODO: Have one tactic unifying wp and ewp. *) `````` Ralf Jung committed Feb 20, 2016 94 95 ``````Tactic Notation "ewp" tactic(tac) := wp (etrans; [|tac]). Tactic Notation "ewp" ">" tactic(tac) := wp> (etrans; [|tac]).``````