Skip to content

[Merged by Bors] - chore: reduce imports#9830

Closed
digama0 wants to merge 9 commits intomasterfrom
shake_mathlib
Closed

[Merged by Bors] - chore: reduce imports#9830
digama0 wants to merge 9 commits intomasterfrom
shake_mathlib

Conversation

@digama0
Copy link
Copy Markdown
Member

@digama0 digama0 commented Jan 18, 2024

This uses the improved shake script from #9772 to reduce imports across mathlib. The corresponding noshake.json file has been added to #9772.


Open in Gitpod

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 18, 2024
@sgouezel
Copy link
Copy Markdown
Contributor

This is essentially impossible to review in the traditional way, so the question is whether we trust your script or not. I'd say yes (the fact that it builds is proof enough that it works at least to reduce some imports) so I think we should merge this as quickly as possible (running the tool again to fix the conflicts), but it would be better that at least two people agree on this, so
maintainer merge

@github-actions
Copy link
Copy Markdown

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

@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 18, 2024

This PR was not actually written by my script, unfortunately. It was a few phases of looking at the output, moving some things to global noshakes, some to local noshakes, and accepting the rest, then cleanup and reformatting of the result, then doing a second and third pass to ensure a minimal diff and checking that things still compile.

The script is able to produce a passable approximation of this PR, but it works best when there are few changes needed and most of the noshakes are already in place; when you run it cold like this it makes a lot of mistakes (because it missed some dependency it wasn't aware of) and makes more mistakes trying to fix its other mistakes, and this requires manual cleanup.

@sgouezel
Copy link
Copy Markdown
Contributor

Let me correct myself, then. The question is whether we trust script + Mario. My answer is yes, because in the end it builds and it reduces imports. Maybe in a slightly non-optimal way if Mario screwed up somewhere, but in any case it's a big improvement.

@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 18, 2024
@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 18, 2024

Going forward it might be worth teaching people (mainly maintainers) how to use noshake.json, because it's grown large enough that it is reasonable to expect it to need to be edited on a regular basis.

In short:

  • ignoreAll is for files which intentionally have unnecessary imports. Files which are import-only are automatically considered as being in this group, so really the only mathlib file we have in this category is Mathlib.Mathport.Syntax.
  • ignoreImport is for files which should be treated as used when importing into another file. This is when there is some property of the file itself which means that downstream users will depend on it without having any direct constant-to-constant dependency. That is, tactics and notation files, and files whose main purpose is to add or declare an attribute.
  • ignore is for individual imports in individual files. This is used when there is some unusual use of a constant which is compile-time only, like double-backtick names, Qq expressions, attribute [foo] bar, as well as check-only commands like #guard and example.

conv_rhs => rw [add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this]
rw [← add_right_inj l.length, ← add_tsub_assoc_of_le, add_tsub_tsub_cancel,
add_tsub_cancel_of_le, add_comm]
rw [← add_right_inj l.length, ← add_tsub_assoc_of_le (α := ℕ), add_tsub_tsub_cancel (α := ℕ),
Copy link
Copy Markdown
Contributor

@kmill kmill Jan 18, 2024

Choose a reason for hiding this comment

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

Why do these now need an explicitly given implicit argument?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not entirely sure; apparently you can do this proof without some imports and it still works when you pass the types explicitly but inferring them seems not to work, or you can add more imports and it will work as is. I felt like it would be better to err on the side of fewer imports since the fallout isn't too much.

@digama0 digama0 force-pushed the shake_mathlib branch 3 times, most recently from a67311d to bde1cd8 Compare January 18, 2024 10:23
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

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

As a bit of penance for my own huge PRs I went through all the changes. Only two additions stood out to me as unusual and there were a couple of weird reorderings, otherwise looks good to me.

@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 18, 2024

I've pushed fixes for the tests, which might warrant additional scrutiny since additional imports there imply some usability loss (to remember to import things otherwise the tactic has degraded behavior).

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 18, 2024
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

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

As far as I can tell, most of the added imports cover extra test cases, not the core functionality. Only rw_search and rw really do seem to need Init.Core to work at all. (And because they're meant to be self-replacing, it's extra important that we don't tweak the test cases too much: other tactics can rely on being tested by the bulk of Mathlib itself.)

I'm confident that this change is going to be an improvement, since things build with minimal modifications outside of the import lines. Let's get this merged!

bors d+

@@ -1,3 +1,4 @@
import Mathlib.Init.Core
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.

This file seems to specifically need the following attributes to work:

attribute [refl] Eq.refl
attribute [trans] Eq.trans
attribute [symm] Eq.symm

So I think we should import them in Tactic.RewriteSearch itself.

Comment on lines 1 to 2
import Mathlib.Init.Core
import Mathlib.Tactic.Rewrites
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.

Idem: we should probably make Init.Core available in Tactic.Rewrites.

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jan 18, 2024

✌️ digama0 can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@urkud
Copy link
Copy Markdown
Member

urkud commented Jan 19, 2024

Could you please merge master and shake it again? I'm surprised that imports of Data.Set.Defs didn't change: it compiles with

import Std.Classes.SetNotation
import Mathlib.Init.Set
import Mathlib.Tactic.Attr.Core
import Mathlib.Tactic.Simps.Basic
import Mathlib.Order.Notation
import Mathlib.Util.CompileInductive
import Mathlib.Data.SProd
import Mathlib.Data.Subtype

(I removed Mathlib.Order.Basic, then fixed compile).

@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 19, 2024
@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 19, 2024

(I hadn't actually done the re-shaking from the last merge yet. I can't shake it until it compiles successfully. Seems I have to merge again and restart the process...)

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 19, 2024
@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 19, 2024

AAH it conflicted again, I literally can't get this out the door fast enough

@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 19, 2024
@digama0
Copy link
Copy Markdown
Member Author

digama0 commented Jan 19, 2024

bors merge p=10

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Jan 19, 2024
mathlib-bors bot pushed a commit that referenced this pull request Jan 19, 2024
This uses the improved `shake` script from #9772 to reduce imports across mathlib. The corresponding `noshake.json` file has been added to #9772.



Co-authored-by: Mario Carneiro <di.gama@gmail.com>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Jan 19, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: reduce imports [Merged by Bors] - chore: reduce imports Jan 19, 2024
@mathlib-bors mathlib-bors bot closed this Jan 19, 2024
@mathlib-bors mathlib-bors bot deleted the shake_mathlib branch January 19, 2024 13:55
riccardobrasca pushed a commit that referenced this pull request Jan 19, 2024
This uses the improved `shake` script from #9772 to reduce imports across mathlib. The corresponding `noshake.json` file has been added to #9772.



Co-authored-by: Mario Carneiro <di.gama@gmail.com>
mathlib-bors bot pushed a commit that referenced this pull request Jan 23, 2024
- [ ] depends on: #9830

This is the `noshake.json` file corresponding to the edits in leanprover-community/batteries#533. There was a small bug in `shake` making it much more conservative than it needed to be, so there is a big mathlib PR #9830, on which this PR depends because CI will not pass without it.



Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
mathlib-bors bot pushed a commit that referenced this pull request Feb 2, 2024
- [X] depends on: #9830
- [X] depends on: #9772
- [X] depends on: #9996

This checks files for unused imports. The output here is piped through `gh-problem-matcher-wrap` so that it will show up as annotations.



Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants