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: port addTacticDoc #639

Closed
wants to merge 22 commits into from
Closed

feat: port addTacticDoc #639

wants to merge 22 commits into from

Conversation

lakesare
Copy link
Collaborator

@lakesare lakesare commented Nov 18, 2022

Ports the add_tactic_doc and getTacticDocEntries from Lean 3 doc_commands.lean.
A notable change is Lean 3 version used user attributes to memorize the doc entries, Lean 4 version uses environment extension.

Questions

  • Should we rename TacticDocEntry just to DocEntry, add_tactic_doc to add_doc_entry, etc.?
  • Rename inherit_description_from to inherit_docstring_from?
  • Whomever will be reviewing this - please take a look at the related PR at feat: port add_decl_doc #499 (comment), answer to that question will tell us how to name/group our documentation files.

test/AddTacticDoc.lean Outdated Show resolved Hide resolved
test/AddTacticDoc.lean Outdated Show resolved Hide resolved
@lakesare lakesare marked this pull request as ready for review November 19, 2022 17:54
Mathlib/Tactic/AddTacticDoc.lean Outdated Show resolved Hide resolved
/--
Serves as a global storage for all `TacticDocEntry`s we have added throughout mathlib codebase.
When [doc-gen](https://github.com/leanprover-community/doc-gen) generates documentation, it will
access this storage to find each `tacticDocEntry` along with its greatest-priority docstring.
Copy link
Member

Choose a reason for hiding this comment

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

tacticDocEntry -> TacticDocEntry

Copy link
Collaborator Author

@lakesare lakesare Nov 21, 2022

Choose a reason for hiding this comment

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

I used tacticDocEntry as "an instance of TacticDocEntry", is that not a widespread way to say things in Lean?

@dwrensha
Copy link
Member

Should we rename TacticDocEntry just to DocEntry, add_tactic_doc to add_doc_entry, etc.?

My opinion is that it's better to keep the old names for now, to maximize discoverability during the port. (I don't think that #align can help us much, because these things are primarily used in tactic files, which are getting ported by hand.) If we want to rename them before the port is done, then backporting the renaming to mathlib3 first seems to me like way to go.

/--
describe what the command does here
-/
add_tactic_doc
Copy link
Member

Choose a reason for hiding this comment

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

It looks like your version actually requires that the TacticDocEntry is split out into a separate def, like this:

def myTde : tde: TacticDocEntry { name := "display name of the tactic",
  category := cat,
  decl_names := [`dcl_1, `dcl_2],
  tags := ["tag_1", "tag_2"] }
  
  add_tactic_doc myTde

Is that right? What is the reason for this change from the mathlib3 version?

Copy link
Collaborator Author

@lakesare lakesare Nov 21, 2022

Choose a reason for hiding this comment

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

The change is accidental, it should accept a structure!
Do you have some pointers as to what tdeStx:______ should be to accept a structure?


Wojciech gave me some pointers (tdeStx:term is already the right type), I'll fix it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed this & added a test.

image

elab metaDocString:docComment ? "add_tactic_doc " tdeStx:term : command => do
-- 1. Turn tde:TSyntax argument into the actual tde:TacticDocEntry object
let tdeName : Name ← resolveGlobalConstNoOverloadWithInfo tdeStx
let tde : TacticDocEntry ← unsafe evalConstCheck TacticDocEntry ``TacticDocEntry tdeName
Copy link
Member

Choose a reason for hiding this comment

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

This unsafe makes me nervous. Is there a way to avoid it?

Copy link
Member

Choose a reason for hiding this comment

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

This particular pattern is fairly normal, and I would expect it to come up in something like this where we want to make an actual TacticDocEntry from a syntax representing such. This is automated to some extent by declare_config_elab but that is specialized for config arguments in tactics.

@lakesare
Copy link
Collaborator Author

lakesare commented Nov 24, 2022

I removed the DocCommands.lean file because we need neither add_decl_doc (it's already implemented in Lean 3) nor copy_doc_string (we can use attribute [inherit_doc ffrom] tto).

Alternatively, we could put addTacticDoc command into DocCommands.lean and describe the new documentation methods in the module docstring (Lean 3's add_decl_doc and inherit_doc).

@dwrensha
Copy link
Member

I removed the DocCommands.lean file because we need neither add_decl_doc (it's already implemented in Lean 3) nor copy_doc_string (we can use attribute [inherit_doc ffrom] tto).

Note that Mario already removed this file in #684.

@lakesare
Copy link
Collaborator Author

lakesare commented Dec 5, 2022

Should it be merged/are we waiting for the second reviewer, @dwrensha?

@dwrensha
Copy link
Member

dwrensha commented Dec 5, 2022

I don't have the permission to merge, so this is waiting on the review of someone who does.

Comment on lines +53 to +57
add_tactic_doc {
name := "never defined separately",
category := DocCategory.hole_cmd,
decl_names := [`one]
}
Copy link
Member

@digama0 digama0 Dec 6, 2022

Choose a reason for hiding this comment

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

Can it also support the following syntax:

Suggested change
add_tactic_doc {
name := "never defined separately",
category := DocCategory.hole_cmd,
decl_names := [`one]
}
add_tactic_doc where
name := "never defined separately"
category := DocCategory.hole_cmd
decl_names := [`one]

This is the Command.whereStructInst parser. You can implement this as a macro that expands to the version with the { }.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It can't!
Not super sure how to do it though (I'm porting another tactic at the moment, so I might only return to learning macros in a few weeks, wouldn't want this PR to go stale in the meantime).

Something along these lines?

macro metaDocString:docComment ? "add_tactic_doc " tdeStx:Lean.Parser.Command.whereStructInst : command => do
  `(add_tactic_doc $tdeStx)

Copy link
Member

Choose a reason for hiding this comment

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

kind of, except that the macro you just wrote calls itself recursively. You would need to convert the where expression into a structure declaration with braces so that you can call the other version of the declaration.

@semorrison semorrison added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review labels Dec 7, 2022
@hrmacbeth hrmacbeth added the t-meta Tactics, attributes or user commands label Jan 2, 2023
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 16, 2023
This reverts commit 9cd961f.
@semorrison semorrison removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 24, 2023
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 2, 2023
@bors bors bot changed the base branch from master to ScottCarnahan/BinomialRing2 September 17, 2023 03:24
@semorrison semorrison changed the base branch from ScottCarnahan/BinomialRing2 to master September 17, 2023 12:19
@fpvandoorn fpvandoorn added the please-adopt Inactive PR (would be valuable to adopt) label Dec 8, 2023
@jcommelin
Copy link
Member

This pull request has not seen any activity for quite a while, and it does not pass all CI checks or has merge conflicts. For these reasons, I am closing it now.

If you are still interested in getting this PR merged, please re-open the PR, update the branch, and make sure that all CI checks pass, Please label the PR with awaiting-review when ready.

@jcommelin jcommelin closed this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author A reviewer has asked the author a question or requested changes merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) please-adopt Inactive PR (would be valuable to adopt) t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants