Skip to content

Commit

Permalink
Create HintDb does not erase pre-existing hint db
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Dec 18, 2024
1 parent eafed8f commit c56f115
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- **Changed:**
:cmd:`Create HintDb` no longer erases pre-existing hint databases
(`#19808 <https://github.com/coq/coq/pull/19808>`_,
by Gaëtan Gilbert).
10 changes: 9 additions & 1 deletion doc/sphinx/proofs/automatic-tactics/auto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ and `Constants`, while implicitly created databases have the `Opaque` setting.

.. cmd:: Create HintDb @ident {? discriminated }

Creates a new hint database named :n:`@ident`. The database is
If there is no hint database named :n:`@name`, creates a new hint database
with that name. Otherwise, does nothing. The database is
implemented by a Discrimination Tree (DT) that serves as a filter to select
the lemmas that will be applied. When discriminated, the DT uses
transparency information to decide if a constant should considered rigid for
Expand All @@ -331,6 +332,13 @@ and `Constants`, while implicitly created databases have the `Opaque` setting.

By default, hint databases are undiscriminated.

.. warn:: @ident already exists and is {? not } discriminated
:name: mismatched-hint-db

`Create HintDb` will not change whether a pre-existing database
is discriminated.


Hint databases defined in the Rocq standard library
```````````````````````````````````````````````````

Expand Down
16 changes: 14 additions & 2 deletions tactics/hints.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,20 @@ type db_obj = {
db_ts : TransparentState.t;
}

let cache_db {db_name=name; db_use_dn=b; db_ts=ts} =
searchtable_add (name, Hint_db.empty ~name ts b)
let warn_mismatch_create_hintdb = CWarnings.create ~name:"mismatched-hint-db" ~category:CWarnings.CoreCategories.automation
Pp.(fun {db_name;db_use_dn} ->
str "Hint Db " ++ str db_name ++ str " already exists and " ++
(if db_use_dn then str "is not" else str "is") ++ str " discriminated.")

let cache_db ({db_name=name; db_use_dn=b; db_ts=ts} as o) =
match searchtable_map name with
| exception Not_found -> searchtable_add (name, Hint_db.empty ~name ts b)
| db ->
(* Explicit DBs start with full TS, implicit DBs start with empty TS
This should probably be controllable in Create Hint Db,
otherwise we have to do eg "Create HintDb foo. Hint Constants Opaque : foo."
and if someone else creates foo and puts some transparency hints they will be overwritten. *)
if Hint_db.use_dn db <> b then warn_mismatch_create_hintdb o

let load_db _ x = cache_db x

Expand Down
26 changes: 26 additions & 0 deletions test-suite/success/Hints.v
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,29 @@ Section HintTransparent.
Qed.

End HintTransparent.

Module RepeatCreat.
Axiom T : Type.
Axiom v : T.

Set Warnings "+mismatched-hint-db".

(* if this fails it means the db already exists as a discriminated db *)
Succeed Create HintDb repeated.

Create HintDb repeated discriminated.

Fail Definition foo : T := ltac:(eauto with foo).

Hint Resolve v : foo.
Definition foo : T := ltac:(eauto with foo).

Create HintDb repeated discriminated.
(* hint is still there *)
Definition foo' : T := ltac:(eauto with foo).

Fail Create HintDb repeated.

(* implicit hint db *)
Fail Create HintDb foo discriminated.
End RepeatCreat.

0 comments on commit c56f115

Please sign in to comment.