Skip to content

fix: pretty printing of constants should consider accessibility of names#12654

Merged
kmill merged 5 commits intoleanprover:masterfrom
kmill:kmill_fix_10771
Feb 25, 2026
Merged

fix: pretty printing of constants should consider accessibility of names#12654
kmill merged 5 commits intoleanprover:masterfrom
kmill:kmill_fix_10771

Conversation

@kmill
Copy link
Copy Markdown
Collaborator

@kmill kmill commented Feb 23, 2026

This PR fixes two aspects of pretty printing of private names.

  1. Name unresolution. Now private names are not special cased: the private prefix is stripped off and the _root_ prefix is added, then it tries resolving all suffixes of the result. This is sufficient to handle imported private names in the new module system. (Additionally, unresolution takes macro scopes into account now.)
  2. Delaboration. Inaccessible private names use a deterministic algorithm to convert private prefixes into macro scopes. The effect is that the same private name appearing in multiple times in the same delaborated expression will now have the same suffix each time. It used to use fresh macro scopes per occurrence.

Note: There is currently a small hack to support pretty printing in the compiler's trace messages, which print constants that do not exist (e.g. obj, tobj, and auxiliary definitions being compiled). Even though these names are inaccessible (for the stronger reason that they don't exist), we make sure that the pretty printer won't add macro scopes. It also does some analysis of private names to see if the private names are for the current module.

Closes #10771, closes #10772, and closes #10773

This PR fixes pretty printing of private names. The name unresolution algorithm now works by finding a valid fully qualified name, if one exists, and then finds an efficient name from that. Inaccessible private names do not have a fully qualified name for this purpose. Secondly, the delaborator for constants now deterministically adds macro scopes to inaccessible names.

There is a small hack to support the compiler's pretty printing. It prints constants that do not exist (e.g. `obj`, `tobj`, and auxiliary definitions being compiled). These still have some accessibility analysis (private names for the current module have the private prefix stripped), and they are otherwise pretty printed as-is without additional macro scopes.

Closes leanprover#10771
@kmill kmill added the changelog-pp Pretty printing label Feb 23, 2026
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 23, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-02-19 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-02-23 17:43:56)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 23, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Feb 23, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 23, 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 Feb 23, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 24, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 24, 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 Feb 24, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

@kmill kmill changed the title fix: pretty printing constants should use accessibility of names fix: pretty printing of constants should consider accessibility of names Feb 24, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 24, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 24, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

@kmill kmill added this pull request to the merge queue Feb 25, 2026
Merged via the queue into leanprover:master with commit 48a7159 Feb 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-pp Pretty printing 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

2 participants