Skip to content

Commit 5edf612

Browse files
committed
coq.redflags.proj to control unfolding of primitive projections
1 parent 42fe74d commit 5edf612

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# UNRELEASED
2+
3+
### API
4+
- New `coq.redflags.proj` to control "unfolding" of primitive projections
5+
16
# [2.5.2] 29/4/2025
27

38
Requires Elpi 2.0.7 and Coq 8.20 or Rocq 9.0.

builtin-doc/coq-builtin.elpi

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,13 @@ external pred coq.arguments.simplification i:gref,
13871387
external pred coq.arguments.set-simplification i:gref,
13881388
i:simplification_strategy.
13891389

1390+
% [coq.arguments.reset-simplification GR] resets the behavior of the
1391+
% simplification tactics.
1392+
% Also resets the ! and / modifiers for the Arguments command.
1393+
% Supported attributes:
1394+
% - @global! (default: false)
1395+
external pred coq.arguments.reset-simplification i:gref.
1396+
13901397
% [coq.locate-abbreviation Name Abbreviation] locates an abbreviation. It's
13911398
% a fatal error if Name cannot be located.
13921399
external pred coq.locate-abbreviation i:id, o:abbreviation.
@@ -1499,6 +1506,8 @@ type coq.redflags.cofix coq.redflag.
14991506
type coq.redflags.zeta coq.redflag.
15001507
type coq.redflags.const constant ->
15011508
coq.redflag. % enable/disable unfolding
1509+
type coq.redflags.proj projection ->
1510+
coq.redflag. % enable/disable unfolding
15021511

15031512
% Set of flags for lazy, cbv, ... reductions
15041513
kind coq.redflags type.
@@ -1844,15 +1853,20 @@ coq.elpi.accumulate S N C :- coq.elpi.accumulate-clauses S N [C].
18441853

18451854

18461855
% [coq.elpi.accumulate-clauses Scope DbName Clauses]
1847-
% Declare that, once the program is over, the given clauses has to be
1848-
% added to the given db (see Elpi Db).
1856+
% Declare that the given clauses have to be added to the given db (see Elpi
1857+
% Db).
18491858
% Clauses usually belong to Coq modules: the Scope argument lets one
18501859
% select which module:
1851-
% - execution site (default) is the module in which the pogram is
1852-
% invoked
1860+
% - execution site (default) is the module in which the program is
1861+
% invoked, the clauses will be accumulated when the execution of the
1862+
% program ends
18531863
% - current is the module currently being constructed (see
1854-
% begin/end-module)
1855-
% - library is the current file (the module that is named after the file)
1864+
% begin/end-module), the clauses will be accumulated when the execution of
1865+
% the program ends
1866+
% or the start of another program (whichever comes first)
1867+
% - library is the current file (the module that is named after the file),
1868+
% the clauses will be accumulated when the execution of the program
1869+
% ends
18561870
% The clauses are visible as soon as the enclosing module is Imported.
18571871
% A clause that mentions a section variable is automatically discarded
18581872
% at the end of the section.

src/rocq_elpi_builtins.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ let reduction_kind = let open API.AlgebraicData in let open RedFlags in declare
725725
K("coq.redflags.const","enable/disable unfolding",A(constant,N),
726726
B (function Constant x -> fCONST x | Variable x -> fVAR x),
727727
M (fun ~ok ~ko x -> nYI "readback for coq.redflags.const"));
728+
K("coq.redflags.proj","enable/disable unfolding",A(projection,N),
729+
B (function x -> fPROJ @@ Projection.repr x),
730+
M (fun ~ok ~ko x -> nYI "readback for coq.redflags.proj"));
728731
]
729732
} |> CConv.(!<)
730733

tests/test_HOAS.v

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,32 @@ Elpi Query lp:{{
184184
std.assert! (T = T2) "normal form is not an opinion".
185185
}}.
186186

187+
Module RP.
188+
Set Primitive Projections.
189+
Record r := mk_r { f : nat }.
190+
191+
Elpi Query lp:{{ std.spy-do! [
192+
app[primitive (proj P _)|_] = {{ (_).(f) }},
193+
coq.redflags.add coq.redflags.nored [
194+
coq.redflags.delta,
195+
coq.redflags.beta,
196+
coq.redflags.match,
197+
] F,
198+
(@redflags! F => coq.reduction.cbv.norm {{ (mk_r 3).(f) }} R0),
199+
std.assert! (R0 = {{ (mk_r 3).(f) }}) "nored expected",
200+
coq.redflags.add coq.redflags.nored [
201+
coq.redflags.proj P,
202+
coq.redflags.delta,
203+
coq.redflags.beta,
204+
coq.redflags.match,
205+
] FP,
206+
(@redflags! FP => coq.reduction.cbv.norm {{ (mk_r 3).(f) }} R1),
207+
std.assert! (R1 = {{ 3 }}) "red expected",
208+
].
209+
}}.
210+
End RP.
211+
212+
187213
(* ------------------------------------ *)
188214

189215
Module P.

0 commit comments

Comments
 (0)