Commit graph

40 commits

Author SHA1 Message Date
Kyle Miller
cdbe29b46d
feat: accurate binder names in signatures (like in output of #check) (#5827)
An important part of the interface of a function is the parameter names,
for making used of named arguments. This PR makes the parameter names
print in a reliable way. The parameters of the type now appear as
hygienic names if they cannot be used as named arguments.

Modifies the heuristic for how parameters are chosen to appear before or
after the colon. The rule is now that parameters start appearing after
the colon at the first non-dependent non-instance-implicit parameter
that has a name unusable as a named argument. This is a refinement of
#2846.

Fixes the issue where consecutive hygienic names pretty print without a
space separating them, so we now have `(x✝ y✝ : Nat)` rather than `(x✝y✝
: Nat)`.

Breaking change: `Lean.PrettyPrinter.Formatter.pushToken` now takes an
additional boolean `ident` argument, which should be `true` for
identifiers. Used to insert discretionary space between consecutive
identifiers.

Closes #5810
2024-10-29 16:43:11 +00:00
Kyle Miller
bd46319aee
feat: add option pp.mvars.delayed (#5643)
Where before we had
```lean
#check fun x : Nat => ?a
-- fun x ↦ ?m.7 x : (x : Nat) → ?m.6 x
```
Now by default we have
```lean
#check fun x : Nat => ?a
-- fun x => ?a : (x : Nat) → ?m.6 x
```
In particular, delayed assignment metavariables such as `?m.7` pretty
print using the name of the metavariable they are delayed assigned to,
suppressing the bound variables used in the delayed assignment (hence
`?a` rather than `?a x`). Hovering over `?a` shows `?m.7 x`.

The benefit is that users can see the user-provided name in local
contexts. A justification for this pretty printing choice is that `?m.7
x` is supposed to stand for `?a`, and furthermore it is just as opaque
to assignment in defeq as `?a` is (however, when synthetic opaque
metavariables are made assignable, delayed assignments can be a little
less assignable than true synthetic opaque metavariables).

The original pretty printing behavior can be recovered using `set_option
pp.mvars.delayed true`.

This PR also extends the documentation for holes and synthetic holes,
with some technical details about what delayed assignments are. This
likely should be moved to the reference manual, but for now it is
included in this docstring.

(This PR is a simplified version of #3494, which has a round-trippable
notation for delayed assignments. The pretty printing in this PR is
unlikely to round trip, but it is better than the current situation,
which is that delayed assignment metavariables never round trip, and
plus it does not require introducing a new notation.)
2024-10-08 17:48:52 +00:00
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
f336525f31
fix: make delabConstWithSignature avoid using inaccessible names (#3625)
The `delabConstWithSignature` delaborator is responsible for pretty
printing constants with a declaration-like signature, with binders, a
colon, and a type. This is used by the `#check` command when it is given
just an identifier.

It used to accumulate binders from pi types indiscriminately, but this
led to unfriendly behavior. For example, `#check String.append` would
give
```
String.append (a✝ : String) (a✝¹ : String) : String
```
with inaccessible names. These appear because `String.append` is defined
using patterns, so it never names these parameters.

Now the delaborator stops accumulating binders once it reaches an
inaccessible name, and for example `#check String.append` now gives
```
String.append : String → String → String
```
We do not synthesize names for the sake of enabling binder syntax
because the binder names are part of the API of a function — one can use
`(arg := ...)` syntax to pass arguments by name. The delaborator also
now stops accumulating binders once it reaches a parameter with a name
already seen before — we then rely on the main delaborator to provide
that parameter with a fresh name when pretty printing the pi type.

As a special case, instance parameters with inaccessible names are
included as binders, pretty printing like `[LT α]`, rather than
relegating them (and all the remaining parameters) to after the colon.
It would be more accurate to pretty print this as `[inst✝ : LT α]`, but
we make the simplifying assumption that such instance parameters are
generally used via typeclass inference. Likely `inst✝` would not
directly appear in pretty printer output, and even if it appears in a
hover, users can likely figure out what is going on. (We may consider
making such `inst✝` variables pretty print as `‹LT α›` or
`infer_instance` in the future, to make this more consistent.)

Something we note here is that we do not do anything to make sure
parameters that can be used as named arguments actually appear named
after the colon (nor do we assure that the names are the correct names).
For example, one sees `foo : String → String → String` rather than `foo
: String → (baz : String) → String`. We can investigate this later if it
is wanted.

We also give `delabConstWithSignature` a `universes` flag to enable
turning off pretty printing universe levels parameters.

Closes #2846
2024-03-07 18:14:06 +00:00
Leonardo de Moura
97e7e668d6
chore: pp.proofs.withType is now false by default (#3379)
`pp.proofs.withType := true` often produces too much noise in the info
view.
2024-02-17 15:09:24 +00:00
Kyle Miller
e29d75a961
feat: have pp.proofs use for omission (#3241)
By having the `pp.proofs` feature use `⋯` when omitting proofs, when
users copy/paste terms from the InfoView the elaborator can give an
error message explaining why the term cannot be elaborated.

Also adds `pp.proofs.threshold` option to allow users to pretty print
shallow proof terms. By default, only atomic proof terms are pretty
printed.

This adjustment was suggested in PR #3201, which added `⋯` and the
related `pp.deepTerms` option.
2024-02-15 21:49:41 +00:00
Sebastian Ullrich
de9a6374f1 feat: make #check <ident> always show the signature without elaboration 2022-12-21 21:59:05 +01:00
Gabriel Ebner
15d7744cca chore: fix tests 2022-10-11 17:24:35 -07:00
Leonardo de Moura
84ff8d4a04 feat: store pending contraints during dependent pattern matching
It is a better solution for issues #1361 and #1279, and it was on the
to-do list for a while.
2022-08-03 17:45:55 -07:00
Leonardo de Moura
764a1d9f51 chore: fix tests 2022-02-14 15:47:12 -08:00
Gabriel Ebner
b905824024 chore: fix tests 2021-12-15 11:42:38 +00:00
Daniel Selsam
0036111db9 feat: pp.analyze original mvars are not unknown 2021-08-03 09:13:18 +02:00
Daniel Selsam
e6b90dde8f fix: pp.analyze mvars can bottom-up 2021-08-03 09:13:18 +02:00
Daniel Selsam
c3d62c1076 chore: patch tests for pp.analyze default 2021-08-03 09:13:18 +02:00
Daniel Selsam
ded51882a0
feat: pp motives and misc delab fixes 2021-06-13 00:06:27 +02:00
Leonardo de Moura
002f96adc1 test: discriminant refinement 2021-03-28 19:06:06 -07:00
Sebastian Ullrich
a74960a4ab fix: delaborator: match with shadowing 2021-02-11 11:30:25 +01:00
Leonardo de Moura
eb25b97501 fix: pattern variables cannot shadow each other 2021-01-16 08:23:45 -08:00
Leonardo de Moura
f73eb1246a feat: add pp.safe_shadowing
When `pp.safe_shadowing` is set to true, we still use the
suggested name if the "body" does not contain a free variable with the
suggested name. This is the approach used in Lean 3, and I think it
improved the result in all affected tests.
The implementation was simple. The only nasty case was `delabAppMatch`.

The main motivation for this feature was hovering information such as
```lean
f : {α_1 : Type} → α_1 → α_1
```
when hovering over the `f` at
```lean
def g (α : Type) (a : α) :=
  f a
```
With `safe_shadowing`, we get the nicer
```lean
f : {α : Type} → α → α
```

cc @Kha
2021-01-15 18:53:25 -08:00
Sebastian Ullrich
b2b78eb222 test: use printMessageEndPos for leantests 2021-01-15 16:27:59 +01:00
Sebastian Ullrich
3e77c7cdef fix: error position 2020-12-21 16:25:01 +01:00
Sebastian Ullrich
4812f2aa64 chore: restore correct position for match errors 2020-12-16 18:27:05 +01:00
Sebastian Ullrich
f9dcbbddc4 refactor: remove optional leading pipe from match, use many1Indent instead of sepBy1 2020-12-16 18:27:05 +01:00
Leonardo de Moura
906cb81319 feat: improve inferAppType
See comment at `Expr.instantiateRevRange`
2020-12-06 19:01:23 -08:00
Leonardo de Moura
1e84fa1eed refactor: more general OfNat, remove One and Zero classes 2020-12-01 07:49:52 -08:00
Leonardo de Moura
390eea3750 feat: use One and Zero classes when expanding numeric literals 2020-11-29 16:23:52 -08:00
Sebastian Ullrich
b22e035b6f fix: pretty print empty matchers as nomatch
/cc @leodemoura
2020-11-25 11:30:24 +01:00
Sebastian Ullrich
9c6c568caf fix: don't try to pretty-print underapplied matcher
Fixes #219
2020-11-14 13:19:21 +01:00
Sebastian Ullrich
e4f53fd92d chore: adjust list & array spacing 2020-11-10 10:11:24 -08:00
Sebastian Ullrich
ce9be52ffb feat: pretty print lists and arrays 2020-11-10 10:11:24 -08:00
Sebastian Ullrich
3665e3b7b5 feat: pretty print match
Fixes #177
2020-11-10 10:11:24 -08:00
Leonardo de Moura
7e8a7e6660 feat: elaborate fun/forall binder extensions 2020-11-09 19:00:40 -08:00
Leonardo de Moura
defa45ae2f feat: improve error message
when match-expression LHSs still contain metavariables after elaboration
2020-11-09 18:26:14 -08:00
Leonardo de Moura
aeac85dadb chore: cleanup 2020-10-17 09:09:30 -07:00
Leonardo de Moura
5a24cb5ef7 feat: add hygienicIntro option
@Kha `hygienicIntro` is true by default. `hygienicIntro == false` is
the Lean3 behavior. If we find `hygienicIntro` too inconvenient in
practice, we set the default to false.
2020-09-18 13:02:38 -07:00
Sebastian Ullrich
3834a89cdc feat: activate new pretty printer 2020-09-17 08:12:28 -07:00
Leonardo de Moura
b136c519e2 fix: scope and improve error message 2020-09-09 16:44:43 -07:00
Leonardo de Moura
c78d0cf1f8 feat: use | position for reporting dependent-match elimination errors 2020-09-09 14:07:23 -07:00
Leonardo de Moura
854cc3418e feat: improve error message for dependent-match elimination failures
@Kha This is a first attempt to improve the error message for examples
like the one Andrew Kent posted on Zulip.
I created a simpler example using "vectors".
2020-09-09 13:43:06 -07:00
Leonardo de Moura
69ee44d68e feat: match-expressions showing signs of life 2020-08-13 16:51:31 -07:00