Skip to content

Add sort cumulativity for polymorphic inductive types#21770

Closed
JasonGross wants to merge 2 commits into
rocq-prover:masterfrom
JasonGross:sort-cumulativity
Closed

Add sort cumulativity for polymorphic inductive types#21770
JasonGross wants to merge 2 commits into
rocq-prover:masterfrom
JasonGross:sort-cumulativity

Conversation

@JasonGross

Copy link
Copy Markdown
Member

When enabled via the "Polymorphic Inductive Sort Cumulativity" flag, cumulative polymorphic inductives allow sorts in the same connected component ({Prop, Type/Set} or {SProp}) to be treated as equivalent at quality positions with non-Invariant inferred variance.

This is implemented via instance normalization: before comparing cumulative instances, quality positions with non-Invariant sort variance where both qualities are in the same connected component are replaced with a canonical representative (QType), making the existing quality equality checks pass transparently.

Key changes:

  • New fields mind_sort_variance/mind_sec_sort_variance in declarations
  • New field mind_entry_sort_variance in entries
  • Sort variance inference in inferCumulativity.ml (SortInf module)
  • Instance normalization via normalize_sort_cumul_instances in uVars.ml
  • sort_cumulative field in PolyFlags.t
  • Normalization applied in conversion, typeops, eConstr, evarconv

Note that I have not looked over the code, creating this PR so @tabareau or @SkySkimmer can review if they want.

  • Added / updated test-suite.

  • Added changelog.

  • Added / updated documentation.

  • Opened overlay pull requests.

@JasonGross JasonGross requested a review from tabareau March 18, 2026 09:07
@JasonGross JasonGross requested review from a team as code owners March 18, 2026 09:07
@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 Mar 18, 2026
@JasonGross JasonGross added part: universes The universe system. part: sort polymorphism The sorts subsystem of the universe system. kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. request: full CI Use this label when you want your next push to trigger a full CI. labels Mar 18, 2026
When enabled via the "Polymorphic Inductive Sort Cumulativity" flag,
cumulative polymorphic inductives allow sorts in the same connected
component ({Prop, Type/Set} or {SProp}) to be treated as equivalent
at quality positions with non-Invariant inferred variance.

This is implemented via instance normalization: before comparing
cumulative instances, quality positions with non-Invariant sort
variance where both qualities are in the same connected component
are replaced with a canonical representative (QType), making the
existing quality equality checks pass transparently.

Key changes:
- New fields mind_sort_variance/mind_sec_sort_variance in declarations
- New field mind_entry_sort_variance in entries
- Sort variance inference in inferCumulativity.ml (SortInf module)
- Instance normalization via normalize_sort_cumul_instances in uVars.ml
- sort_cumulative field in PolyFlags.t
- Normalization applied in conversion, typeops, eConstr, evarconv

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coqbot-app coqbot-app Bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. labels Mar 18, 2026
Instead of normalizing instances at each call site before comparison,
pass sort_variance through the comparison API and normalize internally.

- Add sort_variance parameter to compare_cumul_instances callback type
- Add ?sort_variance optional param to enforce_eq/leq_variance_instances,
  compare_cumulative_instances (UnivProblem, Evarutil), and
  compare_constructor_instances
- Remove normalize_sort_cumul_instances calls from call sites
  (conversion.ml, typeops.ml, eConstr.ml, evarconv.ml)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JasonGross JasonGross requested a review from a team as a code owner March 18, 2026 10:00
@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 Mar 18, 2026
Comment thread kernel/conversion.mli
compare_sorts : conv_pb -> Sorts.t -> Sorts.t -> 'a -> ('a, 'err option) result;
compare_instances: flex:bool -> UVars.Instance.t -> UVars.Instance.t -> 'a -> ('a, 'err option) result;
compare_cumul_instances : conv_pb -> UVars.Variance.t array ->
compare_cumul_instances : conv_pb -> UVars.Variance.t array -> UVars.Variance.t array option ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't be an option, and we should probably introduce a type of variances containing both sort and level variances similarly to what we do with Instance.t

@SkySkimmer

Copy link
Copy Markdown
Contributor

Replaced by #21773

@SkySkimmer SkySkimmer closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. part: sort polymorphism The sorts subsystem of the universe system. part: universes The universe system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants