Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more infrastructure for tactic documentation #4490

Merged
merged 16 commits into from
Jun 21, 2024

Conversation

david-christiansen
Copy link
Contributor

@david-christiansen david-christiansen commented Jun 18, 2024

This is the groundwork for a tactic index in generated documentation, as there was in Lean 3. There are a few challenges to getting this to work well in Lean 4:

  • There's no natural notion of tactic identity - a tactic may be specified by multiple syntax rules (e.g. the pattern-matching version of intro is specified apart from the default version, but both are the same from a user perspective)
  • There's no natural notion of tactic name - here, we take the pragmatic choice of using the first keyword atom in the tactic's syntax specification, but this may need to be overridable someday.
  • Tactics are extensible, but we don't want to allow arbitrary imports to clobber existing tactic docstrings, which could become unpredictable in practice.

For tactic identity, this PR introduces the notion of a tactic alternative, which is a syntax specification that is really "the same as" an existing tactic, but needs to be separate for technical reasons. This provides a notion of tactic identity, which we can use as the basis of a tactic index in generated documentation. Alternative forms of tactics are specified using a new @[tactic_alt IDENT] attribute, applied to the new tactic syntax. It is an error to declare a tactic syntax rule to be an alternative of another one that is itself an alternative. Documentation hovers now take alternatives into account, and display the docs for the canonical name.

Tactic tags, created with the register_tactic_tag command, specify tags that may be applied to tactics. This is intended to be used by doc-gen and Verso. Tags may be applied using the @[tactic_tag TAG1 TAG2 ...] attribute on a canonical tactic parser, which may be used in any module to facilitate downstream projects introducing tags that apply to pre-existing tactics. Tags may not be removed, but it's fine to redundantly add them. The collection of tags, and the tactics to which they're applied, can be seen using the #print tactic tags command.

Extension documentation provides a structured way to document extensions to tactics. The resulting documentation is gathered into a bulleted list at the bottom of the tactic's docstring. Extensions are added using the tactic_extension TAC command. This can be used when adding new interpretations of a tactic via macro_rules, when extending some table or search index used by the tactic, or in any other way. It is a command to facilitate its flexible use with various extension mechanisms.

Introduces the notion of a tactic alias, which is a syntax
specification that is really "the same as" an existing tactic, but
needs to be separate for technical reasons.

Additionally, tactics can be tagged, and extensibility is first-class.

This is a minimal proof of concept for evaluation - missing features
include:
 * Hovers on tactics don't take this new metadata into account
 * There's not yet a user interface for querying the data internally
 in Lean
@david-christiansen david-christiansen marked this pull request as draft June 18, 2024 15:27
@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 Jun 18, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 18, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 18, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jun 18, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Jun 18, 2024

Mathlib CI status (docs):

  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-18 16:48:36) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-19 06:35:48) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-19 07:43:39) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-19 11:34:01) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-19 13:02:25) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-19 13:57:21) View Log
  • ✅ Mathlib branch lean-pr-testing-4490 has successfully built against this PR. (2024-06-20 20:00:07) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase d020a9c5a694726b40ac86da353592eda4122ffe --onto 357b52928f905bfb85a3496e411cf12fa20e730c. (2024-06-21 08:53:02)

Copy link

@robertylewis robertylewis left a comment

Choose a reason for hiding this comment

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

My hotel wifi died and I don't want to get a core dev setup going on phone data, so I'm not 100% sure these code suggestions are right. But this looks fantastic, should do the job very nicely!

src/Lean/Parser/Tactic/Doc.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Tactic/Doc.lean Show resolved Hide resolved
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 19, 2024
Now they don't need to be imported.
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 19, 2024
@david-christiansen david-christiansen marked this pull request as ready for review June 19, 2024 12:08
@david-christiansen
Copy link
Contributor Author

@robertylewis I think this should meet your needs now - please give it a whirl at let me know! I don't want to merge before you've had a chance to validate that it supports the workflow that you're looking for.

@david-christiansen
Copy link
Contributor Author

I like that, but I'll use alt to make the attribute name a bit shorter (@[tactic_alt theRealTactic]).

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 20, 2024
@david-christiansen
Copy link
Contributor Author

!bench

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit ca52b81.
The entire run failed.
Found no significant differences.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 20, 2024
@david-christiansen
Copy link
Contributor Author

!bench

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 20, 2024
@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit 55dc835.
There were significant changes against commit 1cf71e5:

  Benchmark   Metric         Change
  ===========================================
- parser      instructions     1.5% (918.2 σ)

@david-christiansen
Copy link
Contributor Author

david-christiansen commented Jun 20, 2024

@Kha - what do you think? Is that instruction count hit too severe?

@david-christiansen david-christiansen requested a review from Kha June 21, 2024 07:27
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 21, 2024
@david-christiansen david-christiansen added the will-merge-soon …unless someone speaks up label Jun 21, 2024
@david-christiansen david-christiansen added this pull request to the merge queue Jun 21, 2024
Merged via the queue into leanprover:master with commit 84e4616 Jun 21, 2024
14 checks passed
@david-christiansen david-christiansen deleted the tactic-index branch June 21, 2024 13:23
github-merge-queue bot pushed a commit that referenced this pull request Feb 3, 2025
This PR adds a `recommended_spelling` command, which can be used for
recording the recommended spelling of a notation (for example, that the
recommended spelling of `∧` in identifiers is `and`). This information
is then appended to the relevant docstrings for easy lookup.

The function `Lean.Elab.Term.Doc.allRecommendedSpellings` may be used to
obtain a list of all recommended spellings, for example to create a
table that is part of a style guide. In the future, it might be
desirable to be able to partition such a table into smaller tables by
category. This can be added in a future PR.

The implementation is heavily inspired by #4490.
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 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.

5 participants