Commit graph

138 commits

Author SHA1 Message Date
Henrik Böving
09de5cd70e
refactor: remove Lean.RBMap usages (#9260)
This PR removes uses of `Lean.RBMap` in Lean itself.

Furthermore some massaging of the import graph is done in order to avoid
having `Std.Data.TreeMap.AdditionalOperations` (which is quite
expensive) be the critical path for a large chunk of Lean. In particular
we can build `Lean.Meta.Simp` and `Lean.Meta.Grind` without it thanks to
these changes.

We did previously not conduct this change as `Std.TreeMap` was not
outperforming `Lean.RBMap` yet, however this has changed with the new
code generator.
2025-07-21 14:04:45 +00:00
jrr6
5f4e6a86d5
feat: update and explain "unknown constant" and "failed to infer type" errors (#9423)
This PR updates the formatting of, and adds explanations for, "unknown
identifier" errors as well as "failed to infer type" errors for binders
and definitions.

It attempts to ameliorate some of the confusion encountered in #1592 by
modifying the wording of the "header is elaborated before body is
processed" note and adding further discussion and examples of this
behavior in the corresponding error explanation.
2025-07-18 19:20:31 +00:00
Sebastian Ullrich
6c63c9c716
feat: quotations for parser aliases (#4307)
Another papercut towards incremental `have`
2024-05-30 09:22:22 +00:00
Kyle Miller
a7338c5ad8
feat: make frontend normalize line endings to LF (#3903)
To eliminate parsing differences between Windows and other platforms,
the frontend now normalizes all CRLF line endings to LF, like [in
Rust](https://github.com/rust-lang/rust/issues/62865).

Effects:
- This makes Lake hashes be faithful to what Lean sees (Lake already
normalizes line endings before computing hashes).
- Docstrings now have normalized line endings. In particular, this fixes
`#guard_msgs` failing multiline tests for Windows users using CRLF.
- Now strings don't have different lengths depending on the platform.
Before this PR, the following theorem is true for LF and false for CRLF
files.
```lean
example : "
".length = 1 := rfl
```

Note: the normalization will take `\r\r\n` and turn it into `\r\n`. In
the elaborator, we reject loose `\r`'s that appear in whitespace. Rust
instead takes the approach of making the normalization routine fail.
They do this so that there's no downstream confusion about any `\r\n`
that appears.

Implementation note: the LSP maintains its own copy of a source file
that it updates when edit operations are applied. We are assuming that
edit operations never split or join CRLFs. If this assumption is not
correct, then the LSP copy of a source file can become slightly out of
sync. If this is an issue, there is some discussion
[here](https://github.com/leanprover/lean4/pull/3903#discussion_r1592930085).
2024-05-20 17:13:08 +00:00
Mario Carneiro
3c36020d13
feat: @[builtin_doc] attribute (part 1) (#3953)
First part of #3918.
2024-04-19 12:21:10 +00:00
Mario Carneiro
df1e6ba7fe
fix: built-in parser attributes link to the wrong place (#3916)
Go-to-def on `@[builtin_term_parser]` should go to the line
```lean
builtin_initialize registerBuiltinParserAttribute `builtin_term_parser ``Category.term
```
not
```lean
/-- `term` is the builtin syntax category for terms. ... -/
def term : Category := {}
```
2024-04-18 08:28:16 +00:00
David Thrane Christiansen
74e7886ce7
feat: custom error recovery in parser (#3413)
Adds a simple error-recovery mechanism to Lean's parser, similar to
those used in other combinator parsing libraries.

Lean itself isn't very amenable to error recovery with this mechanism,
as it requires global knowledge of the grammar in question to write
recovery rules that don't break backtracking or `<|>`. I only found a
few opportunities.

But for DSLs, this is really important. In particular, Verso parse
errors interacted very badly with Lean parse errors in a way that
required frequent "restart file" commands, but this mechanism allows me
to both recover from Verso parse errors and to have Lean skip the rest
of the file rather than repeatedly trying to parse it as Lean commands.
2024-02-21 14:29:54 +00:00
Henrik Böving
23e49eb519 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Mario Carneiro
2348fb37d3 fix: use Lean.initializing instead of IO.initializing 2023-06-17 06:57:14 -07:00
Sebastian Ullrich
22510db004 refactor: simplify parser code using withFn 2022-11-11 09:13:02 +01:00
Sebastian Ullrich
17782fba1a fix: replace broken ptrEq cache sanity checks with private ParserContext constructor
The context is now manipulated using `adaptCacheableContext` and `adaptUncacheableContext`
and created using `ParserFn.run`.
2022-11-11 09:13:02 +01:00
Sebastian Ullrich
9a4626c495 fix: must cache stack of parser evals 2022-11-11 09:13:02 +01:00
Sebastian Ullrich
ed03ff9d00 perf: cache leading_parser and syntax as well
We better hope the `leading_parser`s are closed terms
2022-11-11 09:13:02 +01:00
Sebastian Ullrich
da6efe1bca fix: make parser caching sound (I hope?) 2022-11-11 09:13:02 +01:00
Mario Carneiro
583e023314 chore: snake-case attributes (part 2) 2022-10-19 09:28:08 -07:00
Mario Carneiro
dd5948d641 chore: snake-case attributes (part 1) 2022-10-19 09:28:08 -07:00
Gabriel Ebner
fb4d90a58b feat: dynamic quotations for categories 2022-10-18 14:59:14 -07:00
Mario Carneiro
391aef5cd7 feat: automatic extension names 2022-10-06 17:19:30 -07:00
Mario Carneiro
6392c5b456 chore: import reductions 2022-09-15 14:02:38 -07:00
Sebastian Ullrich
fb408c024b fix: deleting built-in docstrings 2022-08-27 17:19:25 +02:00
Mario Carneiro
59b32da2d9 feat: go to def on parser aliases 2022-08-06 12:44:14 +02:00
Mario Carneiro
e816424466
chore: use Category declarations for builtin cats too (#1400) 2022-08-03 18:10:54 -07:00
Mario Carneiro
ecb787529a refactor: rename ref to declName 2022-08-01 11:23:09 +02:00
Mario Carneiro
711532f5c6 feat: add ref field to ParserCategory 2022-08-01 11:23:09 +02:00
Mario Carneiro
65e2b8a932 feat: track parser names by category 2022-08-01 11:23:09 +02:00
Mario Carneiro
603b7486e3 feat: add go-to-def for simple attributes 2022-07-31 16:36:54 +02:00
Sebastian Ullrich
6a767a66a1 perf: reduce Lean.Parser.Basic imports 2022-07-23 23:01:52 +02:00
Mario Carneiro
f6211b1a74
chore: convert doc/mod comments from /- to /--//-! (#1354) 2022-07-22 12:05:31 -07:00
Sebastian Ullrich
5d187b8beb fix: register tokens in parser quotation 2022-07-21 23:49:57 +02:00
Gabriel Ebner
a8cab84735 refactor: use computed fields for Expr 2022-07-11 14:19:41 -07:00
Sebastian Ullrich
eab64997cd fix: auto-group syntax parsers where necessary 2022-06-28 11:50:59 +02:00
Sebastian Ullrich
7d48d125da fix: store syntax kinds of parser aliases in order to construct correct antiquotations in macro and elab 2022-06-27 22:37:02 +02:00
Sebastian Ullrich
292d24ba19 feat: always store quoted kind in antiquotation kind 2022-06-27 22:37:02 +02:00
Leonardo de Moura
d56163bd0e refactor: resolveNamespace now return a List 2022-06-16 17:16:36 -07:00
Leonardo de Moura
02c4e548df feat: replace constant with opaque 2022-06-14 17:02:59 -07:00
Leonardo de Moura
041827bed5 chore: unused variables 2022-06-07 17:54:10 -07:00
Sebastian Ullrich
ae7b895f7a refactor: unname some unused variables 2022-06-07 16:37:45 -07:00
Sebastian Ullrich
0a39e9cbdc fix: dynamic quotations should use previous stage by default
@leodemoura as discussed some time ago
2022-05-25 09:46:10 +02:00
Sebastian Ullrich
e1fbc04c3b chore: accept unregistered syntax kinds in stage 1 2022-04-15 08:50:46 -07:00
Sebastian Ullrich
24697026e8 feat: always accept antiquotations, simplify quotDepth code 2022-04-06 19:43:07 +02:00
Sebastian Ullrich
e10e664cc1 chore: typos 2022-04-06 10:21:53 +02:00
Leonardo de Moura
fdd1cb5751 chore: remove workarounds for #1090 2022-04-01 11:28:17 -07:00
Leonardo de Moura
09de67780f chore: prepare for #1090 2022-04-01 09:35:06 -07:00
Leonardo de Moura
12e2a79170 chore: fix codebase after removing auto pure 2022-02-03 18:08:14 -08:00
Leonardo de Moura
cf3b8d4eb4 chore: cleanup
Make the code style more uniform.
We still have a lot of leftovers from the old frontend.
2022-01-26 09:18:17 -08:00
Gabriel Ebner
7e483d3a0a feat: support syntax abbreviations in dynamic quotations 2021-12-15 11:17:58 +00:00
Leonardo de Moura
68bd55af32 chore: fix codebase 2021-12-10 13:12:09 -08:00
Sebastian Ullrich
2a1aee2b7a feat: record declaration ranges of builtin parsers & elaborators 2021-11-26 17:13:19 +01:00
Sebastian Ullrich
e9f7c88299 feat: record doc strings of builtin parsers & elaborators 2021-11-26 17:13:19 +01:00
Sebastian Ullrich
8176084dcf refactor: factor out declareBuiltin 2021-11-26 17:13:19 +01:00