Infer the relevance of inductive parameters by retyping - #1093
Conversation
gares
left a comment
There was a problem hiding this comment.
This approach is worrying, since retyping can be expensive.
I'd rather have the user elaborate a term and get the relevance fixed for him, rather than having it implicitly done at each API call that crosses the language boundary.
dc7a5c9 to
5e2ee9f
Compare
`parameter` binders of an `indt-decl` are read back with the relevance mark carried by the name. Since 3b62afd that mark is *relevant* for a name built from an id, so an inductive with a parameter whose type lives in SProp is rejected by the kernel: Elpi Query lp:{{ coq.locate "sTrue" (indt ST), % Inductive sTrue : SProp := sI. Decl = (parameter "proof" explicit (global (indt ST)) proof\ inductive "i" tt (arity {{ Type }}) ind\ [constructor "k" (arity ind)]), std.assert-ok! (coq.elaborate-indt-decl-skeleton Decl E) "elab", coq.env.add-indt E _. }}. fails with Binder proof has relevance mark set to Relevant but was expected to be Irrelevant (maybe a bugged tactic). The same happens for `parameter` binders occurring inside an `arity`. Fix both readback sites (`readback_arity` and the `inductive_parameterc` case of `lp2inductive_entry`) to recompute the mark, once the type has been read back, from `Retyping.relevance_of_type`, keeping the mark carried by the name when the type does not retype. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012gna9AxbEH5BjMv5V4Q97n
5e2ee9f to
99d1cc6
Compare
|
I've done some rebasing. Note that retyping is only for the parameters of inductives, so I don't think it can be that expensive. If you want the user to retype, I think we'd need to make parameters carry the relevance instead of just the name, but this seems kind-of awkward for the user. What do you think? |
|
right, I find that sticking the relevance in the names was a hack in the first place, both in rocq and elpi. |
parameterbinders of anindt-declbuilt from Elpi receive a fresh, unconstrained relevance variable. The kernel rejects parameters whose type lives inSProp:The same happens for
parameterbinders inside anarity.coq.elaborate-indt-decl-skeletonsucceeds, butcoq.env.add-indtfails, and Elpi surface syntax cannot specify parameter relevance.Both readback sites—
readback_arityand theinductive_parameterccase oflp2inductive_entry—now recompute the mark from the parameter type's sort withRetyping.get_sort_of, after reading back the type. If retyping raises, they retain the name's mark. This matches the kernel check; types inTypeorPropstill yieldRelevant.tests/test_HOAS.vcovers anSPropdeclaration parameter and anSProparity parameter used by a constructor. Both fail onmasterwith the error above and succeed with this change.Wordsmithed by Codex.