Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not rely on floating universes in the upper layers #18956

Merged
merged 3 commits into from May 17, 2024

Conversation

ppedrot
Copy link
Member

@ppedrot ppedrot commented Apr 19, 2024

We remove the lower universe bound from the UState and environment data types, and rely instead on passing a flag to the pretyper to generate sort-polymorphic universes. The kernel still requires pushing floating template universes, but I will defer this cleanup to a later PR.

@ppedrot ppedrot added kind: cleanup Code removal, deprecation, refactorings, etc. request: full CI Use this label when you want your next push to trigger a full CI. labels Apr 19, 2024
@ppedrot ppedrot added this to the 8.20+rc1 milestone Apr 19, 2024
@ppedrot ppedrot requested review from a team as code owners April 19, 2024 12:44
@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 Apr 19, 2024
@@ -491,11 +492,12 @@ let interp_mutual_inductive_constr ~sigma ~template ~udecl ~variances ~ctx_param
constructors
in
let sigma, (default_dep_elim, arities) = inductive_levels env_ar_params sigma arities ctor_args in
let sigma = Evd.minimize_universes sigma in
let lbound = if poly then UGraph.Bound.Set else UGraph.Bound.Prop in
let sigma = Evd.minimize_universes ~lbound 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.

Having to to this is IMO an indication that we're not doing the right thing.

If we naively always pass Set a problem appears with

Inductive T A := C : A -> T nat -> T A.

(a version with option A instead of nat appears in the test suite)
before minimization we have generated T : Type@{Type|u} -> Type@{q|v} with Set <= u, u <= v
(Set <= u from the application T nat, u <= v from include_constructor_argument)
Minimization collapses q := Type and sets u = v, with lbound Set it also forgets Set <= u. We then think the inductive can be template and the kernel will reject it.

Probably we need to

  • in include_constructor_argument in monomorphic mode do not ignore qualities, such that Set <= Type@{q|u} produces q := Type instead of leaving it floating, this would make the example generate q := Type. (include_constructor_argument currently has a comment that ignoring qualities only impacts squashing but that's not correct once we use sort qualities in monomorphic mode)
  • when determining if an inductive may be template, the parameters binding a universe must be at floating (possibly above_prop) quality (this is an interpretation of unbounded_from_below now that we can't check the presence of Set <= u constraints)
  • to be able to do this check we need to delay sort quality collapse (currently done in minimize_universes)

then we should be able to forget Set <= u constraints in minimization ie always use lbound = Set (and the lbound concept can then be deleted since this is the last user)

ppedrot added a commit to ppedrot/coqhammer that referenced this pull request Apr 21, 2024
Should be backwards compatible and future-proof.
lukaszcz pushed a commit to lukaszcz/coqhammer that referenced this pull request Apr 23, 2024
Should be backwards compatible and future-proof.
@ppedrot
Copy link
Member Author

ppedrot commented Apr 23, 2024

The CoqHammer backwards compatible overlay has been merged, this is ready to go.

@ppedrot
Copy link
Member Author

ppedrot commented Apr 24, 2024

@coqbot run full ci

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 remain unconvinced that hacking the minimization call is better than using lbound as we currently do in the upper layers (removing it from environ and using push_floating_context_set seems fine).

@ppedrot
Copy link
Member Author

ppedrot commented Apr 24, 2024

I don't see how you can do it without hacking the lbound at some point, though.

@SkySkimmer
Copy link
Contributor

You have to actually use the sort qualities instead of the current state of the PR which AFAICT uses them possibly by accident to make automatic Prop lowering work and then collapses them.

@ppedrot
Copy link
Member Author

ppedrot commented Apr 24, 2024

I definitely want to refine the criterion to rely on sort qualities in the future, but this is a quick (and dirty) cleanup that ensures that nobody can rely on the lbound hack anymore, because it's just not part of the data structures anymore. If there is time for 8.20 then I can try to come up with the refinement asap, but I thought that the current state was already a net progress.

@SkySkimmer
Copy link
Contributor

I thought that the current state was already a net progress.

I don't agree.

@SkySkimmer SkySkimmer self-assigned this May 13, 2024
@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 May 16, 2024
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.

Still not fully convinced but I'm willing to take the step in this direction.

@ppedrot ppedrot added the request: full CI Use this label when you want your next push to trigger a full CI. label May 16, 2024
@coqbot-app coqbot-app bot removed needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. request: full CI Use this label when you want your next push to trigger a full CI. labels May 16, 2024
@ppedrot ppedrot added the request: full CI Use this label when you want your next push to trigger a full CI. label May 16, 2024
This is not used yet, but it will allow preserving the behaviour where
Type in a template polymorphic inductive type means Type or Prop.
This removes the lbound parameter from the universe unification state, but
we still have to handle universe minimization of inductive types in a special
way.
We introduce a specific function to push the template universes in the
environment context rather than modifying this globally. We should do this
in a more principled way but I will leave this to further enhancement.
@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 May 16, 2024
@SkySkimmer
Copy link
Contributor

@coqbot merge now

@coqbot-app coqbot-app bot merged commit 74640bd into coq:master May 17, 2024
5 of 8 checks passed
@ppedrot ppedrot deleted the template-no-lower-bound branch May 17, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: cleanup Code removal, deprecation, refactorings, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants