Commit graph

26011 commits

Author SHA1 Message Date
Leonardo de Moura
9258a12ed4 feat(library/compiler): add new builtin management module
TODO: register `int`, `string` and `io` primitives
2018-11-14 15:58:12 -08:00
Leonardo de Moura
2fa938220b chore(library/init/data/string): cleanup 2018-11-14 14:09:45 -08:00
Leonardo de Moura
dfdf42ce34 chore(library/init/io): minimize io interface
We are moving to new compiler stack.
2018-11-14 13:59:25 -08:00
Leonardo de Moura
c599d78639 feat(library/init/io): implement io.iterate in Lean
cc @kha
2018-11-14 13:43:02 -08:00
Leonardo de Moura
439d0319f0 fix(library/compiler/specialize): array out of bounds 2018-11-14 13:42:50 -08:00
Leonardo de Moura
835b3a10cc chore(library/init): consistent names 2018-11-14 13:08:57 -08:00
Leonardo de Moura
49d779e3a6 fix(library/vm/vm_string): we were not using the builtin implementation for string.decidable_eq 2018-11-14 09:48:43 -08:00
Sebastian Ullrich
600b7ceb28 fix(library/init/lean/parser/syntax): make sure macro scopes are not pushed inside of ident nodes 2018-11-14 17:23:32 +01:00
Sebastian Ullrich
8d25c6edc5 fix(library/compiler/llnf): fix out-of-bounds access
@leodemoura is this correct?
2018-11-14 09:52:22 +01:00
Sebastian Ullrich
2f8e6cc975 chore(frontends/lean/elaborator,library/compiler/compiler): avoid error recovery errors 2018-11-14 09:52:22 +01:00
Leonardo de Moura
2271d4bccc chore(library/compiler): fix debug build 2018-11-13 15:26:25 -08:00
Leonardo de Moura
7365b9ed30 feat(library/compiler/lambda_lifting): cache names for lifted lambdas
We were creating hundreds of different names for simple lambdas. Example:
```
λ a, @coroutine.done a
```
2018-11-13 15:13:55 -08:00
Leonardo de Moura
a2817c3644 refactor(library/compiler): move closed term cache to separate module 2018-11-13 15:01:57 -08:00
Leonardo de Moura
1e5e28a933 fix(library/compiler/csimp): apply app-of-cases eagerly before other floating *-of-cases variants
Motivation: consider the following example

```
let m := if b then m1 else m2,
state.bind m (fun p, BIG p.1 p.2)
```
we first eta-expand the term, put in LCNF and inline state.bind
```
fun s,
let m   := decidable.cases_on b (fun h, m1) (fun h, m2) in
let x_1 := m s in
prod.cases_on x_1 (fun a s', BIG a s')
```
then, we apply `*-of-cases` at `m := ...` and its continuation, but we
need a joint point since the continuation is big. Then, we get
```
fun s,
let j_1 := fun x_1,
    let x_1 := m s in
    prod.cases_on x_1 (fun a s', BIG a s') in
decidable.cases_on b
  (fun h, let y := m1 in j_1 y)
  (fun h, let y := m2 in j_1 y)
```
This code is not good if `m1` and `m2` are functions. At runtime, we
need to create a closure and pass it to the join point.
If we apply `app-of-cases` before other floating `cases` variants we
avoid this problem.
Here is the sequence of transformations if we apply `app-of-cases`
eagerly. We get
```
fun s,
let m   := decidable.cases_on b (fun h, m1) (fun h, m2) in
let x_1 := m s in
prod.cases_on x_1 (fun a s', BIG a s')
```
as before. Then, we apply `app-of-cases` at `m s`, and get
```
fun s,
let x_1 := decidable.cases_on b (fun h, m1 s) (fun h, m2 s) in
prod.cases_on x_1 (fun a s', BIG a s')
```
Then, we apply `cases-of-cases`, but we again create a join point.
```
fun s,
let j_1 := fun x_1, prod.cases_on x_1 (fun a s', BIG a s') in
decidable.cases_on b
  (fun h, let y := m1 s in j_1 y)
  (fun h, let y := m2 s in j_1 y)
```
However, this time we are passing a value to `j_1` instead of a closure.

`app-of-cases` has two benefits:
1- It never creates new join points since applications are always small in LCNF
2- It may reduce a `cases` that returns a closure into a `cases` that
returns a value.
2018-11-13 09:14:46 -08:00
Leonardo de Moura
4136bad252 feat(library/compiler): insert boxing/unboxing instructions 2018-11-12 17:17:09 -08:00
Leonardo de Moura
3ae908f8de feat(library/compiler): add _jmp instruction, and skeleton for explicit boxing introduction step 2018-11-12 10:51:42 -08:00
Leonardo de Moura
c0ac39f7f0 chore(tests/lean/parser1): fix test output 2018-11-12 08:53:57 -08:00
Sebastian Ullrich
54b330ea66 feat(library/init/lean/expander): recursive, hygienic expansion
Not optimized yet. Some performance numbers:
  352ms    11.0%      75ms     2.4%   expand_core
  339ms    10.6%      58ms     1.8%   list.mmap._main._at._private.1829070809.expand_core
   52ms     1.6%      38ms     1.2%   lean.parser.syntax.flip_scopes
2018-11-12 13:15:14 +01:00
Leonardo de Moura
c111590adf fix(library/compiler/reduce_arity): incorrect assertion 2018-11-11 11:58:19 -08:00
Leonardo de Moura
95830a385d feat(src/library/compiler/reduce_arity): add temporary workaround 2018-11-09 16:09:25 -08:00
Leonardo de Moura
dc54f68222 feat(library/compiler): (try to) improve reduce_arity 2018-11-09 15:53:45 -08:00
Leonardo de Moura
5ab69262c4 chore(library/compiler/util): remove leftover 2018-11-09 15:10:28 -08:00
Leonardo de Moura
7c86a4dae7 feat(library/compiler): add reduce_arity compilation step 2018-11-09 14:30:33 -08:00
Leonardo de Moura
19bf71eb9c chore(library/compiler/simp_app_args): use ll_infer_type 2018-11-09 13:18:28 -08:00
Leonardo de Moura
d3ad1cbfe1 feat(library/compiler): add type inference for ENF and LLNF 2018-11-09 13:17:11 -08:00
Leonardo de Moura
9e7d1d5bd2 chore(kernel/expr): remove leftover 2018-11-09 11:55:02 -08:00
Leonardo de Moura
37df96e3e7 feat(library/compiler/csimp): inline recursive functions marked with [inline_if_reduce] 2018-11-09 10:15:47 -08:00
Leonardo de Moura
182812a278 chore(library/init/lean/parser/token): make sure generate code does contain partially applied reader_t.or_else and reader_t.bind
@kha This one was crazy, the compiler created a join point for the
continuation of the match-expression. Each case of the match was
invoking the join point with a different parser. Two of the branches
were the partially applied `reader_t.bind` and `reader_t.orelse`.
This change did not improve the performance much, but it makes sure we
don't waste time trying to figure out why we have these two partial
applications in the call graph.
2018-11-08 17:39:46 -08:00
Leonardo de Moura
f38cbeda5f perf(library/compiler/csimp): avoid unnecessary local decl 2018-11-08 17:03:34 -08:00
Leonardo de Moura
6eca6bdb0e perf(library/init/lean/parser/term): avoid eta-expansion issues
cc @kha
2018-11-08 16:21:37 -08:00
Leonardo de Moura
1cb22b6801 perf(library/init/lean/parser/command): move common command parsers to the beginning of the list
@kha This modification saved 150k object allocations on my machine.

BTW, the function
```
def command_parser.run (commands : list command_parser) (p : command_parser)
  : parser_t command_parser_config id syntax :=
λ cfg, (p.run cfg).run_parsec $ λ _, any_of $ commands.map (λ p, p.run cfg)
```
is also affected by the problem I described at Zulip. It is another
example where eager eta-expansion is bad. Every time we call it, we
will create approx. 20 closures and 20 cons memory cells. We have at
least 600 commands in core.lean. So, just the `map` nested there will
generate 24k memory allocations. Moreover, the problem will get worse as we add
more commands.
2018-11-08 14:45:34 -08:00
Leonardo de Moura
ad9aa3bc19 perf(library/init/lean/parser/token): optimize symbol
Same trick used at `str`.

@kha: I also replaced `"token " ++ sym'` with `sym'`. We were creating
thousands of strings of the form "token ...".
2018-11-08 14:05:09 -08:00
Leonardo de Moura
0dfeb8a79c perf(library/init/lean/parser/parsec): optimize str and raw_str
Both `str` amd `raw_str` are used with string literals. This commit
makes sure we don't need to recompute the nested term
`dlist.singleton (repr s)`. This modification saves .2 secs when
parsing `core.lean` on my MacBook.

cc @kha
2018-11-08 11:18:21 -08:00
Sebastian Ullrich
eaeb0a40a5 chore(library/init/lean/parser): do not expose the parser cache as monad_state 2018-11-08 16:01:19 +01:00
Sebastian Ullrich
bd70dc1fc9 perf(library/init/lean/parser): move backtrackable state from parser_core_t to module_parser_m 2018-11-08 15:58:41 +01:00
Sebastian Ullrich
41f4a34d4b feat(library/init/lean/parser/token): cache hit statistics 2018-11-08 14:52:54 +01:00
Sebastian Ullrich
d77c6169f4 chore(library/init/lean/parser/combinators): node: small simplification 2018-11-08 10:43:17 +01:00
Leonardo de Moura
b56674cc25 fix(library/compiler/specialize): remove bogus optimization 2018-11-07 18:00:28 -08:00
Leonardo de Moura
df39be927d feat(library/compiler): make sure application arguments are free variables or neutral terms in LLNF 2018-11-07 17:25:20 -08:00
Leonardo de Moura
f9236592cc chore(library/compiler/llnf): remove dead code 2018-11-07 16:48:32 -08:00
Leonardo de Moura
474c743d8a fix(library/compiler/llnf): do not expand atomic values 2018-11-07 16:43:46 -08:00
Leonardo de Moura
17679799a2 fix(library/compiler/cse): must take a flag indicating whether we are applying optimization after/before erasure 2018-11-07 16:38:24 -08:00
Leonardo de Moura
1191dd4deb refactor(library/compiler): move mk_runtime_type to util 2018-11-07 15:19:24 -08:00
Leonardo de Moura
c285d48c96 feat(library/compiler/erase_irrelevant): simplify mk_runtime_type 2018-11-07 15:10:41 -08:00
Leonardo de Moura
687e9d076d feat(library/compiler): add _apply and _closure instructions to LLNF 2018-11-07 13:30:28 -08:00
Sebastian Ullrich
e2bf92ec21 feat(library/module_mgr,shell/lean): identify correct file on error in transitive import 2018-11-07 14:07:51 +01:00
Sebastian Ullrich
80a79336f2 chore(.gitignore): ignore library/Makefile 2018-11-07 09:30:32 +01:00
Sebastian Ullrich
0026b59a88 fix(tests/lean/macro_scopes): expected output 2018-11-07 09:11:49 +01:00
Leonardo de Moura
330e2700b1 chore(library/compiler/compiler): add trace.compiler.boxed option for debugging purposes 2018-11-06 16:55:02 -08:00
Leonardo de Moura
5acb5e63b1 feat(library/compiler): revise llnf instructions
Motivation: make sure we can generate "portable" C++ code. "Portable"
here means we can compile the generated code using 32 and 64 bit machines.
2018-11-06 16:55:02 -08:00