Skip to content

[Merged by Bors] - feat: a linter to deprecate imported modules#20987

Closed
adomani wants to merge 34 commits intomasterfrom
adomani/deprecated_imports_linter
Closed

[Merged by Bors] - feat: a linter to deprecate imported modules#20987
adomani wants to merge 34 commits intomasterfrom
adomani/deprecated_imports_linter

Conversation

@adomani
Copy link
Copy Markdown
Contributor

@adomani adomani commented Jan 23, 2025

Writing

import Bar1
import Bar2

deprecated_module (since := "yyyy-mm-dd")

in file A.lean means that any file that imports A will have import A flagged with a suggestion to import Bar1 and Bar2 instead.

Zulip discussion


Open in Gitpod

@github-actions github-actions bot added the t-linter Linter label Jan 23, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 23, 2025

PR summary 988edcd197

Import changes exceeding 2%

% File
+6.25% Mathlib.Tactic.Linter

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Tactic.Linter 32 34 +2 (+6.25%)
Mathlib.Tactic 2686 2688 +2 (+0.07%)
Import changes for all files
Files Import difference
There are 5363 files with changed transitive imports taking up over 231742 characters: this is too many to display!
You can run scripts/import_trans_difference.sh all locally to see the whole output.

Declarations diff

+ addModuleDeprecation
+ deprecated.moduleLinter

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.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh 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).

@eric-wieser
Copy link
Copy Markdown
Member

Maybe deprecate_module would be a better name?

@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Jan 23, 2025
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Jan 23, 2025

!bench

1 similar comment
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Jan 23, 2025

!bench

Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

I don't have strong opinions on the environment extension set-up (for lack for time spent with them); the remaining infrastructure looks very good. Find below my usual collection of small polish comments.

elab "show_deprecated_modules" : command => do
let directImports := deprecateModuleExt.getState (← getEnv)
logInfo <| "\n".intercalate <|
directImports.fold (init := ["Deprecated modules\n"]) fun nms (i, deps) =>
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'm pretty sure there's room for bikeshedding this formatting. I think we can land something and iterate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use the same import linking that find_home emits?

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.

I don't have time to look into this now, but I like the idea!

adomani and others added 3 commits January 23, 2025 17:55
Co-authored-by: grunweg <rothgami@math.hu-berlin.de>
…over-community/mathlib4 into adomani/deprecated_imports_linter
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit c2b50b2.
There were no significant changes against commit 8fac96b.

@github-actions
Copy link
Copy Markdown

File Instructions %
build +327.990⬝10⁹ (+0.21%)
Mathlib.RingTheory.Kaehler.JacobiZariski +1.42⬝10⁹ (+0.12%)
CI run

Copy link
Copy Markdown
Contributor Author

@adomani adomani left a comment

Choose a reason for hiding this comment

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

Thanks, Michael!

I acted on all comments, except extracting the code from the header linter, since that would take a little more thought.

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Jan 23, 2025

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 5191403.
There were no significant changes against commit 8fac96b.

@github-actions
Copy link
Copy Markdown

File Instructions %
build +208.707⬝10⁹ (+0.13%)
Mathlib.Data.Array.Lemmas +1.495⬝10⁹ (+50.67%)
CI run

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Apr 12, 2025

We now have MathlibTest/{DeprecatedModule,DeprecatedModuleTest1,DeprecatedModuleTest2} - I wouldn't mind to the first two files being merged either. That's not something I'd insist on, though.

I removed the intermediate MathlibTest/DeprecatedModuleTest1, leaving only MathlibTest/DeprecatedModule and MathlibTest/DeprecatedModuleTest.

@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 12, 2025

I don't have an opinion on whether importing it early or not. An alternative could be that the linter, by default, does not suggest itself as an import.

The latter option sounds good. I could implement that tweak tomorrow (or so).

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Apr 12, 2025

I don't have an opinion on whether importing it early or not. An alternative could be that the linter, by default, does not suggest itself as an import.

The latter option sounds good. I could implement that tweak tomorrow (or so).

This modification was easy enough that I just pushed it.

@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 12, 2025

(The current state still looks good to me.)

@kim-em
Copy link
Copy Markdown
Contributor

kim-em commented Apr 12, 2025

Optional, but it might be nice to allow an optional text argument, that would be displayed with the suggestion.

@kim-em
Copy link
Copy Markdown
Contributor

kim-em commented Apr 12, 2025

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Apr 12, 2025

✌️ adomani 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 delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Apr 12, 2025
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Apr 13, 2025

Kim, thank you for the suggestions!

@grunweg I implemented all of Kim's changes: if you want to take a look at them, I'll wait for a few hours before merging.

@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 13, 2025

The changes look great to me; I just pushed one more test.

@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 13, 2025

I'm not sure how to fix the CI failure. The error is unable to locate share/zoneinfo in the local timezone database at '/etc/localtime'; presumably, something needs to be installed on the test runners.

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Apr 13, 2025

I commented out the failing test: it was failing due to some incompatibility of the date package with the CI settings, so it was not really something prejudicial for the PR.

Assuming that this version passes CI, I will merge and we can see whether we want to fix the CI setup in a separate PR.

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Apr 13, 2025

bors merge

@ghost ghost added the ready-to-merge This PR has been sent to bors. label Apr 13, 2025
mathlib-bors bot pushed a commit that referenced this pull request Apr 13, 2025
Writing

```lean
import Bar1
import Bar2

deprecated_module since yyyy-mm-dd
```
in file `A.lean` means that any file that imports `A` will have `import A` flagged with a suggestion to import `Bar1` and `Bar2` instead.

[Zulip discussion](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/.60Deprecated.60.20folder)



Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Apr 13, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: a linter to deprecate imported modules [Merged by Bors] - feat: a linter to deprecate imported modules Apr 13, 2025
@mathlib-bors mathlib-bors bot closed this Apr 13, 2025
@mathlib-bors mathlib-bors bot deleted the adomani/deprecated_imports_linter branch April 13, 2025 18:48
tannerduve pushed a commit that referenced this pull request May 13, 2025
Writing

```lean
import Bar1
import Bar2

deprecated_module since yyyy-mm-dd
```
in file `A.lean` means that any file that imports `A` will have `import A` flagged with a suggestion to import `Bar1` and `Bar2` instead.

[Zulip discussion](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/.60Deprecated.60.20folder)



Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). large-import Automatically added label for PRs with a significant increase in transitive imports ready-to-merge This PR has been sent to bors. t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants