Commit graph

391 commits

Author SHA1 Message Date
Sebastian Ullrich
fea637288d fix(library/init/data/nat/basic,library/vm/vm_nat): regression in old compiler: primitive for nat equality was ignored
Improves parser performance by 26%
2018-09-14 16:33:04 -07:00
Leonardo de Moura
afd54039ab chore(library): remove >>, we should use *> 2018-09-12 17:31:21 -07:00
Leonardo de Moura
9e305a5f26 chore(library): remove return, we should use pure 2018-09-12 16:51:11 -07:00
Leonardo de Moura
4e6748b55b feat(library/init/data/rbmap/basic): add rbmap_core low level functions 2018-09-09 18:18:40 -07:00
Leonardo de Moura
5ae63ea1f2 chore(library/init/data/list/basic): remove unnecessary workaround 2018-09-07 17:10:23 -07:00
Leonardo de Moura
71dd8653bc feat(library/init/core): decidable_eq is a proper class
We need this to take advantage of the new indexing structure we are
going to add to improve performance.
2018-09-07 16:38:11 -07:00
Leonardo de Moura
c48eaed9a4 chore(library): remove relation_manager 2018-09-07 12:35:04 -07:00
Sebastian Ullrich
d4105e1e16 chore(library/init/lean/parser/basic): avoid nesting rbnode in trie
The new two-layer rbnode/list structure is a little faster
2018-09-05 10:37:03 -07:00
Leonardo de Moura
66adac6af6 chore(library/init): avoid calc at corelib 2018-08-27 12:17:30 -07:00
Sebastian Ullrich
80745ba776 chore(library/init/data/string/basic): rename string.iterator's next_to_string to remaining_to_string
The old name implied that `curr` was not part of its result
2018-07-05 10:42:37 +02:00
Sebastian Ullrich
9e51ff5580 feat(library/init/data/string/basic): add forward and is_prefix_of_remaining to iterator 2018-07-05 10:20:25 +02:00
Leonardo de Moura
0a5d5b9036 fix(library/init/data/list/basic): list.lt 2018-06-21 09:16:58 -07:00
Leonardo de Moura
70fc656931 refactor(library/init/data/nat/basic): remove nat.less_than_or_equal inductive predicate
We now define nat.le using (nat.ble : nat -> nat -> bool) function.
We will add builtin support for reducing `nat.ble` efficiently when the arguments are the to be added nat literals.
2018-06-14 11:30:09 -07:00
Leonardo de Moura
a7d08d2f3d feat(kernel/inductive/inductive): dependent elimination for inductive predicates
In Lean4, we will not generate non dependent recursors for inductive
predicates. The main goal is to make the shape of the automatically
generated recursors more uniform. The non uniform representation is
leftover from Lean2. In Lean2, we wanted to support different kernels
with different features. For example: we could create proof relevant
kernels, no impredicative universe, etc.
Recall that, in a kernel with an impredicative Prop and no proof
irrelevance, inductive predicates without dependent elimination are
weaker that inductive predicates with dependent elimination.
When proof irrelevance is enabled, we can generate the dependent
recursor from the non dependent one. Actually, the module drec.cpp
generates the dependent recursor.
Now, we only support one kind of kernel, and it doesn't make sense
anymore to generate non dependent recursors for inductive predicates.
This would only produce an unnecessary asymmetry on the inductive
datatype module.

Remark: we had to create non dependent recursors to help the elaborator.
This can be avoid if we improve the elaborator. I will do that in the
new elaborator implemented in Lean.

Remark: equation lemmas are broken for definitions that pattern match on
nested inductive datatypes. The problem is the super messy
`prove_eq_rec_invertible_aux` function. This function will not be needed
after I finish the new inductive datatype support in the kernel.

cc @kha
2018-06-12 13:03:26 -07:00
Leonardo de Moura
e9b4b811de chore(library/equations_compiler/util): disable generation of equational lemmas
@kha, `eqn_compiler.lemmas` is false by default.
I will keep them disabled until I remove the inductive compiler.
I'm building the new inductive datatype module (to replace the inductive
compiler), and the lemmas will fail to be proved in the next commits
until the transition is complete.
2018-06-12 13:03:25 -07:00
Leonardo de Moura
530c437953 feat(library/init/data/char/basic): missing theorems for equation compiler 2018-06-06 08:47:17 -07:00
Sebastian Ullrich
732c823646 feat(library/init/lean/parser): remove syntax_id, use De Bruijn indices instead 2018-06-06 15:36:28 +02:00
Leonardo de Moura
60339d6c87 feat(library/init/data/hashmap/basic): missing function 2018-06-04 19:58:24 -07:00
Leonardo de Moura
4d7ae73d39 feat(library/init/lean): add level 2018-05-22 09:45:18 -07:00
Leonardo de Moura
afd018d7cc chore(*): remove several tactics 2018-05-21 06:53:01 -07:00
Leonardo de Moura
032a101262 chore(*): remove more files
@kha I'm trying to remove as much as possible before I start
modifying `expr`
2018-05-21 06:42:58 -07:00
Leonardo de Moura
0955962f65 chore(*): remove some unnecessary files and tactics 2018-05-21 06:29:50 -07:00
Leonardo de Moura
0c785f8ab7 feat(library/init/data): add instances for has_repr (id A) and has_to_string (id A) 2018-05-10 17:37:57 -07:00
Leonardo de Moura
224fdc7a78 refactor(library/init/lean/ir): platform dependent IR
Motivation: in 64-bit machines, we can store boxed uint32 values as a
tagged pointer. In 32-bit machines, we need to allocated an object (like
Haskell) to store the uint32 value. So, the generated bytecode is quite
different in each platform.

This change also allow us to simplify the IR. Example: we don't need the
type `sizet` anymore.

Impact: To be able to bootstrap in both platforms,
we will have to store two versions of the generated code: 32 and 64
versions. In principle, we only need to store the 64-bit version,
and use cross-compilation to build the 32-bit version.
2018-05-10 13:15:02 -07:00
Leonardo de Moura
63bddd56d6 feat(library/init/data/rbmap,library/init/data/rbtree): add mfold and mfor for rbtree/rbmap 2018-05-09 15:38:57 -07:00
Leonardo de Moura
d85c30fde1 perf(library/init/data): mark usize, uint16, uint32 and uint64 as [irreducible]
Without these annotations, Lean will timeout when trying to synthesize
the type class instance `decidable_eq uint32`. The type class resolution
problem will produce the unification problem:
```
decidable (@eq uint32 a b) =?= decidable (@eq usize ?x ?y)
```
which Lean tries to solve by assigning `?x := a`.
During the assignment, the types of `?x` and `a` are unified with "full
force". Thus, we get the constraint
```
usize_sz =?= uint32_sz
```
which will take forever to be solved when peforming the computation in
unary arithmetic.

Remark: this commit also makes sure that `type_context` will not unfold
irreducible definitions when trying to unify/match the types.

The new test `type_class_performance1.lean` exposes the problem fixed
by this commit.
2018-05-07 18:07:04 -07:00
Leonardo de Moura
5b89f69e36 chore(library/init/data/dlist): add @[inline] 2018-05-07 18:07:04 -07:00
Leonardo de Moura
89b4bb7210 feat(library/init/data/hashable): add hashable nat instance 2018-05-06 07:53:29 -07:00
Leonardo de Moura
3079d2d007 feat(library/init/lean/name): add hashable instance 2018-05-06 07:49:17 -07:00
Leonardo de Moura
162f817fa3 feat(library/init/data/hashable): add builtin string hash 2018-05-06 07:28:05 -07:00
Leonardo de Moura
e64cb10ded feat(library/init): add hashable type class 2018-05-05 20:48:57 -07:00
Leonardo de Moura
d5fe509c36 chore(*): remove end after each match-expression
`end` is not optional anymore
2018-05-04 11:30:06 -07:00
Leonardo de Moura
752e0a134e chore(library/init/data/nat/basic): cleanup 2018-05-04 11:30:06 -07:00
Leonardo de Moura
11a8a7c4f3 feat(library/init): use usize instead of uint32 in the low level array access primitives 2018-05-04 10:40:14 -07:00
Leonardo de Moura
af4f831a9f feat(library/init/data/hashmap): hash function produces an uint32 instead of nat
Most efficient hash functions use uint32/uint64 and produce values
that do not fit in out small nat representation. Thus, GMP big numbers
would have to be created.
2018-05-03 17:56:10 -07:00
Leonardo de Moura
ff7e691d66 feat(library/vm): add support for system.platform.nbits in the VM 2018-05-03 15:54:54 -07:00
Leonardo de Moura
acade175b6 feat(library/init/data/array): store dimension in the array
The array dimension is now stored inside the array.
The main motivation is that it reflects the actual runtime implementation.
We need to store the array size to be able to GC it.
So, it feels silly to have the array size stored in each array object,
but we cannot use this information.
For example, in the `hashmap` we implemented the bucket array using
`array`, and we store the `size` of the array.
Same for the Lean3 `buffer` object.
The `buffer` object doesn't even need to exist.
The actual `array` implementation is the `buffer`
2018-05-03 15:43:03 -07:00
Leonardo de Moura
668d198991 feat(library/init/data/usize): add usize 2018-05-03 15:43:00 -07:00
Leonardo de Moura
732d638bb8 chore(library/init/data/array/lemmas): remove array theorems 2018-05-03 15:38:42 -07:00
Leonardo de Moura
9aa459c7e1 feat(library/init/data/nat/basic): add auxiliary power theorems 2018-05-03 11:23:59 -07:00
Leonardo de Moura
c135d0ae61 chore(library/init/data/uint): cleanup 2018-05-03 10:42:50 -07:00
Leonardo de Moura
f2df67053f feat(library/init/data/dlist): add dlist back without tactic framework dependency 2018-05-02 12:36:31 -07:00
Leonardo de Moura
45694ae44a fix(library/init/data/nat/basic): performance problem
Before this commit, given `x n : nat` the expression
```
to_bool (n <= x)
```
where `n` is a numeral <= 1024 was being elaborated as
```
@decidable.to_bool (@has_le.le.{0} nat nat.has_le n x) (nat.decidable_lt n' x)
```
where `n'` denotes the numeral `n-1`
Example:
```
to_bool (800 <= x)
```
was elaborated as
```
@decidable.to_bool (@has_le.le.{0} nat nat.has_le 800 x) (nat.decidable_lt 799 x)
```

Reason: `nat.lt` and `nat.le` were reducible. The module `type_context`
has support for solving "offset constraints" for small numerals.
These constraints include:
- `succ ?x =?= n`  ===> `?x := n - 1`

For elaborating `to_bool (800 <= x)`, we need to synthesize
```
decidable (@has_le.le.{0} nat nat.has_le 800 x)
```
using type class resolution.

The instance `nat.decidable_lt` is tried before `nat.decidable_le`. For
this instance, we need to solve the unification problem.
```
decidable (@has_lt.lt.{0} nat nat.has_lt ?n ?x) =?= decidable (@has_le.le.{0} nat nat.has_le 800 x)
```
which reduces to:
```
nat.less_than_or_equal (succ ?n) ?x =?= nat.less_than_or_equal 800 x
```
because `nat.le` and `nat.lt` are marked as `[reducible]`.
This constraint reduces to
```
succ ?n =?= 800
```
which is solved using the offset constraint support as
```
?n := 799
```

The kernel does not have support for offset constraints, and may take
a considerable amount of time to check that `succ 799` is definitionally
equal to `800`. This is particularly expensive when trust level 0 is
used.
It was taking almost 1 minute to execute the leanchecker test before
this commit because we add the new predicates for checking which
characters can be used in a Lean identifier.

This commit fixes the problem by removing the annotation `[reducible]`
from `nat.lt` and `nat.le`. This performance issue may be triggered
by any reducible instance that may create offset constraints during
type class resolution.

cc @kha
2018-05-01 11:50:54 -07:00
Leonardo de Moura
5a560b6d43 feat(library/init/data): add hashmap
We use the same approach used to define rbtree:
1- Structure with minimal number of invariants, AND
2- well_formed inductive predicate

We can use the well_formed predicate to prove auxiliary invariants later.
Example: the keys stored in every bucket have the correct hash code.

This implementation does not depend on the tactic framework,
and it is not a mess like the one in mathlib.
2018-04-30 18:28:29 -07:00
Leonardo de Moura
50b7efe00d refactor(library/init/data/array/basic): make sure init/data/array/basic does not depend on init.meta 2018-04-30 17:16:45 -07:00
Leonardo de Moura
f20f50254c feat(library/init/data/string/basic): add string.line_column 2018-04-30 15:55:34 -07:00
Leonardo de Moura
62d425073e feat(library/init/data/string/basic): add string.iterator.offset 2018-04-30 15:43:51 -07:00
Leonardo de Moura
4fa43f18dd chore(library/init/data/rbtree,library/init/data/rbmap): remove auto_param dependency
The problem is that `auto_param` is defined in the old `init/meta/name` module,
and we don't want to have `init/meta` dependencies in the `init/lean` modules.
2018-04-30 13:24:13 -07:00
Leonardo de Moura
2cb6af9769 refactor(library/init/control): remove init.meta.name spurious dependency 2018-04-30 11:36:07 -07:00
Leonardo de Moura
75a67ceb29 refactor(library/init): move option.lt 2018-04-30 11:19:38 -07:00