Skip to content

Commit 1b5f7eb

Browse files
committed
Support univpoly-cumul declarations again, do not fix undef variables preventing minimization when interpreting inductives
1 parent 4d9d215 commit 1b5f7eb

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

builtin-doc/coq-builtin.elpi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,16 +1090,16 @@ type covariant univ.variable -> univ-variance.
10901090
type invariant univ.variable -> univ-variance.
10911091
type irrelevant univ.variable -> univ-variance.
10921092

1093-
% Constraints for a polymorphic, non-cumulative declaration. Boolean tt means loose
1094-
% (e.g. the '+' in f@{u v + | u < v +})
1093+
% Constraints for a polymorphic declaration. Boolean tt means loose (e.g.
1094+
% the '+' in f@{u v + | u < v +})
10951095
kind upoly-decl type.
10961096
type upoly-decl list univ.variable -> bool -> list univ-constraint ->
10971097
bool -> upoly-decl.
10981098

1099-
% Constraints for a polymorphic cumulative declaration. Boolean tt means loose (e.g.
1099+
% Constraints for a cumulative declaration. Boolean tt means loose (e.g.
11001100
% the '+' in f@{u v + | u < v +})
11011101
kind upoly-decl-cumul type.
1102-
type upoly-decl-cumul list univ.variable -> bool ->
1102+
type upoly-decl-cumul list univ-variance -> bool ->
11031103
list univ-constraint -> bool -> upoly-decl-cumul.
11041104

11051105
% -- Primitive --------------------------------------------------------

elpi/coq-lib.elpi

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,16 @@ coq.upoly-decl.complete-constraints (upoly-decl VS LV CS LC) (upoly-decl VS LV C
199199
].
200200
pred coq.upoly-decl-cumul.complete-constraints i:upoly-decl-cumul, o:upoly-decl-cumul.
201201
coq.upoly-decl-cumul.complete-constraints (upoly-decl-cumul VS LV CS LC) (upoly-decl-cumul VS LV CS1 LC) :- std.do! [
202-
% std.map VS coq.upoly-decl-cumul.complete-constraints.aux ExtraL,
203-
std.map VS coq.univ.variable.constraints ExtraL,
202+
std.map VS coq.upoly-decl-cumul.complete-constraints.aux ExtraL,
204203
std.flatten ExtraL Extra,
205204
std.filter Extra (c\not(std.mem CS c)) New,
206205
std.append CS New CS1,
207206
].
208-
% pred coq.upoly-decl-cumul.complete-constraints.aux i:univ-variance, o:list univ-constraint.
209-
% coq.upoly-decl-cumul.complete-constraints.aux (auto V) CS :- coq.univ.variable.constraints V CS.
210-
% coq.upoly-decl-cumul.complete-constraints.aux (covariant V) CS :- coq.univ.variable.constraints V CS.
211-
% coq.upoly-decl-cumul.complete-constraints.aux (invariant V) CS :- coq.univ.variable.constraints V CS.
212-
% coq.upoly-decl-cumul.complete-constraints.aux (irrelevant V) CS :- coq.univ.variable.constraints V CS.
213-
207+
pred coq.upoly-decl-cumul.complete-constraints.aux i:univ-variance, o:list univ-constraint.
208+
coq.upoly-decl-cumul.complete-constraints.aux (auto V) CS :- coq.univ.variable.constraints V CS.
209+
coq.upoly-decl-cumul.complete-constraints.aux (covariant V) CS :- coq.univ.variable.constraints V CS.
210+
coq.upoly-decl-cumul.complete-constraints.aux (invariant V) CS :- coq.univ.variable.constraints V CS.
211+
coq.upoly-decl-cumul.complete-constraints.aux (irrelevant V) CS :- coq.univ.variable.constraints V CS.
214212

215213
pred coq.build-indt-decl
216214
i:(pair inductive id), i:bool, i:int, i:int, i:term, i:list (pair constructor id), i:list term, o:indt-decl.

src/rocq_elpi_HOAS.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,27 @@ let universe_decl : UState.universe_decl API.Conversion.t =
261261
]
262262
} |> API.ContextualConversion.(!<)
263263

264-
(* type universe_decl_cumul = ((Univ.Level.t * UVars.Variance.t option) list * bool) * (Univ.Constraints.t * bool)
265-
let universe_decl_cumul : universe_decl_cumul API.Conversion.t =
266-
let open API.Conversion in let open API.BuiltInData in let open API.AlgebraicData in let open Elpi.Builtin in declare {
264+
let universe_decl_cumul : UState.universe_decl API.Conversion.t =
265+
let open API.Conversion in let open API.BuiltInData in let open API.AlgebraicData in let open Elpi.Builtin in
266+
let open UState in declare {
267267
ty = TyName "upoly-decl-cumul";
268268
doc = "Constraints for a cumulative declaration. Boolean tt means loose (e.g. the '+' in f@{u v + | u < v +})";
269269
pp = (fun fmt _ -> Format.fprintf fmt "<todo>");
270270
constructors = [
271271
K("upoly-decl-cumul","",A(list universe_variance,A(bool,A(list universe_constraint,A(bool,N)))),
272-
B (fun x sx y sy -> ((x,sx),(Univ.Constraints.of_list y,sy))),
273-
M (fun ~ok ~ko:_ ((x,sx),(y,sy)) -> ok x sx (Univ.Constraints.elements y) sy))
272+
B (fun x sx y sy ->
273+
{ univdecl_qualities = []; univdecl_extensible_qualities = false;
274+
univdecl_instance = List.map fst x; univdecl_extensible_instance = sx;
275+
univdecl_variances = Some (Array.of_list (List.map snd x));
276+
univdecl_constraints = Univ.Constraints.of_list y;
277+
univdecl_extensible_constraints = sy }),
278+
M (fun ~ok ~ko:_ x ->
279+
ok (List.map2 (fun x y -> x, y) x.univdecl_instance (Array.to_list (Option.get x.univdecl_variances)))
280+
x.univdecl_extensible_instance
281+
(Univ.Constraints.elements x.univdecl_constraints)
282+
x.univdecl_extensible_constraints))
274283
]
275-
} |> API.ContextualConversion.(!<) *)
284+
} |> API.ContextualConversion.(!<)
276285

277286
let collapse_to_type_sigma sigma s =
278287
match s with
@@ -1310,7 +1319,7 @@ let get_options ~depth hyps state =
13101319
| None, None -> NotUniversePolymorphic
13111320
| Some _, Some _ -> err Pp.(str"Conflicting attributes: @udecl! and @udecl-cumul! (or @univpoly! and @univpoly-cumul!)")
13121321
| Some (t,depth), None ->
1313-
let _, ud, gl = universe_decl.Elpi.API.Conversion.readback ~depth state t in
1322+
let _, ud, gl = universe_decl_cumul.Elpi.API.Conversion.readback ~depth state t in
13141323
assert (gl = []);
13151324
Cumulative ud
13161325
| None, Some (t,depth) ->
@@ -2958,7 +2967,7 @@ let restricted_sigma_of s state =
29582967
let sigma = get_sigma state in
29592968
let ustate = Evd.evar_universe_context sigma in
29602969
let ustate = UState.restrict_even_binders ustate s in
2961-
let ustate = UState.fix_undefined_variables ustate in
2970+
(* let ustate = UState.fix_undefined_variables ustate in *)
29622971
let ustate = UState.collapse_sort_variables ustate in
29632972
let sigma = Evd.set_universe_context sigma ustate in
29642973
sigma
@@ -3560,7 +3569,7 @@ let upoly_decl_of ~depth state ~loose_udecl mie =
35603569
state, (fun i -> E.mkApp uideclc i [up]), gls
35613570
| Some (Check_variances variance) ->
35623571
let udecl = udecl_of_entry (Array.to_list vars) csts (Some variance) loose_udecl in
3563-
let state, up, gls = universe_decl.API.Conversion.embed ~depth state udecl in
3572+
let state, up, gls = universe_decl_cumul.API.Conversion.embed ~depth state udecl in
35643573
state, (fun i -> E.mkApp uideclc i [up]), gls
35653574
end
35663575
| Monomorphic_ind_entry -> state, (fun i -> E.mkApp ideclc i []), []

src/rocq_elpi_HOAS.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ val uinstance : UVars.Instance.t Conversion.t
222222
val universe_constraint : Univ.univ_constraint Conversion.t
223223
val universe_variance : (Univ.Level.t * UVars.Variance.t option) Conversion.t
224224
val universe_decl : UState.universe_decl Conversion.t
225+
val universe_decl_cumul : UState.universe_decl Conversion.t
225226

226227
module GRMap : Elpi.API.Utils.Map.S with type key = Names.GlobRef.t
227228
module GRSet : Elpi.API.Utils.Set.S with type elt = Names.GlobRef.t

src/rocq_elpi_builtins.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,7 @@ declared as cumulative.|};
28232823
MLData universe_constraint;
28242824
MLData universe_variance;
28252825
MLData universe_decl;
2826+
MLData universe_decl_cumul;
28262827

28272828
LPDoc "-- Primitive --------------------------------------------------------";
28282829

0 commit comments

Comments
 (0)