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

Phrasing and formatting of the unsatisfiable constraints error message #19002

Conversation

herbelin
Copy link
Member

@herbelin herbelin commented May 6, 2024

This PR is an attempt to get:

  • a more consistent printing (same line breaking and non-quote when printing hypotheses and evars)
  • a better space management when reporting about unsatisfiable constraints
  • a better message when there are actually no constraints at all

For instance, in an example I'm working on, it gives:

Unable to satisfy the following constraints:
In environment:
arity : HSet
FrameBlock :
  forall n : nat,
  nat -> forall prefix : Type, FrameBlockPrev n prefix -> Type
n, p : nat
prefix : Type
FramePrev : FrameBlockPrev n prefix
frame : p <= n -> prefix -> HSet
restrFrame :
  forall (q : nat) (Hpq : p.+1 <= q.+1) (Hq : q.+1 <= n),
  arity ->
  forall D : prefix, frame (↓ (Hpq ↕ Hq)) D -> FramePrev.(frame') p D
q, r : nat
Hpr : p.+2 <= r.+2
Hrq : r.+2 <= q.+2
Hq : q.+2 <= n
ε, ω : arity
D : prefix
d : frame (↓ (?Hpq0 ↕ ?Hq0)) D
?Hpq : p.+2 <= q.+2
?Hq : q.+2 <= n
?Hpq0 : p.+1 <= r.+1
?Hq0 : r.+1 <= n
?Hpq1 : p.+2 <= r.+2
?Hq1 : r.+2 <= n
?Hpq2 : p.+1 <= q.+2
?Hq2 : q.+2 <= n
[arity] [FrameBlock n p prefix FramePrev frame restrFrame q r Hpr Hrq Hq ε ω
  D d q0 Hqn] |- ?Hq2 q0 (?Hpq2 q0 Hqn) == (↓ (?Hpq1 ↕ ?Hq1)) q0 Hqn
[arity] [FrameBlock n p prefix FramePrev frame restrFrame q r Hpr Hrq Hq ε ω
  D d q0 Hqn] |- ?Hq0 q0 (?Hpq0 q0 Hqn) == (↓ (?Hpq ↕ ?Hq)) q0 Hqn

while it was before:

Unable to satisfy the following constraints:
In environment:
arity : HSet
FrameBlock :
  forall n : nat,
  nat -> forall prefix : Type, FrameBlockPrev n prefix -> Type
n, p : nat
prefix : Type
FramePrev : FrameBlockPrev n prefix
frame : p <= n -> prefix -> HSet
restrFrame :
  forall (q : nat) (Hpq : p.+1 <= q.+1) (Hq : q.+1 <= n),
  arity ->
  forall D : prefix, frame (↓ (Hpq ↕ Hq)) D -> FramePrev.(frame') p D
q, r : nat
Hpr : p.+2 <= r.+2
Hrq : r.+2 <= q.+2
Hq : q.+2 <= n
ε, ω : arity
D : prefix
d : frame (↓ (?Hpq0 ↕ ?Hq0)) D

?Hpq : "p.+2 <= q.+2"

?Hq : "q.+2 <= n"

?Hpq0 : "p.+1 <= r.+1"

?Hq0 : "r.+1 <= n"

?Hpq1 : "p.+2 <= r.+2"

?Hq1 : "r.+2 <= n"

?Hpq2 : "p.+1 <= q.+2"

?Hq2 : "q.+2 <= n"
[arity] [FrameBlock n p prefix FramePrev frame restrFrame q r Hpr Hrq Hq ε ω D d q0 Hqn] |- ?Hq2
                                                 q0 (?Hpq2 q0 Hqn) == (↓ 
                                                 (?Hpq1 ↕ ?Hq1)) q0 Hqn
[arity] [FrameBlock n p prefix FramePrev frame restrFrame q r Hpr Hrq Hq ε ω D d q0 Hqn] |- ?Hq0
                                                 q0 (?Hpq0 q0 Hqn) == (↓ 
                                                 (?Hpq ↕ ?Hq)) q0 Hqn

Maybe the context and list of evars should be more clearly separated?

Also, in a situation without proper constraints like this one:

Class T : SProp.
Parameter t : T.
Parameter c : T -> T -> T.
Parameter P : T -> Type.
Parameter f : forall x, P (c (c x x) t).
Parameter g : forall x, P (c t (c x x)).
Definition h : f _ = g _.

the message is now:

Could not find an instance for the following existential variables:
?x : T
?x0 : T

while it was before:

Unable to satisfy the following constraints:

?x : "T"

?x0 : "T"

This is to be compared to the case of only one remaining existential variable in a class:

Class T : SProp.
Parameter t : T.
Parameter c : T -> T -> T.
Parameter P : T -> Type.
Parameter f : forall x, P (c (c x x) t).
Definition h : f _ = f _.
(* Could not find an instance for "T". *)

Maybe the message for one or more unresolved evars could be merged actually?

  • Added / updated test-suite.

@herbelin herbelin added kind: user messages Improvement of error messages, new warnings, etc. part: typeclasses The typeclass mechanism. kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. labels May 6, 2024
@herbelin herbelin added this to the 8.20+rc1 milestone May 6, 2024
@herbelin herbelin requested review from a team as code owners May 6, 2024 07:45
@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label May 6, 2024
@SkySkimmer
Copy link
Contributor

SkySkimmer commented May 6, 2024

I think I prefer having the empty newline to separate the evars.

@herbelin herbelin changed the title Phrasing and formatting of the unnsatisfiable constraints error message Phrasing and formatting of the unsatisfiable constraints error message May 6, 2024
@herbelin
Copy link
Member Author

herbelin commented May 6, 2024

I think I prefer having the empty newline to separate the evars.

We could have something similar to the conversion mismatch error, that is, printing the reason after the environment:

In environment:
...
Unable to satisfy the following constraints:
?x : T
?x0 : T
[...] [...] |- t == u

and:

In environment:
...
Could not find an instance for the following existential variables:
?x : T
?x0 : T

??

(And incidentally adding a colon to In environment in the conversion mismatch error.)

@SkySkimmer
Copy link
Contributor

I mean the newline between evars, ie I prefer

?x : T

?x0 : T

rather than

?x : T
?x0 : T

@herbelin
Copy link
Member Author

@SkySkimmer:

But then why newlines between existential variables and not also between the (universal) variables of an environment?

Actually, and more generally, I wonder whether it would not be worth to always print the type and context of evars occurring in a goal. Say, that the following:

Goal forall x, exists y, forall z, z + y + x = x + z.
intro; eexists; intro.
Show.

gives:

  x : nat
  ?y : nat
  z : nat
  ============================
  z + ?y + x = x + z

(possibly with extra context information when the evar derives by unification from a hole not in the current "spine" of the term)

@proux01
Copy link
Contributor

proux01 commented May 13, 2024

We could have something similar to the conversion mismatch error, that is, printing the reason after the environment:

That indeed sounds better.

@SkySkimmer
Copy link
Contributor

But then why newlines between existential variables and not also between the (universal) variables of an environment?

Because I want to quickly distinguish the failed constraints (which is harder when they're a wall of text), I don't need to quickly distinguish env variables.

@herbelin herbelin force-pushed the master+unsatisfiable-constraints-error-formatting branch from 06057b5 to 1e1789a Compare May 14, 2024 11:19
@herbelin
Copy link
Member Author

@proux01, @SkySkimmer: I moved "In environment" before the main explanation and I restored the double newlines (though w/o the last trailing one).

Copy link
Contributor

Choose a reason for hiding this comment

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

??

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently a too eager git add output.

@herbelin herbelin force-pushed the master+unsatisfiable-constraints-error-formatting branch from 1e1789a to bd85479 Compare May 14, 2024 12:00
@SkySkimmer SkySkimmer self-assigned this May 23, 2024
@SkySkimmer SkySkimmer removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label May 23, 2024
@SkySkimmer
Copy link
Contributor

@coqbot merge now

@coqbot-app coqbot-app bot merged commit e940393 into coq:master May 23, 2024
6 checks passed
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. kind: user messages Improvement of error messages, new warnings, etc. part: typeclasses The typeclass mechanism.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants