Skip to content

Commit f4b72c4

Browse files
committed
Actually name the unfold actions
1 parent 1b290db commit f4b72c4

File tree

9 files changed

+85
-104
lines changed

9 files changed

+85
-104
lines changed

src/g_waterproof.mlg

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,43 +209,43 @@ END
209209
}
210210

211211
VERNAC COMMAND EXTEND RegisterUnfold CLASSIFIED AS SIDEFF
212-
| [ "Waterproof" "Register" "Unfold" ne_string_list(s) ref(id) ] => { Vernacextend.(VtSideff ([], VtNow)) }
212+
| [ "Waterproof" "Register" "Unfold" ne_string_list(s) ref(id) ";" string(name)] => { Vernacextend.(VtSideff ([], VtNow)) }
213213
SYNTERP AS notation_data_and_ref
214214
{
215215
let located_id = Nametab.locate id in
216-
(register_unfold s (Nametab.locate id), located_id)
216+
(register_unfold s (Nametab.locate id), located_id, name)
217217
} ->
218218
{
219-
let (notation_data, id) = notation_data_and_ref in
219+
let (notation_data, id, name) = notation_data_and_ref in
220220
register_notation_interpretation notation_data;
221-
register_unfold_entry id Unfold_entry
221+
register_unfold_entry id (Unfold_entry name)
222222
}
223223
END
224224

225225
VERNAC COMMAND EXTEND RegisterUnfoldRewrite CLASSIFIED AS SIDEFF
226-
| [ "Waterproof" "Register" "Unfold" "Rewrite" ne_string_list(s) ref(id) ";" constr(e)] => { Vernacextend.(VtSideff ([], VtNow)) }
226+
| [ "Waterproof" "Register" "Unfold" "Rewrite" ne_string_list(s) ref(id) ";" string(name) ";" constr(e)] => { Vernacextend.(VtSideff ([], VtNow)) }
227227
SYNTERP AS notation_data_and_ref_and_constr_expr
228228
{
229229
let located_id = Nametab.locate id in
230-
(register_unfold s located_id, located_id, e)
230+
(register_unfold s located_id, located_id, name, e)
231231
} ->
232232
{
233-
let (notation_data, id, e) = notation_data_and_ref_and_constr_expr in
233+
let (notation_data, id, name, e) = notation_data_and_ref_and_constr_expr in
234234
register_notation_interpretation notation_data;
235-
register_unfold_entry id (Rewrite_entry e)
235+
register_unfold_entry id (Rewrite_entry (name, e))
236236
}
237237
END
238238

239239
VERNAC COMMAND EXTEND RegisterUnfoldApply CLASSIFIED AS SIDEFF
240-
| [ "Waterproof" "Register" "Unfold" "Apply" ne_string_list(s) ref(id) ";" constr(e)] => { Vernacextend.(VtSideff ([], VtNow)) }
240+
| [ "Waterproof" "Register" "Unfold" "Apply" ne_string_list(s) ref(id) ";" string(name) ";"constr(e)] => { Vernacextend.(VtSideff ([], VtNow)) }
241241
SYNTERP AS notation_data_and_ref_and_constr_expr
242242
{
243243
let located_id = Nametab.locate id in
244-
(register_unfold s located_id, located_id, e)
244+
(register_unfold s located_id, located_id, name, e)
245245
} ->
246246
{
247-
let (notation_data, id, e) = notation_data_and_ref_and_constr_expr in
247+
let (notation_data, id, name, e) = notation_data_and_ref_and_constr_expr in
248248
register_notation_interpretation notation_data;
249-
register_unfold_entry id (Apply_entry e)
249+
register_unfold_entry id (Apply_entry (name, e))
250250
}
251251
END

src/unfold_framework.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ open Names
3333

3434
module StringMap = Map.Make(String)
3535

