Skip to content

[Merged by Bors] - feat: check that every file imports Mathlib.Init - #18281

Closed
grunweg wants to merge 33 commits into
masterfrom
MR-mathlib-init-check
Closed

grunweg wants to merge 33 commits into
masterfrom
MR-mathlib-init-check

Conversation

@grunweg

@grunweg grunweg commented Oct 27, 2024 •

Copy link
Copy Markdown
Contributor

We add a text-based check to the lint-style script, that every file either (transitively) imports Mathlib.Init, or is (transitively) imported by it.


Open in Gitpod

Every file importing Mathlib.Init transitively imports this file already,
thus having its module docstring and copyright header checked by the header
linter. This adds the same input to every file *imported in* Mathlib.Init.

Helps with #17556.
This manually adds 'import Mathlib.Init' to all files which are currently missing this.
A future PR will add an automatic check for this.
Stream'.corec' was pre-existing; add it to the exceptions list
@grunweg grunweg added CI Modifies the continuous integration setup or other automation t-linter Linter labels Oct 27, 2024
@github-actions github-actions Bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Oct 27, 2024
@github-actions

github-actions Bot commented Oct 27, 2024 •

Copy link
Copy Markdown

PR summary 542f8bf287

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ checkInitImports
+ findImports

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Oct 27, 2024
@grunweg
grunweg requested a review from adomani October 27, 2024 13:34
@bryangingechen

Copy link
Copy Markdown
Contributor

Right now the module doc of Mathlib.Init says something like "this file is imported by virtually every file in Mathlib". If we add this linter, perhaps we should update that text and also mention that it's enforced by litner.

@grunweg

grunweg commented Oct 27, 2024

Copy link
Copy Markdown
Contributor Author

Good point, updated the doc-string!

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Oct 28, 2024
@github-actions github-actions Bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label Oct 28, 2024

@adomani adomani 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! Just a few minor remarks.

Comment thread scripts/lint-style.lean Resolved
Comment thread scripts/lint-style.lean Outdated
modulesWithoutMathlibImports := modulesWithoutMathlibImports.push module

-- We check that each of these is imported in `Mathlib/Init.lean`.
let initImports := (← IO.FS.lines "Mathlib/Init.lean").filter (·.startsWith "import ")

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.

If the linter is ran on a computer with path-separator different from /. then the path Mathlib/Init.lean would not be recognized, right?

I also wonder about the lean extension in allModules.

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.

Good catch! Should somebody write a linter against scripts doing manual path manipulation like this? At least for mathlib scripts, gradually forcing less use of duct tape could be useful :-)

allModules parses Mathlib.lean --- lines in it look like import Mathlib.Algebra.Algebra.Pi, so allModules contains entries like Mathlib.Algebra.Algebra.Pi, i.e. is a list of module names. Does that answer your question?

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.

I was more wondering about Mathlib.lean and whether there might be some system-dependent issue in using the extension "manually" instead of going via some addExtension API. It looks fine as is, though.

Comment thread scripts/lint-style.lean Resolved
Comment thread Mathlib/Init.lean Resolved
@grunweg

grunweg commented Oct 28, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks for the comments; I have updated the code accordingly.

And remove Mathlib.Init.Align, which does not exist any more.
@grunweg

grunweg commented Oct 30, 2024

Copy link
Copy Markdown
Contributor Author

I realised that this PR presumably makes init-creation.sh obsolete: I'd leave removing that for a follow-up PR.

@adomani

adomani commented Oct 30, 2024

Copy link
Copy Markdown
Contributor

I am suddenly a bit confused about this "duplication" of Init file.

It seems that before Mathlib.Init was the root file.

However, now everything that is imported by Mathlib.Init imports the header linter (except for the header linter itself).

Would it make more sense to check that every file in Mathlib either is the file with the header linter, or has a Mathlib import?

@grunweg

grunweg commented Oct 30, 2024 •

Copy link
Copy Markdown
Contributor Author

This is also a comment about #18275, right?
You're right - this effectively establishes the Header linter as a file that is "more root" that Mathlib.Init. (Hopefully, only authors of syntax linters need to become aware of this fact.) I agree that this might be slightly unelegant from a theoretical perspective. I like the benefit of checking every file for copyright headers (and that seems fitting as the "most root" check of all, given that it - very unlikely has, but theoretically remotely in principle could - have legal implications, unlike any style linter).
That said, I don't care very strongly about this: if you find this confusing and less helpful, I'm happy to remove this "pre-root" file.

Taking a step back:

  • I would like to remove the Python copyright linter. It's just nicer to have infrastructure written in Lean, and as syntax linters.
  • Currently, the header linter doesn't cover the imports of Mathlib.Init - so there is a small gap. You were not really happy with the gap (I agree with this).
  • Importing the header linter closes the above gap, by making sure the copyright is checked everywhere.

I am happy to un-import the header linter, but that means a previous concern of yours in addressed less. What do you think which of these options do you prefer?

I would like to, however, land this check for importing Mathlib.Init. The dependent PRs show this is easy to get wrong; I personally like this solution as it is more lightweight that init-creation.sh. (That script was great for creating the Init file! But for checking, a different mechanism suffices.)

@grunweg

grunweg commented Nov 2, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for explaining - I have clarified the comment now, and made findImports not return Init.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Nov 4, 2024
@github-actions github-actions Bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label Nov 4, 2024
@grunweg

grunweg commented Nov 11, 2024

Copy link
Copy Markdown
Contributor Author

I just merged master again. Assuming CI passes, is there anything left you would like to see?

@adomani adomani 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.

Apart from the (optional) style suggestions, I am happy with this version, thanks!

maintainer delegate

Comment thread Mathlib/Tactic/Linter/TextBased.lean Resolved
Comment thread scripts/lint-style.lean Resolved
@github-actions

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Nov 12, 2024
@grunweg

grunweg commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the style suggestions! Both work, so I applied them.

Comment thread scripts/lint-style.lean Resolved
Comment thread scripts/lint-style.lean Resolved

@Vierkantor Vierkantor 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.

LGTM, thanks!

bors d+

@mathlib-bors

mathlib-bors Bot commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

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

@ghost ghost added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Nov 13, 2024
@grunweg

grunweg commented Nov 13, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the review!
bors merge

grunweg added a commit that referenced this pull request Nov 13, 2024
Its functionality has been replaced by a text-based linter in #18281.
mathlib-bors Bot pushed a commit that referenced this pull request Nov 13, 2024
We add a text-based check to the `lint-style` script, that every file either (transitively) imports Mathlib.Init, or is (transitively) imported by it.



Co-authored-by: grunweg <[email protected]>
@mathlib-bors

mathlib-bors Bot commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat: check that every file imports Mathlib.Init [Merged by Bors] - feat: check that every file imports Mathlib.Init Nov 13, 2024
@mathlib-bors mathlib-bors Bot closed this Nov 13, 2024
@mathlib-bors
mathlib-bors Bot deleted the MR-mathlib-init-check branch November 13, 2024 14:02
mathlib-bors Bot pushed a commit that referenced this pull request Nov 13, 2024
Its functionality has been replaced by a text-based linter in #18281.
mathlib-bors Bot pushed a commit that referenced this pull request Nov 13, 2024
Its functionality has been replaced by a text-based linter in #18281.
mathlib-bors Bot pushed a commit that referenced this pull request Nov 13, 2024
Its functionality has been replaced by a text-based linter in #18281.
TobiasLeichtfried pushed a commit that referenced this pull request Nov 21, 2024
We add a text-based check to the `lint-style` script, that every file either (transitively) imports Mathlib.Init, or is (transitively) imported by it.



Co-authored-by: grunweg <[email protected]>
TobiasLeichtfried pushed a commit that referenced this pull request Nov 21, 2024
Its functionality has been replaced by a text-based linter in #18281.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Modifies the continuous integration setup or other automation delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants