Commit graph

9613 commits

Author SHA1 Message Date
Leonardo de Moura
c75387b5d3 chore(util/lean_obj): style 2018-04-24 15:23:53 -07:00
Leonardo de Moura
118c909504 feat(frontends/lean/elaborator,library/type_context): fine grain unifier approximation control
Now, the elaborator only uses the quasi-pattern unifier approximation
for inferring the implicit motive in recursor-like applications.

This change was motivated by counterintuitive behavior associated with
this approximation. For example, before this commit

```
variables {δ σ : Type}

def ex1 : state_t δ (state_t σ id) σ :=
monad_lift (get : state_t σ id σ) -- doesn't work

def ex2 : state_t δ (state_t σ id) σ :=
do s ← monad_lift (get : state_t σ id σ), -- works
   return s
```

The first one doesn't work because when we elaborate
`@monad_lift ?m ?n ?c ?α (get : state_t σ id σ) : ?n ?α`
with expected type `state_t δ (state_t σ id) σ`
It first produces the following unification problem by processing
matching the inferred type with the expected one.
```
?n ?α =?= state_t δ (state_t σ id) σ
==> (approximate using first-order unification)
?n := state_t δ (state_t σ id)
?α := σ
```

Then we try to solve
```
?m ?α =?= state_t σ id σ
==> instantiate metavars
?m σ =?= state_t σ id σ
==> (approximate since it is a quasi-pattern unification constraint)
?m := λ σ, state_t σ id σ
```

Remark: the constraint is not a Milner pattern because `σ` is in
the local context of `?m`. By assuming it is a Milner pattern,
we are ignoring the other possible solutions:
```
?m := λ σ', state_t σ id σ
?m := λ σ', state_t σ' id σ
?m := λ σ', state_t σ id σ'
```

We need the quasi-pattern approximation for elaborating recursors.
So, this commit enable this kind of approximation only when
elaborating recursors and executing induction-like tactics.

If we had used first-order unification, then we would have produced
the right answer: `?m := state_t σ id`

Haskell would solve this example since it always uses
first-order unification during elaboration.

The second one works because when we elaborate
`monad_lift (get : state_t σ id σ)`, the expected type is `state_t δ (state_t σ id) ?α`.
So, `?m ?α =?= state_t σ id σ` will not considered to be a quasi-pattern
since `?α` is not yet assigned to a local constant.

We are not fully confident this commit produces a better user
experience. We know that

- Full higher-order unification (used in Lean2) produces a combinatoric
explosion, and generates a lot of non-termination in complex type class
hierarchies (monad library, has_coe, etc). The problem is that
higher-order unification manages to create new solutions that we
cannot find using first-order unification.

- Lean3 is more reliable than Lean2 for elaborating monadic code because
 it does not use higher-order unification.

- For elaborating recursor-like applications, we need at least the
quasi-patterns. We need it when trying to infer the implicit
motive. First-order unification works poorly in this case.  Note that
the lack of higher-order unification in Lean3 forces us to provide the
motive explicitly for terms that Lean2 can elaborate.

- We need quasi-patterns for solving unification constraints in the
induction-like tactics. Similar to the previous item. We use it to infer
the motive. (edited) I will try to disable the quasi-pattern
approximation when elaborating regular applications. At least, we will
behave like Haskell for this kind of application.
2018-04-24 15:09:19 -07:00
Leonardo de Moura
055518bacf feat(util/lean_obj): remove lean_string
We don't need anymore since we removed the field `m_length`.
We can use lean_sarray for implementing them.
2018-04-23 08:54:39 -07:00
Leonardo de Moura
49dbcfb1ac fix(util/lean_obj): static assertion is not supported on Clang
g++ 4.9 can check it statically, but clang++ fails (at least on OSX).
2018-04-20 11:28:45 -07:00
Leonardo de Moura
5cac9ee01d feat(util/lean_obj): add static_assert's to make the assumptions used in the object GC explicit 2018-04-20 11:16:58 -07:00
Sebastian Ullrich
a7688a10b8 feat(frontends/lean/definition_cmds): elaborate a def's type separately when explicit return type is given 2018-04-20 09:59:09 -07:00
Leonardo de Moura
ccc433876e feat(util/lean_obj): develop lean_obj 2018-04-19 17:53:03 -07:00
Leonardo de Moura
3a93106596 feat(util/lean_obj): new objects for code extraction, virtual machine and implementing Lean itself
We will implement: format, name, options, level, expr, ... using this module.
2018-04-18 15:50:14 -07:00
Leonardo de Moura
70b181d88f fix(library/type_context): unifier failed to solve ?m =?= fun x_1 ... x_n, ?m x_1 ... x_n
Before this commit, the unifier would try to solve the unification consraint

     ?m =?= fun x_1 ... x_n, ?m x_1 ... x_n

by assigning

     ?m := fun x_1 ... x_n, ?m x_1 ... x_n

which fails the occurs check.

This commit skips the assignment by using eta-reduction.
2018-04-16 14:27:20 -07:00
Leonardo de Moura
008b7b2ac2 fix(library/noncomputable): bug at is_noncomputable
In Lean4, the check should be based on the compiler.
That is, a definition should be marked as noncomputable when we cannot
generate code for it.
2018-04-16 14:26:37 -07:00
Leonardo de Moura
d60ce19099 fix(library/type_context): improve is_def_eq_args 2018-04-16 14:26:05 -07:00
Leonardo de Moura
a241bd3328 chore(kernel/type_checker): remove dead code 2018-04-12 16:43:11 -07:00
Leonardo de Moura
5b530f24aa chore(library/parray): style 2018-04-12 16:43:11 -07:00
Leonardo de Moura
3d9c0ab277 fix(library/parray): bug introduced when memory_pool was removed 2018-04-12 16:43:11 -07:00
Leonardo de Moura
1e11611388 chore(library): cleanup constants.txt 2018-04-12 16:43:11 -07:00
Leonardo de Moura
8b8c2ddf37 chore(library/app_builder): remove dead code 2018-04-12 16:43:11 -07:00
Leonardo de Moura
a41ad717ed chore(library/tactic/algebraic_normalizer): remove dead code
This is going to be implemented in Lean.
2018-04-12 16:43:11 -07:00
Leonardo de Moura
4b6583ae9f refactor(util): move mpz/mpq to util
The new lean_obj objects will be defined at util.
Reason: we will define `name`, `options`, `format`, ... on top of lean_obj.
lean_obj depends on mpz.
Remark: lean_obj will replace vm_obj.
2018-04-12 16:43:11 -07:00
Leonardo de Moura
74f10fdf5c chore(numerics): remove numeric_traits
numeric_traits is dead code. It was used to implement a simplex that was
parametric on the number type. This code has been moved to Z3.
So, we don't need it anymore.
2018-04-12 16:43:11 -07:00
Leonardo de Moura
3e4594d6be chore(library/shared_environment): remove dead file 2018-04-12 16:43:11 -07:00
Leonardo de Moura
aa39591be5 chore(library/ac_match): remove dead file 2018-04-12 16:43:10 -07:00
Leonardo de Moura
d1cdae9d90 chore(util/sequence): remove dead code 2018-04-12 16:43:10 -07:00
Leonardo de Moura
efb9fb0802 chore(kernel): remove opportunistic hash consing support
It just adds extra complexity and is in conflict for our plans for
Lean4. Moreover, in our experiments it impacts negatively on
performance: master and lean4 branches. The negative impact has been
confirmed by @kha too.
2018-04-12 16:43:10 -07:00
Leonardo de Moura
39ef7aeee2 chore(util): remove memory_pool
memory_pool object introduces memory contention and unnecessary
complexity. Moreover, it actually reduces performance when we compile
Lean using JEMALLOC.

Here are the numbers for corelib

jemalloc with memory_pool:    13.83 secs
jemalloc without memory_pool: 13.60 secs
2018-04-12 16:43:10 -07:00
Leonardo de Moura
1dd7165694 chore(util): remove dead code 2018-04-12 16:43:10 -07:00
Leonardo de Moura
db4b00c7d8 chore(util,library): remove small_object_allocator
We use small_object_allocator to allocate vm_obj's.
However small_object_allocator is not thread safe. So, we need to copy
vm_obj's between threads. Moreover, in our experiments, we observed that
JEMALLOC is actually faster than the small_object_allocator.

Here are numbers for the reduced corelib.

