Commit graph

3786 commits

Author SHA1 Message Date
Leonardo de Moura
308bc8de4a chore(tests/lean): fix test suite 2017-11-10 16:59:09 -08:00
Leonardo de Moura
f2ef24696d perf(library/compiler/cse): make sure we eliminate common sub expressions in match-cases associated with 0-ary constructors
The new test exposes the problem. Before this commit, the common
subexpressions at

```
def tst : tree → nat
| (tree.leaf v) := v
| (tree.node v l r) :=
  match f v with
  | tt := tst l + tst l - tst l   -- <<< HERE
  | ff := tst r
  end
```

were not converted into a let-exprs.
2017-11-09 13:32:15 -08:00
Leonardo de Moura
fabf7f6380 perf(library/equations_compiler, library/compiler): expand auxiliary _match_idx definitions when generating byte code
We use the auxiliary procedure pull_nested_rec_fn to pull recursive
application in nested match expressions. This is needed because the
nested match expression is compiled before we process the recursive
procedure that contains it. This transformation may produce
performance problems if the recursive application does not depend on
the data being matched. Here is an example from the new test:

```
def tst : tree → nat
| (tree.leaf v) := v
| (tree.node v l r) :=
  match f v with
  | tt := tst l
  | ff := tst r
  end
```

pull_nested_rec_fn will convert it into

```
def tst : tree → nat
| (tree.leaf v)     := v
| (tree.node v l r) := tst._match_1 (f v) (tst l) (tst r)
```

Since our interpreter uses eager evaluation, both `(tst l)` and `(tst r)`
are executed. This commit fixes this issue by expanding `tst._match_1`
during code generation.
2017-11-09 11:14:57 -08:00
Leonardo de Moura
2c1f50cc04 fix(library/num): fixes #1862 2017-11-09 09:49:53 -08:00
Leonardo de Moura
b40f3af801 feat(library/init/meta): move rb_tree and rb_map to native namespace
cc @kha
2017-11-07 13:41:45 -08:00
Sebastian Ullrich
3930085865 fix(library/type_context): zeta-expand reflected quotations before trying to substitute local refs
Fixes #1860
2017-11-07 11:27:39 +01:00
Leonardo de Moura
426a9064bf feat(frontends/lean/builtin_cmds): display warning message if has_repr instance could not be synthesized
See issue #1861
2017-11-06 19:26:18 -08:00
Leonardo de Moura
8ffdef0b3a feat(library/vm/vm): add # when displaying simple VM objects.
See explanation at issue #1861.
2017-11-06 19:15:57 -08:00
Leonardo de Moura
e96026651b feat(library/init): add d_array type
@kha I added the `d_array` type that we discussed today.
However, the VM implemantion is still using persistent arrays.
If we remove the persistent array support, then code using
hash_map will only be efficient if the hash_map is used linearly.
This is not the case in the reader module because we are planning
to support backtracking.

On the other hand, it is awkward we currently don't have a vanilla
array implementation in the VM. I suspect this will be a problem in
the future.

So, I see the following possibilities:

1- We implement a map data-structure using red-black trees in Lean.
We use this new data-structure to implement all maps in the new reader and
macro expander.

2- We implement a very simple map as a list of pairs.
Then, we replace it in the VM with an efficient implementation.
The VM implementation may use our internal red-black trees.
We may also use a persistent hash table implemented in C++,
but it would be awkward to ask the user to provide a hash function in the reference
implementation (i.e., the one using list of pairs), but not use it
anywhere :)
In contrast, if we use the red-black tree implementation we
would have to ask the user to provide a total order.
It is overkill for the list of pair reference implementation because
we just need an equality test, but, at least, the comparison function
will be used in the implementation.

