Skip to content

Inductive cumulativity supports sort cumulativity (Prop <= Type)#21773

Closed
SkySkimmer wants to merge 1 commit into
rocq-prover:masterfrom
SkySkimmer:cumul-sort-poly
Closed

Inductive cumulativity supports sort cumulativity (Prop <= Type)#21773
SkySkimmer wants to merge 1 commit into
rocq-prover:masterfrom
SkySkimmer:cumul-sort-poly

Conversation

@SkySkimmer

@SkySkimmer SkySkimmer commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@SkySkimmer SkySkimmer requested review from a team as code owners March 18, 2026 11:34
@SkySkimmer SkySkimmer added the needs: changelog entry This should be documented in doc/changelog. label Mar 18, 2026
@SkySkimmer SkySkimmer requested review from a team as code owners March 18, 2026 11:34
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 18, 2026
@SkySkimmer SkySkimmer requested a review from a team as a code owner March 18, 2026 11:34
@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 Mar 18, 2026
@SkySkimmer SkySkimmer added this to the 9.3+rc1 milestone Mar 18, 2026
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 18, 2026
@SkySkimmer SkySkimmer requested a review from a team as a code owner March 18, 2026 11:39
@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 Mar 18, 2026
SkySkimmer added a commit to SkySkimmer/coq-elpi that referenced this pull request Mar 18, 2026
SkySkimmer added a commit to SkySkimmer/MetaRocq that referenced this pull request Mar 18, 2026
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 18, 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 Mar 18, 2026
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 18, 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 Mar 18, 2026
@ppedrot ppedrot self-assigned this Mar 18, 2026
@SkySkimmer SkySkimmer added 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. and removed needs: changelog entry This should be documented in doc/changelog. labels Mar 18, 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 Mar 18, 2026
@JasonGross

Copy link
Copy Markdown
Member

This does not look right:

Set Universe Polymorphism.
Set Polymorphic Inductive Cumulativity.

Inductive Box@{s;l} (A : Type@{l}) : Type@{s;l} := box : A -> Box A.

Definition unbox (x : Box@{Prop;Type} Type) := match (x : Box@{Type;Type} Type) return Type with box _ A => A end.

Hm, this is supposed to be justified by η-expansion (match (x : Box@{Prop;u} A) return Box@{Type;u} A with box v => box v end and vice versa). I guess there is some interaction between sorts appearing in the return type of the inductive and elimination into the connected component of that sort.

JasonGross added a commit to JasonGross/metacoq that referenced this pull request Mar 19, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JasonGross

Copy link
Copy Markdown
Member

I think the following two files fail with this PR (I haven't quite narrowed it down to being this PR rather than another one in my stack of patches):

(* -*- mode: coq; coq-prog-args: ("-emacs" "-w" "-deprecated-native-compiler-option,-native-compiler-disabled" "-native-compiler" "ondemand" "-R" "." "IsomorphismChecker" "-top" "IsomorphismChecker.EqualityLemmas") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 1889 lines to 24 lines, then from 38 lines to 192 lines, then from 199 lines to 46 lines, then from 61 lines to 46 lines, then from 61 lines to 37 lines, then from 52 lines to 37 lines *)
(* coqc version 9.2+rc2 compiled with OCaml 4.14.2
   coqtop version 9.2+rc2
   Expected coqc runtime on this file: 3.272 sec
   Expected coqc peak memory usage on this file: 181856.0 kb *)
#[export]
Set Universe Polymorphism.
#[local] Set Primitive Projections.
Inductive eq@{s|u|} {α:Type@{s|u}} (a:α) : α -> SProp
  := eq_refl : eq a a.

#[local] Notation "x = y" := (eq x y) : type_scope.
Arguments eq_refl {α a} , [α] a.
#[export]
Set Implicit Arguments.
Record Iso@{s s'|u u'|} (A : Type@{s|u}) (B : Type@{s'|u'}) := {
    to :> A -> B;
    from : B -> A;
    to_from : forall x, to (from x) = x;
    from_to : forall x, from (to x) = x;
}.
Record > rel_iso@{s s'|u u'|} {A B} (i : Iso@{s s'|u u'} A B) (x : A) (y : B) : SProp := { proj_rel_iso :> i.(to) x = y }.
Axiom functional_extensionality_dep@{s s'|u u' u''|u<=u'',u'<=u''}
  : forall {A : Type@{s|u}} {B : A -> Type@{s'|u'}} (f g : forall x : A, B x), (forall x : A, f x = g x) -> eq@{s'|u''} f g.

Definition IsoForall@{s0 s1 s2 s3|u0 u1 u2 u3 u4 u5|u0 <= u4,u1 <= u5,u2 <= u4,u3 <= u5}
  {A A'} (isoA : Iso@{s0 s1|u0 u1} A A') (B : A -> Type@{s2|u2}) (B' : A' -> Type@{s3|u3})
  : (forall a a' (He : rel_iso isoA a a'), Iso (B a) (B' a'))
    -> Iso@{s2 s3|u4 u5} (forall a, B a) (forall a', B' a').
Proof.
  intro H; unshelve esplit; [ intros f a .. | intro x; shelve | intro x; shelve ].
  all: first [ specialize (H a) | specialize (fun a' => H a' a) ].
  all: first [ specialize (H (isoA.(to) a)) | specialize (H (isoA.(from) a)) ].
  all: first [ specialize (H eq_refl) | specialize (H (isoA.(to_from) a)) ].
  all: [ > first [ apply H.(to) | apply H.(from) ]; auto .. ].
  Unshelve.
  all: cbn.
  all: apply functional_extensionality_dep; intro.
  {
 destruct to_from. (* Error: Unable to find an instance for the variables A, B, i, x. *)

and

(* -*- mode: coq; coq-prog-args: ("-emacs" "-w" "-deprecated-native-compiler-option,-native-compiler-disabled" "-native-compiler" "ondemand" "-R" "." "IsomorphismChecker" "-top" "IsomorphismChecker.EqualityLemmas") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 1889 lines to 9 lines, then from 23 lines to 176 lines, then from 183 lines to 20 lines, then from 35 lines to 20 lines, then from 35 lines to 14 lines, then from 29 lines to 14 lines *)
(* coqc version 9.1.0 compiled with OCaml 4.14.2
   coqtop version 9.1.0
   Expected coqc runtime on this file: 1.191 sec
   Expected coqc peak memory usage on this file: 329464.0 kb *)
Module Export IsomorphismDefinitions.
#[export]
Set Universe Polymorphism.
#[export]
Set Polymorphic Inductive Cumulativity.
Inductive eq@{s|u|} {α:Type@{s|u}} (a:α) : α -> SProp
  := eq_refl : eq a a.
#[local] Notation "x = y" := (IsomorphismDefinitions.eq x y) : type_scope.
Lemma seq_of_peq@{u} {A : Prop} {x y : A} (H : Logic.eq x y) : IsomorphismDefinitions.eq@{Prop|u} x y.
Proof.
destruct H; reflexivity.
Defined.
(* File "./bug_eq_refl_01.v", line 18, characters 0-8:
Error: In pattern-matching on term "H" the branch for constructor
"Logic.eq_refl" has type "@eq@{Type ; bug_eq_refl_01.23} A x x"
which should be "@eq@{Prop ; bug_eq_refl_01.23} A x x". *)

@SkySkimmer SkySkimmer added the needs: fixing The proposed code change is broken. label Mar 19, 2026
@SkySkimmer

SkySkimmer commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

I think the following two files fail with this PR (I haven't quite narrowed it down to being this PR rather than another one in my stack of patches):

first one fails in master (050e23e) and 9.2 (#21781)
second one succeeds in the PR

@SkySkimmer SkySkimmer added request: full CI Use this label when you want your next push to trigger a full CI. and removed needs: fixing The proposed code change is broken. labels Mar 20, 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 Mar 20, 2026
@SkySkimmer SkySkimmer requested a review from ppedrot March 20, 2026 16:36

@ppedrot ppedrot left a comment

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.

Sounds fine now (famous last words).

@ppedrot

ppedrot commented Mar 23, 2026

Copy link
Copy Markdown
Member

I'm leaving a bit of time before merging for others to chime in and double check that we did not miss a case both in the code and in the theory.

@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 Mar 24, 2026
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 24, 2026

@yannl35133 yannl35133 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feature needs documentation (universe cumulative inductives also lack a formal specification in the reference manual).

Comment thread kernel/indtypes.ml Outdated
Comment on lines +580 to +583
let mk nsec variance =
(Array.sub variance nsec (Array.length variance - nsec)),
(Array.sub variance 0 nsec)
in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't that Array.chop flipped?

Comment thread kernel/indTyping.ml Outdated
Comment on lines +604 to +605
let quals = Array.map2 (fun a b -> a,b) quals qvariances in
let univs = Array.map2 (fun a b -> a,b) univs uvariances in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let quals = Array.map2 (fun a b -> a,b) quals qvariances in
let univs = Array.map2 (fun a b -> a,b) univs uvariances in
let quals = Array.combine quals qvariances in
let univs = Array.combine univs uvariances in

@yannl35133 yannl35133 added the needs: documentation Documentation was not added or updated. label Mar 24, 2026
@coqbot-app coqbot-app Bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. labels Mar 24, 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 Mar 27, 2026
JasonGross pushed a commit to JasonGross/coq-elpi that referenced this pull request Mar 29, 2026
@coqbot-app

coqbot-app Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

The "needs: rebase" label was set more than 30 days ago. If the PR is not rebased in 30 days, it will be automatically closed.

@coqbot-app coqbot-app Bot added the stale This PR will be closed unless it is rebased. label Apr 27, 2026
@SkySkimmer

Copy link
Copy Markdown
Contributor Author

The inconsistency scared me enough that I'm not sure if we want to continue this, especially considering we intend to remove Prop <= Type eventually.

@coqbot-app

coqbot-app Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

This PR was not rebased after 30 days despite the warning, it is now closed.

@coqbot-app coqbot-app Bot closed this May 27, 2026
@coqbot-app coqbot-app Bot removed this from the 9.3+rc1 milestone May 27, 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: documentation Documentation was not added or updated. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. stale This PR will be closed unless it is rebased.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants