feat: add @[attribute] for registering custom attributes#13629
Draft
Kha wants to merge 1 commit intoleanprover:masterfrom
Draft
feat: add @[attribute] for registering custom attributes#13629Kha wants to merge 1 commit intoleanprover:masterfrom
@[attribute] for registering custom attributes#13629Kha wants to merge 1 commit intoleanprover:masterfrom
Conversation
This PR adds a new `@[attribute]` attribute that registers a constant of type `Lean.AttributeImpl` as a custom attribute, lifting the previous restriction that all attributes had to be registered via `registerBuiltinAttribute` from inside an `initialize` block. A new `attributeExt` environment extension stores the registered attributes, and `getAttributeImpl` now consults both it and the existing `attributeExtension` (which keeps serving builtin attributes and parser category builders). Because `@[attribute]` registers eagerly during elaboration (via `applicationTime := .afterCompilation`) rather than at module load, custom attributes can be applied in modules that import the defining module — including in the same file as the orphan applications they target — without the artificial split that `initialize`-based registration forces. The accompanying parser change registers `attribute` as a syntax kind in the `attr` category alongside the other keyword-named attribute forms (`class`, `instance`, `macro`, `export`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
!bench |
|
Benchmark results for 944beb6 against fe3c739 are in. No significant results found. @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.
Small changes (1✅, 4🟥)
|
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
nomeata
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
@[attribute]attribute that registers a constant of typeLean.AttributeImplas a custom attribute, lifting the previous restriction that all attributes had to be registered viaregisterBuiltinAttributefrom inside aninitializeblock. A newattributeExtenvironment extension stores the registered attributes, andgetAttributeImplnow consults both it and the existingattributeExtension(which keeps serving builtin attributes and parser category builders).Because
@[attribute]registers eagerly during elaboration (viaapplicationTime := .afterCompilation) rather than at module load, custom attributes can be applied in modules that import the defining module — including in the same file as the orphan applications they target — without the artificial split thatinitialize-based registration forces. The attribute definition and the underlying environment extension, if any, however still need to be split.The accompanying parser change registers
attributeas a syntax kind in theattrcategory alongside the other keyword-named attribute forms (class,instance,macro,export).