small_object_allocator:  15.62 secs
gcc 4.9 allocator:       16.19 secs
jemalloc:                13.83 secs
2018-04-12 16:43:10 -07:00
Leonardo de Moura
4c14668bf0 chore(util/lru_cache): remove dead code 2018-04-12 16:43:10 -07:00
Leonardo de Moura
1465b58369 chore(library): remove arith_instance
It was used by norm_num. We don't need it anymore.
2018-04-12 16:43:10 -07:00
Leonardo de Moura
e3c1f6c7da chore(util/numerics): remove more leftovers from Lean1 2018-04-12 16:43:10 -07:00
Leonardo de Moura
d22ce2a335 chore(util/polynomial): remove leftover from Lean1 2018-04-12 16:43:10 -07:00
Leonardo de Moura
09baa982e6 chore(util/numerics): leftover from when we had Lua bindings 2018-04-12 16:43:10 -07:00
Leonardo de Moura
46b0fd35ec chore(util/numerics): remove Z/pZ field
This abstraction was added when we started Lean.
We wanted to focus on nonlinear arithmetic and support dReal.
The zpz module was going to be used to implement polynomial
factorization procedures similar to the ones in Z3 and computer algebra
systems.

This is not a goal for the Lean project anymore.
2018-04-12 16:43:10 -07:00
Leonardo de Moura
ee3589d99c chore(util/numerics): remove float/double
These two abstractions were added when we planned to have an efficient
Simplex module, written in C++, in Lean. We have moved this module to
Z3. So, we don't need these abstractions anymore.
2018-04-12 16:43:10 -07:00
Leonardo de Moura
e938a75361 chore(util/numerics): remove binary rationals
Binary rationals were added when we started the Lean project.
We wanted to use them to implement an algebraic number module similar to the
one we implemented in Z3.
If one day we implement algebraic numbers in Lean, we will do it in Lean
instead of C++.
2018-04-12 16:43:10 -07:00
Sebastian Ullrich
2b1e207e02 chore(shell/CMakeLists): disable leanpkg tests 2018-04-12 13:54:49 +02:00
Leonardo de Moura
429edd7a5e fix(frontends/lean/definition_cmds): fixes #1956 2018-04-11 16:48:04 -07:00
Leonardo de Moura
ee8a79a270 chore(*): remove C API 2018-04-10 16:48:02 -07:00
Leonardo de Moura
e1322491c5 chore(*): remove discr_tree 2018-04-10 16:31:55 -07:00
Leonardo de Moura
ce0467638e chore(*): remove unification hints 2018-04-10 16:29:04 -07:00
Leonardo de Moura
10ddfdafbd chore(*): remove VM monitor 2018-04-10 16:08:47 -07:00
Leonardo de Moura
1b1495aea4 chore(*): remove norm_num 2018-04-10 15:59:29 -07:00
Leonardo de Moura
6234c60aae chore(*): disable test suite 2018-04-10 12:56:55 -07:00
Leonardo de Moura
47cd2ee61a chore(leanpkg): delete 2018-04-10 12:43:17 -07:00
Leonardo de Moura
b14d69b1d7 chore(*): remove converter, ac_tactics, hole_commands, rbtree/rbmap proofs, bitvec 2018-04-10 12:25:51 -07:00
Leonardo de Moura
a2f0bf7c1b chore(*): disable SMT tactic framework and backward chaining 2018-04-10 12:05:51 -07:00
Leonardo de Moura
d36b859c65 chore(library/delayed_abstraction): add missing 'virtual' 2018-04-09 17:07:57 -07:00
Leonardo de Moura
c08a3bc557 refactor(library/typed_expr): move typed_expr to frontends/lean 2018-04-09 15:25:40 -07:00
Leonardo de Moura
bcaa0b2ad3 refactor(library/typed_expr): do not use macros for implementing typed_expr
Remark: in Lean4, we will not have macro_defs.
2018-04-09 15:16:46 -07:00
Leonardo de Moura
8dd53cd94f chore(*): rename expr_struct_* to expr_*
We don't need to modifier `_struct` anymore since we don't use the
pointer equality based hashtables anymore.
2018-04-09 12:55:48 -07:00
Leonardo de Moura
faf8e025e7 chore(kernel): remove m_hash_alloc field from expressions
This field was originally added to create hashtables based on pointer
equality. We don't use them anymore, and the caches based on
m_hash_alloc can be implemented using m_hash without any performance
impact. This commit also fixes two places where `expr_set` was used
instead of `expr_struct_set`.

This commit is also important for the Lean4 plans where `expr` will
be implemented in Lean, and fields like `m_hash_alloc` would require us
to track state.
2018-04-09 10:05:56 -07:00