Commit graph

191 commits

Author SHA1 Message Date
Leonardo de Moura
229e4a25b3 refactor(library/init/array): implement mkArray in Lean, add allow mkEmpty to set initial capacity 2019-03-29 10:19:21 -07:00
Sebastian Ullrich
21f1d231b8 fix(runtime/object): do not return temporary borrowed reference from a builtin 2019-03-29 14:32:15 +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
ea3a38c5d3 chore(runtime/object): style 2019-03-27 14:08:10 -07:00
Leonardo de Moura
d536ee347d chore(runtime/object): remove fixpoint* primitives 2019-03-27 13:17:25 -07:00
Leonardo de Moura
4b83585103 chore(stage0, runtime): update stage0 and remove old String API 2019-03-26 15:51:13 -07:00
Leonardo de Moura
dd48d5ae18 feat(runtime/object): implement string primitives using Nat index 2019-03-26 15:27:14 -07:00
Leonardo de Moura
0d5ac5288a feat(runtime): increase small nat size
In 64-bit machines, the max small nat value should now be (2^63 - 1), and on 32-bit
machines (2^32 - 1).

The main motivation for this modification are the array indexing
operations. With the new representation, if a Nat index is not small,
then it must not be a valid index. This was not true in 64-bit
machines. Example: an array of size 2^33 would fit in memory, and but
an index `i` > 2^32 - 1 would not be a small nat value.
2019-03-26 14:21:03 -07:00
Leonardo de Moura
b0da4360d0 chore(runtime, library/init/data/string/basic): prepare to change String.Pos 2019-03-26 12:25:12 -07:00
Leonardo de Moura
d110a607fe fix(runtime/io): bug at IO.Ref primitives in multi-threaded mode 2019-03-23 09:06:04 -07:00
Leonardo de Moura
3202840959 fix(runtime/io): make IO.Ref thread-safe again
See new comment at `io.cpp`
2019-03-22 09:59:32 -07:00
Leonardo de Moura
452d5107ac chore(library/init/data/array): naming convention
The array read and write operations are now called:

- "Comfortable" version (with runtime bound checks):
  `Array.get` and `Array.set` like OCaml.
   It is also consistent with `Ref.get` and `Ref.put`,
   and `get` and `set` for `MonadState`.

- `Fin` version (without runtime bound checks):
  `Array.index` and `Array.update` like in F*.

- `USize` version (without runtime bound checks and unboxing):
  `Array.idx` and `Array.updt`.

cc @kha
2019-03-21 18:03:29 -07:00
Leonardo de Moura
a79b00d733 chore(runtime, stage0): update Ref primitive operation names 2019-03-21 16:43:54 -07:00
Leonardo de Moura
b8c786117c chore(runtime/allocprof): style checker 2019-03-21 15:11:05 -07:00
Leonardo de Moura
1da4782483 feat(runtime, library/init/io): add io.ref 2019-03-16 22:16:28 -07:00
Leonardo de Moura
b1c187f717 feat(library/compiler): allow io unit as main function result type
When `io unit` is used, we use `return 0` for `result.ok`, and `return
1` for `result.except`.
2019-03-16 16:05:45 -07:00
Leonardo de Moura
dcdeff1794 chore(runtime): remove dead file 2019-03-16 15:34:58 -07:00
Leonardo de Moura
6d0ec3a8c9 refactor(library/init/io): implement io monad using estate monad 2019-03-16 15:34:58 -07:00
Leonardo de Moura
0888dee25e chore(*): meta ==> unsafe 2019-03-15 15:04:40 -07:00
Leonardo de Moura
39dd079e37 feat(runtime): low tech allocation profiler
```
@[extern 4 "lean_io_allocprof"]
constant allocprof {α : Type} (msg : @& string) (fn : io α) : io α
```
2019-03-14 15:15:29 -07:00
Leonardo de Moura
562f530522 chore(runtime/io): use std::cerr 2019-03-14 11:04:12 -07:00
Leonardo de Moura
64e60f77b3 chore(runtime/object): remove dead code 2019-03-12 12:25:11 -07:00
Leonardo de Moura
b320452f70 chore(runtime/object): remove iterator primitives from runtime
They are now implemented in Lean.
2019-03-12 07:09:48 -07:00
Leonardo de Moura
cf3bbd7e25 feat(runtime): add utf8_prev and utf8_set
Next goal: implement string.iterator in Lean
2019-03-11 18:05:40 -07:00
Leonardo de Moura
ff3bf508aa feat(library/init/fix, runtime): add fixpoint2, ..., fixpoint6
The idea is to avoid allocating tuples when creating the fixpoint of
nary functions. For example, consider the new tests:
- tests/playground/fix.lean
- tests/playground/fix_with_tuples.lean

The second one (`fix_with_tuples`) uses the `fix` operator and tuples. For input = 20,
it creates more than 1 million extra objects. The first implementation
(`fix.lean`) using `fix₂` avoids this overhead.

TODO: Add support for pattern #N with N > 9 at
```
def expand_extern_pattern_aux (args : list string) : nat → string.iterator → string → string
```
2019-03-10 11:19:02 -07:00
Leonardo de Moura
4ca9c6f22e feat(runtime): add efficient fixpoint implementation 2019-03-10 10:09:57 -07:00
Leonardo de Moura
eb2633a5f2 fix(runtime/alloc): segment recycling 2019-03-09 13:42:55 -08:00
Leonardo de Moura
8f6998acac fix(runtime/alloc): we may deallocate in a new thread before we allocated anything 2019-03-09 13:20:06 -08:00
Leonardo de Moura
01b4983fa2 fix(runtime/object): string_utf8_extract 2019-03-09 12:57:51 -08:00
Leonardo de Moura
c862ce4a75 feat(runtime, library/init/data/string/basic): add utf8_pos
`utf8_pos` is a low level alternative for `string.iterator`.
TODO: implement `string.iterator` using it.
2019-03-09 12:30:19 -08:00
Leonardo de Moura
057d90b7ff chore(runtime/object): track number of external objects allocated 2019-03-07 12:31:05 -08:00
Leonardo de Moura
b5b2adea49 refactor(runtime): proper external objects without vtable
A C++ vtable at `external_object` is bad because it prevents users
from implementing external object in different programming languages.

Another problem was memory leaks because of the vtable in the
beginning of the object.

cc @kha
2019-03-07 10:26:05 -08:00
Sebastian Ullrich
1e248013f7 chore(runtime/alloc): don't init heap if LEAN_SMALL_ALLOCATOR is off
makes tracking down leaks a bit nicer
2019-03-07 15:52:06 +01:00
Leonardo de Moura
333ba43266 feat(runtime): statistics
We can enabled runtime statistics by using cmake option `-D RUNTIME_STATS`.

cc @kha
2019-03-05 16:01:06 -08:00
Leonardo de Moura
7051099997 fix(runtime/object): performance bug
The "quick" filter `&s1 != &s2` was incorrect.
It was actually always false, since it just comparing the stack address
of `s1` and `s2`.
I incorporated the quick filter into `string_eq`.

I measured the impact using `lean --new-frontend core.lean` and checking
the number of instructions executed reported by Valgrind.
Before: 5,210,225,530
After:  4,891,642,264

@kha
2019-03-04 12:23:12 -08:00
Leonardo de Moura
2a0f5186e8 fix(runtime/object): bug at array_push
Small object allocator was masking this bug.
2019-02-26 14:19:37 -08:00
Leonardo de Moura
5635057549 feat(runtime/object): improve m_queue 2019-02-26 09:15:00 -08:00
Leonardo de Moura
f2ef0eb597 fix(runtime/alloc): bug at import_objs 2019-02-26 07:34:26 -08:00
Leonardo de Moura
a9458fdcb3 chore(runtime/alloc): remove incorrect assertion 2019-02-26 07:33:53 -08:00
Leonardo de Moura
1f3de14f9c fix(runtime/object): embarrassing bug at del_core 2019-02-25 17:42:56 -08:00
Leonardo de Moura
3a252f5b55 chore(runtime/object): avoid overhead when SMALL_ALLOCATOR is disabled 2019-02-25 15:32:59 -08:00
Leonardo de Moura
66b55d9d12 chore(CMakeLists.txt): add options for enabling/disabling LAZY_RC and SMALL_ALLOCATOR 2019-02-24 15:11:48 -08:00
Leonardo de Moura
67d197a2e0 fix(runtime/object): correct support for objects without RC
Lean was not crashing because we do not have region objects yet, and
the persistent objects still have a RC.
2019-02-24 09:29:20 -08:00
Leonardo de Moura
935d90e77c chore(runtime/object): disable lazy RC to collect data at speedcenter 2019-02-23 17:37:11 -08:00
Leonardo de Moura
abd0f89820 feat(runtime): avoid extra switch 2019-02-23 17:35:21 -08:00
Leonardo de Moura
4b44c5ce36 feat(runtime/object): small object allocator 2019-02-23 17:17:56 -08:00
Leonardo de Moura
a9276c8834 fix(runtime/object): incorrect { 2019-02-23 17:16:49 -08:00
Leonardo de Moura
feea8ecccd feat(library/compiler/llnf): avoid inc/dec operations on persistent objects
inc/dec operations are noop's for persistent objects.
2019-02-18 20:22:18 -08:00
Leonardo de Moura
b752dd1984 fix(library/compiler/emit_cpp): mark global objects as persistent
They may be used by tasks, but they are not directly reachable from
task starting point.
2019-02-17 11:45:51 -08:00
Leonardo de Moura
8ac1a1969d fix(runtime/object): task.bind and task.map should also invoke to_mt 2019-02-17 11:11:41 -08:00