Skip to content

Commit 9b74851

Browse files
committed
fix compilation 8.19 and 8.20
1 parent a5bffcf commit 9b74851

File tree

2 files changed

+131
-28
lines changed

2 files changed

+131
-28
lines changed

src/coq_elpi_HOAS.ml

Lines changed: 25 additions & 14 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 =
@@ -3040,27 +3056,22 @@ let lp2inductive_entry ~depth coq_ctx constraints state t =
30403056
(universes_of_term state t))
30413057
used (nuparams @ params) in
30423058
let sigma = restricted_sigma_of used state in
3043-
let flags = {
3044-
ComInductive.poly;
3045-
cumulative;
3046-
template = Some false;
3047-
auto_prop_lowering = false;
3048-
finite = finiteness;
3049-
}
3050-
in
30513059

30523060
state, comInductive_interp_mutual_inductive_constr
30533061
env_ar_params sigma arity
30543062
~sigma
3055-
~flags
3063+
~template:(Some false)
30563064
~udecl
30573065
~variances
30583066
~ctx_params:(nuparams @ params)
30593067
~indnames:[itname]
30603068
~arities:[arity]
30613069
~constructors:[knames, ktypes]
30623070
~env_ar_params
3063-
~private_ind |> comInductive_interp_mutual_inductive_constr_post
3071+
~cumulative
3072+
~poly
3073+
~private_ind
3074+
~finite:finiteness |> comInductive_interp_mutual_inductive_constr_post
30643075
in
30653076
let mind = { mind with
30663077
Entries.mind_entry_record =

src/coq_elpi_arg_HOAS.ml

Lines changed: 106 additions & 14 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; udecl; 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
@@ -243,7 +244,7 @@ let univpoly_of ~poly ~cumulative =
243244
List.map (function (Vernacexpr.(_,NoCoercion,NoInstance),c) -> c
244245
| _ -> CErrors.user_err Pp.(str "coercion and instance flags not supported"))
245246
constructors in
246-
let { ComInductive.template; cumulative; poly; finite } = flags in
247+
let { template; udecl; cumulative; poly; finite } = flags in
247248
if template <> None then nYI "raw template polymorphic inductives";
248249
if udecl <> None then nYI "raw universe polymorphic inductives with universe declaration";
249250
{
@@ -255,9 +256,37 @@ 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
260-
let { flags; udecl; primitive_proj; kind; records; } : record = id in
289+
let { flags; primitive_proj; kind; records; } : record = id in
261290
if List.length records != 1 then nYI "mutual inductives";
262291
let open Record.Ast in
263292
let { name; is_coercion; binders : Constrexpr.local_binder_expr list; cfs; idbuild; sort; default_inhabitant_id : Names.Id.t option; } = List.hd records in
@@ -267,7 +296,7 @@ let univpoly_of ~poly ~cumulative =
267296
match sort.CAst.v with
268297
| Constrexpr.CSort s -> s
269298
| _ -> CErrors.user_err ?loc:sort.CAst.loc Pp.(str "only explicits sorts are supported")) in
270-
let { ComInductive.template; cumulative; poly; finite } = flags in
299+
let { template; udecl; cumulative; poly; finite } = flags in
271300
if template <> None then nYI "raw template polymorphic inductives";
272301
if udecl <> None then nYI "raw universe polymorphic inductives with universe declaration";
273302
{
@@ -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,8 +1049,14 @@ 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]
9991057
let handle_template_polymorphism flags =
10001058
{ flags with ComInductive.template = handle_template_polymorphism flags.ComInductive.template }
1059+
[%%endif]
10011060

10021061
let in_elpi_cmd_synterp ~depth ?calldepth state (x : Cmd.raw) =
10031062
let open Cmd in
@@ -1024,6 +1083,43 @@ let in_elpi_cmd_synterp ~depth ?calldepth state (x : Cmd.raw) =
10241083
| Term raw_term ->
10251084
state, E.mkApp trmc E.mkDiscard [], []
10261085

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+
10271123
let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10281124
let open Cmd in
10291125
let hyps = [] in
@@ -1035,12 +1131,11 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10351131
let state, t = grecord2lp ~depth state glob_rdecl in
10361132
state, t, []
10371133
| RecordDecl (_ist,(glob_sign,raw_rdecl)) ->
1038-
let open Vernacentries.Preprocessed_Mind_decl in
1039-
let { flags; udecl; primitive_proj; kind; records } = raw_rdecl in
1134+
let flags, udecl, primitive_proj, kind, records = dest_rdecl raw_rdecl in
10401135
let flags = handle_template_polymorphism flags in
10411136
(* Definitional type classes cannot be interpreted using this function (why?) *)
10421137
let kind = if kind = Vernacexpr.Class true then Vernacexpr.Class false else kind in
1043-
let e = Record.interp_structure ~flags udecl kind ~primitive_proj records in
1138+
let e = interp_structure ~flags udecl kind ~primitive_proj records in
10441139
record_entry2lp ~depth coq_ctx E.no_constraints state ~loose_udecl:(udecl = None) e
10451140
| IndtDecl (_ist,(glob_sign,raw_indt)) when raw ->
10461141
let raw_indt = of_coq_inductive_definition raw_indt in
@@ -1049,15 +1144,12 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
10491144
let state, t = ginductive2lp ~depth state glob_indt in
10501145
state, t, []
10511146
| IndtDecl (_ist,(glob_sign,raw_indt)) ->
1052-
let open Vernacentries.Preprocessed_Mind_decl in
1053-
let { flags; udecl; typing_flags; uniform; private_ind; inductives } = raw_indt in
1147+
let flags, udecl, typing_flags, uniform, private_ind, inductives = dest_idecl raw_indt in
10541148
let flags = handle_template_polymorphism flags in
10551149
let e =
10561150
match inductives with
10571151
| [mind_w_not] ->
1058-
ComInductive.interp_mutual_inductive ~env:coq_ctx.env
1059-
~flags ~uniform ~private_ind ?typing_flags
1060-
udecl [mind_w_not]
1152+
interp_mutual_inductive ~flags ~env:coq_ctx.env ~uniform ~private_ind ?typing_flags ~udecl [mind_w_not]
10611153
| _ -> nYI "(HOAS) mutual inductives"
10621154
in
10631155
inductive_entry2lp ~depth coq_ctx E.no_constraints state ~loose_udecl:(udecl = None) e

0 commit comments

Comments
 (0)