Commit graph

15669 commits

Author SHA1 Message Date
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
Leonardo de Moura
e10240fe5c refactor(runtime/io): use extern "C" for io primitives 2019-02-13 11:21:29 -08:00
Leonardo de Moura
71f5290567 feat(kernel): expose level primitives 2019-02-13 10:37:13 -08:00
Leonardo de Moura
90260e005e feat(library/compiler/emit_bytecode): ignore unknown decls
cc @kha
2019-02-13 10:31:52 -08:00
Leonardo de Moura
4627929a83 refactor(boot,runtime,util): move name runtime implementation to util/name, and use "extern C" ABI 2019-02-13 08:27:23 -08:00
Leonardo de Moura
b3f0ce5355 fix(kernel/runtime): use extern "C" 2019-02-13 08:04:47 -08:00
Leonardo de Moura
6afad35aac feat(library/compiler): emit extern "C" for extern/foreign dependencies when needed 2019-02-13 07:58:06 -08:00
Leonardo de Moura
19b6a5d0d1 chore(kernel): builtin => runtime
We don't need builtin.h anymore
2019-02-13 07:56:14 -08:00
Leonardo de Moura
d4dce78b0e chore(library/compiler): delete compiler/builtin module
It has been replaced with `compiler/extern_attribute`
2019-02-12 18:23:09 -08:00
Leonardo de Moura
008ac698d7 chore(boot): update 2019-02-12 18:18:18 -08:00
Leonardo de Moura
456ed23cc2 feat(library/init): use extern when declarating nat primitives 2019-02-12 18:12:29 -08:00
Leonardo de Moura
532a51b152 chore(boot): update 2019-02-12 17:58:52 -08:00
Leonardo de Moura
f41e4dac72 fix(frontends/lean): must set m_gen_code = false for auxiliary declarations of extern declarations
We cannot check the `[extern]` attribute because the auxiliary
declarations are compiled before we even define the main declaration
and set the attribute.
We should consider a better design in the future where we first define
all auxiliary and main definitions, then set the attributes, and then
compile the code.

cc @kha
2019-02-12 17:52:06 -08:00
Leonardo de Moura
cd4b8c0c28 fix(library/equations_compiler/unbounded_rec): it was ignored m_gen_code flag 2019-02-12 17:48:11 -08:00
Leonardo de Moura
64a2742859 chore(boot): update 2019-02-12 16:11:49 -08:00
Leonardo de Moura
a82eab824a fix(library/compiler/emit_cpp): skip inline and adhoc extern declarations 2019-02-12 16:05:49 -08:00
Leonardo de Moura
52db59eb87 fix(library/init/data/int/basic): nasty bug at int.repr 2019-02-12 15:58:59 -08:00
Leonardo de Moura
0e98f6bd66 chore(boot): update 2019-02-12 15:48:44 -08:00
Leonardo de Moura
09d194d5b7 feat(library/compiler): emit external declarations
We only skip `inline` and `adhoc` externs.
2019-02-12 15:42:59 -08:00
Leonardo de Moura
4df56faf6a chore(boot): update 2019-02-12 14:11:36 -08:00
Leonardo de Moura
888252b5db feat(library/private): more deterministic private names 2019-02-12 14:00:24 -08:00
Leonardo de Moura
88de217cb7 chore(library/init): remove version.lean.in
We are currently not using this file. In the future, we should
reintroduce it, but its functions should be implemented as builtins.
Thus, every `chore(boot): update` commit will not have to update it.
2019-02-12 11:57:09 -08:00
Leonardo de Moura
c8e8fbf840 chore(boot): update after rebase 2019-02-12 11:49:49 -08:00