Skip to content

fix(ClickSuggestions): also consider side goals when deduplicating rw/grw suggestions - #46819

Open
JovanGerb wants to merge 1 commit into
leanprover-community:masterfrom
JovanGerb:Jovan-click_suggestions-rw-dedup
Open

JovanGerb wants to merge 1 commit into
leanprover-community:masterfrom
JovanGerb:Jovan-click_suggestions-rw-dedup

Conversation

@JovanGerb

@JovanGerb JovanGerb commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This PR improves the deduplication of rw and grw suggestions in #click_suggestions. Previously, it would only look at the replacement expression and not at side goals. As a result, important suggestions could get lost.

This PR makes it compare the side goals as well, so that it only consider two rewrites the same when the replacement expression and the new side goals are all the same. This might cause some unwanted suggestions to not be filtered out, but that is better than that good suggestions are filtered out.

Example by Floris van Doorn:

import Mathlib.Tactic

#click_suggestions
example {a b c : ℝ} (hb : 0 ≤ b) (h : 0 ≤ c) :
    a * b ≤ (a + c) * b := by
  -- shift-click on `a + c`.
  -- grw [← lt_add_of_pos_right]
  -- ^ this is suggested by default, but leaves an unprovable goal
  -- grw [← le_add_of_nonneg_right]
  -- ^ this is filtered out by default, and is what you want.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR summary 02bbed9e6f

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 02bbed9).

  • +2 new declarations
  • −2 removed declarations
+Mathlib.Tactic.ClickSuggestions.GrwKey.newExprs
-Mathlib.Tactic.ClickSuggestions.GrwKey.replacement
+Mathlib.Tactic.ClickSuggestions.RwKey.newExprs
-Mathlib.Tactic.ClickSuggestions.RwKey.replacement

No changes to strong technical debt.
No changes to weak technical debt.

Current commit 02bbed9e6f
Reference commit b456952725

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-meta Tactics, attributes or user commands label Dec 1, 2026
@JovanGerb
JovanGerb marked this pull request as draft December 1, 2026 17:40
@JovanGerb
JovanGerb marked this pull request as ready for review December 1, 2026 17:44

@grunweg grunweg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Looks reasonable to me, but I'd appreciate another pair of eyes.
maintainer delegate?

-- different side conditions!
/-- The new subexpression. -/
replacement : AbstractMVarsResult
/-- The new subexpression and the corresponding side goals. -/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that the side goals are put before the subexpression. Do you think such ordering is worth documenting? (Same question above.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My idea was that the ordering doesn't really matter, as long as it's done consistently.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by grunweg.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Dec 2, 2026
@adomani

adomani commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks! This looks very good!

I only have two questions.

  • Should #click_suggestions be turned on by default, will this have performance implications?
  • Is there a way in which you can add a test that checks the suggestion in the description does not get lost?

@grunweg

grunweg commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Should #click_suggestions be turned on by default, will this have performance implications?

This was discussed in yesterday's maintainers meeting, I'm tasked with following up on this. Opinion in the meeting was "yes" and "seems rather unlikely". In any case, this should be a separate PR :)

@grunweg

grunweg commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Having a test for this would obviously be great, but I don't know if this is feasible.

@JovanGerb

Copy link
Copy Markdown
Contributor Author

Adding a test for this is a bit awkward, because the current testing setup can only tell which tactics are suggested at all. Since there is also an unfiltered section of the output, this is not affected by the deduplication. 🫤

The way the test works is that it traverses the produced Html, finding all suggested tactics. Hmm, maybe it could also count the number of occurrences of each suggestion in the Html, which would allow this PR to gain a test.

@grunweg

grunweg commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Hm. What you suggest is certainly an improvement!

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants