Skip to content

chore: get cache - #42756

Draft
thorimur wants to merge 42 commits into
leanprover-community:masterfrom
thorimur:private-proof-lint
Draft

chore: get cache#42756
thorimur wants to merge 42 commits into
leanprover-community:masterfrom
thorimur:private-proof-lint

Conversation

@thorimur

Copy link
Copy Markdown
Contributor

Open in Gitpod

thorimur and others added 22 commits August 7, 2026 23:59
…via `by as_aux_lemma`

Delegating to `by as_aux_lemma => exact @$t` had three problems:

* `by` only leaves the exporting context when `backward.proofsInPublic` is
  `false` (`Lean.Elab.Term.runTactic`), so under that option `private` silently
  became a no-op and failed to resolve private declarations at all. This
  contradicted the existing comment stating we deliberately do not check that
  option.
* `@$t` only means "no implicit lambda" for non-identifiers; for an identifier
  it takes the `elabAtom` branch and makes implicit arguments *explicit*, so
  `private` broke any lemma with leading implicit arguments.
* `by` already abstracts proofs into an auxiliary theorem itself, so
  `as_aux_lemma` emitted a redundant second one.

Elaborate the term outside the exporting context and call `mkAuxTheorem`
ourselves instead. This matches what `by exact` does (`exact` is
`elabTermEnsuringType` against the goal type, and `runTactic` wraps using the
expected type rather than re-inferring), minus the three problems above.

`withSynthesize` is required so that synthetic metavariables created while
elaborating the term are solved before abstracting; otherwise `mkValueTypeClosure`
abstracts them into parameters of the auxiliary theorem and the proof is hoisted
back out into the exporting context.

Also skip the wrapper for a local hypothesis, pass `cache := !e.hasSorry`, and
make the module docstring an actual docstring (`/-!`), which silences a
`linter.style.header` warning on every build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds a temporary linter which finds uses of `set_option backward.privateInPublic true` that are
caused by a bare term proof appearing in a position elaborated in an exporting environment, and
suggests wrapping that proof in the `private` term elaborator from `Mathlib.Util.PrivateProof`
instead.

Detection uses a stateful linter to track the declarations of the current module, and then looks
for references to the private ones which were elaborated in an exporting environment, discarding
those inside `by` blocks with `Prop` goals. Suggestions are produced by slicing the original text
out of the `FileMap` using the (canonical) infotree positions, so nothing is re-printed.

This linter is intended to drive a one-off sweep, and is to be removed afterwards.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The linter now skips references enclosed in the `private` term elaborator or in `private_decl%`,
which is what `field := private ..` in a structure instance expands to. Suggestions in structure
instance fields are deliberately left unparenthesized, so that they are taken as the structure
instance `private` modifier.

Also restricts references to identifier syntax: wrapper nodes such as `(..)` carry the referenced
constant as their `TermInfo.expr` too, and were being reported as references to it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…otal

The metavariable context available to the linter is the one saved at the nearest enclosing infotree
context node, not the one in force when a given term was elaborated, so `instantiateMVars` can
produce expressions mentioning free variables outside the term's local context. `inferType` then
fails with "unknown free variable", which the stateful linter framework reports as a linter
failure. Both checks now catch such failures.

Also fixes `isProofByBlock`, which ran the `Prop` check in an empty local context rather than the
goal's own: the goal's type generally mentions the local hypotheses of the enclosing declaration.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
When every reference in a command can be wrapped in `private` and nothing is reported as
unfixable, the linter now also walks the chain of `set_option .. in`s wrapping the command and
suggests deleting each one which sets `backward.privateInPublic` to `true` or
`backward.privateInPublic.warn` to `false`. Each deletion is its own message, one per `set_option`
rather than one per wrap, and the suggested range runs from the `set_option` keyword through the
trailing whitespace of the `in`, so applying it removes the whole line.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 noreply@anthropic.com
@github-actions github-actions Bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

PR summary 782e4ee4e4

Import changes exceeding 2%

% File
+5.17% Mathlib.Init

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
../mathlib-ci/scripts/pr_summary/import_trans_difference.sh all
There are 8269 files with changed transitive imports taking up over 361009 characters: this is too many to display!
You can run this locally from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci


Declarations diff (regex)

+ F
+ Foo
+ MyPreorder
+ Occurrence
+ S
+ Wrap
+ aPriv
+ aPrivBothErrors
+ aPrivSilenced
+ bPriv
+ bPrivSilenced
+ chainInner
+ chainOuter
+ check
+ commandAt?
+ eq0
+ eq0'
+ exportedPrivateNames
+ f
+ f'
+ fImplicit
+ fImplicit'
+ fLocal
+ fLocalSilenced
+ fNestedBy
+ fProofsInPublic
+ findWrap
+ fixed1
+ fixed2
+ fixed3
+ fixed4
+ fixed5
+ fixed6
+ fixed7
+ foo
+ fooLeRefl
+ fooPub
+ fooThm
+ fα
+ fα'
+ fα''
+ fαPub'
+ fαPub''
+ gImplicit
+ implicitThm
+ inst1
+ isOptionValue
+ isPrivateWrapper
+ isProofByBlock
+ isWrappableProof
+ plain
+ precZeroOpeners
+ precedingTokenIsOpener
+ publicPrivateNames
+ publicUses
+ run
+ stacked
+ stacked'
+ sup_aux
+ thm1
+ truncatedSup
+ typ1
+ unused
+ usePriv
+ used
+ usesIt
+ usesPlain
+ usesS
+ val1
+ val2
+ val3
+ val4
+ val5
+ val6
+ whose
+++ FEq

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

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

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean -- pending)

Computed after the build finishes.


Increase in strong tech debt: (relative, absolute) = (0.72, 0.73)
Current number Change Type (strong)
5130 1 backward.isDefEq.respectTransparency
2677 1 backward.isDefEq.respectTransparency.types
649 -35 backward.privateInPublic
272 -60 backward.privateInPublic.warn
1 1 backward.proofsInPublic
No changes to weak technical debt.

Current commit 782e4ee4e4
Reference commit 4d476f6d44

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

thorimur and others added 14 commits August 13, 2026 22:23
Module linters run on the terminal command, so their messages cannot be captured by `#guard_msgs`
in the usual way. The test invokes the linter by hand at the end of the file, on the commands
obtained by re-parsing the file out of the elaborator's own `FileMap`, so that the commands carry
exactly the positions the declarations were recorded with.

Also updates the `privateProof` test for `val4`: now that a deletion is suggested whenever nothing
is left unfixable, a command whose only private references sit inside a `Prop`-goal `by` block has
its `set_option` reported too, which is correct — it never needed the option.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…f public values

Two statements in the module docstring were wrong.

The exported view of a declaration is not simply "definitions with a body": bodies are always
recorded in the file, but `Environment.setExporting true` replaces the value of an unexposed
definition with an axiom, even in the current module, while declarations exported only because of
`backward.privateInPublic` are exported as is and so keep their bodies regardless of exposure. Also
records why theorem values are not followed: an exported theorem whose proof mentions an unexported
private declaration is accepted.

The caveat about which commands might still need the option for their own elaboration named private
`abbrev`s and `@[expose] private def`s. Neither is exposed: a command all of whose declared names
are private is elaborated in a non-exporting environment throughout, per the `withExporting` call
in `Lean.Elab.MutualDef.elabMutualDef`, and `@[expose]` warns that it is meaningless there. Only a
command declaring a public name alongside a private one is affected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…hen we want to use it in definitions that are not fully ready to remove `backward.privateInPublic`.

Note: we also insist on wrapping the proof anyway now (unless it's a free variable), since the user probably wants to see if that'll work.
…t is used

A single command can declare several candidates — a `mutual` block, or a structure and its
projections, constructors and recursors — and the linter suggested deleting its `set_option` as
soon as any one of them was unused, which would have unexported the others along with it. The
`set_option`s of commands declaring a used candidate are now collected as safeguarded, and
deletions of them suppressed.

The test case added here is a private structure whose type is used in a public signature: the
command declares sixteen candidates, of which only the structure itself is used. Without the
safeguard the linter proposes deleting the `set_option` that exports it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant