Commit graph

3987 commits

Author SHA1 Message Date
Leonardo de Moura
d5fd86791d chore(tests/lean/run/ext_eff*): reduce number of iterations
My machine was taking forever to run these tests in debug mode.
2018-05-09 10:52:33 -07:00
Leonardo de Moura
14e19502f0 chore(tests/lean/run/type_class_performance1): remove #exit 2018-05-09 10:24:45 -07:00
Leonardo de Moura
d05e93f763 test(tests/lean/run/name_mangling): add tests for name mangling 2018-05-09 10:10:00 -07:00
Leonardo de Moura
b77cd740a8 test(tests/lean/run/display_hw_term_hack_deps): add helper function for displaying functions that use wf_term_hack 2018-05-08 16:28:42 -07:00
Sebastian Ullrich
4ed7b57903 test(tests/lean/run/ext_eff): add IO exception handling example 2018-05-08 17:29:12 +02:00
Leonardo de Moura
50f883a946 chore(tests/lean/parser1): fix test 2018-05-07 18:11:41 -07:00
Leonardo de Moura
e40f37b08e feat(library/init/lean/ir): add type checker 2018-05-07 18:07:04 -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
79f351d177 fix(library/init/lean/ir): parser and test 2018-05-07 18:07:04 -07:00
Leonardo de Moura
0a9bd8caa8 chore(library/init/lean/ir): improve sizet syntax 2018-05-07 18:07:04 -07:00
Sebastian Ullrich
91e3e2435a test(tests/lean/run/ext_eff): document quadratic run time issue and implement solution from paper
~3x slowdown on right-associated binds
2018-05-07 23:58:17 +02:00
Leonardo de Moura
88082cd16d fix(library/init/lean/ir/parser): case 2018-05-06 10:11:58 -07:00
Leonardo de Moura
e2e124626f feat(library/init/lean/ir): add elim_phi function 2018-05-06 10:07:44 -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
Sebastian Ullrich
7da6d5c50d test(tests/lean/run/ext_eff): add extensible effects monad example 2018-05-04 19:44:33 +02:00
Leonardo de Moura
7aeae54522 chore(tests/lean/trust0/basic): fix test 2018-05-03 15:57:59 -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
d9101cb950 chore(tests/lean/parser1): fix test 2018-05-02 17:37:55 -07:00
Leonardo de Moura
bf71068b14 feat(library/init/lean/ir): parse IR definitions 2018-05-02 16:59:50 -07:00
Leonardo de Moura
0d49ae3f69 feat(library/init/lean/parser): add not_followed_by and not_followed_by_sat
The new parsers are useful to implement the longest match rule.
2018-05-02 15:55:57 -07:00
Leonardo de Moura
6e2ebb5fab feat(library/init/lean/ir): add IR instruction parser 2018-05-01 17:45:50 -07:00
Leonardo de Moura
263391bdbb refactor(library/init/lean): add init/lean/parser/identifier 2018-05-01 11:53:55 -07:00
Leonardo de Moura
7305a7a65e feat(library/init/lean): identifier parser 2018-05-01 10:29:34 -07:00
Leonardo de Moura
ba8b85f4c0 chore(library/init/lean/parser/parser): adjust variable names 2018-04-30 16:36:09 -07:00
Leonardo de Moura
cd10ca74f7 chore(tests/lean/string_imp): fix test 2018-04-30 16:15:51 -07:00
Leonardo de Moura
9879cb46be feat(library/init/lean/parser/parser): store offset in error messages 2018-04-30 16:08:52 -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
0405a67a70 feat(library/init): add wf_term_hack (unsound) axiom
We use the axiom instead of `sorry` to avoid a tsunami of warnings.
2018-04-30 11:06:51 -07:00
Leonardo de Moura
9b5297901b fix(tests/lean/trust0/basic): test 2018-04-30 10:13:35 -07:00
Leonardo de Moura
12f2831f9f test(tests/lean/parser1): add parser tests 2018-04-28 15:58:50 -07:00
Leonardo de Moura
c427fb4086 refactor(*): create library/init/lean folder
The new folder will contain the new parser, macro expander and compiler.
This commit also renames the namespace for the old parser `lean3.parser`
2018-04-27 08:02:40 -07:00
Leonardo de Moura
9e9a0d103f feat(library/vm/vm_string): add fast string.iterator.remaining 2018-04-26 18:03:41 -07:00
Leonardo de Moura
77993c967d chore(tests/lean): restore string tests 2018-04-26 17:36:41 -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
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
d57c2df9c1 test(tests/lean/run/deriv): add benchmark 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
Sebastian Ullrich
726a5547de fix(init/core): typed_expr should accept Props
Fixes #1954
2018-04-12 16:14:47 +02:00
Leonardo de Moura
6234c60aae chore(*): disable test suite 2018-04-10 12:56:55 -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
Sebastian Ullrich
3d692c53b5 chore(tests/lean/struct_class): make test less prone to breakage 2018-04-04 13:04:38 +02:00
Leonardo de Moura
d387103aa2 fix(library/init/core): closes #1951
- Add has_pow type class
- Make `^` notation right associative
2018-03-29 16:25:47 -07:00
Leonardo de Moura
6e0bf8473b test(tests/lean/1952b): another test for issue #1952
This is an example used in one of the comments.
2018-03-29 16:01:26 -07:00
Leonardo de Moura
66e7873c22 fix(library/type_context): elim_delayed_abstraction must check whether metavariable is already assigned
fixes #1952
2018-03-29 15:53:17 -07:00
Sebastian Ullrich
3fefe94757 refactor(library/init/core,library/init/unit): make unit an abbreviation of punit.{0} 2018-03-27 10:33:04 -07:00
Leonardo de Moura
efa9d7e110 perf(library/type_context): performance issue when proving equation lemmas 2018-03-26 12:57:19 -07:00
Sebastian Ullrich
80d68a7605 chore(tests/lean/leanpkg/test_single): ignore empty lines around warning 2018-03-20 15:14:45 -07:00
Sebastian Ullrich
7daf6a2133 refactor(init/category): change _functor classes into new _adapter classes, add docs 2018-03-20 14:58:37 -07:00