Skip to content

Commit 68e32cb

Browse files
authored
Merge pull request #657 from SkySkimmer/func-auto-prop-lower
Adapt to rocq-prover/rocq#19346 (ComInductive flags)
2 parents 56b874c + ff443b1 commit 68e32cb

File tree

3 files changed

+133
-18
lines changed

3 files changed

+133
-18
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ jobs:
4343
- run: opam repo add coq-dev https://coq.inria.fr/opam/core-dev
4444
- run: opam install coq-core.${{ matrix.coq_version }}
4545
- run: opam install coq-stdlib.${{ matrix.coq_version }}
46+
- run: |
47+
opam pin add coq-core ${{ matrix.coq_version }}
48+
opam pin add coq-stdlib ${{ matrix.coq_version }}
49+
if: ${{ matrix.coq_version != 'dev' }}
4650
- run: opam install ./coq-elpi.opam --deps-only --with-test -y
4751
- run: opam exec make build
4852
- run: opam exec make test

src/coq_elpi_HOAS.ml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,18 +2924,34 @@ let poly_cumul_udecl_variance_of_options state options =
29242924
Array.of_list variance
29252925

29262926
[%%if coq = "8.19"]
2927-
let comInductive_interp_mutual_inductive_constr env_ar_params sigma arity =
2927+
let comInductive_interp_mutual_inductive_constr env_ar_params sigma arity ~cumulative ~poly ~template ~finite =
29282928
let arityconcl =
29292929
match Reductionops.sort_of_arity env_ar_params sigma arity with
29302930
| exception Reduction.NotArity -> None
29312931
| s -> Some s in
2932-
ComInductive.interp_mutual_inductive_constr ~arityconcl:[arityconcl]
2932+
ComInductive.interp_mutual_inductive_constr ~arityconcl:[arityconcl] ~cumulative ~poly ~template ~finite
2933+
[%%elif coq = "8.20"]
2934+
let comInductive_interp_mutual_inductive_constr _ _ _ ~cumulative ~poly ~template ~finite =
2935+
ComInductive.interp_mutual_inductive_constr ~arities_explicit:[true] ~template_syntax:[SyntaxAllowsTemplatePoly] ~cumulative ~poly ~template ~finite
2936+
[%%else]
2937+
let comInductive_interp_mutual_inductive_constr _ _ _ ~cumulative ~poly ~template ~finite =
2938+
let flags = {
2939+
ComInductive.poly;
2940+
cumulative;
2941+
template = Some false;
2942+
auto_prop_lowering = false;
2943+
finite;
2944+
}
2945+
in
2946+
ComInductive.interp_mutual_inductive_constr ~arities_explicit:[true] ~template_syntax:[SyntaxAllowsTemplatePoly] ~flags
2947+
[%%endif]
2948+
2949+
[%%if coq = "8.19"]
29332950
let comInductive_interp_mutual_inductive_constr_post (a,b,c) = [],a,b,c
29342951
[%%else]
2935-
let comInductive_interp_mutual_inductive_constr _ _ _ =
2936-
ComInductive.interp_mutual_inductive_constr ~arities_explicit:[true] ~template_syntax:[SyntaxAllowsTemplatePoly]
29372952
let comInductive_interp_mutual_inductive_constr_post x = x
29382953
[%%endif]
2954+
29392955
let lp2inductive_entry ~depth coq_ctx constraints state t =
29402956

29412957
let lp2constr coq_ctx ~depth state t =
@@ -3039,7 +3055,7 @@ let lp2inductive_entry ~depth coq_ctx constraints state t =
30393055
Univ.Level.Set.union acc
30403056
(universes_of_term state t))
30413057
used (nuparams @ params) in
3042-
let sigma = restricted_sigma_of used state in
3058+
let sigma = restricted_sigma_of used state in
30433059

30443060
state, comInductive_interp_mutual_inductive_constr
30453061
env_ar_params sigma arity

src/coq_elpi_arg_HOAS.ml

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,10 @@ let univpoly_of ~poly ~cumulative =
231231
| true, false -> Poly
232232
| false, _ -> Mono
233233

234+
[%%if coq = "8.19" || coq = "8.20"]
234235
let of_coq_inductive_definition id =
235236
let open Vernacentries.Preprocessed_Mind_decl in
236-
let { flags; typing_flags; private_ind; uniform; inductives } = id in
237+
let { flags; typing_flags; private_ind; uniform; inductives } = id in
237238
if List.length inductives != 1 then nYI "mutual inductives";
238239
let inductive = List.hd inductives in
239240
let (((name),(parameters,non_uniform_parameters),arity,constructors),notations) = inductive in
@@ -255,6 +256,34 @@ let univpoly_of ~poly ~cumulative =
255256
constructors;
256257
univpoly = univpoly_of ~poly ~cumulative
257258
}
259+
[%%else]
260+
let of_coq_inductive_definition id =
261+
let open Vernacentries.Preprocessed_Mind_decl in
262+
let { flags; udecl; typing_flags; private_ind; uniform; inductives } = id in
263+
if List.length inductives != 1 then nYI "mutual inductives";
264+
let inductive = List.hd inductives in
265+
let (((name),(parameters,non_uniform_parameters),arity,constructors),notations) = inductive in
266+
if notations != [] then CErrors.user_err Pp.(str "notations not supported");
267+
let name = [Names.Id.to_string name.CAst.v] in
268+
let constructors =
269+
List.map (function (Vernacexpr.(_,NoCoercion,NoInstance),c) -> c
270+
| _ -> CErrors.user_err Pp.(str "coercion and instance flags not supported"))
271+
constructors in
272+
let { ComInductive.template; cumulative; poly; finite } = flags in
273+
if template <> None then nYI "raw template polymorphic inductives";
274+
if udecl <> None then nYI "raw universe polymorphic inductives with universe declaration";
275+
{
276+
finiteness = finite;
277+
name;
278+
parameters;
279+
non_uniform_parameters;
280+
arity;
281+
constructors;
282+
univpoly = univpoly_of ~poly ~cumulative
283+
}
284+
[%%endif]
285+
286+
[%%if coq = "8.19" || coq = "8.20"]
258287
let of_coq_record_definition id =
259288
let open Vernacentries.Preprocessed_Mind_decl in
260289
let { flags; primitive_proj; kind; records; } : record = id in
@@ -277,8 +306,32 @@ let univpoly_of ~poly ~cumulative =
277306
constructor = Some idbuild;
278307
fields = cfs;
279308
univpoly = univpoly_of ~poly ~cumulative
280-
}
281-
309+
}
310+
[%%else]
311+
let of_coq_record_definition id =
312+
let open Vernacentries.Preprocessed_Mind_decl in
313+
let { flags; udecl; primitive_proj; kind; records; } : record = id in
314+
if List.length records != 1 then nYI "mutual inductives";
315+
let open Record.Ast in
316+
let { name; is_coercion; binders : Constrexpr.local_binder_expr list; cfs; idbuild; sort; default_inhabitant_id : Names.Id.t option; } = List.hd records in
317+
if is_coercion = Vernacexpr.AddCoercion then CErrors.user_err Pp.(str "coercion flag not supported");
318+
let name = [Names.Id.to_string name.CAst.v] in
319+
let sort = sort |> Option.map (fun sort ->
320+
match sort.CAst.v with
321+
| Constrexpr.CSort s -> s
322+
| _ -> CErrors.user_err ?loc:sort.CAst.loc Pp.(str "only explicits sorts are supported")) in
323+
let { ComInductive.template; cumulative; poly; finite } = flags in
324+
if template <> None then nYI "raw template polymorphic inductives";
325+
if udecl <> None then nYI "raw universe polymorphic inductives with universe declaration";
326+
{
327+
name;
328+
parameters = binders;
329+
sort;
330+
constructor = Some idbuild;
331+
fields = cfs;
332+
univpoly = univpoly_of ~poly ~cumulative
333+
}
334+
[%%endif]
282335
let intern_record_decl glob_sign (it : raw_record_decl) = glob_sign, it
283336

284337
[%%if coq = "8.19"]
@@ -996,6 +1049,15 @@ let handle_template_polymorphism = function
9961049
| Some false -> Some false
9971050
| Some true -> err Pp.(str "#[universes(template)] is not supported")
9981051

1052+
[%%if coq = "8.19" || coq = "8.20"]
1053+
let handle_template_polymorphism flags =
1054+
let open Vernacentries.Preprocessed_Mind_decl in
1055+
{ flags with template = handle_template_polymorphism flags.template }
1056+
[%%else]
1057+
let handle_template_polymorphism flags =
1058+
{ flags with ComInductive.template = handle_template_polymorphism flags.ComInductive.template }
1059+
[%%endif]
1060+
9991061
let in_elpi_cmd_synterp ~depth ?calldepth state (x : Cmd.raw) =
10001062
let open Cmd in
10011063
match x with
@@ -1021,6 +1083,43 @@ let in_elpi_cmd_synterp ~depth ?calldepth state (x : Cmd.raw) =
10211083
| Term raw_term ->
10221084
state, E.mkApp trmc E.mkDiscard [], []
10231085

1086+
[%%if coq = "8.19" || coq = "8.20"]
1087+
let dest_rdecl raw_rdecl =
1088+
let open Vernacentries.Preprocessed_Mind_decl in
1089+
let { flags = ({ template; poly; cumulative; udecl; finite } as flags); primitive_proj; kind; records } = raw_rdecl in
1090+
flags, udecl, primitive_proj, kind, records
1091+
let interp_structure ~flags udecl kind ~primitive_proj x =
1092+
let open Vernacentries.Preprocessed_Mind_decl in
1093+
let { template; poly; cumulative; finite } = flags in
1094+
Record.interp_structure ~template udecl kind ~cumulative ~poly ~primitive_proj finite x
1095+
[%%else]
1096+
let dest_rdecl (raw_rdecl : Cmd.raw_record_decl) =
1097+
let open Vernacentries.Preprocessed_Mind_decl in
1098+
let { flags; udecl; primitive_proj; kind; records } = raw_rdecl in
1099+
flags, udecl, primitive_proj, kind, records
1100+
let interp_structure ~flags udecl kind ~primitive_proj x =
1101+
Record.interp_structure ~flags udecl kind ~primitive_proj x
1102+
[%%endif]
1103+
1104+
[%%if coq = "8.19" || coq = "8.20"]
1105+
let dest_idecl raw_indt =
1106+
let open Vernacentries.Preprocessed_Mind_decl in
1107+
let { flags = ({ udecl } as flags); typing_flags; uniform; private_ind; inductives } = raw_indt in
1108+
flags, udecl, typing_flags, uniform, private_ind, inductives
1109+
let interp_mutual_inductive ~flags ~env ~uniform ~private_ind ?typing_flags ~udecl x =
1110+
let open Vernacentries.Preprocessed_Mind_decl in
1111+
let { template; poly; cumulative; finite } = flags in
1112+
ComInductive.interp_mutual_inductive ~env ~template ~cumulative ~poly ~uniform ~private_ind ?typing_flags udecl x finite
1113+
[%%else]
1114+
let dest_idecl raw_indt =
1115+
let open Vernacentries.Preprocessed_Mind_decl in
1116+
let { flags; udecl; typing_flags; uniform; private_ind; inductives } = raw_indt in
1117+
flags, udecl, typing_flags, uniform, private_ind, inductives
1118+
let interp_mutual_inductive ~flags ~env ~uniform ~private_ind ?typing_flags ~udecl x =
1119+
ComInductive.interp_mutual_inductive ~env ~flags ~uniform ~private_ind ?typing_flags udecl x
1120+
[%%endif]
1121+
1122+
10241123
let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10251124
let open Cmd in
10261125
let hyps = [] in
@@ -1032,12 +1131,11 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10321131
let state, t = grecord2lp ~depth state glob_rdecl in
10331132
state, t, []
10341133
| RecordDecl (_ist,(glob_sign,raw_rdecl)) ->
1035-
let open Vernacentries.Preprocessed_Mind_decl in
1036-
let { flags = { template; poly; cumulative; udecl; finite }; primitive_proj; kind; records } = raw_rdecl in
1037-
let template = handle_template_polymorphism template in
1134+
let flags, udecl, primitive_proj, kind, records = dest_rdecl raw_rdecl in
1135+
let flags = handle_template_polymorphism flags in
10381136
(* Definitional type classes cannot be interpreted using this function (why?) *)
10391137
let kind = if kind = Vernacexpr.Class true then Vernacexpr.Class false else kind in
1040-
let e = Record.interp_structure ~template udecl kind ~cumulative ~poly ~primitive_proj finite records in
1138+
let e = interp_structure ~flags udecl kind ~primitive_proj records in
10411139
record_entry2lp ~depth coq_ctx E.no_constraints state ~loose_udecl:(udecl = None) e
10421140
| IndtDecl (_ist,(glob_sign,raw_indt)) when raw ->
10431141
let raw_indt = of_coq_inductive_definition raw_indt in
@@ -1046,15 +1144,12 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10461144
let state, t = ginductive2lp ~depth state glob_indt in
10471145
state, t, []
10481146
| IndtDecl (_ist,(glob_sign,raw_indt)) ->
1049-
let open Vernacentries.Preprocessed_Mind_decl in
1050-
let { flags = { template; poly; cumulative; udecl; finite }; typing_flags; uniform; private_ind; inductives } = raw_indt in
1051-
let template = handle_template_polymorphism template in
1147+
let flags, udecl, typing_flags, uniform, private_ind, inductives = dest_idecl raw_indt in
1148+
let flags = handle_template_polymorphism flags in
10521149
let e =
10531150
match inductives with
10541151
| [mind_w_not] ->
1055-
ComInductive.interp_mutual_inductive ~env:coq_ctx.env
1056-
~template ~cumulative ~poly ~uniform ~private_ind ?typing_flags
1057-
udecl [mind_w_not] finite
1152+
interp_mutual_inductive ~flags ~env:coq_ctx.env ~uniform ~private_ind ?typing_flags ~udecl [mind_w_not]
10581153
| _ -> nYI "(HOAS) mutual inductives"
10591154
in
10601155
inductive_entry2lp ~depth coq_ctx E.no_constraints state ~loose_udecl:(udecl = None) e

0 commit comments

Comments
 (0)