Commit graph

31 commits

Author SHA1 Message Date
Kyle Miller
d39b0415f0
feat: enable pp.fieldNotation.generalized globally (#3744)
Sets the default value to `pp.fieldNotation.generalized` to `true`.
Updates tests, and fixes some minor flaws in the implementation of the
generalized field notation pretty printer.

Now generalized field notation won't be used for any function that has a
`motive` argument. This is intended to prevent recursors from pretty
printing using it as (1) recursors are more like control flow structures
than actual functions and (2) generalized field notation tends to cause
elaboration problems for recursors.

Note: be sure functions that have an `@[app_unexpander]` use
`@[pp_nodot]` if applicable. For example, `List.toArray` needs
`@[pp_nodot]` to ensure the unexpander prints it using `#[...]`
notation.
2024-03-23 02:38:09 +00:00
Kyle Miller
6e408ee402
feat: apply app unexpanders for all prefixes of an application (#3375)
Before, app unexpanders would only be applied to entire applications.
However, some notations produce functions, and these functions can be
given additional arguments. The solution so far has been to write app
unexpanders so that they can take an arbitrary number of additional
arguments. However, as reported in [this Zulip
thread](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/pretty.20printer.20bug/near/420662236),
this leads to misleading hover information in the Infoview. For example,
while `HAdd.hAdd f g 1` pretty prints as `(f + g) 1`, hovering over `f +
g` shows `f`. There is no way to fix the situation from within an app
unexpander; the expression position for `HAdd.hAdd f g` is absent, and
app unexpanders cannot register TermInfo.

This commit changes the app delaborator to try running app unexpanders
on every prefix of an application, from longest to shortest prefix. For
efficiency, it is careful to only try this when app delaborators do in
fact exist for the head constant, and it also ensures arguments are only
delaborated once. Then, in `(f + g) 1`, the `f + g` gets TermInfo
registered for that subexpression, making it properly hoverable.

The app delaborator is also refactored, and there are some bug fixes:
- app unexpanders only run when `pp.explicit` is false
- trailing parameters in under-applied applications are now only
considered up to reducible & instance transparency, which lets, for
example, optional arguments for `IO`-valued functions to be omitted.
(`IO` is a reader monad, so it's hiding a pi type)
- app unexpanders will no longer run for delaborators that use
`withOverApp`
- auto parameters now always pretty print, since we are not verifying
that the provided argument equals the result of evaluating the tactic

Furthermore, the `notation` command has been modified to generate an app
unexpander that relies on the app delaborator's new behavior.

The change to app unexpanders is reverse-compatible, but it's
recommended to update `@[app_unexpander]`s in downstream projects so
that they no longer handle overapplication themselves.
2024-02-27 07:04:17 +00:00
Sebastian Ullrich
8a4059dc65 fix: avoid notation in quotation elaborator output 2023-01-26 13:05:33 +01:00
Sebastian Ullrich
18297d8d91 fix: notation unexpander on overapplication of non-nullary notation 2023-01-26 13:05:33 +01:00
Gabriel Ebner
0d598dcfdf fix: Format.align always prints whitespace 2022-12-21 22:54:42 +01:00
Leonardo de Moura
c20febff31 feat: add helper Syntax.node* functions 2022-10-16 08:40:01 -07:00
Mario Carneiro
0acdaddcf2 feat: unexpander for mkArray0 2022-10-14 08:51:45 -07:00
Gabriel Ebner
79569c9003 chore: replace let by have in stx matches 2022-10-12 11:52:28 -07:00
Gabriel Ebner
15d7744cca chore: fix tests 2022-10-11 17:24:35 -07:00
Leonardo de Moura
f63734cba4 chore: unexpanders for Name.mkStr* and Array.mkArray*
closes #1675
2022-10-04 17:18:36 -07:00
Leonardo de Moura
5746338c15 fix: mark Lean.Name.mkStr* functions as [reducible]
This is needed for type checking `TSyntax`.
2022-09-29 17:36:30 -07:00
Leonardo de Moura
126da8185d feat: more compact quotations
Trying to control the generated code size.
2022-09-29 16:56:43 -07:00
Sebastian Ullrich
5ce5576b5d fix: hygienic resolution of namespaces 2022-08-20 22:29:46 +02:00
Gabriel Ebner
34b0b4b7e2 chore: fix tests 2022-08-15 08:55:25 -07:00
Sebastian Ullrich
81c744b12f chore: update tests 2022-08-13 18:07:30 -07:00
Sebastian Ullrich
da44604c1b fix: notation delaborator on over-application 2022-07-25 13:42:37 -07:00
Sebastian Ullrich
3a56db2812 chore: fix tests 2022-06-27 22:37:02 +02:00
Leonardo de Moura
1f2618adba feat: delaborate cond using bif-then-else 2022-03-03 07:41:39 -08:00
Henrik Böving
2d85c9ba2f chore: fix notation test
The ppNotationCode.lean test failed because the output of the notation
elaborator changed (purposely), adapt it to the new output.
2022-01-03 13:47:11 +01:00
Sebastian Ullrich
cd94ec20b0 fix: aux_def: avoid creating unparseable names 2021-12-17 14:21:35 -08:00
Gabriel Ebner
b905824024 chore: fix tests 2021-12-15 11:42:38 +00:00
Gabriel Ebner
bfc74decde feat: add info field to Syntax.node 2021-10-26 20:19:27 +02:00
Gabriel Ebner
6063c662de feat: predictable naming for notation 2021-10-26 20:19:27 +02:00
Gabriel Ebner
ce15ea98c5 feat: predictable naming for macro_rules 2021-10-26 20:19:27 +02:00
Leonardo de Moura
1e44902243 fix: add withFreshMacroScope at expandMacroImpl? 2021-10-02 16:57:25 -07:00
Daniel Selsam
c3d62c1076 chore: patch tests for pp.analyze default 2021-08-03 09:13:18 +02:00
Daniel Selsam
89364b802b feat: top-down heuristic delaboration 2021-08-03 09:13:18 +02:00
Sebastian Ullrich
dc3d94ff61 fix: check arity in notation unexpander
Fixes #469
2021-07-22 16:59:19 +02:00
Sebastian Ullrich
8637220927 fix: make precedence mandatory for mixfix commands
Resolves #577
2021-07-19 13:18:58 -07:00
Sebastian Ullrich
3f4ab0a2af feat: implement elab_rules
TODO: infer category from quotation type
2021-06-21 10:17:26 -07:00
Sebastian Ullrich
7c3101a51c chore: produce more efficient/pp-able array code from quotations 2021-05-19 09:52:35 +02:00