Skip to content

Add elaboration of qualities#21450

Merged
coqbot-app[bot] merged 1 commit intorocq-prover:masterfrom
TDiazT:elab-sorts
Feb 20, 2026
Merged

Add elaboration of qualities#21450
coqbot-app[bot] merged 1 commit intorocq-prover:masterfrom
TDiazT:elab-sorts

Conversation

@TDiazT
Copy link
Contributor

@TDiazT TDiazT commented Dec 22, 2025

This PR depends on #21417 .

This PR adds elaboration of (implicit) qualities, which is enabled by setting the flag Universe Polymorphism and disabling a new flag Collapse Sorts ToType.

Associated RFC : rocq-prover/rfcs#111.

Examples

The test file test-suite/success/sort_poly_elab.v has been updated with more examples.

Set Universe Polymorphism.
Unset Collapse Sorts ToType.

Definition qsort := Type.
(* qsort@{α ; u |} = Type@{α ; u} : Univ@{u+1} *)

Definition qsort' := Type.
(* qsort'@{u} : Type@{u+1} *)

Inductive implicit := mk.
(* implicit@{α ; u} : Type@{α ; u} *)

Inductive foo1 : Type := .
(* foo1@{α ; u |} : Type@{α ; _} :=  . *)

Inductive sigma (A:Type) (B:A -> Type) : Type
    := pair : forall x : A, B x -> sigma A B.
  (* sigma@{α α0 α1 ; u u0 u1} : forall (A : Type@{α ; u}) (_ : forall _ : A, Type@{α0 ; u0}), Type@{α1 ; u1} *)

(* Elimination constraints are added *)
Definition pr1 {A B} (s:sigma A B) : A
  := match s with pair _ _ x _ => x end.
(* α α0 α1 ; u u0 u1 |= α1 -> α *)

Definition pr2 {A B} (s:sigma A B) : B (pr1 s)
  := match s with pair _ _ _ y => y end.
(* α α0 α1 ; u u0 u1 |= α1 -> α
                                    α1 -> α0 *)

Overlays


  • Added / updated test-suite.
  • Added changelog.
  • Added / updated documentation.
    • Documented any new / changed user messages.
  • Opened overlay pull requests.

@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Dec 22, 2025
@TDiazT TDiazT force-pushed the elab-sorts branch 3 times, most recently from cda08c0 to 26bf881 Compare December 24, 2025 13:19
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Dec 31, 2025
@coqbot-app coqbot-app bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Jan 6, 2026
@tabareau
Copy link
Contributor

tabareau commented Jan 6, 2026

@coqbot run full ci

@coqbot-app coqbot-app bot removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Jan 6, 2026
TDiazT added a commit to TDiazT/rocq-lean-import that referenced this pull request Jan 7, 2026
TDiazT added a commit to TDiazT/Coq-Equations that referenced this pull request Jan 7, 2026
TDiazT added a commit to TDiazT/Coq-HoTT that referenced this pull request Jan 7, 2026
TDiazT added a commit to TDiazT/coq-elpi that referenced this pull request Jan 7, 2026
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Jan 8, 2026
@coqbot-app coqbot-app bot added needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. and removed needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. labels Jan 15, 2026
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Jan 16, 2026
@coqbot-app coqbot-app bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Jan 17, 2026
@TDiazT TDiazT force-pushed the elab-sorts branch 2 times, most recently from 4cfacbd to 3f8c2f6 Compare January 19, 2026 10:40
@TDiazT TDiazT marked this pull request as ready for review January 19, 2026 10:41
@TDiazT TDiazT requested review from a team as code owners January 19, 2026 10:41
@TDiazT TDiazT force-pushed the elab-sorts branch 2 times, most recently from c1101c4 to cc003ef Compare February 10, 2026 10:36
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Feb 11, 2026
@coqbot-app coqbot-app bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Feb 16, 2026
@SkySkimmer
Copy link
Contributor

@coqbot run full ci

@coqbot-app coqbot-app bot removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 17, 2026
@SkySkimmer SkySkimmer added needs: squashing Some commits should be squashed together. kind: feature New user-facing feature request or implementation. request: full CI Use this label when you want your next push to trigger a full CI. and removed needs: progress Work in progress: awaiting action from the author. labels Feb 17, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 18, 2026
@SkySkimmer SkySkimmer removed the request for review from a team February 18, 2026 12:25
Copy link
Contributor

@SkySkimmer SkySkimmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you squash everything into 1 commit this should be ready

@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 18, 2026
@TDiazT
Copy link
Contributor Author

TDiazT commented Feb 19, 2026

@SkySkimmer squashing ready 👌

@SkySkimmer
Copy link
Contributor

@coqbot run full ci

@coqbot-app coqbot-app bot removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 19, 2026
@SkySkimmer SkySkimmer removed the needs: squashing Some commits should be squashed together. label Feb 19, 2026


let check_fix ?evars ?elim_to env ((nvect,_),(names,_,bodies as recdef) as fix) =
(* Returns the pairs of (inductive sort * output sort) or None if Type in Type *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(* Returns the pairs of (inductive sort * output sort) or None if Type in Type *)
(* Returns the pairs of (inductive sort * output sort)
or None if any elimination constraint was ignored. *)

let sorts_of_mutfix env minds names =
let ind_ignores_elim_constraints (ind, _) = Environ.ind_ignores_elim_constraints env ind in
(* recursive sprop means non record with projections -> squashed *)
if Array.exists ind_ignores_elim_constraints minds then None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip all constraints if only one is allowed to be ignored? If universe constraints are to be taken as a reference, we should keep all constraints, remembering whether they may be ignored, and try to add them all, only ignoring in case of failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be a check of type in type, which made it unnecessary to check all cases. I assumed that the change to use ind_ignores_elim_constraints instead was including this type in type scenario, and so the logic remained the same. Is there more to this flag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The currently proposed behaviour is fine, this can be modified in a later PR.

uj_type = expected_type }

let check_fix_with_elims env sigma fix =
let evars = Evd.evar_handler sigma in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As was suggested in another comment, this function should take in econstrs and deal with the translation to constr here : a hidden invariant is that check_fix_pre_sorts (because of check_one_fix) needs to take in evar-normalised terms, so that call to EConstr.to_constr should be reinstated (here instead).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't check_fix_pre_sorts take a evar handler? why would it need evar normal terms?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_one_fix doesn't evar-reduce before inspecting its body, so it may find an evar that is actually defined and not check the definition. The evar handler is only passed to the weak-head reducing function, which is not systematically called (for good reasons).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_fix_sorts operating on constr can be changed at a later time, only EConstr.to_constr instead of Unsafe.to_constr is required.

(* Or should inductive_levels be cut off earlier, e.g. at L646 ? *)
let candidates = if not @@ PolyFlags.collapse_sort_variables poly
then []
else prop_lowering_candidates evd ~arities_explicit inds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

[declare_mutual_definitions] where we get it from UState. *)
let sigma = Option.default (Evd.from_env env) sigma in
let res = Pretyping.search_guard env sigma possible_guard rec_declaration in
(* We are forgetting about sigma here -- probably missing something *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does look fishy, but I'm already surprised by the fact that this code handles regular constrs and not econstrs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it just an outdated comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the evar_map isn't forgotten, but it's still weird that this code doesn't handle econstrs. This is unrelated to this PR now though.

Currently behind a Sort Polymorphism flag.

fix: Generate proper sort variable in record

feat: Add sort elab for interactive definitions

fix: Thread sort poly flag more correctly

It was being passed as unconstrained_sorts in some cases.

refactor: Remove unnecessary sort_poly flags

fix: Add sort_poly to prepare_obligations

refactor: Remove remaining fixmes and todos

refactor: General cleanup

refactor: Get ?evar_handler from evd

refactor: Remove search_fix_guard

doc: comment collapse

refactor: Remove unnecessary unconstrained_sorts

refactor: Remove unnecessary check for collapse_sort_variables

revert: Some changes in unify quality

feat: Add elim constraints to non-prim records with sort variables

doc: Add doc on flag + implicit elab of sorts

chore: Add changelog entry

chore: Add overlays

refactor: indentation

feat: Add more specific elim constraints to non-prim projections

Address comments

refactor: Pass on sigma in search_guard

test: Move sort_poly_elab test to output folder

fix: Change assert implicit sort vars for error in sections

fix(attempt): Return evd from make_recursive_bodies

refactor: Change option array to list option

refactor: Use Cmap_env to keep elim constraints from projs

Apply suggestion from @SkySkimmer

update test
@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 20, 2026
@yannl35133
Copy link
Contributor

@coqbot run full ci

@coqbot-app coqbot-app bot removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 20, 2026
@SkySkimmer
Copy link
Contributor

@coqbot merge now

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Feb 20, 2026

@SkySkimmer: Please take care of the following overlays:

  • 21450-TDiazT-elab-sorts.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: feature New user-facing feature request or implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants