Skip to content

feat: add @[trusted_axiom] attribute and linter.untrustedAxioms linter#14407

Open
Kha wants to merge 4 commits into
masterfrom
untrusted-axioms-linter
Open

feat: add @[trusted_axiom] attribute and linter.untrustedAxioms linter#14407
Kha wants to merge 4 commits into
masterfrom
untrusted-axioms-linter

Conversation

@Kha

@Kha Kha commented Jul 16, 2026

Copy link
Copy Markdown
Member

This PR adds a @[trusted_axiom] attribute for marking axioms as "linter-trusted" and a new (default-off) linter.untrustedAxioms linter that warns when a declaration added to the environment transitively depends on an axiom not tagged @[trusted_axiom].

TODO: tag standard axioms as trusted after stage0 update

@Kha

Kha commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 16, 2026

Copy link
Copy Markdown

Benchmark results for 3c2f4be against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +32.4G (+0.27%)

Large changes (2🟥)

  • 🟥 build/module/Std.Data.DTreeMap.Internal.Balancing//instructions: +8.4G (+13.29%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.WF.Lemmas//instructions: +8.2G (+19.80%)

Medium changes (2🟥)

  • 🟥 build/module/Std.Data.DTreeMap.Internal.Model//instructions: +2.1G (+3.33%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Operations//instructions: +3.5G (+8.28%) (reduced significance based on absolute threshold)

Small changes (1✅, 64🟥)

  • 🟥 build/lakeprof/longest rebuild path//instructions: +13.0G (+2.10%)
  • 🟥 build/module/Init.Data.Nat.Sqrt.Lemmas//instructions: +59.7M (+2.01%)
  • 🟥 build/module/Lean.Elab.MutualDef//instructions: +279.6M (+1.02%) (reduced significance based on *//lines)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Balanced//instructions: +52.4M (+3.77%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Cell//instructions: +57.5M (+4.27%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Ordered//instructions: +20.4M (+2.61%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Queries//instructions: +228.3M (+1.30%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.WF.Defs//instructions: +69.7M (+4.72%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Body.Empty//instructions: +26.1M (+2.08%)
  • 🟥 build/module/Std.Http.Data.Body.Full//instructions: +47.5M (+2.61%)
  • 🟥 build/module/Std.Http.Data.Body.Stream//instructions: +239.8M (+4.83%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Chunk//instructions: +143.5M (+7.69%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Extensions//instructions: +27.9M (+3.49%)
  • 🟥 build/module/Std.Http.Data.Headers.Basic//instructions: +99.3M (+3.61%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Headers.Name//instructions: +103.3M (+1.04%)
  • 🟥 build/module/Std.Http.Data.Headers.Value//instructions: +39.9M (+3.67%)
  • 🟥 build/module/Std.Http.Data.Headers//instructions: +133.9M (+6.44%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Request//instructions: +90.2M (+4.72%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Response//instructions: +87.0M (+5.73%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.Status//instructions: +201.1M (+3.12%) (reduced significance based on absolute threshold)
  • and 44 more
  • and 1 hidden

@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels Jul 16, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Jul 16, 2026
@leanprover-bot

leanprover-bot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

@Kha

Kha commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 16, 2026

Copy link
Copy Markdown

Benchmark results for ee3ac10 against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +16.6G (+0.14%)

Large changes (2🟥)

  • 🟥 build/profile/type checking//wall-clock: +14s (+12.01%)
  • 🟥 elab/grind_ring_5//instructions: +422.3M (+4.94%)

Medium changes (1✅, 12🟥)

  • 🟥 build/module/Init.Data.Range.Polymorphic.SInt//instructions: +1.4G (+19.49%) (reduced significance based on absolute threshold)
  • build/profile/.olean serialization//wall-clock: -8s (-10.16%)
  • 🟥 elab/big_struct//instructions: +69.5M (+2.70%)
  • 🟥 elab/big_struct_dep//instructions: +431.4M (+3.14%)
  • 🟥 elab/big_struct_dep1//instructions: +151.3M (+2.88%)
  • 🟥 elab/cbv_arm_ldst//instructions: +929.0M (+1.44%)
  • 🟥 elab/grind_bitvec2//instructions: +1.9G (+1.30%)
  • 🟥 elab/grind_list2//instructions: +468.9M (+1.07%)
  • 🟥 elab/mut_rec_wf//instructions: +201.9M (+0.93%)
  • 🟥 elab/omega_stress//instructions: +63.5M (+1.65%)
  • 🟥 elab/riscv-ast//instructions: +998.3M (+1.12%)
  • 🟥 misc/import Init.Data.BitVec.Lemmas//instructions: +1.9G (+1.66%)
  • 🟥 misc/import Init.Prelude//instructions: +226.3M (+2.08%)

Small changes (1✅, 56🟥)

  • 🟥 build/module/Init.Data.Array.Basic//instructions: +42.6M (+0.38%)
  • 🟥 build/module/Init.Data.Array.BinSearch//instructions: +90.9M (+1.37%)
  • 🟥 build/module/Init.Data.Array.QSort.Basic//instructions: +72.5M (+0.66%)
  • 🟥 build/module/Init.Data.Array.Sort.Basic//instructions: +32.1M (+1.15%)
  • 🟥 build/module/Init.Data.Format.Basic//instructions: +15.7M (+0.65%)
  • 🟥 build/module/Init.Data.List.Sort.Impl//instructions: +54.6M (+0.45%)
  • 🟥 build/module/Init.Data.List.ToArray//instructions: +87.0M (+0.45%)
  • 🟥 build/module/Init.Data.Range.Basic//instructions: +36.1M (+1.00%)
  • 🟥 build/module/Init.Data.Range.Lemmas//instructions: +97.7M (+1.93%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Range.Polymorphic.Internal.SignedBitVec//instructions: +93.4M (+1.52%)
  • 🟥 build/module/Init.Data.String.Extra//instructions: +19.6M (+0.63%)
  • 🟥 build/module/Init.Prelude//instructions: +94.0M (+0.77%)
  • 🟥 build/module/Lean.AddDecl//instructions: +101.6M (+1.75%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Compiler.LCNF.Basic//instructions: +83.0M (+0.46%)
  • 🟥 build/module/Lean.Compiler.LCNF.ExplicitRC//instructions: +38.5M (+0.49%)
  • 🟥 build/module/Lean.Compiler.NameMangling//instructions: +50.7M (+0.68%)
  • 🟥 build/module/Lean.Data.RBMap//instructions: +24.7M (+0.47%)
  • 🟥 build/module/Lean.Elab.DocString//instructions: +95.1M (+0.22%)
  • 🟥 build/module/Lean.Elab.MutualDef//instructions: +272.0M (+0.99%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Elab.MutualInductive//instructions: +90.9M (+0.28%)
  • and 37 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 16, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 16, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 16, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Jul 16, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 16, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

Kha added 3 commits July 16, 2026 11:42
…inter

This PR adds a `@[trusted_axiom]` attribute for marking axioms as trusted and a new (default-off) `linter.untrustedAxioms` linter that warns when a declaration added to the environment transitively depends on an axiom not tagged `@[trusted_axiom]`.

Co-Authored-By: Claude
`linter.untrustedAxioms` called `collectAxioms` with a fresh cache per declaration, re-walking the module-local dependency subgraph each time (up to +20% instructions on proof-heavy stdlib modules, which enable the linter via `set_option linter.all true`). `exportedAxiomsExt` is now `sync` and filled eagerly by `recordAxioms` from `addDecl`, so entries accumulate along the `checked` environment chain and each constant is walked only once per module; olean serialization reuses the recorded entries instead of recomputing them, making the eager fill instruction-neutral when the linter is off (`Std.Data.DTreeMap.Internal.WF.Lemmas` with export: linter off 40.29G → 40.31G instructions, linter on 48.85G → 42.01G; the remaining enabled-mode delta is mostly warning emission, which core axiom tagging will remove). Also, the `hasSorry` suppression check now runs only when `sorryAx` appears in the collected axioms, skipping the term traversal for sorry-free declarations.

Co-Authored-By: Claude
The linter now runs only when `linter.untrustedAxioms` is set explicitly, instead of also being enabled by `linter.all`. The check is useful only with a curated set of `@[trusted_axiom]` declarations and comes with per-declaration cost, so it should not be implied by a blanket linter enable; in particular, the stdlib sets `set_option linter.all true` in many files, which flooded stdlib builds with warnings about the not-yet-tagged core axioms (with `@[trusted_axiom]` tags for them still pending on a stage0 update). `Std.Data.DTreeMap.Internal.WF.Lemmas` now builds warning-free at 40.30G instructions, matching the linter-off baseline.

Co-Authored-By: Claude
@Kha
Kha force-pushed the untrusted-axioms-linter branch from ee3ac10 to b978969 Compare July 16, 2026 11:42
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 16, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 16, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 16, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Jul 16, 2026
…rded entries

The per-run `seen` cache no longer copies entries answered by `exportedAxiomsExt`; it now contains exactly the constants walked by the run, forming a second layer over the recorded entries. `collectAndGet` answers imported and already-recorded constants directly, and `recordAxioms` inserts the walked constants wholesale instead of filtering every referenced constant. Measured neutral on elaboration benchmarks (the dominant eager-fill cost is the `getUsedConstants` term walk itself, which is accepted); reduces per-declaration allocation and map bookkeeping.

Co-Authored-By: Claude
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 17, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 17, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 17, 2026
@Kha

Kha commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 20, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@602a72a against leanprover-community/mathlib4-nightly-testing@7318bbb are in. No significant results found. @Kha

  • 🟥 build//instructions: +44.3G (+0.03%)

No significant changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR builds-mathlib CI has verified that Mathlib builds against this PR changelog-other mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants