Commit graph

355 commits

Author SHA1 Message Date
Leonardo de Moura
da09ef4f66 feat(frontends/lean/builtin_exprs): minor improvement 2019-06-24 15:48:11 -07:00
Leonardo de Moura
8f1345dc53 chore(library/init/lean/syntax): simplify SyntaxNodeKind 2019-06-21 14:24:44 -07:00
Leonardo de Moura
e4344b0c94 chore(library/init/lean/parser/default): update default 2019-06-21 14:20:40 -07:00
Leonardo de Moura
0fe8fd1307 feat(library/init/lean/parser/parser): notation 2019-06-21 14:20:22 -07:00
Leonardo de Moura
bc9e460f62 fix(library/init/lean/compiler/ir): collectUsedDecls must take initialization functions into account
Move builtin parser level to its own directory
2019-06-21 13:34:42 -07:00
Leonardo de Moura
93e5746739 chore(library/init/lean/parser/parser): naming consistency 2019-06-20 16:47:55 -07:00
Leonardo de Moura
98879f1580 refactor(library/init/lean/parser/parser): simplify SyntaxNodeKind
The numeric `id` generation is works well for builtin parsers, but it
creates problems when defining dynamic ones.
2019-06-20 14:51:59 -07:00
Leonardo de Moura
8724a8cfd5 feat(library/init/lean/parser/parser): builtin parser attributes must be applied after compilation 2019-06-20 09:22:03 -07:00
Leonardo de Moura
d7fb0aa908 feat(library/init/lean/parser/parser): simpler cache
cc @kha
2019-06-19 16:48:18 -07:00
Leonardo de Moura
f180b3f32e feat(library/init/lean/parser/parser): improve error messages on prattParser 2019-06-19 16:36:18 -07:00
Leonardo de Moura
4db487fb42 fix(library/init/lean/parser/parser): sepBy1 2019-06-19 16:34:49 -07:00
Leonardo de Moura
cf9a29152d fix(library/init/lean/parser/parser): ParserInfo for ident, strLit, and numLit 2019-06-19 16:19:00 -07:00
Leonardo de Moura
401de35b6c chore(library/init/lean/parser/parser): remove unnecessary import
It turns out we don't need evalConst for implementing `builtinParsers`.
2019-06-19 10:53:51 -07:00
Leonardo de Moura
5f014415a9 feat(library/init/lean/parser/parser): add helper functions for invoking builting parsers
TODO: add scoped attributes for dynamically extending parsers.
2019-06-19 10:48:19 -07:00
Leonardo de Moura
89dae7f877 fix(library/init/lean/parser/parser): missing result 2019-06-19 10:33:53 -07:00
Leonardo de Moura
697f69020f fix(library/init/lean/parser/parser): new registerBuiltinParserAttribute
It is still broken since we apply attributes before we compile code.

Recall that attributes such as `@[export]` and `@[extern]` must be applied before we
compile code.

On the other hand, any attribute `attrName`
```
@[attrName] def foo := ...
```
which creates auxiliary definitions that depend on `foo` must be applied
AFTER we generate code for `foo`. Otherwise, we will fail to compile the
auxiliary definition since we don't have code for `foo` yet.

I will fix the issue above by allowing attributes to specify when they
should be applied. I will start with only two options: before and after
code compilation. In the future, we may need more options (e.g., before
elaboration), but I don't see the need yet.

cc @kha
2019-06-19 09:52:56 -07:00
Leonardo de Moura
444d942b1c fix(library/init/lean/parser/parser): bootstrapping/initialization issue
`evalConst` was being invoked "too early".
2019-06-18 11:27:37 -07:00
Leonardo de Moura
14e902cf8e feat(library/init/lean/parser): register builtin parsing tables 2019-06-18 09:25:10 -07:00
Leonardo de Moura
03ca8734f3 feat(library/init/lean/parser/parser): add runParser for testing 2019-06-18 09:01:58 -07:00
Leonardo de Moura
b558ac424f feat(library/init/lean/parser/parser): add prattParser 2019-06-18 08:37:15 -07:00
Leonardo de Moura
e9535e5792 feat(library/init/lean/parser/parser): add longestMatch combinator 2019-06-18 08:07:46 -07:00
Leonardo de Moura
e9b877c334 feat(library/init/lean/parser/parser): add registerBuiltinParserAttribute 2019-06-17 16:49:44 -07:00
Leonardo de Moura
a495a4ce86 feat(library/init/lean/parser/parser): new parser combinators based on tests/playground/parser
Main differences with respect to `tests/playground/parser`

1- There is a single (parametric) parser type: `Parser k`, where `k` is
   used to identify whether it is a `nud` or `led` parser.
2- It assumes parsing tables are stored in the `Environment`.
3- We check precedence mismatch, and use the value `none` to represent
   "use existing precedence".
4- We have support for silent (aka epsilon) parsing actions.

Remark: the experiments at `tests/playground/parser` demonstrated that the new
parsing infrastructure is at least 10x faster than the one based on the
`Parsec` monad.
2019-06-17 13:29:01 -07:00
Leonardo de Moura
d74f52e8dd feat(library/init/lean/parser/identifier): add indentifier.lean back 2019-06-06 15:18:22 -07:00
Leonardo de Moura
f0bb48a48a chore(library/init/lean/parser/trie): put trie back 2019-06-06 15:14:27 -07:00
Leonardo de Moura
55626ba60d chore(library/init/lean): disable new frontend for now
We are going to start making drastic changes in the parser,
elaborator, attributes, etc. Examples:
- No View objects. I am going to implement match_syntax.
- No RecT in the parser. I am going to implement parser extensions
using an approach similar to the one I used to implement environment
extensions.
- No Parsec. I will use an approach similar to the one used in the
experiment https://github.com/leanprover/lean4/tree/master/tests/playground/parser

It is easier to perform these changes with the new frontend disabled.
I will slowly re-active it as I apply the changes.

cc @kha
2019-06-05 15:26:43 -07:00
Leonardo de Moura
40ecbb7cbc feat(library/init/control/monad): mark monadInhabited as an instance 2019-05-20 09:33:17 -07:00
Leonardo de Moura
02f90485e6 feat(library/init/lean): use Environment in the new frontend 2019-05-13 13:04:57 -07:00
Sebastian Ullrich
c77970a00f refactor(library): remove now-redundant parentheses 2019-05-03 13:57:21 +02:00
Leonardo de Moura
807c9bff6d refactor(library/init): HasToFormat ==> HasFormat, toFormat ==> format 2019-04-28 09:16:47 -07:00
Leonardo de Moura
4aa3036e14 chore(library/init/lean/parser/trie): add HasEmptyc instance 2019-04-12 07:30:06 -07:00
Leonardo de Moura
a883042dc8 chore(library/init): fold functions argument order consistency 2019-04-03 07:42:14 -07:00
Leonardo de Moura
dc6c1e329f refactor(library/init/data/rbmap): use Bool instead of Prop 2019-04-03 02:54:34 -07:00
Leonardo de Moura
5e14a5f561 refactor(library/init/lean/parser/trie): use String.Pos instead of OldIterator
Renamed the old `matchPrefix` to `oldMatchPrefix`.
2019-03-29 18:17:27 -07:00
Leonardo de Moura
e58949e938 chore(library/init/control/id): rename id monad to Id 2019-03-29 16:45:52 -07:00
Sebastian Ullrich
1a6a87d4e2 chore(library/init/lean/parser/token): avoid tryView 2019-03-29 14:32:21 +01:00
Leonardo de Moura
42fbe3c18c chore(library/init,runtime,library/compiler): add fix primitive back
The new `partial def`s allow us to define `fix` in Lean, but the Lean
implementation is not as efficient as the native one. The native one
in C++ use weak pointers to prevent a closure allocation at every
recursive invocation.

This commit also fixes the `fixCore` helper functions that were broken
after we switched to camelCase.

We have updated the test `fix1.lean` to demonstrate the native
implementation is faster. Here are the numbers on my desktop.

```
./run.sh fix1.lean 24
721420279
Time for 'native fix': 816ms
721420279
Time for 'fix in lean': 1.34s
```
2019-03-27 17:13:53 -07:00
Leonardo de Moura
a43a40b7f5 chore(library/init): remove fix.lean
`partial def` is much more general
2019-03-27 13:11:00 -07:00
Leonardo de Moura
a3f30a5573 feat(library/init/lean): avoid wf_term_hack 2019-03-27 12:36:17 -07:00
Leonardo de Moura
b66f5dcf5c chore(library/init): avoid wf_term_hack 2019-03-27 12:12:21 -07:00
Leonardo de Moura
b29fb57fcf refactor(library/init/data/string/basic): String.Pos as Nat
@kha: I initially planned to use the UTF8 API only in very special
cases, but I found them to be super useful. They allow us to implement
an efficient String library mostly in Lean.
However, the there was a problem: `abbrev String.Pos := USize`.
This definition is fine for a low level API, but this is not the case
anymore. By having `String.Pos := USize`, we will not be able to
prove natural theorems for the `String` API. For example,
`String.map id s = s` did not hold. We would have to include the
artificial antecedent `s.length <= usizeMax` (or something like this).
I suspect it would be very painful.
So, this commit defines `String.Pos` as `Nat`. The performance
overhead seems to be very small.
2019-03-26 15:35:52 -07:00
Sebastian Ullrich
040ec9767d fix(library/init/lean/parser/combinators): (x) -> e should not be a dependent function 2019-03-26 11:26:39 +01:00
Sebastian Ullrich
beec014890 feat(library/init/lean/{parser/term,expander}): remove (x : e) → f macro hack and replace with actual parser 2019-03-25 16:12:14 +01:00
Leonardo de Moura
60f8d17942 refactor(library/init/data/string/basic): simplify String.Iterator
The `offset` field is problematic because it prevents us from having an
efficient way of moving back and forth between `String.Pos` and `String.Iterator`.

@kha I temporarily added `String.OldIterator` for making sure the
parser doesn't break. This is a temporary fix that will be eliminated
after we replace `parsec`.
2019-03-25 07:57:12 -07:00
Leonardo de Moura
5b08bf18c5 feat(library/init/lean): improving options
@kha It will be awesome to automate the following idiom with a macro :)
```
def defIndent  := 4
def getIndent (o : Options) : Nat   := o.get `format.indent defIndent
@[init] def indentOption : IO Unit :=
registerOption `format.indent { defValue := defIndent, group := "format", descr := "indentation" }
```
2019-03-24 09:30:20 -07:00
Leonardo de Moura
4a08d6715a chore(library/init/data/array): add HasEmptyc instance 2019-03-21 17:06:56 -07:00
Leonardo de Moura
91204a52d6 chore(library/init/data/dlist): Dlist => DList 2019-03-21 17:03:22 -07:00
Leonardo de Moura
3befc219c9 chore(library/init): Empty => empty when it is a function 2019-03-21 17:03:15 -07:00
Leonardo de Moura
dfe15cf743 refactor(library/init): use get and set for State EState and Ref
TODO: use the same naming convention for array reads and writes.
2019-03-21 16:34:32 -07:00
Leonardo de Moura
930164b597 chore(library/init/lean/parser/term): remove hack used during conversion 2019-03-21 15:06:45 -07:00