36-
(** A type to represent the different unfold actions, and the data they need. *)
36+
(** A type to represent the different unfold actions, a name for the action, and the data they need. *)
3737
type unfold_action =
38-
| Unfold of GlobRef.t
39-
| Apply of EConstr.constr
40-
| Rewrite of EConstr.constr
38+
| Unfold of string * GlobRef.t
39+
| Apply of string * EConstr.constr
40+
| Rewrite of string * EConstr.constr
4141

4242
(** The map that associate notation strings to references *)
4343
let wp_unfold_map = Summary.ref ~name:"wp_unfold_map" StringMap.empty
@@ -105,9 +105,9 @@ let register_unfold (toks : string list) (id : GlobRef.t) : notation_interpretat
105105
to an unfold action.
106106
*)
107107
type unfold_entry =
108-
| Unfold_entry
109-
| Apply_entry of Constrexpr.constr_expr
110-
| Rewrite_entry of Constrexpr.constr_expr
108+
| Unfold_entry of string
109+
| Apply_entry of string * Constrexpr.constr_expr
110+
| Rewrite_entry of string * Constrexpr.constr_expr
111111

112112
(** Registers a new entry in the table that stores a list of
113113
unfold actions associated to a reference.
@@ -126,11 +126,11 @@ let register_unfold_entry (id : GlobRef.t) (ue : unfold_entry) : unit =
126126
let (constr_e, _) = Constrintern.interp_constr env sigma e in
127127
constr_e in
128128
match ue with
129-
| Unfold_entry -> add_to_unfold_tbl id (Unfold id)
130-
| Apply_entry e ->
131-
add_to_unfold_tbl id (Apply (f e))
132-
| Rewrite_entry e ->
133-
add_to_unfold_tbl id (Rewrite (f e))
129+
| Unfold_entry s -> add_to_unfold_tbl id (Unfold (s, id))
130+
| Apply_entry (s, e) ->
131+
add_to_unfold_tbl id (Apply (s, f e))
132+
| Rewrite_entry (s, e) ->
133+
add_to_unfold_tbl id (Rewrite (s, f e))
134134

135135
let get_all_references () : GlobRef.t list =
136136
let lst = !wp_unfold_tbl |> Hashtbl.to_seq_keys |> List.of_seq in

src/unfold_framework.mli

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ introduced notations, and the global reference they are associated with
3333

3434
(** A type to represent the different unfold actions, and the data they need. *)
3535
type unfold_action =
36-
| Unfold of GlobRef.t
37-
| Apply of EConstr.constr
38-
| Rewrite of EConstr.constr
36+
| Unfold of string * GlobRef.t
37+
| Apply of string * EConstr.constr
38+
| Rewrite of string * EConstr.constr
3939

4040
(** A type that represents the datastructure that can be added
4141
to the unfold table. When it is added, it will be converted
4242
to an unfold action. *)
4343
type unfold_entry =
44-
| Unfold_entry
45-
| Apply_entry of Constrexpr.constr_expr
46-
| Rewrite_entry of Constrexpr.constr_expr
44+
| Unfold_entry of string
45+
| Apply_entry of string * Constrexpr.constr_expr
46+
| Rewrite_entry of string * Constrexpr.constr_expr
4747

4848
module StringMap : Map.S with type key = string
4949

src/wp_ffi.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ let feedback_lvl_from_valexpr (value : valexpr): Feedback.level = match value wi
173173

174174
let of_unfold_action =
175175
function
176-
| Unfold gr -> of_block (0, [|of_reference gr|])
177-
| Apply c -> of_block (1, [|of_constr c|])
178-
| Rewrite c -> of_block(2, [|of_constr c|])
176+
| Unfold (s, gr) -> of_block (0, [|of_string s; of_reference gr|])
177+
| Apply (s, c) -> of_block (1, [|of_string s; of_constr c|])
178+
| Rewrite (s, c) -> of_block(2, [|of_string s; of_constr c|])
179179

180180
let to_unfold_action = let open Ltac2_plugin.Tac2val in function
181-
| ValBlk (0, [|gr|]) -> Unfold (to_reference gr)
182-
| ValBlk (1, [|c|]) -> Apply (to_constr c)
183-
| ValBlk (2, [|c|]) -> Rewrite (to_constr c)
181+
| ValBlk (0, [|s; gr|]) -> Unfold (to_string s, to_reference gr)
182+
| ValBlk (1, [|s; c|]) -> Apply (to_string s, to_constr c)
183+
| ValBlk (2, [|s; c|]) -> Rewrite (to_string s, to_constr c)
184184
| _ -> assert false
185185

186186
let unfold_action_repr = make_repr of_unfold_action to_unfold_action

tests/libs/Analysis/OpenAndClosed.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Proof.
4545
(fun () => Expand the definition of open)
4646
"Remove this line in the final version of your proof.")
4747
Info
48-
["Expanded definition in statements where applicable.";
48+
["open";
49+
"Expanded definition in statements where applicable.";
4950
"Hint, insert: We need to show that (∀ a ∈ A, a is an _interior point_ of A).";
5051
"Hint, insert: It holds that (∀ a ∈ A, a is an _interior point_ of A)."].
5152
Abort.

tests/tactics/Unfold.v

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Abort.
101101
Local Parameter P Q R : Prop.
102102
Local Parameter HPQ : P <-> Q.
103103

104-
Waterproof Register Unfold Apply "notation" "for" "P" P ; (HPQ).
104+
Waterproof Register Unfold Apply "notation" "for" "P" P ; "Alternative characterization of P"; (HPQ).
105105

106106
(* Test 8: Use alternative characterization, with concept in conclusion,
107107
but without having the automation able to prove the alternative
@@ -150,7 +150,8 @@ Proof.
150150
(fun () => Unfold the definition of notation for P)
151151
"Remove this line in the final version of your proof.")
152152
Info
153-
["Applied alternative characterizations in statements where applicable.";
153+
["Alternative characterization of P";
154+
"Applied alternative characterizations in statements where applicable.";
154155
"Hint, replace with: It suffices to show that Q."].
155156
It suffices to show that Q.
156157
Abort.
@@ -165,7 +166,8 @@ Proof.
165166
(fun () => Unfold the definition of notation for P)
166167
"Remove this line in the final version of your proof.")
167168
Info
168-
["Applied alternative characterizations in statements where applicable.";
169+
["Alternative characterization of P";
170+
"Applied alternative characterizations in statements where applicable.";
169171
"Hint, replace with: It holds that Q."].
170172
It holds that Q.
171173
Abort.
@@ -178,7 +180,7 @@ Proof.
178180
assert_constr_equal (tactic_in_constr constr:(HPR) constr:(P -> Q)) constr:(R -> Q).
179181
Abort.
180182

181-
Waterproof Register Unfold Rewrite "characterization" "of" "P" P ; HPR.
183+
Waterproof Register Unfold Rewrite "characterization" "of" "P" P ; "Characterization of P"; HPR.
182184

183185
Local Hint Extern 1 => rewrite HPR : core.
184186

@@ -193,8 +195,10 @@ intros.
193195
(fun () => Unfold the definition of notation for P)
194196
"Remove this line in the final version of your proof.")
195197
Info
196-
["Applied alternative characterizations in statements where applicable.";
198+
["Characterization of P";
199+
"Applied alternative characterizations in statements where applicable.";
197200
"Hint, replace with: It suffices to show that R.";
201+
"Alternative characterization of P";
198202
"Applied alternative characterizations in statements where applicable.";
199203
"Hint, replace with: It suffices to show that Q."].
200204
It suffices to show that Q.
@@ -223,11 +227,13 @@ assert_feedback_with_strings
223227
(fun () => Unfold the definition of infimum)
224228
"Remove this line in the final version of your proof.")
225229
Info
226-
["Expanded definition in statements where applicable.";
230+
["Definition infimum";
231+
"Expanded definition in statements where applicable.";
227232
"Hint, insert: We need to show that (3 is a _lower bound_ for A
228233
∧ (∀ l ∈ ℝ, l is a _lower bound_ for A ⇨ l ≤ 3)).";
229234
"Hint, insert: It holds that (4 is a _lower bound_ for A
230235
∧ (∀ l ∈ ℝ, l is a _lower bound_ for A ⇨ l ≤ 4)).";
236+
"Alternative characterization infimum";
231237
"Applied alternative characterizations in statements where applicable.";
232238
"Hint, insert: It suffices to show that (3 is a _lower bound_ for A
233239
∧ (∀ ε > 0, ∃ a ∈ A, a < 3 + ε)).";
@@ -244,11 +250,13 @@ assert_feedback_with_strings
244250
(fun () => Unfold the definition of supremum)
245251
"Remove this line in the final version of your proof.")
246252
Info
247-
["Expanded definition in statements where applicable.";
253+
["Definition supremum";
254+
"Expanded definition in statements where applicable.";
248255
"Hint, insert: We need to show that (3 is an _upper bound_ for A
249256
∧ (∀ L ∈ ℝ, L is an _upper bound_ for A ⇨ 3 ≤ L)).";
250257
"Hint, insert: It holds that (4 is an _upper bound_ for A
251258
∧ (∀ L ∈ ℝ, L is an _upper bound_ for A ⇨ 4 ≤ L)).";
259+
"Alternative characterization supremum";
252260
"Applied alternative characterizations in statements where applicable.";
253261
"Hint, insert: It suffices to show that (3 is an _upper bound_ for A
254262
∧ (∀ ε > 0, ∃ a ∈ A, 3 - ε < a)).";
@@ -265,15 +273,20 @@ assert_feedback_with_strings
265273
(fun () => Unfold All)
266274
"Remove this line in the final version of your proof.")
267275
Info
268-
["Expanded definition in statements where applicable.";
276+
[
277+
"Definition infimum";
278+
"Expanded definition in statements where applicable.";
269279
"Hint, replace with: We need to show that (3 is a _lower bound_ for A
270280
∧ (∀ l ∈ ℝ, l is a _lower bound_ for A ⇨ l ≤ 3)).";
281+
"Alternative characterization infimum";
271282
"Applied alternative characterizations in statements where applicable.";
272283
"Hint, replace with: It suffices to show that (3 is a _lower bound_ for A
273284
∧ (∀ ε > 0, ∃ a ∈ A, a < 3 + ε)).";
285+
"Definition supremum";
274286
"Expanded definition in statements where applicable.";
275287
"Hint, replace with: It holds that (4 is an _upper bound_ for A
276288
∧ (∀ L ∈ ℝ, L is an _upper bound_ for A ⇨ 4 ≤ L)).";
289+
"Alternative characterization supremum";
277290
"Applied alternative characterizations in statements where applicable.";
278291
"Hint, replace with: It holds that (4 is an _upper bound_ for A ∧ (∀ ε > 0, ∃ a ∈ A, 4 - ε < a))."].
279292
Abort.

