Skip to content

[Merged by Bors] - fix(lint-style): parse linter options and load environment extensions correctly#29513

Closed
grunweg wants to merge 10 commits intoleanprover-community:masterfrom
grunweg:debug-mathlibinit-missing
Closed

[Merged by Bors] - fix(lint-style): parse linter options and load environment extensions correctly#29513
grunweg wants to merge 10 commits intoleanprover-community:masterfrom
grunweg:debug-mathlibinit-missing

Conversation

@grunweg
Copy link
Copy Markdown
Contributor

@grunweg grunweg commented Sep 10, 2025

Parse options and load linter set extension correctly.

This fixes two issues:

  • We never called the toOptions function that parses Lakefile options into a Lean.Options structure: the function we use instead is only meant for command-line options and doesn't handle the weak. prefix correctly.
  • The way we load linter sets was incorrect: withImportModules stopped updating environment extensions since lean4#6325, and that is exactly what we use to store linter sets. At the time of writing, importModules might be a suitable replacement (but this is not very safe, and not documented to be stable). Instead, write a small elaborator returning the environment at the point of elaboration, and use that instead.

Open in Gitpod

@grunweg grunweg added the WIP Work in progress label Sep 10, 2025
@github-actions github-actions bot added the t-meta Tactics, attributes or user commands label Sep 10, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 10, 2025

PR summary 14871d5175

Import changes exceeding 2%

% File
+4400.00% Mathlib.Tactic.Polyrith

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Tactic.Polyrith 1 45 +44 (+4400.00%)
Import changes for all files
Files Import difference
Mathlib.Tactic.Polyrith 44

Declarations diff

+ instance : ToExpr LinterSets := inferInstanceAs <| ToExpr (NameMap _)
+ instance [ToExpr α] : ToExpr (NameMap α)

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

Copy link
Copy Markdown
Contributor Author

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

These are nice fixes, thank you!
Can/should the doc-string for Lean.withImportModules be updated to mention that this does not load environment extensions? Just from the docs alone, that is only obvious by implicit comparison with Lean.importModules (and it's not clear if that's an intentional difference or just different levels of details, etc).

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Sep 12, 2025

With the commits I just pushed, lake exe lint-style now passes locally 🎉
I'll extract those fixes to separate PRs.

grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
This should have been documented in the first place, but the CI check for
this was broken. leanprover-community#29513 fixes the check (hence discovered this issue).
@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Sep 12, 2025
@grunweg grunweg changed the title debug the Mathlib.Init imports check fix(lint-style): parse linter options and load environment extensions correctly Sep 12, 2025
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
This should have been documented in the first place, but the CI check for
this was broken. leanprover-community#29513 fixes the check (hence discovered this issue).
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
Discovered by leanprover-community#29513, which fixes the CI check enforcing these.
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
Discovered by leanprover-community#29513, which fixes the CI check enforcing these.
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
This should have been documented in the first place, but the CI check for
this was broken. leanprover-community#29513 fixes the check (hence discovered this issue).
@grunweg grunweg force-pushed the debug-mathlibinit-missing branch from 41b2fa1 to 075258b Compare September 12, 2025 11:26
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Sep 12, 2025

Let's rebase, that hopefully fixes the unrelated lint-style failure.

@grunweg grunweg removed the WIP Work in progress label Sep 12, 2025
@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 Sep 12, 2025
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Sep 12, 2025
This should have been documented in the first place, but the CI check for
this was broken. leanprover-community#29513 fixes the check (hence discovered this issue).
mathlib-bors bot pushed a commit that referenced this pull request Sep 12, 2025
Discovered by #29513, which fixes the CI check enforcing these.

Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
mathlib-bors bot pushed a commit that referenced this pull request Sep 12, 2025
…Init` as such (#29586)

Uncovered by the fix of CI in #29513.

Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
mathlib-bors bot pushed a commit that referenced this pull request Sep 12, 2025
This should have been documented in the first place, but the CI check for this was broken. #29513 fixes the check (hence discovered this issue).

Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
@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 Sep 12, 2025
This fixes two issues:

We never called the `toOptions` function that parses Lakefile options into a `Lean.Options` structure: the function we use instead is only meant for command-line options and doesn't handle the `weak.` prefix correctly.

The way we load linter sets was incorrect: `withImportModules` doesn't update any environment extensions, and that is exactly what we use to store linter sets. We can replace it with `importModules` instead, but that is a bit less safe. It would be great if we had some sort of macro that can give us the environment at the point of elaboration instead.
@grunweg grunweg force-pushed the debug-mathlibinit-missing branch from bf0eea6 to 1d48b0d Compare September 12, 2025 20:59
@github-actions github-actions bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label Sep 12, 2025
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Sep 12, 2025

@Vierkantor Oh no, seems I did a major rebase blunder and force-pushed away your last commit. I'm so sorry. (I have no idea how or why this happened.) Do you mind re-doing it...?

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Sep 12, 2025

(At least the link to xxx in "... force-pushed from xxx to yyy" shows the last commit's diff, so you just need to manually make a commit with that again.)

zhuyizheng pushed a commit to zhuyizheng/mathlib4 that referenced this pull request Oct 2, 2025
…#29584)

This should have been documented in the first place, but the CI check for this was broken. leanprover-community#29513 fixes the check (hence discovered this issue).

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

grunweg commented Oct 9, 2025

I just added a stub test file, but am not sure how to call it in a test. Help is appreciated!

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Oct 9, 2025

I just merged master and fixed another two violations. Can we get this in? Having this stay in perpetual limbo is not helpful for anybody.

@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Oct 9, 2025
instance : ToExpr LinterSets := inferInstanceAs <| ToExpr (NameMap _)

/-- Return the linter sets defined at this point of elaborating the current file. -/
elab "linter_sets%" : term => do
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 having issues with my computer, so I cannot really open this file. However, does it make sense to test this term elaborator? Maybe just partly by checking that the resulting term contains something that is more stable than all of its output? E.g. check that it contains the header linter option?

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.

How about: we check that any option is enabled, and fail otherwise? That is also helpful for debugging downstream usages of this script that may not have the header requirement like Mathlib does.

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.

Hmm. But deciding whether a specific linter is enabled happens inside that linter. So we would not be able to read out this information easily from outside. I'll add something like your test instead!

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Oct 10, 2025

Thanks for adding the new self-tests: I like how they work. (You can probably delete MathlibTest/LintStyle2.lean, which was never used.)

@adomani
Copy link
Copy Markdown
Contributor

adomani commented Oct 13, 2025

Thanks! 🐙

bors merge

@ghost ghost added ready-to-merge This PR has been sent to bors. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Oct 13, 2025
mathlib-bors bot pushed a commit that referenced this pull request Oct 13, 2025
… correctly (#29513)

Parse options and load linter set extension correctly.

This fixes two issues:
- We never called the `toOptions` function that parses Lakefile options into a `Lean.Options` structure: the function we use instead is only meant for command-line options and doesn't handle the `weak.` prefix correctly.
- The way we load linter sets was incorrect: `withImportModules` stopped updating environment extensions since [lean4#6325](leanprover/lean4#6325), and that is exactly what we use to store linter sets. At the time of writing, `importModules` might be a suitable replacement (but this is not very safe, and not documented to be stable). Instead, write a small elaborator returning the environment at the point of elaboration, and use that instead.

Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 13, 2025

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title fix(lint-style): parse linter options and load environment extensions correctly [Merged by Bors] - fix(lint-style): parse linter options and load environment extensions correctly Oct 13, 2025
@mathlib-bors mathlib-bors bot closed this Oct 13, 2025
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Oct 13, 2025
This file as added in leanprover-community#29513, but never hooked up to the unit tests.
It is thus unused; delete it.
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Oct 13, 2025

#30497 deletes LintStyle2, which ultimately was never used.

@grunweg grunweg deleted the debug-mathlibinit-missing branch October 13, 2025 08:35
mathlib-bors bot pushed a commit that referenced this pull request Oct 13, 2025
This file as added in #29513, but never hooked up to the unit tests. It is thus unused; delete it.
BeibeiX0 pushed a commit to BeibeiX0/mathlib4 that referenced this pull request Nov 7, 2025
… correctly (leanprover-community#29513)

Parse options and load linter set extension correctly.

This fixes two issues:
- We never called the `toOptions` function that parses Lakefile options into a `Lean.Options` structure: the function we use instead is only meant for command-line options and doesn't handle the `weak.` prefix correctly.
- The way we load linter sets was incorrect: `withImportModules` stopped updating environment extensions since [lean4#6325](leanprover/lean4#6325), and that is exactly what we use to store linter sets. At the time of writing, `importModules` might be a suitable replacement (but this is not very safe, and not documented to be stable). Instead, write a small elaborator returning the environment at the point of elaboration, and use that instead.

Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
BeibeiX0 pushed a commit to BeibeiX0/mathlib4 that referenced this pull request Nov 7, 2025
This file as added in leanprover-community#29513, but never hooked up to the unit tests. It is thus unused; delete it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants