Skip to content

Commit 0369d06

Browse files
authored
Merge pull request #555 from LPCIC/namegen
namegen API
2 parents 7a5e4bc + b81eaee commit 0369d06

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- New `tc-priority`, contains the priority of an instance and if the priority
1111
has been given by the user or computed by `coq`
1212
- Change `tc-instance`, now the type is `gref -> tc-priority -> tc-instance` i.e. the priority is not an integer anymore
13+
- New `coq.ltac.fresh-id` to generate fresh names in the proof context
1314
- New `@no-tc!` attribute supported by `coq.ltac.call-ltac1`
1415

1516
### Apps

coq-builtin.elpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ external pred coq.ltac.call-ltac1 i:any, i:goal, o:list sealed-goal.
15741574
%
15751575
external pred coq.ltac.id-free? i:id, i:goal.
15761576

1577+
% [coq.ltac.fresh-id Default Ty FreshID] TODO
1578+
external pred coq.ltac.fresh-id i:id, i:term, o:id.
1579+
15771580
% -- Coq's options system --------------------------------------------
15781581

15791582
% Coq option value

src/coq_elpi_builtins.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,20 @@ Supported attributes:
38083808
else raise No_clause)),
38093809
DocAbove);
38103810

3811+
MLCode(Pred("coq.ltac.fresh-id",
3812+
In(B.unspec id, "Default",
3813+
CIn(B.unspecC term, "Ty",
3814+
Out(id,"FreshID",
3815+
Read(proof_context, "TODO")))),
3816+
(fun id ty _ ~depth proof_context _ _ ->
3817+
let id = match id with Unspec -> "x" | Given x -> x in
3818+
let id =
3819+
match ty with
3820+
| Unspec -> Namegen.next_ident_away (Names.Id.of_string_soft id) proof_context.names
3821+
| Given ty -> Namegen.next_name_away_with_default_using_types id Name.Anonymous proof_context.names ty in
3822+
!: (Id.to_string id))),
3823+
DocAbove);
3824+
38113825
LPDoc "-- Coq's options system --------------------------------------------";
38123826

38133827
MLData goption;

tests/test_tactic.v

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,29 @@ Goal forall n, n + 1 = 1.
389389
trivial.
390390
match goal with |- S m + 1 = 1 => idtac end.
391391
Abort.
392+
393+
394+
395+
Elpi Tactic fresh1.
396+
Elpi Accumulate lp:{{
397+
solve (goal _ _ {{ forall _ : lp:Ty, _ }} _ _ as G) GL :-
398+
coq.ltac.fresh-id "x" Ty ID,
399+
coq.id->name ID N,
400+
refine (fun N _ _) G GL.
401+
}}.
402+
Elpi Typecheck.
403+
Goal forall x z y, x = 1 + y + z.
404+
intros x x0.
405+
elpi fresh1.
406+
Check x1.
407+
Abort.
408+
409+
Implicit Type (w : nat).
410+
411+
Goal forall x z y, x = 1 + y + z.
412+
intros ??.
413+
elpi fresh1.
414+
Check w.
415+
Abort.
416+
417+

0 commit comments

Comments
 (0)