tests/util/Unfold_framework.v

Lines changed: 0 additions & 45 deletions
This file was deleted.

theories/Libs/Analysis/SupAndInf.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,8 @@ Qed.
824824

825825
Local Ltac2 unfold_is_inf (statement : constr) := eval unfold is_inf in $statement.
826826

827-
Waterproof Register Unfold Apply "infimum" is_inf; (alt_char_inf).
828-
Waterproof Register Unfold "infimum" is_inf.
827+
Waterproof Register Unfold Apply "infimum" is_inf; "Alternative characterization infimum"; (alt_char_inf).
828+
Waterproof Register Unfold "infimum" is_inf; "Definition infimum".
829829

830830
Ltac2 Notation "Expand" "the" "definition" "of" "infimum" x(opt(seq("in", constr))) :=
831831
wp_unfold unfold_is_inf (Some "infimum") false true x;
@@ -842,8 +842,8 @@ Ltac2 Notation "Expand" "the" "definition" "of" "supremum" x(opt(seq("in", const
842842
Ltac2 Notation "_internal_" "Expand" "the" "definition" "of" "supremum" x(opt(seq("in", constr))) :=
843843
wp_unfold unfold_is_sup (Some "supremum") false true x.
844844

845-
Waterproof Register Unfold Apply "supremum" is_sup; (alt_char_sup).
846-
Waterproof Register Unfold "supremum" is_sup.
845+
Waterproof Register Unfold Apply "supremum" is_sup; "Alternative characterization supremum";(alt_char_sup).
846+
Waterproof Register Unfold "supremum" is_sup; "Definition supremum".
847847

848848
#[export] Hint Resolve bounded_by_upper_bound_propform : wp_reals.
849849
#[export] Hint Resolve bounded_by_lower_bound_propform : wp_reals.

theories/Tactics/Unfold.v

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Require Import Util.Goals.
2828
Require Import Util.MessagesToUser.
2929

3030
Ltac2 Type unfold_action := [
31-
| Unfold (reference)
32-
| Apply (constr)
33-
| Rewrite (constr)
31+
| Unfold (string, reference)
32+
| Apply (string, constr)
33+
| Rewrite (string, constr)
3434
].
3535

3636
Ltac2 @ external extract_def_ffi : string -> reference option := "rocq-runtime.plugins.coq-waterproof" "extract_def_external".
@@ -128,9 +128,9 @@ Ltac2 tactic_in_constr (equality : constr) (x : constr) : constr :=
128128

129129
Ltac2 unfold_method_for_action (ua : unfold_action) (stmt : constr) : constr :=
130130
match ua with
131-
| Unfold r => eval unfold $r in $stmt
132-
| Apply equiv => apply_in_constr equiv stmt
133-
| Rewrite eq => tactic_in_constr eq stmt
131+
| Unfold _ name => eval unfold $name in $stmt
132+
| Apply _ equiv => apply_in_constr equiv stmt
133+
| Rewrite _ eq => tactic_in_constr eq stmt
134134
end.
135135

136136
(**
@@ -171,6 +171,10 @@ Ltac2 unfold_in_all (unfold_method: constr -> constr)
171171
(* Print output *)
172172
if (Bool.or did_unfold_goal (Bool.neg (_is_empty only_unfolded_hyps)))
173173
then
174+
match def_name with
175+
| Some s => info_notice (of_string s)
176+
| _ => ()
177+
end;
174178
(* Print initial statement *)
175179
if definitional then
176180
(info_notice (of_string "Expanded definition in statements where applicable."))
@@ -267,14 +271,22 @@ Ltac2 Notation "Expand" "the" "definition" "of" targets(list1(seq(reference, occ
267271

268272
wp_unfold (eval_unfold targets) None true true None.
269273

274+
Ltac2 name_from_action (ua : unfold_action) : string :=
275+
match ua with
276+
| Unfold name _ => name
277+
| Apply name _ => name
278+
| Rewrite name _ => name
279+
end.
280+
270281
Local Ltac2 wp_unfold_from_action_list (ua_list : unfold_action list) :=
271282
let definitional_for_action (ua : unfold_action) := match ua with
272-
| Unfold _ => true
273-
| Apply _ => false
274-
| Rewrite _ => false
283+
| Unfold _ _ => true
284+
| Apply _ _ => false
285+
| Rewrite _ _ => false
275286
end in
276287
List.iter (fun z =>
277-
wp_unfold (unfold_method_for_action z) None false (definitional_for_action z) None)
288+
wp_unfold (unfold_method_for_action z)
289+
(Some (name_from_action z)) false (definitional_for_action z) None)
278290
ua_list.
279291

280292

0 commit comments

Comments
 (0)