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: show diffs when #guard_msgs fails #3912

Merged

Conversation

david-christiansen
Copy link
Contributor

Adds the ability to show a diff when guard_msgs fails, using the histogram diff algorithm pioneered in jgit. This algorithm tends to produce more user-friendly diffs, but it can be quadratic in the worst case. Empirically, the quadratic case of this implementation doesn't seem to be slow enough to matter for messages smaller than hundreds of megabytes, but if it's ever a problem, we can mitigate it the same way jgit does by falling back to Myers diff.

See lean/run/guard_msgs.lean in the tests directory for some examples of its output.

@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 Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 15, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Apr 15, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Apr 15, 2024

Mathlib CI status (docs):

  • ✅ Mathlib branch lean-pr-testing-3912 has successfully built against this PR. (2024-04-15 10:59:44) View Log
  • ✅ Mathlib branch lean-pr-testing-3912 has successfully built against this PR. (2024-04-15 11:42:28) View Log
  • 🟡 Mathlib branch lean-pr-testing-3912 build against this PR was cancelled. (2024-04-15 12:38:55) View Log
  • ✅ Mathlib branch lean-pr-testing-3912 has successfully built against this PR. (2024-04-15 13:54:11) View Log
  • ✅ Mathlib branch lean-pr-testing-3912 has successfully built against this PR. (2024-04-17 05:16:51) View Log
  • ❗ Std/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0c9f9ab37a0b76249f3bcd0fe45a67e30f6b84c8 --onto d3e004932c1f5ac3946850692940512d381c7634. (2024-04-18 15:11:56)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 15, 2024
@david-christiansen
Copy link
Contributor Author

@nomeata you've asked about this a few times. Does this PR cover your use case?

@semorrison
Copy link
Collaborator

Sounds great to me, but maybe should be 3 separate PRs (diffs, subarrays, guard_msgs)? No objection if someone else wants to merge as is.

@semorrison semorrison closed this Apr 17, 2024
@semorrison semorrison reopened this Apr 17, 2024
@semorrison
Copy link
Collaborator

(Sorry, wrong button!)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 17, 2024
@@ -99,6 +99,10 @@ v4.8.0 (development in progress)
and `#guard_msgs (ordering := sorted) in cmd` sorts the messages in lexicographic order before checking.
PR [#3883](https://github.com/leanprover/lean4/pull/3883).

* The `#guard_msgs` command now supports showing a diff between the expected and actual outputs. This feature is currently
disabled by default, but can be enabled with `set_option guard_msgs.diff true`. Depending on user feedback, this option
may default to `true` in a future version of Lean.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not on by default? If it's off I expect few people will ever benefit from it, simply because they don't know about it.

We can still turn it off by default if it's not well received.

Copy link
Collaborator

@digama0 digama0 Apr 17, 2024

Choose a reason for hiding this comment

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

For both this and in expected type mismatch messages, I think both views are useful, but I don't think a set_option is the best way to surface it to users, a toggle button in the info view would be better. (The issue with only having the diff view is that it can make it difficult to see what either the before or after expression is because the two are mixed together. Also, if there is very little similarity between the two I think the diff formatting is not so helpful.)

Copy link
Contributor Author

@david-christiansen david-christiansen Apr 17, 2024

Choose a reason for hiding this comment

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

I agree that an infoview toggle would be better, but it's not achievable in the time I have right now. Any creative ideas to implement something nicer on the Lean side?

Another reason to have it off by default right now is that the practicality of something like this is hard to assess in the abstract, or with contrived examples. I plan to have it on for a couple of months, and I'm sure a bunch of little papercuts will surface that I can fix.

I'm already expecting that I'll want a threshold of similarity that triggers the diff rendering (e.g. if less than X% of lines are edited, show a diff, otherwise don't), but I'd rather base that kind of thing on real experience by myself and others.

The plan is to make it on by default once it makes people happy enough, but I'd rather have the experiment be opt-in to start with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough!

@david-christiansen
Copy link
Contributor Author

OK, I think this is both good enough to be useful and unlikely to get substantially better in the next little while - I'll merge, then dogfood for a while to make it really nice and polished

@david-christiansen david-christiansen added this pull request to the merge queue Apr 18, 2024
Merged via the queue into leanprover:master with commit b6d77be Apr 18, 2024
10 checks passed
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.

None yet

5 participants