Skip to content

Commit

Permalink
Merge PR coq#19073: Univ declarations can have extensible qualities (…
Browse files Browse the repository at this point in the history
…internally)

Reviewed-by: ppedrot
Co-authored-by: ppedrot <[email protected]>
  • Loading branch information
coqbot-app[bot] and ppedrot authored Jun 4, 2024
2 parents 2e621ae + 435896b commit 344c7b4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
overlay elpi https://github.com/SkySkimmer/coq-elpi abstract-sort-poly 19073
15 changes: 11 additions & 4 deletions engine/uState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ let pr_uctx_qvar uctx l = pr_uctx_qvar_names uctx.names l

type ('a, 'b, 'c) gen_universe_decl = {
univdecl_qualities : 'a;
univdecl_extensible_qualities : bool;
univdecl_instance : 'b; (* Declared universes *)
univdecl_extensible_instance : bool; (* Can new universes be added *)
univdecl_constraints : 'c; (* Declared constraints *)
Expand All @@ -772,6 +773,10 @@ type universe_decl =

let default_univ_decl =
{ univdecl_qualities = [];
(* in practice non named qualities will get collapsed for toplevel definitions,
but side effects see named qualities from the surrounding definitions
while using default_univ_decl *)
univdecl_extensible_qualities = true;
univdecl_instance = [];
univdecl_extensible_instance = true;
univdecl_constraints = Constraints.empty;
Expand Down Expand Up @@ -825,9 +830,10 @@ let universe_context_inst decl qvars levels names =
let leftqs = List.fold_left (fun acc l -> QVar.Set.remove l acc) qvars decl.univdecl_qualities in
let leftus = List.fold_left (fun acc l -> Level.Set.remove l acc) levels decl.univdecl_instance in
let () =
let unboundqs = if decl.univdecl_extensible_qualities then QVar.Set.empty else leftqs in
let unboundus = if decl.univdecl_extensible_instance then Level.Set.empty else leftus in
if not (QVar.Set.is_empty leftqs && Level.Set.is_empty unboundus)
then error_unbound_universes leftqs unboundus names
if not (QVar.Set.is_empty unboundqs && Level.Set.is_empty unboundus)
then error_unbound_universes unboundqs unboundus names
in
let leftqs = UContext.sort_qualities
(Array.map_of_list (fun q -> Quality.QVar q) (QVar.Set.elements leftqs))
Expand Down Expand Up @@ -1179,9 +1185,10 @@ let universe_context_inst_decl decl qvars levels names =
let leftqs = List.fold_left (fun acc l -> QVar.Set.remove l acc) qvars decl.univdecl_qualities in
let leftus = List.fold_left (fun acc l -> Level.Set.remove l acc) levels decl.univdecl_instance in
let () =
let unboundqs = if decl.univdecl_extensible_qualities then QVar.Set.empty else leftqs in
let unboundus = if decl.univdecl_extensible_instance then Level.Set.empty else leftus in
if not (QVar.Set.is_empty leftqs && Level.Set.is_empty unboundus)
then error_unbound_universes leftqs unboundus names
if not (QVar.Set.is_empty unboundqs && Level.Set.is_empty unboundus)
then error_unbound_universes unboundqs unboundus names
in
let instq = Array.map_of_list (fun q -> Quality.QVar q) decl.univdecl_qualities in
let instu = Array.of_list decl.univdecl_instance in
Expand Down
1 change: 1 addition & 0 deletions engine/uState.mli
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ val collapse_sort_variables : t -> t

type ('a, 'b, 'c) gen_universe_decl = {
univdecl_qualities : 'a;
univdecl_extensible_qualities : bool;
univdecl_instance : 'b; (* Declared universes *)
univdecl_extensible_instance : bool; (* Can new universes be added *)
univdecl_constraints : 'c; (* Declared constraints *)
Expand Down
2 changes: 2 additions & 0 deletions interp/constrintern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,7 @@ let interp_univ_decl env decl =
let evd, cstrs = interp_univ_constraints env evd decl.univdecl_constraints in
let decl = {
univdecl_qualities = qualities;
univdecl_extensible_qualities = decl.univdecl_extensible_qualities;
univdecl_instance = instance;
univdecl_extensible_instance = decl.univdecl_extensible_instance;
univdecl_constraints = cstrs;
Expand All @@ -2992,6 +2993,7 @@ let interp_cumul_univ_decl env decl =
let evd, cstrs = interp_univ_constraints env evd decl.univdecl_constraints in
let decl = {
univdecl_qualities = qualities;
univdecl_extensible_qualities = decl.univdecl_extensible_qualities;
univdecl_instance = instance;
univdecl_extensible_instance = decl.univdecl_extensible_instance;
univdecl_constraints = cstrs;
Expand Down
15 changes: 15 additions & 0 deletions test-suite/bugs/bug_19072.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Set Universe Polymorphism.

Definition demo@{srt|u |} : True.
Proof.
abstract exact I.
Defined.

(* abstract doesn't restrict named qualities and universes
(debatable behaviour but that's what it does currently) *)
Check demo@{Type|Set}.

Definition baz@{q|u|} (A:Type@{q|u}) (x:A) : A.
Proof.
abstract exact x.
Defined.
1 change: 1 addition & 0 deletions vernac/comRewriteRule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ let interp_rule (udecl, lhs, rhs: Constrexpr.universe_decl_expr option * _ * _)
in
let decl = {
univdecl_qualities = qualities;
univdecl_extensible_qualities = udecl.univdecl_extensible_qualities;
univdecl_instance = instance;
univdecl_extensible_instance = udecl.univdecl_extensible_instance;
univdecl_constraints = cstrs;
Expand Down
6 changes: 5 additions & 1 deletion vernac/g_vernac.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ GRAMMAR EXTEND Gram
->
{ let open UState in
{ univdecl_qualities = l0;
univdecl_extensible_qualities = false;
univdecl_instance = l;
univdecl_extensible_instance = ext;
univdecl_constraints = fst cs;
Expand All @@ -361,7 +362,8 @@ GRAMMAR EXTEND Gram
cs = univ_decl_constraints
->
{ let open UState in
{ univdecl_qualities = []; (* TODO *)
{ univdecl_qualities = [];
univdecl_extensible_qualities = false;
univdecl_instance = l;
univdecl_extensible_instance = ext;
univdecl_constraints = fst cs;
Expand All @@ -388,6 +390,7 @@ GRAMMAR EXTEND Gram
->
{ let open UState in
{ univdecl_qualities = l0;
univdecl_extensible_qualities = false;
univdecl_instance = l;
univdecl_extensible_instance = ext;
univdecl_constraints = fst cs;
Expand All @@ -398,6 +401,7 @@ GRAMMAR EXTEND Gram
->
{ let open UState in
{ univdecl_qualities = [];
univdecl_extensible_qualities = false;
univdecl_instance = l;
univdecl_extensible_instance = ext;
univdecl_constraints = fst cs;
Expand Down

0 comments on commit 344c7b4

Please sign in to comment.