Commit graph

26741 commits

Author SHA1 Message Date
Leonardo de Moura
821bdcdac0 chore(tests/playground): add helper files 2019-02-15 18:13:37 -08:00
Leonardo de Moura
98d8657f74 chore(boot): update 2019-02-15 18:11:20 -08:00
Leonardo de Moura
61274c7d35 feat(library/init/data/char): use uint32 instead of nat for defining char 2019-02-15 18:07:55 -08:00
Leonardo de Moura
38c7ec133d fix(library/compiler/llnf): missing case 2019-02-15 17:51:08 -08:00
Leonardo de Moura
e819e980f0 chore(boot): update 2019-02-15 17:48:26 -08:00
Leonardo de Moura
ab45af5936 fix(library/compiler/csimp): avoid potential expensive reduction at csimp
`whnf_core(e)` uses `whnf` to reduce the major premise of recursors and
projections, and `whnf` unfolds arbitrary definitions.
This commit adds a new option (`cheap`) to `whnf_core`. When
`whnf_core(e, true)` is used, the type checker will not unfolding
definitions when reducing the major premises.
2019-02-15 17:43:21 -08:00
Leonardo de Moura
9ebe820410 chore(boot): update 2019-02-15 16:21:20 -08:00
Leonardo de Moura
e0fd89e165 feat(library/init/lean/compiler): fold nat predicates 2019-02-15 16:17:16 -08:00
Leonardo de Moura
90a1616cff chore(boot): update 2019-02-15 15:26:41 -08:00
Leonardo de Moura
1080edd490 fix(library/compiler/lambda_lifting): make sure auxiliary _lambda declarations come before the declarations that use them
This fixes a nasty initialization bug where an auxiliary `_closed`
declaration for an auxiliary `_lambda` is accessed before it is
initialized.
2019-02-15 15:23:46 -08:00
Leonardo de Moura
542bd432f8 test(tests/compiler): uint constant folding tests 2019-02-15 14:53:29 -08:00
Leonardo de Moura
11c4e2dd94 chore(boot): update 2019-02-15 14:42:20 -08:00
Leonardo de Moura
0cb3ac683d feat(library/compiler): connect new const_folding module implemented in Lean with csimp 2019-02-15 14:37:48 -08:00
Sebastian Ullrich
4c357dfbd6 fix(frontends/lean/decl_attributes): fix attribute parsing in old frontend 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
c9c1df6f98 test(shell/CMakeLists): add --new-frontend test 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
f6fde1a53d fix(frontends/lean/vm_elaborator): correctly set up declaration_info_scope 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
d083f8457a feat(frontends/lean/vm_elaborator): use attribute parsers 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
a6ac98966a refactor(library/attribute_manager): parse attribute data from pexpr instead of abstract_parser 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
03456ab752 chore(tests/compiler/t2): fix test 2019-02-15 12:13:45 -08:00
Sebastian Ullrich
b8900fad80 chore(tests/compiler/test.sh): rename to conventional test_single.sh so that (lean4-diff-test-file) works 2019-02-15 12:13:45 -08:00
Leonardo de Moura
00b177ad54 chore(runtime/object): enable Lazy RC by default
@kha I tried a compiling a few .lean examples using Lazy RC, and I did
not observe any significant increase in memory consumption.
2019-02-15 12:10:57 -08:00
Leonardo de Moura
eef60279e4 tests(tests/playground/expr_const_folding): another example for the paper
@kha I implemented a more complex example for the paper. The difference
in performance is awesome. On my Linux desktop:

Lean time:  3.34  secs
OCaml time: 11.72 secs

I believe that the difference in performance is due to destructive
updates happening in transformation functions such as `reassoc` and
`const_folding`. I will add a flag to Lean to disable `reuse/reset`
automatic insertion.

BTW, this test requires `ulimit -s unlimited` to avoid stack overflows.
2019-02-15 12:07:52 -08:00
Leonardo de Moura
06f1a2b1a0 feat(runtime/object): lazy RC
In this commit, we replace the option `LEAN_DEFERRED_FREE` with
`LEAN_LAZY_RC`. The idea is to match the nomenclature used in the
literature. See paper:
https://dl.acm.org/citation.cfm?id=964019
The following slide deck summarizes the paper:
http://www.hboehm.info/popl04/refcnt.pdf

We also implement the very simple approach described on this paper
where a `del(o)` just puts `o` in the "to free" list, and each
allocation frees at most one object. As pointed out in the paper
above lazy RC may prevent a lot of memory from being reclaimed.
For now, I am keeping the new option disabled.

That being said, the test `arith_eval_nat.lean` is 29% faster when
using lazy RC, and beats the OCaml version.

In the following paper
https://www.microsoft.com/en-us/research/wp-content/uploads/2017/01/tm567-1.pdf
a separate thread keeps processing the "to free" list. However, I
think this approach is not compatible with our
`object_memory_kind::STHeap` trick.

Tomorrow, I will measure the space overhead when compiling the Lean
corelib using Lazy RC using my linux desktop

cc @kha
2019-02-14 17:41:11 -08:00
Leonardo de Moura
f879cdb12f test(tests/playground): add new example in Lean and OCaml
@kha I wrote a simple test in Lean and OCaml. Right now, the numbers on
my machine are

arith_eval.ml         8.13 secs
arith_eval_nat.lean   10.71 secs

OCaml is computing with machine boxed integers, and we are computing
with `nat`. Our version is more expensive since we have to check
whether the number is small or big, and whether the result needs to be a
mpz value or not.

Almost half of our runtime is spent deallocating the big object returned
by `mk_expr`. The deferred free feature does not help here because
we don't deallocate the object in the end but as we execute `eeval`.
So, we perform many small invocations to `del`. None of them take
long, but the overall cost is super high. I can use a different strategy
where `del(o)` just updates the `g_to_free` list, and we deallocate
at most `LEAN_DEFERRED_FREE_QUOTA` at each allocation. The current
deferred free approach would also work if we could use the borrowed
annotations in `eeval`. In this case, we would not delete the input
expression as we evaluate it.

As an experiment, I manually added a `lean::inc` before invoking
`eeval`. The idea was prevent memory deallocation. With this
modification, the program runs in 5.87 secs.

BTW, I also wrote a version using uint32 (arith_eval_uint32.lean),
but the current compiler generates poor code for it.
I know how to fix the performance problem.
2019-02-14 15:50:07 -08:00
Leonardo de Moura
6785ad9844 fix(library/init/lean/default): missing file 2019-02-14 15:21:53 -08:00
Leonardo de Moura
390c9009f7 chore(shell,boot): update boot, and initialization process 2019-02-14 14:49:16 -08:00
Leonardo de Moura
a8ac25e1ef fix(library/compiler/emit_cpp): bug at emitting exported function headers 2019-02-14 14:35:51 -08:00
Leonardo de Moura
68e8aa8d1d feat(library/init/lean/compiler): add constant folding helper functions 2019-02-14 14:35:10 -08:00
Leonardo de Moura
b02ec6370c chore(boot): update 2019-02-14 14:25:50 -08:00
Leonardo de Moura
5e7308d22d chore(library/init/lean/expr): get_app_fn 2019-02-14 14:12:25 -08:00
Sebastian Ullrich
956a047d1e chore(library/compiler/extern_attribute): style 2019-02-14 14:07:05 -08:00
Sebastian Ullrich
7bea9a1bea chore(frontends/lean/vm_elaborator): ignore [extern] for now 2019-02-14 14:07:05 -08:00
Sebastian Ullrich
587a7a001a feat(library/init/lean/elaborator): to_pexpr: support string literals 2019-02-14 14:07:05 -08:00
Sebastian Ullrich
dbc470d7e4 feat(library/init/lean/{parser/term,elaborator}): support @& borrowed annotations 2019-02-14 14:07:05 -08:00
Sebastian Ullrich
9da149c2df fix(library/messages): message_severity is unboxed 2019-02-14 14:07:05 -08:00
Sebastian Ullrich
01942c8e26 feat(shell/lean): --new-frontend
TODO: parse imports with new frontend, pass environment to and from it
2019-02-14 14:07:05 -08:00
Sebastian Ullrich
7cffe6935e feat(frontends/lean/vm_elaborator): port to new runtime 2019-02-14 14:07:05 -08:00
Leonardo de Moura
6083bde3bc chore(tests/playground/deriv): add example for testing in the playground 2019-02-14 10:49:46 -08:00
Leonardo de Moura
b6d1506434 fix(tests/compiler/t2): pause at the end
@kha I figured out why we had a long pause in the end of this benchmark
when using `11` instead of `9`. The function `deriv` was computing
`d := d "x" f` (the expensive computation), printing the size of `f` and
returning `d`. So, in the last step we were quickly printing the size
of the input 40230090 (when using `nest deriv 11 f`), and then computing
`d := d "x" f` which returns an object of size 374429936 which is never
used for anything.
That is, the pause had nothing to do with memory deallocation. I found
this issue after I implemented the deferred free feature which did not
fix the pause :)
2019-02-14 10:44:59 -08:00
Leonardo de Moura
03d5ac2a3c feat(runtime): add LEAN_DEFERRED_FREE compilation option
It prevents the runtime from performing arbitrarily long pauses when
invoking `del`.
2019-02-14 10:40:10 -08:00
Leonardo de Moura
1716f1f6c9 test(tests/playground/perf): performance test
On my macbook,
- with default kind STHeap: 3.15 secs
- with default kind MTHeap: 3.75 secs

@cc kha
2019-02-14 08:43:04 -08:00
Wojciech Nawrocki
1c7ee616a2 fix(src/CMakeLists): sanitize regex 2019-02-13 20:14:52 -08:00
Leonardo de Moura
6f852cf7af feat(tests/playground): add run.sh script for running tests
@kha I have added `timeit` for running experiments for the paper.
We have to be careful because `timeit` may produce incorrect results
due to compiler optimizations (e.g., ground term extraction).
Here are examples that do not produce the result we expect:

```
def main : io uint32 :=
timeit "tst" (io.println' ("result " ++ to_string (tst 1000000))) *>
pure 0
```

```
def main (xs : list string) : io uint32 :=
timeit "tst" (io.println' ("result " ++ to_string (tst xs.head.to_nat))) *>
pure 0
```
2019-02-13 17:17:14 -08:00
Leonardo de Moura
b722885137 feat(library/init/io): add unsafe_io and timeit 2019-02-13 16:59:24 -08:00
Leonardo de Moura
19e111c2ff feat(library/compiler): allow main function to also have type io uint32 2019-02-13 16:29:10 -08:00
Leonardo de Moura
06bb9b7ea8 test(tests/compiler): add simple test for expr 2019-02-13 16:22:01 -08:00
Leonardo de Moura
9cb2005e8e feat(library/init/lean): add hash functions and dbg_to_string 2019-02-13 16:19:25 -08:00
Leonardo de Moura
6ccdd18260 feat(library/compiler/emit_cpp): initialize the whole system if main module depends directly/indirectly of lean. declarations 2019-02-13 16:16:43 -08:00
Leonardo de Moura
b89eb64cf1 refactor(library/init/lean/expr): use native constructors 2019-02-13 15:07:49 -08:00
Leonardo de Moura
811a480d77 feat(kernel/expr): low level API for expr 2019-02-13 14:59:18 -08:00