3- Add types `d_parray` (dependent persistent array) and
`parray` (persistent array). In Lean, they would just wrap the
`d_array` and `array` types. In the VM, `d_array` and `array` would
be implemented using vanilla arrays and `d_parray` and `parray` would
be implemented using persistent arrays. Then, we could have
`d_hash_map`, `hash_map`, `d_phash_map` and `phash_map`. Argh, so many
versions :(
We would use `phash_map` to implement our reader and macro expander.

4- Add a `(persistent : bool := ff)` parameter to `d_array` and
`array` types. The disadvantage of this approach is that it has
a performance impact. The VM implementation would have to check
the `persisent` flag at runtime. The value of this flag is known
at compilation time, but we currently don't have a mechanism
for specializing native builtin C++ implementations for VM functions.
2017-11-06 14:56:11 -08:00
Sebastian Ullrich
191065d963 fix(frontends/lean/elaborator): change assertion into type mismatch error
Fixes #1859
2017-11-06 10:51:37 +01:00
Floris van Doorn
1b4d2a850a test(focus): add test 2017-11-03 12:58:48 -07:00
Floris van Doorn
52ee29cb48 fix(interactive): fix focus tactic.
Previously it would fail if there was more than one goal.
2017-11-03 12:58:48 -07:00
Leonardo de Moura
91079faf97 fix(library/equations_compiler/compiler): problem introduced by recent changes
The problem was reported by @digama at slack.
2017-11-03 10:46:40 -07:00
Leonardo de Moura
cd8c154bcd feat(library/compiler/vm_compiler): clear runtime cost model
The equation compiler uses different strategies for processing
recursive equations. Some of them may produce unclear runtime cost
model. For example, the following fibonacci functions was running in
linear time instead of exponential time because the equation compiler
used the brec_on recursor.

def fib : nat → nat
| 0     := 1
| 1     := 1
| (n+2) := fib (n+1) + fib n

@dselsam and @jroesch have reported examples were the equation compiler
produces a negative performance impact. The new test (`eval` function)
captures the problem reported by @jroesch. In this example, the runtime
should not depend on the "amount of fuel".

This commit addresses this issue.
2017-11-01 14:11:09 -07:00
Leonardo de Moura
14301a7f9f feat(library/equations_compiler/compiler): generate meta auxiliary definitions for regular (recursive) definitions
Motivations:

- Clear execution cost semantics for recursive functions.

- Auxiliary meta definition may assist recursive definition unfolding in the type_context object.

Next step: use meta auxiliary definition at code generation.
2017-11-01 11:58:45 -07:00
Leonardo de Moura
482e06427b feat(library/equations_compiler): meta mutual definitions
closes #1622
2017-10-30 15:06:12 -07:00
Sebastian Ullrich
1a80ea9c8e fix(util/utf8): UTF8 decoding 2017-10-27 09:48:09 -07:00
Sebastian Ullrich
734ee66514 fix(library/string): unicode char literals 2017-10-27 09:48:09 -07:00
Leonardo de Moura
ce4e316e09 fix(library/equations_compiler/util): fixes #1841 2017-10-26 11:25:16 -07:00
Leonardo de Moura
d2497d554f feat(frontends/lean): add support for unicode char literals and escape sequences
TODO: we are not checking if the unicode escape values provide by the
user correspond to valud unicode scalar values. We should check how
other languanges handle this case.
2017-10-23 13:46:57 -07:00
Sebastian Ullrich
032e0701e0 fix(frontends/lean/elaborator): non-recursive local shouldn't shadow projection 2017-10-23 12:12:06 -07:00
Sebastian Ullrich
716c730c38 fix(frontends/lean/structure_cmd): allow extending structures in the current context 2017-10-23 11:12:14 -07:00
Leonardo de Moura
e53f8021ec feat(library/vm/vm_string): add builtin VM implementation for string.cmp 2017-10-23 10:55:26 -07:00
Leonardo de Moura
10184315fb feat(library/vm/vm_string): add builtin VM implementation for string.has_decidable_eq 2017-10-23 10:55:26 -07:00
Leonardo de Moura
a9e884cc1d fix(library/vm/vm_string): bug at string.iterator.remove VM builtin implementation 2017-10-23 10:55:26 -07:00
Leonardo de Moura
f8ce142da7 fix(library/vm/vm_string): bug at string.iterator.insert VM builtin implementation 2017-10-23 10:55:26 -07:00
Leonardo de Moura
e30f2f6604 fix(library/vm/vm): bug at update_vm_constructor 2017-10-23 10:55:26 -07:00
Leonardo de Moura
47a8c2baef fix(library/vm/vm_string): missing VM builtin for string_imp projections 2017-10-23 10:55:26 -07:00
Leonardo de Moura
ffb2464f1f fix(library/vm/vm_string): missing VM builtin for string.iterator_imp projections 2017-10-23 10:55:26 -07:00
Leonardo de Moura
9399ce8346 feat(library/vm/vm_string): provide native implementation of type string in the VM
closes #1175

The types `string_imp` and `string.iterator_imp` were supposed to be
marked private, but we cannot do it because we need to provide
`string_imp.mk`, `string_imp.cases_on`, `string.iterator_imp.mk` and
`string.iterator_imp.cases_on` in the VM since we use a different
internal representation. Note that marking them as private does not
work since users can still access `string_imp.cases_on` using
meta-programming.
So, we need better support for private declarations.

Missing feature, char literals do not support non ASCII values.
That is, in the current implementation, we cannot write 'α'.
This will be implemented in the future.

The VM native implementation does not behave correctly for huge
strings (i.e., strings with more than 4G characters).
The problem is that the current implementation relies on
```
size_t force_to_size_t(vm_obj const & o, size_t def)
```
We may also have overflow problems in the string.iterator implementation
code. This is not a big deal right now, since I doubt we will try
to process string with more than 2^32 characters.

@Kha the `core_lib` and tests seem to be working correctly, but
we need more tests.
2017-10-23 10:55:26 -07:00
Leonardo de Moura
bdc8e1ced8 feat(library/init/data/char): char as an unicode scalar value
TODO: this is the first step to have better unicode support.
2017-10-23 10:55:26 -07:00
Sebastian Ullrich
87e1a88d01 feat(init/meta/pexpr): allow creating structure instance pre-terms 2017-10-11 16:13:34 +02:00
Jeremy Avigad
bcad5309d9 fix(library/init/meta/interactive): implement docstring fixes from kha 2017-09-22 16:53:22 -04:00
Jeremy Avigad
57f9cbeb78 fix(tests/lean/interactive/*): fix tests 2017-09-21 21:16:20 -04:00
Leonardo de Moura
f0bf1624fe feat(frontends/lean/brackets): closes #1820 2017-09-15 12:54:21 -07:00
Leonardo de Moura
f36fca875c feag(frontends/lean): explicit delimiters in declaration parameters
Comment from parser.h

This commit makes sure that all declaration parameters must be surrounded with some kind of bracket. (e.g., '()', '{}', '[]').
The goal is to avoid counter-intuitive declarations such as:

              example p : false := trivial
              def main proof : false := trivial

which would be parsed as

              example (p : false) : _ := trivial

              def main (proof : false) : _ := trivial

where `_` in both cases is elaborated into `true`. This issue was raised by @gebner in the slack channel.

Remark: we still want implicit delimiters for lambda/pi expressions. That is, we want to write

               fun x : t, s
           or
               fun x, s

instead of

               fun (x : t), s
2017-09-15 10:07:09 -07:00
Sebastian Ullrich
7ff06b2184 chore(init/meta/attribute): rename user_attribute.set_param to user_attribute.set
Setting the parameter value really is a side effect of setting the whole attribute
2017-09-14 18:48:18 +02:00
Sebastian Ullrich
928e982565 chore(init/meta/mk_has_reflect_instance): disallow indexed families for now
We need to adapt the recursion code to pass `reflected` instances for indices
2017-09-14 18:48:18 +02:00
Sebastian Ullrich
8d9c0ac806 fix(frontends/lean/tactic_notation): by tactic: accept non-atomic proof 2017-09-14 18:48:18 +02:00
Sebastian Ullrich
87b39bd1c3 fix(init/meta/derive): handle indexed families 2017-09-14 18:48:18 +02:00
Gabriel Ebner
341cf71fb9 fix(frontends/lean/structure_cmd): check parent expression after elaboration as well 2017-09-14 09:36:40 +02:00
Leonardo de Moura
6781681ae5 feat(frontends/lean/definition_cmds): when the kernel fails to type check a declaration include the fully elaborated term in the error message 2017-09-13 16:43:54 -07:00
Leonardo de Moura
dbe1033427 fix(library/init/meta/mk_has_sizeof_instance): indexed families
see #1818
2017-09-12 15:17:34 -07:00
Sebastian Ullrich
f2c5342aaa feat(init/meta/derive): handle parameters, parameter instances, universes 2017-09-11 16:56:03 -07:00
Sebastian Ullrich
230bf7e8d9 fix(frontends/lean/decl_cmds): constant/axiom cmds: apply attributes 2017-09-11 16:56:02 -07:00
Leonardo de Moura
d428eca8a7 fix(library/equations_compiler,frontends/lean): private name support and alias generation for auxialiary declarations
fixes #1804

Remark: now, all auxiliary definitions in a private declaration share
the same "private" prefix.
2017-09-11 16:46:56 -07:00
Sebastian Ullrich
d82df26ff0 fix(frontends/lean/elaborator): go back to ignoring implicit args in quote patterns 2017-09-11 09:33:38 -07:00
Sebastian Ullrich
869ac974b2 fix(init/meta/interactive): assume: use rbp 2 2017-09-10 09:53:07 +02:00
Leonardo de Moura
1f757ba84e fix(frontends/lean/pp): fixes #1817 2017-09-07 15:23:58 -07:00
Mario Carneiro
87f2ec08ad feat(init/meta/interactive): suffices tactic
Just a simple manipulation of the `have` tactic, but it allows the use of `suffices h : T, from p,` in tactic mode.
2017-09-06 10:50:31 -07:00