Fix two BadVarianceQ anomalies in inductive cumulativity - #5
Merged
JasonGross merged 2 commits intoAug 12, 2026
Merged
Conversation
Set Universe Polymorphism.
Set Polymorphic Inductive Cumulativity.
Inductive t@{*s;u} : Prop := c (_ : Type@{s;u}).
Anomaly "Uncaught exception InferCumulativity.BadVarianceQ(_, 0, 1)."
infer_inductive converted BadVariance to a type error but left
BadVarianceQ, its sort quality counterpart, uncaught. The universe
analogue (t@{s;*u}) already reported "Incorrect variance for universe".
Add BadQVariance to ptype_error and print it the same way:
Incorrect variance for sort quality α1: expected * but cannot be less
restrictive than +.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9BGQT7XUuubV6C619DW4b
Set Universe Polymorphism.
Set Polymorphic Inductive Cumulativity.
Definition idT@{s;u} (A:Type@{s;u}) : Type@{s;u} := A.
Inductive t@{*s;u} (A:Type@{s;u}) : Prop := c (_ : idT A).
Anomaly "Uncaught exception InferCumulativity.BadVarianceQ(_, 0, 2)."
The declaration is valid: unfolding idT satisfies the annotation. The
FFlex handler in infer_cumul_stack retries after unfolding when the
constant's variance check fails, but it only caught BadVariance, so the
quality counterpart escaped. In Infer mode the same position raises
NotInferring, which was caught, hence the anomaly only shows in Check
mode -- reached either by an explicit variance annotation, or by rocqchk,
which sets every recorded variance to Some v (checker/checkInductive.ml:99).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9BGQT7XUuubV6C619DW4b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent
BadVarianceQanomalies, one per commit. Both are cases where theuniverse path is handled and the sort-quality path was never wired up alongside it.
1. Valid declaration anomalies when the quality check needs delta unfolding
Expected: accepted, since unfolding
idTsatisfies the annotation. The universeanalogue
Inductive t@{s;*u} (A:Type@{s;u}) : Prop := c (_ : idT A).is accepted.The
FFlex (ConstKey _)case ofinfer_cumul_stack(kernel/inferCumulativity.ml:284)retries after unfolding when the constant's recorded variance fails the check, but its
handler listed only
BadVariance, so the quality counterpart escaped. In Infer mode thesame position raises
NotInferring, which was caught — hence the anomaly is Check-modeonly.
Check mode is entered two ways: an explicit variance annotation as above, or rocqchk,
which maps every recorded variance to
Some v(checker/checkInductive.ml:99) and soruns every cumulative inductive in Check mode with no user syntax. That is the route in
theorem-labs/grading-tools#287, where the anomaly follows the line
checking cst:IsomorphismChecker.IsomorphismDefinitions.from_to. That label ismisleading:
mod_checkingprints no progress line for inductives(
checker/mod_checking.ml:290), only for constants, modules and module types, so theconstant named is the previous declaration, not the failing one.
2. Invalid annotation anomalies instead of erroring
Expected: a type error.
infer_inductiveconvertedBadVarianceto a type error butleft
BadVarianceQ; the universe analoguet@{s;*u}already reportsIncorrect variance for universe. No constant is involved here, so commit 1 does notcover this case.
Adds
BadQVariancetoptype_errorand prints it the same way asBadVariance:The qvar prints as
α1rather thansbecauseTermops.pr_evd_qvaris used, matchingexplain_undeclared_qualities; the universe analogue likewise printsd2u.1rather thanu. Not changed here.checker/coqchk_main.mlgains a one-line arm for the new constructor; without it thechecker does not compile.
Tests
test-suite/success/CumulInd.vgains quality analogues of the file's existingnot_irrelevant,check_covariantandmust_unfolduniverse cases. The whole file runsat rc=0 with no
Error/Anomalyoutput after the patch.Measured at
Base
c9469b7be409866c36dc12556350d3cd940fe80a(v9.2+typewise-isomorphism), 9.2+rc2,OCaml 4.14.2.
dune build -p rocq-runtime,dune build topbin/rocqworker.exeanddune build rocq-core.installall rc=0.Not applicable upstream: sort quality variance does not exist in rocq-prover/rocq master
(
6df5ae331262750d9fc2d115dd2198a6373e4dd0), whoseinferCumulativity.mlcarries(* no variance for qualities *)and whoseinfer_inductivetakes noqualsargument.The feature entered this fork with
77b78068d4a34787f50d0550870189ce0206d1ec, cherry-pickedfrom rocq-prover#21773, which was closed unmerged.
Other affected branches
BadVarianceQis present inkernel/inferCumulativity.mlon 6 of 16 branches of thisrepo, and the six touched files are blob-identical across all six, so both commits apply
unchanged:
v9.2+typewise-isomorphism,v9.2+typewise-isomorphism-stable,v9.2+typewise-isomorphism+rocq-dune,backport/22294-v9.2-typewise-isomorphism,backport/22294-v9.2-typewise-isomorphism-stable,codex/restricted-model-thin-slice.🤖 Generated with Claude Code