Skip to content

Commit 0b112db

Browse files
committed
Search: don't search local defs (unless Unset Search Blacklist Locals)
1 parent 0c7fb9c commit 0b112db

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- **Changed:**
2+
:cmd:`Search` ignores lemmas declared with :attr:`local` unless
3+
new flag :flag:`Search Blacklist Locals` is unset
4+
(`#20349 <https://github.com/coq/coq/pull/20349>`_,
5+
by Gaëtan Gilbert).

doc/sphinx/proof-engine/vernacular-commands.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ described elsewhere
369369

370370
SearchRewrite (_ + _ + _).
371371

372+
.. flag:: Search Blacklist Locals
373+
374+
By default :cmd:`Search` excludes lemmas declared with :attr:`local` from its results
375+
(except for those from the current module or its parents).
376+
Unsetting this :term:`flag` will include such lemmas in the results.
377+
372378
.. table:: Search Blacklist @string
373379

374380
This :term:`table` specifies a set of strings used to exclude lemmas from the results of :cmd:`Search`,

test-suite/output/Search.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,14 @@ plus_O_n: forall n : nat, 0 + n = n
451451
plus_n_Sm: forall n m : nat, S (n + m) = n + S m
452452
plus_Sn_m: forall n m : nat, S n + m = S (n + m)
453453
mult_n_Sm: forall n m : nat, n * m + n = n * S m
454+
should say both t and t_alias
455+
- : Init.unit = ()
456+
t: T
457+
t_alias: T
458+
should say only t
459+
- : Init.unit = ()
460+
BlacklistLocals.t: BlacklistLocals.T
461+
should say both t and t_alias
462+
- : Init.unit = ()
463+
BlacklistLocals.t_alias: BlacklistLocals.T
464+
BlacklistLocals.t: BlacklistLocals.T

test-suite/output/Search.v

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,23 @@ Search "+".
5252
Search hyp:bool -headhyp:bool.
5353
Search concl:bool -headconcl:bool.
5454
Search [ is:Definition headconcl:nat | is:Lemma (_ + _) ].
55+
56+
(* used to print something between search outputs, otherwise we can't
57+
tell which lines are from which command *)
58+
Require Import Ltac2.Printf.
59+
60+
Module BlacklistLocals.
61+
Axiom T : Type.
62+
Axiom t : T.
63+
Local Definition t_alias := t.
64+
65+
Ltac2 Eval printf "should say both t and t_alias".
66+
Search T.
67+
End BlacklistLocals.
68+
69+
Ltac2 Eval printf "should say only t".
70+
Search BlacklistLocals.T.
71+
72+
Unset Search Blacklist Locals.
73+
Ltac2 Eval printf "should say both t and t_alias".
74+
Search BlacklistLocals.T.

vernac/declare.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ val program_inference_hook : Environ.env -> Evd.evar_map -> Evar.t -> (Evd.evar_
625625
end
626626

627627
val is_local_constant : Constant.t -> bool
628+
(** [true] on constants declared Local and not from the current
629+
interactive module (or its parents). *)
628630

629631
(** {6 For internal support, do not use} *)
630632

vernac/search.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ module SearchBlacklist =
5151
str "Search blacklist does " ++ (if b then mt () else str "not ") ++ str "include " ++ str s
5252
end)
5353

54+
let { Goptions.get = blacklist_locals } =
55+
Goptions.declare_bool_option_and_ref ~key:["Search";"Blacklist";"Locals"] ~value:true ()
56+
5457
(* The functions iter_constructors and iter_declarations implement the behavior
5558
needed for the Rocq searching commands.
5659
These functions take as first argument the procedure
@@ -184,11 +187,17 @@ let full_name_of_reference ref =
184187
let (dir,id) = repr_path (Nametab.path_of_global ref) in
185188
DirPath.to_string dir ^ "." ^ Id.to_string id
186189

190+
let is_local_ref : GlobRef.t -> bool = function
191+
| ConstRef c -> Declare.is_local_constant c
192+
| IndRef _ | ConstructRef _ | VarRef _ -> false
193+
187194
(** Whether a reference is blacklisted *)
188195
let blacklist_filter : filter_function = fun ref kind env sigma typ ->
189-
let name = full_name_of_reference ref in
190-
let is_not_bl str = not (String.string_contains ~where:name ~what:str) in
191-
CString.Set.for_all is_not_bl (SearchBlacklist.v ())
196+
if blacklist_locals() && is_local_ref ref then false
197+
else
198+
let name = full_name_of_reference ref in
199+
let is_not_bl str = not (String.string_contains ~where:name ~what:str) in
200+
CString.Set.for_all is_not_bl (SearchBlacklist.v ())
192201

193202
let module_filter : _ -> filter_function = fun mods ref kind env sigma typ ->
194203
let sp = Nametab.path_of_global ref in

0 commit comments

Comments
 (0)