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

Fix #11039: proof of False with template poly and nonlinear universes #11128

Merged

Conversation

SkySkimmer
Copy link
Contributor

Using the parameter universes in the constructor causes implicit
equality constraints, so those universes may not be template
polymorphic.

@SkySkimmer SkySkimmer added part: universes The universe system. kind: inconsistency Proof of False accepted by the kernel and/or checker. labels Nov 15, 2019
@SkySkimmer SkySkimmer added this to the 8.10.2 milestone Nov 15, 2019
@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from 591a729 to 9f554a2 Compare November 15, 2019 15:18
@SkySkimmer SkySkimmer requested review from Zimmi48 and a team as code owners November 15, 2019 15:18
@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from 9f554a2 to 2bf6820 Compare November 15, 2019 15:20
@@ -257,7 +257,6 @@ Ltac blocked t := block_goal ; t ; unblock_goal.
be used by the [equations] resolver. It is especially useful to register the dependent elimination
principles for things in [Prop] which are not automatically generated. *)

#[universes(template)]
Class DependentEliminationPackage (A : Type) :=
{ elim_type : Type ; elim : elim_type }.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type and the one in ssrbool were not actually template.

(fun levels (d,c) ->
List.fold_left (fun levels d ->
Context.Rel.Declaration.fold_constr (fun c levels ->
Vars.with_universes_of_constr levels c)
Copy link
Member

Choose a reason for hiding this comment

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

Why not simply a union instead of exporting a new function? This is very unlikely to be performance-critical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I got tired of typing these damn unions in the middle of writing the patch

Copy link
Member

Choose a reason for hiding this comment

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

Come on, write a union and be done with it.

-> Entries.universes_entry
-> Constr.rel_context
-> Sorts.t option
-> bool
(** [template_polymorphism_candidate env uctx params conclsort] is
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to update this comment as well.

Copy link
Member

@mattam82 mattam82 left a comment

Choose a reason for hiding this comment

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

Appart from @ppedrot 's suggestion to use a union, which I second, the patch looks good to me.
If the universe is local, and does not appear in the constructors, then it can't be hidden under a definition. The only thing I can see that would allow to refer to the level is hence Ind I (A : Type@{i}) : Type@{j} := foo (B : Type@{k}) : I B -> I A but that would bound i from below, or nesting Ind I (A : Type@{i}) : Type@{i} := bar : list A -> I A and that is just transitively template poly.

@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from 2bf6820 to d6e9338 Compare November 19, 2019 12:31
@SkySkimmer SkySkimmer added the needs: progress Work in progress: awaiting action from the author. label Nov 19, 2019
@SkySkimmer
Copy link
Contributor Author

SkySkimmer commented Nov 19, 2019

This patch is still not enough,

#[universes(template)]
 Inductive foo@{i} (A:Type@{i}) (T:=Type@{i}:Type@{i+1}) : Type@{i+1}
  := bar (X:T) : foo A.

goes through.

Not sure how to fix this, maybe use a variant of universes_of_constr which unfolds letins?

@ppedrot
Copy link
Member

ppedrot commented Nov 19, 2019

What about using the same code as the one for irrelevant cumulative inductive types?

@SkySkimmer
Copy link
Contributor Author

I don't know what you mean by that.

@mattam82
Copy link
Member

A variant of universes_of_constr that can crawl the local context sounds ok. "smashing" the context would be more complicated I guess.

@ppedrot
Copy link
Member

ppedrot commented Nov 19, 2019

Type-check the inductive type as if it were a polymorphic cumulative one, check that all template indices are indeed irrelevant, and use the monomorphic constraints above for partial application.

@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from d6e9338 to 076984b Compare November 19, 2019 13:26
@SkySkimmer
Copy link
Contributor Author

Type-check the inductive type as if it were a polymorphic cumulative one, check that all template indices are indeed irrelevant, and use the monomorphic constraints above for partial application.

That sounds complicated, especially considering we run the check in the upper layers to decide if we're auto template. I added an optional rel_context argument to univs_of_constr instead.

@SkySkimmer SkySkimmer removed the needs: progress Work in progress: awaiting action from the author. label Nov 19, 2019
@SkySkimmer SkySkimmer requested a review from mattam82 November 19, 2019 13:32
@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from a975dfc to f6ba117 Compare November 19, 2019 13:41
@ppedrot
Copy link
Member

ppedrot commented Nov 19, 2019

@SkySkimmer this still looks a bit ad-hoc and probably leaky. What about unconditionally adding the constraints appearing in let bodies? If the user starts using let binders in the context, they deserve it.

@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from f6ba117 to f11f1cf Compare November 20, 2019 13:08
@SkySkimmer
Copy link
Contributor Author

@SkySkimmer this still looks a bit ad-hoc and probably leaky. What about unconditionally adding the constraints appearing in let bodies? If the user starts using let binders in the context, they deserve it.

Sure, why not

@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from f11f1cf to 8e7de1e Compare November 20, 2019 13:10
@Zimmi48
Copy link
Member

Zimmi48 commented Nov 26, 2019

Is this still waiting on something?

previous issue about template polymorphism exploiting other ways to
generate untracked constraints
introduced: morally at the introduction of template polymorphism, 23
May 2006, 9c2d70b, r8845, Herbelin impacted released versions: at
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
May 2006, 9c2d70b, r8845, Herbelin impacted released versions: at
May 2006, 9c2d70b, r8845, Herbelin
impacted released versions: at

@ppedrot
Copy link
Member

ppedrot commented Nov 26, 2019

I can assign and merge if needed.

Using the parameter universes in the constructor causes implicit
equality constraints, so those universes may not be template
polymorphic.

A couple types in the stdlib were erroneously marked template, which
is now detected. Removing the marking doesn't actually change
behaviour though.

Also fixes coq#10504.
and do not run template_candidate in the upper layers when the
template attribute is given.

This means we can use an over-approximation in the upper layer
implementation of template_candidate (returning false even in cases
which the kernel may accept) if we ever want to.
@SkySkimmer SkySkimmer force-pushed the fix-11039-template-poly-nonlinear-false branch from 8e7de1e to 1db8720 Compare November 26, 2019 10:29
@vbgl
Copy link
Contributor

vbgl commented Nov 26, 2019

Pierre-Marie, please do so. And we will contemplate the release of 8.10.2.

@ppedrot ppedrot self-assigned this Nov 26, 2019
@ppedrot ppedrot added the kind: fix This fixes a bug or incorrect documentation. label Nov 27, 2019
ppedrot added a commit that referenced this pull request Nov 27, 2019
…nlinear universes

Reviewed-by: Zimmi48
Reviewed-by: mattam82
Reviewed-by: ppedrot
@ppedrot ppedrot merged commit 1db8720 into coq:master Nov 27, 2019
ppedrot added a commit to ppedrot/coq that referenced this pull request Nov 27, 2019
@SkySkimmer SkySkimmer deleted the fix-11039-template-poly-nonlinear-false branch November 27, 2019 11:40
vbgl added a commit to vbgl/coq that referenced this pull request Nov 27, 2019
@vbgl vbgl mentioned this pull request Nov 27, 2019
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: fix This fixes a bug or incorrect documentation. kind: inconsistency Proof of False accepted by the kernel and/or checker. part: universes The universe system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants