Skip to content

feat(deprecated module): automate the generation of deprecated modules - #24861

Closed
adomani wants to merge 32 commits into
masterfrom
adomani/deprecated_module_automation
Closed

adomani wants to merge 32 commits into
masterfrom
adomani/deprecated_module_automation

Conversation

@adomani

@adomani adomani commented May 13, 2025 •

Copy link
Copy Markdown
Contributor

There is a competing PR at #24917: I personally like the other one better! 😄

I will likely close this PR soon, since the other one seems better than this one.


This PR takes a step further in automating deprecated modules.

The command #create_deprecated_modules (n)? (comment)? (write)? generates deprecated modules.

Writing

#create_deprecated_modules 5 "These files are no longer relevant"

looks at the lean files in Mathlib that existed 4 commits ago
(i.e. the commit that you see with git log -5) and that are no longer present.
It shows how the corresponding deprecated modules should look like, using
"These files are no longer relevant" as the (optional) comment.

If the number of commits is not explicitly used, #create_deprecated_modules defaults to 2,
namely, the commit just prior to the current one.

If the message is not explicitly used, #create_deprecated_modules defaults to
"Auto-generated deprecation".
If you wish there to be no comment, use #create_deprecated_modules 5 "".

Note that the command applies the same comment to all the files that it generates.

Finally, if everything looks correct, adding a final write actually generates the files:

#create_deprecated_modules 5 "These files are no longer relevant" write

Open in Gitpod

@github-actions github-actions Bot added the t-linter Linter label May 13, 2025
@github-actions

github-actions Bot commented May 13, 2025 •

Copy link
Copy Markdown

PR summary 9834785757

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ getHeader
+ getHeaderFromFileName
+ mkDeprecation

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).

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

Wow; I would have probably gone with something much simpler/a quick shell script. And you just wrote a proper Lean command. Great to see more infrastructure being written in Lean!
I have my usual share of pernickety comments, otherwise this looks good to me. Let's merge this and try it out!

Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
import Mathlib.Tactic.Linter.DeprecatedModule
-/
#guard_msgs in
run_cmd

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 wonder if there's a way to test the actual deprecation output; that seems harder to arrange, though. I'm fine with just these tests!

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 could extract lots of small functions that perform each part of the deprecation and test them separately, but I am not sure that it would improve the script.

Right now, the script is pretty verbose in saying what it is doing and what the outcome is, so testing "live" should be straightforward.

@grunweg grunweg added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label May 13, 2025
@grunweg grunweg self-assigned this May 13, 2025

@adomani adomani left a comment

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.

Michael, thank you very much for your comments!

Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
Comment thread scripts/create_deprecated_module.lean Resolved
import Mathlib.Tactic.Linter.DeprecatedModule
-/
#guard_msgs in
run_cmd

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 could extract lots of small functions that perform each part of the deprecation and test them separately, but I am not sure that it would improve the script.

Right now, the script is pretty verbose in saying what it is doing and what the outcome is, so testing "live" should be straightforward.

@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 for the fast response. Let me add "writing in Lean means everything is documented well and there are no hidden pitfalls" (don't remember if that syntax was specific to bash? you don't need to) to the list of good reasons. Plus, actually parsing a file header is more robust than whatever shell hack I would have come up with.

One last question and then let's ship this!
maintainer delegate

Comment thread scripts/create_deprecated_modules.lean Resolved
@github-actions

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label May 14, 2025
mathlib-bors Bot pushed a commit that referenced this pull request May 14, 2025
Automatically created by #24861. These files were removed in the toolchain bump in ##24561.
@adomani adomani removed the t-linter Linter label May 14, 2025
jano-wol pushed a commit that referenced this pull request May 16, 2025
This was discovered while developing #24861.

Without this change,
```lean
deprecated_module "hello" (since := "YYYY-MM-DD")
```
gets pretty-printed as
```lean
deprecated_module "hello"(since := "YYYY-MM-DD")
```
Note the missing space between `"hello"` and `(since...)`!
jano-wol pushed a commit that referenced this pull request May 16, 2025
Automatically created by #24861. These files were removed in the toolchain bump in ##24561.
@Vierkantor

Copy link
Copy Markdown
Contributor

There is a competing PR at #24917: I personally like the other one better! 😄

Sorry, I'm not completely sure what the description means for this PR: do you want to continue with this one simultaneously? Or should the PR description be updated?

@Vierkantor Vierkantor added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label May 19, 2025
@adomani adomani removed the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label May 19, 2025
@adomani
adomani marked this pull request as draft May 19, 2025 10:15
@adomani

adomani commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

Anne, sorry for the confusion: I opened this PR first, then I tried something out in the other one and commented on this one. Now, I think that the other PR is definitely better, but I forgot to update the comment on this one.

I now changed this one to draft, removed the maintainer-merge label and expanded the PR description with my likely intention to close this one soon.

@Vierkantor

Copy link
Copy Markdown
Contributor

Got it, thank you!

@adomani adomani closed this May 26, 2025
bwehlin pushed a commit to bwehlin/mathlib4 that referenced this pull request May 31, 2025
…rover-community#24864)

This was discovered while developing leanprover-community#24861.

Without this change,
```lean
deprecated_module "hello" (since := "YYYY-MM-DD")
```
gets pretty-printed as
```lean
deprecated_module "hello"(since := "YYYY-MM-DD")
```
Note the missing space between `"hello"` and `(since...)`!
bwehlin pushed a commit to bwehlin/mathlib4 that referenced this pull request May 31, 2025
@YaelDillies
YaelDillies deleted the adomani/deprecated_module_automation branch August 15, 2025 16:30
mathlib-bors Bot pushed a commit that referenced this pull request Sep 3, 2025
This PR is a revised version of #24861.  It splits the `#create_deprecated_modules` into two commands:
* `#create_deprecated_module path/to/file.lean` that guides you through generating a deprecated file for a file that has been *erased* (so that the deprecated file will import the same files as the erased one);
* `#create_deprecated_module path/to/old/file.lean rename_to path/to/renamed/file.lean`
  that guides you through generating a deprecated file for a file that has been *renamed* (so that the deprecated file will import just the renamed one);
* `#find_deleted_files n` that looks at the repository `n` commits ago and returns a `#create_deprecated_module` for each file that existed then and does not exist now.

This is integrated with `Try these:` suggestions and is intended as a first step in making this process completely automatic.

Each regenerated file consists of either the imports of the deleted file or just imports the renamed file, followed by `deprecated_module (since := "YYYY-MM-DD")`.

Co-authored-by: Michael Rothgang <[email protected]>
CBirkbeck pushed a commit to CBirkbeck/mathlib4 that referenced this pull request Sep 8, 2025
This PR is a revised version of leanprover-community#24861.  It splits the `#create_deprecated_modules` into two commands:
* `#create_deprecated_module path/to/file.lean` that guides you through generating a deprecated file for a file that has been *erased* (so that the deprecated file will import the same files as the erased one);
* `#create_deprecated_module path/to/old/file.lean rename_to path/to/renamed/file.lean`
  that guides you through generating a deprecated file for a file that has been *renamed* (so that the deprecated file will import just the renamed one);
* `#find_deleted_files n` that looks at the repository `n` commits ago and returns a `#create_deprecated_module` for each file that existed then and does not exist now.

This is integrated with `Try these:` suggestions and is intended as a first step in making this process completely automatic.

Each regenerated file consists of either the imports of the deleted file or just imports the renamed file, followed by `deprecated_module (since := "YYYY-MM-DD")`.

Co-authored-by: Michael Rothgang <[email protected]>
robertmaxton42 pushed a commit to robertmaxton42/mathlib4 that referenced this pull request Sep 11, 2025
This PR is a revised version of leanprover-community#24861.  It splits the `#create_deprecated_modules` into two commands:
* `#create_deprecated_module path/to/file.lean` that guides you through generating a deprecated file for a file that has been *erased* (so that the deprecated file will import the same files as the erased one);
* `#create_deprecated_module path/to/old/file.lean rename_to path/to/renamed/file.lean`
  that guides you through generating a deprecated file for a file that has been *renamed* (so that the deprecated file will import just the renamed one);
* `#find_deleted_files n` that looks at the repository `n` commits ago and returns a `#create_deprecated_module` for each file that existed then and does not exist now.

This is integrated with `Try these:` suggestions and is intended as a first step in making this process completely automatic.

Each regenerated file consists of either the imports of the deleted file or just imports the renamed file, followed by `deprecated_module (since := "YYYY-MM-DD")`.

Co-authored-by: Michael Rothgang <[email protected]>
joelriou pushed a commit to joelriou/mathlib4 that referenced this pull request Oct 2, 2025
This PR is a revised version of leanprover-community#24861.  It splits the `#create_deprecated_modules` into two commands:
* `#create_deprecated_module path/to/file.lean` that guides you through generating a deprecated file for a file that has been *erased* (so that the deprecated file will import the same files as the erased one);
* `#create_deprecated_module path/to/old/file.lean rename_to path/to/renamed/file.lean`
  that guides you through generating a deprecated file for a file that has been *renamed* (so that the deprecated file will import just the renamed one);
* `#find_deleted_files n` that looks at the repository `n` commits ago and returns a `#create_deprecated_module` for each file that existed then and does not exist now.

This is integrated with `Try these:` suggestions and is intended as a first step in making this process completely automatic.

Each regenerated file consists of either the imports of the deleted file or just imports the renamed file, followed by `deprecated_module (since := "YYYY-MM-DD")`.

Co-authored-by: Michael Rothgang <[email protected]>
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants