Skip to content

chore: remove superfluous @[expose] - #38477

Closed
grunweg wants to merge 4 commits into
leanprover-community:masterfrom
grunweg:less-exposure
Closed

grunweg wants to merge 4 commits into
leanprover-community:masterfrom
grunweg:less-exposure

Conversation

@grunweg

@grunweg grunweg commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

All these files contain no single definition or instance: similar to #33581 and friends.

During mathlib's migration to the module system, @[expose] public section was added at the beginning
of each file. In the medium-term, we would like to be more conscious about mathlib's use of the module
system. This PR helps by clarifying how many definitions' status need to actually be checked.

Zulip thread

A future PR may make the privateModule linter also lint about files with @[expose] section and no definitions; this would avoid regressions.


Open in Gitpod

@github-actions

github-actions Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

PR summary ca31f024ee

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

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

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

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


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/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 added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Apr 24, 2026
@grunweg

grunweg commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

The last commit was generated with
cat test.txt | xargs -d '\n' sed -i s/"@\[expose\] public section"/"public section"/g, where test.txt is the list of all files [here](#mathlib4 > Removing unnecessary `@[expose]` @ 💬) (i.e., containing @[expose] public section and no def nor instance ).

@grunweg grunweg added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Apr 24, 2026
@grunweg

grunweg commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Apr 24, 2026 •

Copy link
Copy Markdown

Benchmark results for c584f13 against ca31f02 are in. No significant results found. @grunweg

  • 🟥 build//instructions: +318.8M (+0.00%)

Small changes (2✅)

  • ✅ build/module/Mathlib.Algebra.Order.Ring.Units//instructions: -132.8M (-2.46%)
  • ✅ build/module/Mathlib.Util.ParseCommand//instructions: -134.8M (-5.17%) (reduced significance based on absolute threshold)

@grunweg

grunweg commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

The last commit adds another batch, auto-generated in the following way.

  1. Find all files with an @[expose]d public section:
    rg --files-with-matches --fixed-strings "@[expose] public section" > matches.txt
  2. Find all files among those without the string def .
    xargs -rd '\n' -a matches.txt rg --files-without-match "def " > hits.txt runs on all files.
  3. Manually remove two MathlibTest false positives from the file.
  4. Replace in all files: cat hits.txt | xargs -d '\n' sed -i s/"@\[expose\] public section"/"public section"/g

@github-actions github-actions Bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Apr 24, 2026
@jcommelin

Copy link
Copy Markdown
Member

!bench

@leanprover-radar

Copy link
Copy Markdown

Benchmark results for c584f13 against ca31f02 are in. (These commits have already been benchmarked in a previous command.) No significant results found. @jcommelin

  • 🟥 build//instructions: +318.8M (+0.00%)

Small changes (2✅)

  • ✅ build/module/Mathlib.Algebra.Order.Ring.Units//instructions: -132.8M (-2.46%)
  • ✅ build/module/Mathlib.Util.ParseCommand//instructions: -134.8M (-5.17%) (reduced significance based on absolute threshold)

@eric-wieser

Copy link
Copy Markdown
Member

What's the benefit of doing this?

@grunweg

grunweg commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

My understanding is that

  • adding @[expose] public section at the beginning of each file was done to ease mathlib's transition to the module system,
  • in the medium-term, we'd like to be more conscious about making definitions un-exposed (or auxiliary declarations private). This is a herculean effort, so can only be done incrementally, but it's probably worthwhile.
  • Knowing the scope of this task is helpful: this PR clarifies that a number of files don't need auditing for expose-ure.
  • Kim prepared a similar sequence of PR, zulip thread
  • I'm happy to follow up by making the privateModule linter also lint about files with @[expose] section and no definitions; this would avoid regressions.

I have added the essence of the above to the PR description.

@mcdoll

mcdoll commented Apr 25, 2026

Copy link
Copy Markdown
Member

What's the benefit of doing this?

I think this PR in some sense doesn't do anything, because since no def was there none could be exposed (this also why there is zero change in the build time). I think I tend to agree with the idea that definitions should not be exposed by default (hence files shouldn't start with the expose attribute on a section) and should have a well defined interface (in that file) that restricts what we can do with that object.
A very mathy example would be to unexpose the definition of the reals to only expose an interface with the axioms and then we theoretically could change the definition from Cauchy sequences to Dedekind cuts and we are sure that mathlib still builds

@grunweg

grunweg commented Apr 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing: merged with #38480.

@grunweg grunweg closed this Apr 26, 2026
@grunweg
grunweg deleted the less-exposure branch April 26, 2026 07:56
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
marcelolynch pushed a commit to marcelolynch/mathlib4 that referenced this pull request May 14, 2026
Inverse of `privateModule` linter: detects modules where `@[expose] public
section` is superfluous because no decl in the file would benefit from
exposure downstream. Suggested by PR leanprover-community#38477 as the long-term mechanism to
prevent regressions of the kind that leanprover-community#38480 and related PRs cleaned up
manually.

A decl 'benefits from exposure' iff it's a public, non-internal `def` or
`inductive` that is:
- not private / reserved / internal-detail-named,
- not an auxiliary recursor / projection / matcher,
- not a notation/syntax-generated name,
- not a meta-namespace declaration,
- not an instance (incl. local/scoped/auto-named),
- not an abbrev / @[irreducible] / @[implicit_reducible]... wait, implicit_reducible DOES benefit,
- not a structure/class (those go through `inductInfo` but have special projection handling).

Includes 11 test files covering positive (theorem-only, class-only,
abbrev-only, irreducible-def-only, local-instance, scoped-instance, notation,
recursors) and negative (plain def, to_additive-derived, inductive) cases.

Known limitations the linter currently misses (would block in error):
- Tactic macros from `scoped macro (name := X) ...`
- `simproc_decl` (creates def whose body is a simprocedure)
- `alias`es with non-trivial bodies (technically real defs)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants