Commit graph

16309 commits

Author SHA1 Message Date
Leonardo de Moura
240ca3fc68 test(tests/playground/badupdate1): add test for exposing performance bug at struct_cases_on_fn
```
./run.sh badupdate1.lean 4000
8000
test1 2.12s
8000
test2 1.11ms
```
2019-04-26 15:04:39 -07:00
Leonardo de Moura
3c52183e3c fix(library/compiler/struct_cases_on): bug 2019-04-26 15:04:16 -07:00
Leonardo de Moura
c6d0083456 fear(library/init/data/array/basic): add Array.modify 2019-04-26 14:41:17 -07:00
Leonardo de Moura
1a1105b533 test(tests/playground/lazylist): perf tests 2019-04-26 13:12:39 -07:00
Leonardo de Moura
a5128484a1 test(tests/playground/lazylist): perf tests 2019-04-26 12:05:16 -07:00
Leonardo de Moura
07a68375f5 chore(library/init/lean/compiler/ir): style 2019-04-26 09:15:37 -07:00
Leonardo de Moura
5c7849a869 feat(runtime): eager heap initialization 2019-04-25 18:10:36 -07:00
Leonardo de Moura
9a39eb254a chore(tests/playground): fix tests 2019-04-25 16:48:06 -07:00
Leonardo de Moura
9fb404353e test(tests/playground/lazylist): add cycle 2019-04-25 11:04:04 -07:00
Leonardo de Moura
c8a045d69f test(tests/playground/parser/parser): add HasAndthen and HasOrelse instances 2019-04-24 14:05:45 -07:00
Leonardo de Moura
abaf181495 refactor(core): homogeneous andthen
The motivation is to make sure `andthen` and `orelse` are both
homogeneous.
2019-04-24 14:00:34 -07:00
Leonardo de Moura
69e46881cb feat(library/init/control/alternative): more general HasOrelse class 2019-04-24 14:00:20 -07:00
Leonardo de Moura
865bb8df97 chore(README): update 2019-04-24 11:40:46 -07:00
Leonardo de Moura
014c7e3374 test(tests/playground/parser/parser): "liftable" longestMatch
For lists of size 0, 1 and 2, it avoids the overhead of creating
temporary lists of closures. I measure the overhead with `test1.lean`
and there is no overhead in this case.
`test1.lean` has a test for length = 4, and the overhead is 7%.
We only use longestMatch to implement the Pratt Parser.
The lists should be small. So, the overhead is acceptable.
If it is not. We can add back the `longestMatch` specific for `TermParser`.

cc @kha
2019-04-24 11:23:06 -07:00
Leonardo de Moura
5991337279 test(tests/playground/parser/test1): add test and timeit 2019-04-24 11:20:44 -07:00
Leonardo de Moura
5188adc685 test(tests/playground/parser): add longestMatch and other helper functions 2019-04-23 17:29:38 -07:00
Leonardo de Moura
3d8c3d5789 test(tests/playground/parser/parser): add unicodeSymbol parser 2019-04-23 09:34:41 -07:00
Leonardo de Moura
7c0f3aef5b feat(library/init/data/rbmap/basic): add RBMap.empty 2019-04-23 09:14:54 -07:00
Leonardo de Moura
cac080f504 test(tests/playground/mapVShmap): use {x with ...} notation in the test 2019-04-22 13:42:53 -07:00
Leonardo de Moura
f222dc7cca feat(library/compiler): destructive updates for {x with ...} expressions 2019-04-22 13:35:11 -07:00
Leonardo de Moura
ee0851921b fix(library/compiler/csimp): missing simplification opportunity 2019-04-22 13:15:08 -07:00
Leonardo de Moura
32f41f60d3 feat(runtime/object): add dbgTraceIfShared primitive for debugging RC reuse issues 2019-04-19 16:26:45 -07:00
Leonardo de Moura
363f7dc6f4 test(tests/playground/mapVShmap): add example where hmap is almost 3x faster than map 2019-04-19 14:52:52 -07:00
Leonardo de Moura
e844afb64a test(tests/playground/parser/syntax): propagate lazy macro scopes 2019-04-19 14:52:52 -07:00
Leonardo de Moura
b1503f2c56 perf(library/init/data/array/basic): remove inefficient mforeachAux and add new hmmap and hmap
The `mforeachAux` function was keeping two references to the array
because it was implemented using `miterate a ⟨a, rfl⟩ ...`
Thus, we would have to allocate a new array even if `a` was not shared.

Another issue is that when invoking `x ← f i v`, the array would still
have a reference to `v`, and consequently `RC(v) > 1`, and `f` would not
be able to perform destructive updates to `v` or reuse its memory cell.

Thus, I removed `mforeach` (we only used it to implement `hmap`: the
homogeneous map), and implemented a new `hmap` which makes sure
destructive updates can be performed modulo the issue with float `let`
inwards I described in the previous commit.

@kha I found the problem described in the previous commit when I was
using `Array.hmap`. If we use `Array`s to implement `Syntax` as we discussed,
then a `hmap` that does not prevent destructive updates from happening is
a must-have. Otherwise, any benefit we get from using `Array`s instead
of `List`s is gone.
2019-04-19 14:52:52 -07:00
Leonardo de Moura
b76deb4f0d fix(tests/playground/parser/syntax): another issue with float let inwards
@kha I keep finding problems with the float `let` inwards
transformation. It is always a nasty interaction between this
transformation and the `reset/reuse` insertion procedure.

The example I used in the new comment can be modified to a
`casesOn` with more than one branch (e.g., `Option.casesOn`).
Suppose we wrote
```
let o : Option Nat := Array.index a i in
let a              := Array.update a i none in
Option.casesOn o
  none
  (fun n, some (Array.update a i (some (n + 1))))
```
In the example above, the compiler will float
`a := Array.update a i none` inwards.
```
let o : Option Nat := Array.index a i in
Option.casesOn o
  none
  (fun n,
   let a := Array.update a i none in
   some (Array.update a i (some (n + 1))))
```
Then, adding reset/reuse:
```
let o : Option Nat := Array.index a i in
Option.casesOn o
  none
  (fun n,
   let o := reset o in
   let a := Array.update a i none in
   let n := n + 1 in
   let o := reuse o (some n)
   some (Array.update a i o))
```
Similarly to the example in the new comment, the `reset o` will fail since
the array `a` would still have a reference to `o`.

Remarks:
- Haskell also implements float `let` inwards.
- I am not sure how important the float `let` inward transformation is.
- I can see other nasty interactions after we implement user-defined
  simplification rules. For example, I guess many users would find the
  following lemma to be a good rewriting rule:
  ```
  (Array.update (Array.update a i v) i w) = (Array.update a i w)
  ```
  However, if we use this lemma in the example above, then `Array.update a i none` will be eliminated,
  and `reset o` will fail.
2019-04-19 14:52:52 -07:00
Leonardo de Moura
549b07a815 chore(library/init/data/array/basic): missing [inline] 2019-04-19 14:52:52 -07:00
Leonardo de Moura
62b8954ec4 chore(library/init/data/array/basic): heterogeneous Array.mmap 2019-04-19 14:52:52 -07:00
Leonardo de Moura
6659836734 chore(tests/playground): fix tests 2019-04-18 17:29:49 -07:00
Leonardo de Moura
d22debefe3 fix(library/compiler/csimp): move to branch optimization
@kha The move `x := val` to `casesOn` branch was producing nasty
problems. I documented the issue, and implemented a simple
and sufficient condition for preventing the problem. The approach is very
similar to the one used at `push_proj_fn` at `llnf.cpp`.
I hope this change will not impact existing benchmarks :)
2019-04-18 16:34:08 -07:00
Leonardo de Moura
35d54c17bd chore(library/compiler): remove [inline2] attribute
We may add it back in the future if we find compelling applications for
it. Right now, we don't have any.
2019-04-18 13:24:20 -07:00
Leonardo de Moura
2eed00039a chore(tests/playground/parser/parser): remove Thunk hack
The artificial `Thunk` was being used just to make sure a `Parser`
object was small enough to be inlined. We don't need this hack anymore.
Commit 0ea944a adds a new transformation that makes sure the size of
field `info` does not impact the decision on whether field `fn` will be
inlined or not.
2019-04-18 13:18:31 -07:00
Leonardo de Moura
0ea944ad9f feat(library/compiler/csimp): add transformation to complement eager lambda lifting 2019-04-18 13:12:11 -07:00
Leonardo de Moura
e3dfc73b3a chore(tests/playground/deriv): fix test 2019-04-17 18:12:08 -07:00
Leonardo de Moura
89874edc14 feat(library/compiler/eager_lambda_lifting): lift selected lambdas 2019-04-17 18:10:21 -07:00
Leonardo de Moura
2b4ef62323 fix(library/compiler/eager_lambda_lifting): preserve binding_info
`specialize.cpp` needs this information
2019-04-17 18:07:08 -07:00
Leonardo de Moura
4bbecf93ed fix(library/compiler/eager_lambda_lifting): assertion violation 2019-04-17 18:02:48 -07:00
Leonardo de Moura
c4dc338d7d feat(library/compiler): add eager_lambda_lifting skeleton
The current commit only detects lambda expressions that should be
lifted eagerly.

@kha I added a comment describing why this optimization is useful.
Right now, we are not writing code that benefits from this optimization,
but it seems very useful for implementing combinators that return
a tuple containing functions. I think this is a useful idiom, for
example, the combinator may have two parts: one that is the actual
action, and another that collects "static properties".
Last summer, if I remember correctly, you considered building this
kind of combinator for the new Lean parser, but gave up because we
did not have compiler support for it. In your case, the "static
property" would be the set of tokens. It could also contain the left
most token for initializing the Pratt parser table, etc.
This commit is the first step to make this kind of code efficient.
It will also improve the experiment at `tests/playground/parser/`
2019-04-17 14:18:47 -07:00
Leonardo de Moura
ad2e7a2d60 chore(library/compiler/specialize): remove dead code
In LCNF, a type `ty` at `let x : ty := v in t` must not be irrelevant.
2019-04-17 08:11:39 -07:00
Leonardo de Moura
d662f312df fix(library/compiler/util): loose bvars 2019-04-17 07:57:30 -07:00
Leonardo de Moura
f12e580ac2 chore(library/compiler/csimp): compilation error in debug mode 2019-04-17 07:41:48 -07:00
Leonardo de Moura
32a309c566 fix(library/compiler/specialize): make sure specialize generates valid LCNF 2019-04-17 07:34:42 -07:00
Leonardo de Moura
5e9f2e4e6a chore(library/compiler/specialize): remove leftover that is now a noop 2019-04-17 07:14:35 -07:00
Leonardo de Moura
8612c1ecae chore(library/compiler/util): add debugging helper function 2019-04-16 17:12:09 -07:00
Leonardo de Moura
6b53700d60 test(tests/playground/parser/test1): improve 2019-04-13 08:15:56 -07:00
Leonardo de Moura
a716528067 fix(tests/playground/parser/parser): reset position 2019-04-13 08:07:29 -07:00
Leonardo de Moura
68e8faeef1 test(tests/playground/parser/parser): add sepBy and sepBy1 2019-04-13 07:56:35 -07:00
Leonardo de Moura
52fa06ad38 fix(tests/playground/parser/parser): fix tryFn 2019-04-13 07:36:48 -07:00
Leonardo de Moura
2377b10c2c test(tests/playground/parser): minor 2019-04-12 09:05:22 -07:00
Leonardo de Moura
52b72c85bf fix(library/init/data/array/basic): typo 2019-04-12 09:03:20 -07:00