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

Delaboration of constants in function applications #911

Closed
wants to merge 6 commits into from

Conversation

hargoniX
Copy link
Contributor

As described in https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Function.20application.20delaboration it would be nice to be able to (optionally) add info tags to the syntactic node representing the function in a function application, instead of just the entire function application, for automatic documentation generation purposes. However this would break the LSP's hovering behavior so this feature is disabled per default. Furthermore this PR fixes a few bugs along the delaboration/formatting pipeline which dropped the generated information at two places.

src/Init/Prelude.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Notation.lean Outdated Show resolved Hide resolved
src/Lean/PrettyPrinter/Delaborator/Builtins.lean Outdated Show resolved Hide resolved
@gebner
Copy link
Member

gebner commented Dec 27, 2021

Furthermore this PR fixes a few bugs along the delaboration/formatting pipeline which dropped the generated information at two places.

This was the fun x => 42 where the x wasn't tagged, right? Do we also tag it with the correct position now? Did you fix anything else?

It would be cool if we had tests for that (like infoTree.lean but for delaboration), but I guess that can go in another PR.

@hargoniX
Copy link
Contributor Author

hargoniX commented Dec 27, 2021

The first place where they were dropped was in automatically generated delaborators for syntax that was defined using notation and derived keywords. The second one was in the formatter, which simply ignored the information that was now being preserved by the notation change. I specifically checked whether it tags stuff like the f in f (x y z) and operators such as = in x = y
which seem to work correctly, even in more complex scenarios when I view the current output of doc-gen.

@@ -90,6 +90,11 @@ register_builtin_option pp.safeShadowing : Bool := {
group := "pp"
descr := "(pretty printer) allow variable shadowing if there is no collision"
}
register_builtin_option pp.tagSymbols : Bool := {
Copy link
Member

Choose a reason for hiding this comment

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

The name here is a bit misleading, the option does not only affect symbols (which I associate with +, etc.) but any head symbol (such as f in f a b). The terminology isn't great, we have lots of things that are called symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe tagAllFunctions ?

Copy link
Member

Choose a reason for hiding this comment

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

The All seems redundant. How about tagAppFns, in reference to Expr.getAppFn?

Copy link
Member

Choose a reason for hiding this comment

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

Would also be good to have a comment that if the constant is not part of an application, the tagging is unconditionally done by delabFor.

src/Init/Prelude.lean Outdated Show resolved Hide resolved
src/Init/Prelude.lean Outdated Show resolved Hide resolved
src/Init/Prelude.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Notation.lean Outdated Show resolved Hide resolved
src/Lean/Elab/Notation.lean Outdated Show resolved Hide resolved
@Kha
Copy link
Member

Kha commented Dec 30, 2021

nit: you shouldn't capitalize the first word in commit messages

Add an option called pp.tagSymbols which, if set, makes the
delaborator add term information to all symbols it can during
delaboration. This option is disabled per default because it would
break the LSP server's hovering behaviour. It is however useful
when for example automatically generating interactive documentation.
Previously automatically generated delaborators for syntax declared with
the notation (and derived) keywords would silently drop information
during delaboration.
@hargoniX hargoniX force-pushed the const-delab branch 3 times, most recently from 36ff74a to 1ee2d89 Compare December 31, 2021 00:19
`(@[$attrKind:attrKind appUnexpander $(mkIdent c):ident]
aux_def unexpand $(mkIdent c) : Lean.PrettyPrinter.Unexpander := fun
| `($$(_):ident $args*) => `($pat)
| _ => throw ())
| `($$fun_ref:ident $args*) => withRef fun_ref `($pat)
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't match our naming convention, let's go with just f? Same below. And mind the indentation.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, the why I was missing yesterday is that the quotation uses the reference as the source location of any newly introduced identifiers, which in this case is the function head.

@@ -90,6 +90,11 @@ register_builtin_option pp.safeShadowing : Bool := {
group := "pp"
descr := "(pretty printer) allow variable shadowing if there is no collision"
}
register_builtin_option pp.tagSymbols : Bool := {
Copy link
Member

Choose a reason for hiding this comment

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

The All seems redundant. How about tagAppFns, in reference to Expr.getAppFn?

@@ -90,6 +90,11 @@ register_builtin_option pp.safeShadowing : Bool := {
group := "pp"
descr := "(pretty printer) allow variable shadowing if there is no collision"
}
register_builtin_option pp.tagSymbols : Bool := {
Copy link
Member

Choose a reason for hiding this comment

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

Would also be good to have a comment that if the constant is not part of an application, the tagging is unconditionally done by delabFor.

hargoniX and others added 3 commits December 31, 2021 13:11
Co-authored-by: Gabriel Ebner <gebner@gebner.org>
The ppNotationCode.lean test failed because the output of the notation
elaborator changed (purposely), adapt it to the new output.
| `($$(_):ident) => `($pat)
| _ => throw ())
| `($$f:ident) => withRef f `($pat)
| _ => throw ())
| _ => failure
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I'm unsure with the indentation here, is this correct? Should it be further to the left? Is there some written down style guide for this?

@Kha
Copy link
Member

Kha commented Jan 3, 2022

Merged manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants