Skip to content

Commit 874aa96

Browse files
committed
Separate some concerns: let notations do as little logic as possible
1 parent a4f26f4 commit 874aa96

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

theories/Tactics/By.v

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ Ltac2 Notation "By"
5757
let xtr_dbs := List.filter (fun z => Constr.equal (Constr.type z) constr:(string)) parsed_args in
5858
let xtr_dbs := List.map rocq_string_to_ltac2_string xtr_dbs in
5959
if String.equal x "it holds" then
60-
panic_if_goal_wrapped();
61-
(wp_assert_by claim label xtr_lemmas xtr_dbs)
60+
(wp_assert_by_with_checks claim label xtr_lemmas xtr_dbs)
6261
else if String.equal x "we conclude" then
63-
unwrap_state_goal_no_check ();
64-
panic_if_goal_wrapped();
65-
guarantee_stated_goal_matches claim;
66-
(conclude_by xtr_lemmas xtr_dbs)
62+
(wp_conclude_by_with_checks claim xtr_lemmas xtr_dbs)
6763
else
68-
(wp_enough_by claim xtr_lemmas xtr_dbs).
64+
(wp_enough_by_with_checks claim xtr_lemmas xtr_dbs).

theories/Tactics/Conclusion.v

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Local Ltac2 target_equals_goal_judgementally (target : constr) :=
7171
*)
7272

7373

74-
Ltac2 guarantee_stated_goal_matches (sttd_goal : constr) :=
74+
Local Ltac2 guarantee_stated_goal_matches (sttd_goal : constr) :=
7575
let sttd_goal := correct_type_by_wrapping sttd_goal in
7676
let sttd_goal := (eval unfold subset_type, ge_op, R_ge_type, nat_ge_type, gt_op, R_gt_type, nat_gt_type in $sttd_goal) in
7777
let current_goal := Control.goal () in
@@ -145,7 +145,7 @@ Local Ltac2 core_conclude_by (xtr_lemmas : constr list) (xtr_dbs : hint_db_name
145145

146146
(** Adaptation of [core_conclude_by] that turns the [FailedToUse] errors
147147
which might be thrown into user readable errors. *)
148-
Ltac2 conclude_by (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
148+
Local Ltac2 conclude_by (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
149149
wrapper_core_by_tactic core_conclude_by xtr_lemmas xtr_dbs.
150150

151151
(** Adaptation of [core_conclude_by] that allows user to use mathematical statements themselves
@@ -164,7 +164,7 @@ Local Ltac2 conclude_since (xtr_claim : constr) :=
164164
Does:
165165
- Removes the wrapper [StateGoal.Wrapper G].
166166
*)
167-
Ltac2 unwrap_state_goal_no_check () :=
167+
Local Ltac2 unwrap_state_goal_no_check () :=
168168
lazy_match! goal with
169169
| [|- StateGoal.Wrapper _] => apply StateGoal.wrap
170170
| [|- VerifyGoal.Wrapper _] => apply VerifyGoal.wrap
@@ -203,12 +203,19 @@ Ltac2 Notation "It" "follows" _(opt("that")) target_goal(lconstr) :=
203203
204204
Arguments:
205205
- [target_goal: constr], expression that should equal the goal under focus.
206-
- [xtr_lemma: constr], lemma that can be and has to be used for proof of [target_goal].
206+
- [xtr_lemmas: constr list], extra lemmas that can be used for proof of [target_goal].
207+
- [xtr_dbs: hint_db_name list], extra hint databases that can be used for proof of [target_goal].
207208
208209
Raises exceptions:
209210
- [AutomationFailure], if [waterprove] fails the prove the goal (i.e. the goal is too difficult, or does not hold).
210211
- [ConcludeError], if [target_goal] is not equivalent to the actual goal under focus, even after rewriting.
211212
*)
213+
Ltac2 wp_conclude_by_with_checks (target_goal : constr) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
214+
unwrap_state_goal_no_check ();
215+
panic_if_goal_wrapped ();
216+
guarantee_stated_goal_matches target_goal;
217+
conclude_by xtr_lemmas xtr_dbs.
218+
212219
Ltac2 Notation "Since" xtr_claim(lconstr) "we" "conclude" _(opt("that")) target_goal(lconstr) :=
213220
unwrap_state_goal_no_check ();
214221
panic_if_goal_wrapped ();

theories/Tactics/ItHolds.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Local Ltac2 core_wp_assert_by (claim : constr) (label : ident option) (xtr_lemma
118118

119119
(** Adaptation of [core_wp_assert_by] that turns the [FailedToUse] errors
120120
which might be thrown into user readable errors. *)
121-
Ltac2 wp_assert_by (claim : constr) (label : ident option) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
121+
Local Ltac2 wp_assert_by (claim : constr) (label : ident option) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
122122
wrapper_core_by_tactic (core_wp_assert_by claim label) xtr_lemmas xtr_dbs;
123123
(* Print suggestion on how to use new statement. *)
124124
HelpNewHyp.suggest_how_to_use claim label.
@@ -146,7 +146,9 @@ Local Ltac2 wp_assert_since (claim : constr) (label : ident option) (xtr_claim :
146146
- (fatal) if [rwaterprove] fails to prove the claim using the specified lemma.
147147
- [[label] is already used], if there is already another hypothesis with identifier [label].
148148
*)
149-
149+
Ltac2 wp_assert_by_with_checks (claim : constr) (label : ident option) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
150+
panic_if_goal_wrapped ();
151+
wp_assert_by claim label xtr_lemmas xtr_dbs.
150152

151153

152154
(** Attempts to prove that proposed goal is enough to show current goal,

theories/Tactics/ItSuffices.v

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,25 @@ Local Ltac2 core_wp_enough_by (new_goal : constr) (xtr_lemmas : constr list) (xt
6262

6363
(** Adaptation of [core_wp_enough_by] that turns the [FailedToUse] errors
6464
which might be thrown into user readable errors. *)
65-
Ltac2 wp_enough_by (claim : constr) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
65+
Local Ltac2 wp_enough_by (claim : constr) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
6666
wrapper_core_by_tactic (core_wp_enough_by claim) xtr_lemmas xtr_dbs.
6767

68+
(**
69+
Proves that proposed goal is enough to show current goal.
70+
71+
Arguments:
72+
- [claim]: proposed goal.
73+
- [xtr_lemmas]: list of extra lemmas that can be used in the proof.
74+
- [xtr_dbs]: list of extra hint databases to use in the proof.
75+
76+
Throws:
77+
- [FailedToProve] if [rwaterprove] fails to prove that [claim] is enough to show current goal using the specified lemmas and hint databases.
78+
- [FailedToUse] if [rwaterprove] fails to use a lemma in the proof while it should have used it.
79+
*)
80+
Ltac2 wp_enough_by_with_checks (claim : constr) (xtr_lemmas : constr list) (xtr_dbs : hint_db_name list) :=
81+
panic_if_goal_wrapped ();
82+
wp_enough_by claim xtr_lemmas xtr_dbs.
83+
6884
(** Adaptation of [core_wp_assert_by] that allows user to use mathematical statements themselves
6985
instead of references to them as extra information for the automation system.
7086
Uses the code in [Since.v]. *)

0 commit comments

Comments
 (0)