Commit graph

483 commits

Author SHA1 Message Date
Leonardo de Moura
b23251fd6e feat(library/compiler/lambda_lifting): preserve join points when performing lambda lifting 2018-11-01 16:04:25 -07:00
Leonardo de Moura
e11fe27de2 chore(library/compiler/lambda_lifting): temporary hack
Make sure that a join point that has been lambda lifted is not tagged as
a join point anymore.
2018-11-01 15:21:14 -07:00
Leonardo de Moura
f27ab2bb38 chore(library/compiler/emit_bytecode): remove dead code 2018-11-01 14:21:20 -07:00
Leonardo de Moura
f22bdec775 feat(library/vm): add support for join-points in the old VM
Motivation: to make progress in the new compiler stack, we have
to preserve join points during lambda lifting. Right now, they are
lifted as regular lambdas. So, to keep them, we need some basic
support for them in the old VM. The implementation here is quick and
dirty. This is not an issue since this code will be deleted soon.
2018-11-01 14:07:59 -07:00
Leonardo de Moura
ae30b16f0d fix(library/compiler/lcnf): nat.zero ==> literal 2018-11-01 11:59:17 -07:00
Leonardo de Moura
5d89347241 feat(library/compiler/llnf): improve memory cell reuse heuristic 2018-10-31 14:44:33 -07:00
Leonardo de Moura
e21608d456 chore(library/compiler/csimp): style 2018-10-31 13:25:54 -07:00
Leonardo de Moura
e68372cfd9 fix(library/compiler/csimp): another join point related bug 2018-10-31 13:22:20 -07:00
Leonardo de Moura
39c2ee2931 chore(library/compiler/llnf): typo 2018-10-31 13:22:14 -07:00
Leonardo de Moura
12a01d101c refactor(library/compiler/llnf): memory cell reuse instruction set 2018-10-31 09:35:22 -07:00
Leonardo de Moura
67a78d1c76 chore(library/compiler/llnf): cleanup 2018-10-31 08:36:09 -07:00
Leonardo de Moura
d98a1d1da3 feat(library/compiler/llnf): refine reset operation placement
This is not a perfect solution yet. I have identified two problems:
1) The heuristic used at `mark_to_reset_fields` is too weak.
   Suppose we have
   ```
      let ...
          _x := prod.mk field_1 0
      in some _x
   ```
   The current implementation will mark `field_1` to be reset since it
   occurs in a non tail call `prod.mk field_1 0`. However, we can
   assume `prod.mk field_1 0` is part of the return value.

2) The current semantics of the reset instruction may produce
   unnecessary memory allocation. Consider the following example
   ```
   let _x_1 := x.1,
       _x_2 := x.2,
       _x_3 := _reset.2 x
   in @bool.cases_on y
      (_cnstr.0.0)
      (let _x_4 := f _x_2,
       in _updt.2 _x_3 _x_4)
   ```
   The memory cell `_x_3` is only used in the second branch of
   the `bool.cases_on`. So, if `y` is `ff`, and `x` is a shared
   object, we will allocate memory at `_reset.2 x` for nothing.
2018-10-30 17:34:36 -07:00
Leonardo de Moura
b6bc0bb284 feat(library/compiler/llnf): add reset.idx obj primitive
The idea is to make it clear the intent, and simplify the IR conversion.
2018-10-30 13:48:09 -07:00
Leonardo de Moura
5c3639a5c0 feat(library/compiler/llnf): avoid unnecessary resets 2018-10-30 13:32:50 -07:00
Leonardo de Moura
8527fdc338 refactor(library/compiler/llnf): memory reuse optimization 2018-10-30 10:28:56 -07:00
Leonardo de Moura
bcc4956ca5 feat(library/compiler/llnf): reuse constructor memory cells
This commit also add two new instructions to the old VM: `updt` and
`updt_cidx`.
They allow us to test the new new memory reuse technique.

TODO: We need to reset fields after we project. Otherwise, we prevent
destructive updates on nested objects.
2018-10-29 18:46:26 -07:00
Leonardo de Moura
998293b8ca feat(library/compiler/llnf): eliminate cases term where all reachable branches are equal 2018-10-29 14:57:37 -07:00
Leonardo de Moura
91b59a2f12 fix(library/compiler/extract_closed): do not extract is_enf_unreachable 2018-10-29 14:41:12 -07:00
Leonardo de Moura
c076ac8e1a feat(library/compiler/llnf): remove identity cases terms
Example: a term such as
```
decidable.cases_on t _cnstr.0.0 _cnstr.1.0
```
is replaced with `t`
2018-10-29 14:29:03 -07:00
Leonardo de Moura
c3d700ece1 feat(library/compiler/csimp): nat.succ x ==> x + 1 2018-10-29 13:53:59 -07:00
Leonardo de Moura
91022dd62e chore(library/compiler/llnf): style 2018-10-29 13:10:23 -07:00
Leonardo de Moura
d871c4f7d8 feat(library/compiler): replace simp_inductive with llnf 2018-10-29 13:07:46 -07:00
Leonardo de Moura
ca1e2d3d1d fix(library/compiler/llnf): typo and missing case 2018-10-29 13:05:09 -07:00
Leonardo de Moura
6fe50bd298 fix(library/compiler/llnf): missing mk_let 2018-10-29 11:48:14 -07:00
Leonardo de Moura
28c21b4340 fix(library/compiler/csimp): make sure constants (of arity 0) marked with [inline] or [inline_if_reduce] are inlined 2018-10-29 11:46:56 -07:00
Leonardo de Moura
388b4ea6ac feat(library/compiler/llnf): basic llnf module with support for unboxed types
TODO: support for reusing memory cells
2018-10-29 11:02:04 -07:00
Leonardo de Moura
28a34e798a feat(library/compiler/csimp): projection to field
The new test demonstrations this transformation.
2018-10-28 09:38:45 -07:00
Leonardo de Moura
6607720b5f feat(library/compiler/llnf): store offset and size for scalar fields 2018-10-27 17:27:53 -07:00
Leonardo de Moura
7a3fb4d32a feat(library/compiler/llnf): add updt_cidx 2018-10-27 17:16:09 -07:00
Leonardo de Moura
7dcc12ba6f feat(library/compiler/util): add is_runtime_builtin_cnstr 2018-10-27 17:09:12 -07:00
Leonardo de Moura
74b92cd419 feat(library/compiler/llnf): collect constructor info 2018-10-27 16:58:51 -07:00
Leonardo de Moura
a161eec8f2 feat(library/compiler): add llnf (low level normal form) skeleton 2018-10-27 12:36:30 -07:00
Leonardo de Moura
571be8616a refactor(library/compiler/erase_irrelevant): postpone simplification
Remove transformations such as
```
prod.cases_on M (\fun a b, t)
```
==>
```
let a := M.0 in
let b := M.1 in
t
```

We will perform this kind of transformation in a later stage.
2018-10-26 15:59:04 -07:00
Leonardo de Moura
76ba67a290 chore(library/compiler/simp_inductive): remove dead code 2018-10-26 15:02:34 -07:00
Leonardo de Moura
76b6188a3e chore(library/compiler/emit_bytecode): remove useless instruction
The VM based debugger was never used in practice.
2018-10-26 14:23:15 -07:00
Leonardo de Moura
f336dde4ef chore(library/compiler/simp_inductive): don't need type_checker::state 2018-10-26 14:16:06 -07:00
Leonardo de Moura
7d2a507824 fix(library/compiler/csimp): bug at move_to_entries 2018-10-25 17:07:31 -07:00
Leonardo de Moura
7ec00c97e9 feat(library/compiler/csimp): float all cases
Motivation: explicit control flow graph

TODO: disabled `split_entries` for now.
I believe the new feature exposed a bug at `move_to_entries`.
I will fix this new issue in another commit.
2018-10-25 15:41:11 -07:00
Leonardo de Moura
4ba3cc390f fix(library/compiler/specialize): assertion violation lean_assert(!has_fvar(code));
We were getting assertion violations when compiling corelib in debug
mode. There were two problems:

1- We were not capturing free variables occurring in types.
2- A paremeter could depend on a free variable associated with a let-declaration.
2018-10-25 13:23:43 -07:00
Leonardo de Moura
8175dab1a6 chore(library/compiler/csimp): remove leftover assertion used yesterday when debugging code 2018-10-25 12:55:25 -07:00
Leonardo de Moura
b18135a4c8 feat(library/compiler/csimp): cheap float cases 2018-10-25 11:15:21 -07:00
Leonardo de Moura
628b0c7919 feat(library/compiler): add [inline_if_reduce] attribute 2018-10-25 10:01:26 -07:00
Leonardo de Moura
a1798a2c24 feat(library/compiler/csimp): new joint point placement and preservation algorithm 2018-10-24 16:46:16 -07:00
Leonardo de Moura
5eaed3a21a chore(library/compiler/csimp): make sure local_ctx is monotonically increasing
We need this feature to implement the new join point management system
for csimp.
2018-10-24 08:55:00 -07:00
Leonardo de Moura
70746b499e chore(library/vm): remove BuiltinCases and NatCases instructions
They are not needed anymore.
2018-10-23 15:09:55 -07:00
Leonardo de Moura
3ee863da68 feat(library/compiler/erase_irrelevant): eliminate cases_on for builtin types 2018-10-23 14:58:38 -07:00
Leonardo de Moura
de1dc3be88 chore(library/vm): remove vm_array
We are currently not using arrays in the old VM.
2018-10-23 12:49:25 -07:00
Leonardo de Moura
d07f115f21 chore(library/compiler/util): fix style 2018-10-23 11:32:56 -07:00
Leonardo de Moura
17377c55f3 feat(library/compiler/extract_closed): create an auxiliary constant of arity 0 for constant with arity > 0
This transformation is useful for caching the construction of closures
at runtime. For example, consider the following piece of code
```
λ α a,
  @tree.cases_on a visit._main._lambda_1
    (λ a_a a_a_1 a_a_2,
       let _x_1 := visit._main  a_a,
           _x_2 := visit._main._lambda_5 a_a_1 a_a_2
       in bind._main     _x_1 _x_2)
```
where `visit._main._lambda_1` is of the form
```
visit._main._lambda_1 :=
λ _x, ...
```
At runtime, we will create a closure object for `visit._main._lambda_1`
since it has arity 1, but no arguments have been provided.
This commit implements a new transformation that creates an auxiliary
declaration with arity 0.
```
visit._main._closed_1 :=
visit._main._lambda_1
```
Its value is cached by the runtime. That is, the closure is created only
once.

@kha This optimizations reduces the number of closures by another 200k
at `parser1.lean`. We are now under 2million :)
2018-10-22 16:13:58 -07:00
Leonardo de Moura
01229425a2 feat(library/compiler/compiler): inline "small" stage2 declarations at csimp after erasure 2018-10-22 15:49:07 -07:00