Commit graph

3974 commits

Author SHA1 Message Date
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
Sebastian Ullrich
70167def6f refactor(init/category/state): replace monad_state_lift with Haskell's MonadState
* does not leak information about the inner monad via out_param
* can be derived from an inner `monad_state` instance
2018-03-20 14:58:37 -07:00
Sebastian Ullrich
3adc5113cb feat(init/category/state): make zoom work linearly 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
da5c8e21df chore(init/category/cont): move to test 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
e6f5ce1303 doc(init/category/reader): add docs and test 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
e044030cd2 doc(init/category/cont): add docs and test 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
c104d5d34b doc(init/category/state): add docs and tests 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
b372dd94d3 feat(init/category/transformers): add monad_run class 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
69cfdbd290 refactor(init/category): make all monad transformers structures, replace monad classes with has_monad_lift_t wrappers 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
c36393066e feat(init/category): introduce monad_functor and implement it for reader, state, and except 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
788e8695eb refactor(init/category/state): replace modify/put (returning unit) with modify'/put' (returning punit) 2018-03-20 14:58:35 -07:00
Sebastian Ullrich
940aca1ec3 refactor(init/category/lawful): unbundle lawful classes 2018-03-20 14:58:35 -07:00
Sebastian Ullrich
159b45c74f refactor(init/category/state): introduce monad_state
* rename `read/write` to `get/put`, as in Haskell
* define `state` as `state_t id`
2018-03-20 14:58:35 -07:00
Sebastian Ullrich
1c6861528b refactor(init/category): move monad laws into separate type classes defined after the tactic framework 2018-03-20 14:58:35 -07:00