Commit graph

3800 commits

Author SHA1 Message Date
Leonardo de Moura
517923d362 feat(kernel/inductive): generate recursors in the new inductive datatype module 2018-08-31 17:47:22 -07:00
Sebastian Ullrich
93d13ffea3 chore(library/init/lean): lean.parser.reader ~> lean.parser 2018-08-30 16:34:47 -07:00
Sebastian Ullrich
d60e3a66ce refactor(library/init/lean/parser/reader): make monad stack not reducible 2018-08-30 15:59:38 -07:00
Sebastian Ullrich
de9d894c14 feat(library/init/lean/parser/reader): use coroutine on the module level 2018-08-29 16:42:24 -07:00
Sebastian Ullrich
2528aee72b refactor(library/init/lean/parser/reader): use different monad stacks for different parts of the reader 2018-08-29 16:42:24 -07:00
Sebastian Ullrich
cec1ee2564 feat(library/init/lean/parser/parsec): reintroduce parsec_t 2018-08-29 16:42:24 -07:00
Leonardo de Moura
863355c6a0 feat(kernel/inductive): continue new inductive datatype module
Add more validation, and create new inductive_val and constant_val objects.
2018-08-29 09:27:06 -07:00
Leonardo de Moura
5d41046170 refactor(library/init/core): remove exists_unique
We never used it in the corelib. Users can define it if they need it.
2018-08-28 14:01:33 -07:00
Leonardo de Moura
101886ffae feat(kernel): proper constant_info and declaration objects for quot type 2018-08-28 13:46:31 -07:00
Sebastian Ullrich
a178f181a8 chore(library/init/lean/parser/macro): remove old name resolution prototype 2018-08-28 13:13:14 -07:00
Sebastian Ullrich
46f734b1b1 refactor(library/init/lean/parser/reader): replace macro with syntax_node_kind
Also make sure that the name inside a node kind is the full name of the
declaration. This way, we cannot have accidentally conflicting node kind names.
2018-08-28 13:13:14 -07:00
Sebastian Ullrich
47bff1ddcd fix(library/init/core): ∃! should not accept multiple binders 2018-08-28 13:13:14 -07:00
Leonardo de Moura
5c47ff82f6 chore(library/init/lean/core): remove dead code 2018-08-28 08:56:03 -07:00
Leonardo de Moura
5313cd3467 fix(library/init/meta/pos): missing file 2018-08-28 07:41:41 -07:00
Leonardo de Moura
776c977742 refactor(kernel): continue constant_info/declaration refactoring 2018-08-27 17:23:26 -07:00
Leonardo de Moura
3f5db74ab4 refactor(library/init/lean/declaration): rename declaration_val ==> constant_val
It doesn't make sense to call it `declaration_val` anymore.
2018-08-27 16:07:38 -07:00
Leonardo de Moura
27ef29a50f refactor(kernel/declaration): continue constant_info/declaration refactoring 2018-08-27 13:22:10 -07:00
Leonardo de Moura
66adac6af6 chore(library/init): avoid calc at corelib 2018-08-27 12:17:30 -07:00
Leonardo de Moura
d334bb1fa7 chore(*): remove more stuff 2018-08-23 15:56:31 -07:00
Leonardo de Moura
17ae59b5b0 chore(*): remove more stuff 2018-08-23 15:27:12 -07:00
Leonardo de Moura
c21555240a chore(library/tactic): remove more stuff 2018-08-23 15:20:07 -07:00
Leonardo de Moura
646cdfdf40 chore(library/init/meta): remove well_founded_tactics 2018-08-23 15:14:22 -07:00
Leonardo de Moura
8434f43146 chore(library/init/meta): remove interactive.lean 2018-08-23 14:41:47 -07:00
Leonardo de Moura
973eb89e40 chore(library/init/meta/lean): remove old parser support 2018-08-23 14:39:10 -07:00
Leonardo de Moura
d405e54a6f chore(library/init/meta/tactic): reduce tactic.lean 2018-08-23 14:37:40 -07:00
Leonardo de Moura
ed5d884d8f chore(library/tactic): remove app_builder_tactics 2018-08-23 14:22:00 -07:00
Leonardo de Moura
a6604dcf56 chore(library/tactic): remove rewrite and apply and interactive tactics 2018-08-23 14:18:16 -07:00
Leonardo de Moura
7a47406c4c chore(library/tactic): remove simp_lemmas 2018-08-23 14:10:36 -07:00
Leonardo de Moura
e5c3f04937 chore(frontends/lean): remove tactic notation 2018-08-23 13:44:52 -07:00
Leonardo de Moura
a10e81e6a6 chore(frontends/lean/elaborator): remove unfold tactic dependency 2018-08-23 11:57:38 -07:00
Leonardo de Moura
c7cf75508d feat(init/control/coroutine): avoid mutual inductive
Reason: we want to delete the inductive compiler.
2018-08-23 10:49:40 -07:00
Sebastian Ullrich
61f8ebf4ef refactor(library/init/lean/parser/reader): destructure reader into monad and has_tokens typeclass 2018-08-23 10:38:59 -07:00
Sebastian Ullrich
666c431982 chore(library/init/io): hide/remove io.put_str/put_str_ln 2018-08-22 17:48:02 -07:00
Sebastian Ullrich
762259a96f chore(library/init/lean/parser/reader): cleanup 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
287fdce45b refactor(library/init/lean/parser/reader): remove reader.has_view default instance 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
c69cc61292 feat(frontends/lean,library/init/lean/parser/reader/module): add node_choice! macro
Creates an inductive type from an ordered choice reader
2018-08-22 14:32:03 -07:00
Sebastian Ullrich
1b8e74123c feat(frontends/lean/{builtin_exprs,elaborator}): special-case try inside of node! 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
26d696a937 feat(frontends/lean,library/init/lean/parser/reader/module): basic node! macro 2018-08-22 14:32:03 -07:00
Leonardo de Moura
d64a49a7da feat(library/init/lean/declaration): use task at theorem and definition declaration objects 2018-08-22 10:31:50 -07:00
Leonardo de Moura
d0dc998873 chore(library/init/core): remove opaque comments
We don't need to use `opaque` for `thunk` and `task`. Their recursor and
projections can be implemented in constant time. We just need to create
a closure which uses the runtime thunk_get/task_get primitive.
2018-08-22 10:27:04 -07:00
Leonardo de Moura
3ab1ebcb3f feat(init/core): add task 2018-08-21 16:10:07 -07:00
Leonardo de Moura
261dc999d0 refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion
@kha I was working in the new declaration type and using tasks there.
Since we don't have tasks yet in Lean, I decided to start refactoring
the `thunk` type. I defined it as:

```
-- TODO(Leo): mark as opaque, it is implemented by the new runtime
structure thunk (α : Type u) : Type u :=
(fn : unit → α)

def thunk.pure {α : Type u} (a : α) : thunk α :=
⟨λ _, a⟩

def thunk.get {α : Type u} (t : thunk α) : α :=
t.fn ()
```

The idea is to use the runtime primitives to implement them.
Then, I realized the support for `thunk`s in the elaborator are quite
hacky. Given `f x`, if `f`'s domain has type `thunk A`, we elaborate
`f x` as `f (fun _, x)` even if `x` has type `thunk A`.
This is quite bad, for example, suppose we have
```
def f (x : thunk A) := ...
```
Then, the following definition is type incorrect.
```
def g (x : thunk A) := f x
```
and we are forced to write
```
def g (x : thunk A) := f (x ())
```
The term `f (x ())` will be elaborated as `f (fun _, x ())` and an
unnecessary closure is created at runtime.

This mechanism inherited from Lean 3 is also incompatible with the
new thunk definition. Given `x : thunk A`, I want to write `x.get`
to retrieve the value instead of `x ()` as in Lean 3.
However, `x.get` expands into the nonsensical `(fun _, x).get`.

So, I decided to view the mapping `A` to `thunk A` as a "coercion".
I used double quotes, because it is a macro instead of a function.
If it were a coercion, then we would be using `thunk.pure` to coerce
values but this is not we want most of the time.
For example, given `f : thunk A -> B` and a term `t : A`, when we write
`f t`, we want it to be converted into `f (fun _, t)` instead of
`f (thunk.pure t)` which would eagerly compute `t`. The transformation
`t` into `fun _, t` is syntactic.
We cannot implement it using type classes. I implemented it as
a hard-coded extra case like the one from `Prop` to `bool`.
We can also add a coercion from `thunk A` to `A` to avoid the `.get`.

That being said, I had a few breakages in the code base since we only
use coercions when the given and expected type do not contain
metavariables.
2018-08-21 15:27:51 -07:00
Leonardo de Moura
682cfa14e8 chore(library/init/lean/declaration): add new declaration type 2018-08-21 10:13:16 -07:00
Leonardo de Moura
04fbbbb0d6 refactor(library/init/lean/declaration): declaration -> constant_info
This is the first step in the declaration vs constant_info refactor.
Here is the design notes:

In Lean3, we use the `declaration` objects to represent new declarations
that are sent to the kernel, and to store information for all constants
declared in an environment.
This design decision was done when we did not have support for
mutual (meta) declarations, and information about inductive datatypes,
constructors and recursors were stored in an environment extension.
This design now seems weird since we have four different methods for
adding declarations into the environment:
```
    environment add(certified_declaration const & d) const;
    environment add_meta(buffer<declaration> const & ds, bool check = true) const;
    environment add(inductive_decl const & decl) const;
    environment add_quot() const;
```
Moreover, we use `mk_constant_assumption` to represent inductive
datatype, constructors, recursors, and `quot` primitives.
Since inductive datatypes, constructors, recursors and `quot` primitives
are not considered axioms, we have the method:
```
    bool environment::is_builtin(name const & n) const;
```

We can avoid these hacks by having a type for representing
declarations (i.e., objects that are sent to the kernel) and
objects for storing information of the constant declarations stored
in an environment object.

A `declaration` object is now of the form
```
inductive declaration
| defn_decl        (val : definition_val)
| axiom_decl       (val : axiom_val)
| thm_decl         (val : theorem_val)
| quot_decl
| mutual_defn_decl (defns : list definition_val) -- All definitions must be marked as `meta`
| induct_decl      (lparams : list name) (nparams : nat) (types : list inductive_type) (is_meta : bool)

/-
If we want, we can let users specify their own names for `quot`,
`quot.mk`, `quot.lift` and `quot.ind`. We just need to add them
as fields of `declaration.quot_decl`.
-/
```

When we check a declaration, one or more `constant_info` objects are
created for each new constant in the declaration.
```
inductive constant_info
| assump_info   (val : assumption_val)
| defn_info     (val : definition_val)
| axiom_info    (val : axiom_val)
| thm_info      (val : theorem_val)
| quot_info     (val : quot_val)
| induct_info   (val : inductive_val)
| cnstr_info    (val : constructor_val)
| rec_info      (val : recursor_val)
```
For simple declarations `constant` (aka `assumption`), `definition`,
`theorem` and `axiom`, the information stored in the `constant_info` is
identical to the information in the `declaration` object. This is
expected since these are the original Lean3 declarations.

The `environment` object stores a mapping from `name` to
`constant_info`. The function `check` validates a declaration
and produces a `certified_declaration`. A `certified_declaration` is
a pair `(declaration, list constant_info)`. The `list` here makes it
explicit that a declaration may add one or more new constants into the
environment. Finally, the `environment` object has a single `add`
method and a single `get` and `find`:
```
    environment add(certified_declaration const & d) const;

    /** \brief Return info for the constant with name \c n (if it is defined in this environment). */
    optional<constant_info> find(name const & n) const;

    /** \brief Return info for the constant with name \c n. Throws an
        exception if has not been declared in this environment. */
    constant_info get(name const & n) const;
```

Moreover, the method `environment::builtin` is not necessary anymore.
If `environment::get(n)` returns an `axiom_info` or an `assump_info`, then
we know for sure the constant named `n` has been postulated.

This commit only defined the new types in Lean. I still need to make
the changes to the C++ code base.
2018-08-21 09:59:30 -07:00
Leonardo de Moura
4314617a85 chore(library/init/io): remove dead code 2018-08-21 09:00:14 -07:00
Sebastian Ullrich
6dbe54a01b chore(library/init/io): rename io.print_ln to io.println 2018-08-21 08:43:10 -07:00
Sebastian Ullrich
3516c37ec9 feat(library/init/control/coroutine_io): coroutine_io 2018-08-21 08:43:10 -07:00
Sebastian Ullrich
a42fb533f4 fix(library/vm/vm_io): move all primitives into io
While `cmdline_args` has no side-effects, it is certainly not a pure function.
The `stdin` etc. should have been safe since all accessors are in `io`, but
better be safe than sorry.
2018-08-21 08:43:10 -07:00
Sebastian Ullrich
fb2ee24ba6 refactor(library/init/io): replace ioe with eio
Old MacDonald had a monad stack
eio = except_t io.error io
And in his stack he had I/O, io = state io.real_world
With a monad here and a monad there
Here a monad there a monad
Everywhere a monad!
2018-08-21 08:43:10 -07:00
Sebastian Ullrich
6b55e24ab7 feat(library/init/{io,control/except}): use lift_t to automatically upcast io and other errors 2018-08-21 08:43:09 -07:00