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

feat: detailed feedback on decide tactic failure #4674

Merged
merged 9 commits into from
Jul 11, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Jul 6, 2024

When the decide tactic fails, it can try to give hints about the failure:

  • It tells you which Decidable instances it unfolded, by making use of the diagnostics feature.
  • If it encounters Eq.rec, it gives you a hint that one of these instances was likely defined using tactics.
  • If it encounters Classical.choice, it hints that you might have classical instances in scope.
  • During this, it tries to process Decidable.recs and matchers to pin blame on a particular instance that failed to reduce.

This idea comes from discussion with Heather Macbeth on Zulip.

When the `decide` tactic fails, it can try to give hints about the failure:
- It tells you which `Decidable` instances it unfolded, by making use of the diagnostics feature.
- If it encounters `Eq.rec`, it gives you a hint that one of these instances was likely defined using tactics.
- If it encounters `Classical.choice`, it hints that you might have classical instances in scope.

This idea comes from discussion with Heather Macbeth [on Zulip](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Decidable.20with.20structures/near/449409870).
@kmill kmill requested a review from kim-em as a code owner July 6, 2024 20:34
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 6, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Jul 6, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4ed79472af1f85b13c51e9ed77d15d3b4c40e3cc --onto 5ad5c2cf049bea5829ccd3e72875ae375f8c422b. (2024-07-06 21:00:26)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2024-07-10 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. (2024-07-10 17:24:04)
  • ✅ Mathlib branch lean-pr-testing-4674 has successfully built against this PR. (2024-07-11 21:12:38) View Log

Copy link
Contributor

@hrmacbeth hrmacbeth left a comment

Choose a reason for hiding this comment

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

This PR seems to me like a very good idea!

src/Lean/Elab/Tactic/ElabTerm.lean Outdated Show resolved Hide resolved
@kmill
Copy link
Collaborator Author

kmill commented Jul 10, 2024

@david-christiansen Would you mind taking a look at the wordings of the error messages in the test files?

One thing that might be confusing is that the expression it reports as being to blame might not be the original instance — that's by design since we want to diagnose where whnf got stuck. We can't use the word "subexpression" here because it's only a subexpression after enough reduction. Instead, I went for being slightly vague with the phrase "reduction got stuck at".

Comment on lines 74 to 76
Hint: Reduction got stuck on '▸' (Eq.rec), which suggests that one of the decidability instances is
defined using tactics such as 'rw' or 'simp'. Use definitions such as inferInstanceAs or
decidable_of_decidable_of_iff to alter a proposition.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Hint: Reduction got stuck on '▸' (Eq.rec), which suggests that one of the decidability instances is
defined using tactics such as 'rw' or 'simp'. Use definitions such as inferInstanceAs or
decidable_of_decidable_of_iff to alter a proposition.
Hint: Reduction got stuck on '▸' (Eq.rec), which suggests that one of the 'Decidable' instances is
defined using tactics such as 'rw' or 'simp'. Instead of these tactics, use functions such as 'inferInstanceAs' or
'decidable_of_decidable_of_iff' to alter a proposition.

I'm not too happy with the term "function" here, but I think it's better than "definitions" (as the definition is not what's being used, really). Perhaps "operator"?

Thanks for being careful about making them all clickable :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about "declarations"? Something I want to be clear about here is that these are plain old definitions that you could have written yourself, and I worry that "operator" would suggest that they're in a special category of their own.

If "declaration" is no good, "function" works too.

Copy link
Contributor

Choose a reason for hiding this comment

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

For me, "declaration" and "definition" have the same downside: a declaration/definition is that which results in a name being given a meaning, but not the name nor the meaning itself. User's aren't expected to stick def ... here, they're expected to invoke something that was previously defined.

This is indeed a bit nitpicky, and I think the risk of someone being misled is fairly low.

"function", then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Imagine if these were theorems instead of definitions. Would you have the same objection to "Instead of these tactics, use theorems such as 'thm1' or 'thm2'"? Definitions and theorems are fundamental notions that we need to refer to somehow (both of which are kind of declarations).

Is the analogy "definition is to function/constant as theorem is to theorem"?

@david-christiansen
Copy link
Contributor

I have only nitpicks. This is a great improvement!

'Nat.decEq', reduction got stuck at the 'Decidable' instance
match h : (((mul 4 1).mul 1).mul 1).num.beq 4 with
| true => isTrue ⋯
| false => isFalse ⋯
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible future addition: add another "Hint" covering this situation (one of the definitions is marked as irreducible)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would be nice to have a more general system to diagnose reduction issues! Right now, I'm a little worried that this reduction blamer might mis-blame match discriminants. At least every Decidable instance that appears should be reducible, so it should be harmless. With arbitrary discriminants, there's more risk of being wrong, unless perhaps we report each discriminant that doesn't reduce to a constructor.

(Somewhat related, today on Zulip I was thinking about this problem for diagnosing type mismatches. It's a bit different, since it's for isDefEq, but isDefEq depends on whnf.)

@kmill kmill enabled auto-merge July 11, 2024 19:48
@kmill kmill added this pull request to the merge queue Jul 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jul 11, 2024
Merged via the queue into leanprover:master with commit ce73bbe Jul 11, 2024
13 checks passed
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants