Commit graph

5709 commits

Author SHA1 Message Date
Leonardo de Moura
ee0851921b fix(library/compiler/csimp): missing simplification opportunity 2019-04-22 13:15:08 -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
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
0ea944ad9f feat(library/compiler/csimp): add transformation to complement eager lambda lifting 2019-04-18 13:12:11 -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
bfbdddad1a fix(library/compiler/emit_cpp): initialization bug 2019-04-12 08:24:06 -07:00
Leonardo de Moura
da00dae9df fix(library/compiler/util): typo at has_inline2_attribute 2019-04-11 14:28:54 -07:00
Leonardo de Moura
7461bf9d1d fix(library/compiler/extract_closed): do not inline closed constants that have been extracted 2019-04-11 14:12:13 -07:00
Leonardo de Moura
b46f5f3eca fix(library/compiler/reduce_arity): bug at arity_was_reduced
It was retuning true for declarations such as
```lean
def f (n : Nat) :=
g._rarg n
```
It should only return true if the nested application is of the form
`f._rarg ...`
2019-04-11 14:12:13 -07:00
Leonardo de Moura
0c9fe3c7d4 feat(library/compiler): add [inline2] attribute, and stage2 inlining
This feature is useful since it allows us to perform inlining
after lambda lifting has been performed.
2019-04-06 08:00:58 -07:00
Leonardo de Moura
d3afb41f51 feat(library/compiler/lambda_lifting): add function detecting lambda_lifting aux declarations 2019-04-06 07:42:45 -07:00
Leonardo de Moura
c54589007e feat(library/compiler): extract closed terms after caching stage2 decls 2019-04-06 07:19:19 -07:00
Leonardo de Moura
50d2488946 fix(library/compiler/csimp): cases-merging was failing when scrutinee was a constant 2019-04-05 17:24:01 -07:00
Leonardo de Moura
1e198ca72e fix(library/compiler/csimp): missing optimization opportunity 2019-04-05 16:16:24 -07:00
Leonardo de Moura
7b835f3d02 feat(library/compiler/csimp): keep simplifying if cse and elim_dead_let reduced expression
Both `cse` and `elim_dead_let` may create new simplification opportunities for `csimp`.
2019-04-05 15:39:43 -07:00
Leonardo de Moura
6c44a5d997 feat(library/compiler/csimp): add Thunk.get (Thunk.mk f) ==> f () simplification 2019-04-05 14:55:48 -07:00
Leonardo de Moura
48fbaefa2a chore(library/constants.txt): remove leftover 2019-04-05 14:29:51 -07:00
Leonardo de Moura
994ca779ef feat(library/compiler/csimp): improve try_inline_instance 2019-04-05 14:16:38 -07:00
Leonardo de Moura
3d393d9b1d fix(library/compiler/csimp): bug introduced earlier today 2019-04-02 17:21:25 -07:00
Leonardo de Moura
6ab935ebf6 feat(library/compiler/csimp): merge equal casesOn branches 2019-04-02 11:06:07 -07:00
Leonardo de Moura
95ca283854 chore(library/compiler/csimp): remove m_proj2var, we can use m_var2ctor instead 2019-04-02 10:05:20 -07:00
Leonardo de Moura
005d62185d feat(library/compiler/csimp): add "case merging" optimization 2019-04-02 09:41:53 -07:00
Leonardo de Moura
12595fb501 feat(library/compiler/specialize): cache whenever possible
There were many opportunities for reusing previously specialized code at
stdlib
2019-03-29 15:21:17 -07:00
Leonardo de Moura
9d325515d4 chore(library/compiler/util): reduce term size if possible 2019-03-28 17:35:12 -07:00
Leonardo de Moura
8c58314b84 fix(library/compiler/csimp): lc_unreachable simplifications
The simplifications were introducing dangling free variables.
2019-03-28 17:32:41 -07:00
Leonardo de Moura
1ebdb9f1b1 fix(library/compiler): do not inline definitions using unsafe inductives
This commit also makes sure that `has_trivial_structure` returns false
for `unsafe` inductive datatypes.

See new test for further details.
2019-03-28 16:07:57 -07:00
Leonardo de Moura
427d3b4d40 chore(library/compiler/specialize): reduce stack consumption 2019-03-28 15:05:48 -07:00
Leonardo de Moura
4dbae58646 fix(library/equations_compiler): make sure _unsafe_rec auxiliary definitions contain all local constants used in the safe one
cc @kha
2019-03-28 12:57:15 -07:00
Leonardo de Moura
1f197b5293 feat(library/equations_compiler/unbounded_rec): check whether f._unsafe_rec and f have the same type
`f._unsafe_rec` is the auxiliary definition created by the equation
compiler to help the code generator to produce better code.
2019-03-28 12:39:44 -07:00
Leonardo de Moura
b74a9b63de feat(library/equations_compiler/partial_rec): improve base case synthesis 2019-03-28 10:19:57 -07:00
Leonardo de Moura
0161ef8487 fix(library/compiler/name_mangling): bug 2019-03-28 08:23:38 -07: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
9b47d134ae feat(library/equations_compiler/partial_rec): consider elements before : when constructing base case 2019-03-27 13:49:23 -07:00
Leonardo de Moura
a43a40b7f5 chore(library/init): remove fix.lean
`partial def` is much more general
2019-03-27 13:11:00 -07:00
Leonardo de Moura
62d7cc6b37 feat(library/init/wf): remove wf_term_hack 2019-03-27 12:41:16 -07:00
Leonardo de Moura
895bf2c91d feat(library/equations_compiler/partial_rec): try assumption if inhabitant could not be found 2019-03-27 12:24:24 -07:00
Leonardo de Moura
9a071c18e7 feat(library/equations_compiler): add support for partial definitions 2019-03-27 11:09:32 -07:00
Leonardo de Moura
ef5fac1481 chore(library/equations_compiler): add partial_rec skeleton 2019-03-27 08:37:59 -07:00
Leonardo de Moura
9ddc778ac3 feat(library/equations_compiler/equations): add m_is_partial to equation header 2019-03-26 16:18:43 -07:00
Leonardo de Moura
f1f2994781 chore(library/compiler/emit_cpp): update 2019-03-26 14:51:14 -07:00