Skip to content

Conversation

@Rob23oba
Copy link
Contributor

@Rob23oba Rob23oba commented Apr 30, 2025

This PR adds documentation to builtin attributes like @[refl] or @[implemented_by].

Closes #8432

@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 Apr 30, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Apr 30, 2025

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2025-04-30 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2025-04-30 11:45:47)
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-04-30 17:38:15) View Log
  • ❗ Batteries CI can not be attempted yet, as the nightly-testing-2025-05-21 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Batteries CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2025-05-21 19:06:07)
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-22 16:27:46) View Log
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-23 16:33:44) View Log
  • 🟡 Mathlib branch lean-pr-testing-8173 build against this PR was cancelled. (2025-05-27 16:16:01) View Log
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-27 16:58:26) View Log
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-27 18:09:13) View Log
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-27 18:56:15) View Log
  • ✅ Mathlib branch lean-pr-testing-8173 has successfully built against this PR. (2025-05-27 21:19:40) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2f4e56b5d2ce5e0800d53d93a5ad939e8b8fb1c3 --onto c12159b51982221bdd66f0c5997f85e1f9d91772. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-04 19:57:23)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2f4e56b5d2ce5e0800d53d93a5ad939e8b8fb1c3 --onto 9b9dd8546a123d746580649b239f26c26d370d20. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-05 17:06:17)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2f4e56b5d2ce5e0800d53d93a5ad939e8b8fb1c3 --onto 0a9c24649767dea857a388e5385b7ae94bfd0185. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-11 09:11:53)

@Rob23oba
Copy link
Contributor Author

I'm going to need some help for the @[extern] attribute, if anyone knows the details it would be nice.

@nomeata
Copy link
Collaborator

nomeata commented Apr 30, 2025

Not sure if anyone with that knowledge will be around soon, so maybe split into one PR per (set of related) attributes, for quicker merging of easy ones?

@Rob23oba
Copy link
Contributor Author

I guess I'll just postpone @[extern] and keep the remaining ones where I'm pretty sure.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 30, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 30, 2025
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Apr 30, 2025
@nomeata
Copy link
Collaborator

nomeata commented May 21, 2025

I guess this would fix #8432 well enough.

@Rob23oba
Copy link
Contributor Author

@david-christiansen, could you take a look at the documentation? I'm sure there some parts that could be improved

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 22, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 22, 2025
Comment on lines 23 to 38
This feature can be used in combination with `@[extern]` to allow for cyclic references
between files:
```
-- File1.lean
@[extern "my_foo_function"]
opaque fooFn : Nat → Nat
def bar (x : Nat) : Nat := ... -- can use `foo` indirectly as `fooFn`
-- File2.lean
import File1
@[export my_foo_function]
def foo (x : Nat) : Nat := ... -- can use `bar`
```
Note however that this only works in compiled code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that we want to advertise in the docstring? I've always understood it to be more of a necessary kludge than something we really want to be encouraging the use of. Perhaps this should be an in-source comment instead of the docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to answer the question "why is @[export] here" for everyone who sees it in the Lean source code. Should I maybe refer to it as a "hack" then and remove the example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really prefer that we not advertise this to everyone who sees @[export] in any Lean code anywhere in the world and scrubs the mouse over it. Users of Lean are a more important audience than people working on Lean itself, and I think this is more likely to make their lives worse, rather than better.

A comment next to the attribute would let any Lean developer who does "go to def" see this, resolving their curiosity, as would comments next to instances of the trick.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this trick actually doesn't work in user code, it's a lean core exclusive. It needs to be compiled as a builtin or something; I never managed to get the lake invocation to make it work, if one exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I changed the documentation to instead mention an FFI example

Makes the documentation and location of a declaration available as a builtin.
This allows the documentation of core Lean features to be visible without importing the file they
are defined in. This is only possible because of bootstrapping and should not be used outside of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
are defined in. This is only possible because of bootstrapping and should not be used outside of
are defined in. This is only needed because of bootstrapping and should not be used outside of

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I wanted to say here is "you can only have documentation visible without importing the file it's in if you have a bootstrapping step"

with `Formatter` in the parameter types."
@[builtin_init mkCombinatorFormatterAttribute] opaque combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute
"Register a formatter for a parser combinator"
`Lean.PrettyPrinter.mkCombinatorFormatterAttribute -- TODO (bootstrapping): remove if possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment mean here? Does this meant here should be a stage0 update, after which this could then be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this would be removed, the attribute would correctly have a ref to combinatorFormatterAttribute, where the documentation is. But, the environment extension would also be renamed, causing existing .olean data to be ignored (I think that's how it works?). Which is to say there would probably need to be a separate PR for removing this line and doing a stage0 update (the usual stage0 update probably wouldn't work because test failures).

@david-christiansen
Copy link
Contributor

david-christiansen commented Jun 5, 2025

OK, I found a couple tiny detail things, and one substantive question. Otherwise, we're good to go - thanks!

I see that the initialize and builtin_initialize elaborators were modified to take docstrings. Does that obviate the need for all the private def init := changes?

@Rob23oba
Copy link
Contributor Author

Rob23oba commented Jun 5, 2025

Does that obviate the need for all the private def init := changes?

After a stage0 update, yeah. So there needs to be a follow-up PR (maybe also with mkCombinatorFormatterAttribute / mkCombinatorParenthesizer fixes)

@david-christiansen
Copy link
Contributor

Does that obviate the need for all the private def init := changes?

After a stage0 update, yeah. So there needs to be a follow-up PR (maybe also with mkCombinatorFormatterAttribute / mkCombinatorParenthesizer fixes)

OK. In the morning, I'll just give it a quick local test to make sure things work as we expect after the stage0 update.

Thanks!

@david-christiansen david-christiansen added the will-merge-soon …unless someone speaks up label Jun 11, 2025
@david-christiansen david-christiansen added this pull request to the merge queue Jun 11, 2025
Merged via the queue into leanprover:master with commit ee5b652 Jun 11, 2025
19 checks passed
@nomeata
Copy link
Collaborator

nomeata commented Jun 11, 2025

Thanks for the contribution and the reviewing!

david-christiansen added a commit to david-christiansen/lean4 that referenced this pull request Jun 11, 2025
david-christiansen added a commit to david-christiansen/lean4 that referenced this pull request Jun 11, 2025
@Rob23oba Rob23oba deleted the attribute-docs branch June 11, 2025 13:00
github-merge-queue bot pushed a commit that referenced this pull request Jun 16, 2025
This PR un-does the temporary changes made in #8173 for bootstrapping
purposes.
algebraic-dev pushed a commit to algebraic-dev/lean4 that referenced this pull request Jun 18, 2025
This PR adds documentation to builtin attributes like `@[refl]` or
`@[implemented_by]`.

Closes leanprover#8432

---------

Co-authored-by: David Thrane Christiansen <[email protected]>
Co-authored-by: David Thrane Christiansen <[email protected]>
algebraic-dev pushed a commit to algebraic-dev/lean4 that referenced this pull request Jun 18, 2025
This PR un-does the temporary changes made in leanprover#8173 for bootstrapping
purposes.
wkrozowski pushed a commit to wkrozowski/lean4 that referenced this pull request Jun 24, 2025
This PR un-does the temporary changes made in leanprover#8173 for bootstrapping
purposes.
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 P-medium We may work on this issue if we find the time toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN will-merge-soon …unless someone speaks up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hovering on syntax-less attributes shows no docstring

8 participants