Commit graph

996 commits

Author SHA1 Message Date
Leonardo de Moura
a31f12d8cd chore(library/init/core): revert ite+thunks modification
We don't need it since we marked `ite` as `[macro_inline]`
2018-09-23 19:27:06 -07:00
Leonardo de Moura
b07c718425 refactor(library/init/core): change ite signature 2018-09-17 14:27:28 -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
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
5313cd3467 fix(library/init/meta/pos): missing file 2018-08-28 07:41:41 -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
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
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
f62256853c refactor(library/init/lean/declaration): use lean.declaration to implement init.meta.declaration 2018-06-25 13:08:13 -07:00
Leonardo de Moura
91d2ad5925 chore(library/init/meta): remove level and expr unused functions 2018-06-22 10:54:43 -07:00
Leonardo de Moura
318530cf07 refactor(library/init/meta/expr): use lean.expr
`expr` is finally non-meta
2018-06-22 10:29:56 -07:00
Leonardo de Moura
c30f40e4ac feat(library/init/meta/level): use lean.level 2018-06-22 10:29:49 -07:00
Leonardo de Moura
ede1a51d60 refactor(kernel/declaration): remove self_opt flag from reducibility hints
This flag was used by the kernel to decide whether the following
heuristic should be used to avoid unfolding `f` at `is_def_eq`.

       f a =?= f b
       -----------
         a =?= b

This heuristic was introduced at Lean1 after a discussion with
Georges Gontier. Since this discussion, we added support for
caching failures of this heuristic. This proved to be much more
effective to attack the performance problems.
Moreover, we do not even use this flag in the `type_context::is_def_eq`
used during elaboration.

The current codebase contains only one place where this flag was set to
`false`: coercions generated at structure_cmd. This change was
made at commit
1c70514231
in the Lean2 codebase when we were not caching failures and
the kernel type checker was also used during elaboration.
2018-06-22 09:02:50 -07:00
Leonardo de Moura
c5714c2fac chore(kernel): remove expr.macro constructor
We are now ready to implement `expr` using `runtime/object`.
2018-06-19 17:54:43 -07:00
Leonardo de Moura
9e7e600ad7 feat(kernel): add expr.proj constructor
TODO: implement infer_proj and reduce_proj
2018-06-19 15:45:49 -07:00
Leonardo de Moura
b84090aaca feat(library/annotation): remove annonation macro
We now use the new `expr.mdata` constructor.
2018-06-18 13:39:02 -07:00
Leonardo de Moura
0847571ea6 feat(kernel): add mdata constructor 2018-06-18 13:36:22 -07:00
Leonardo de Moura
71fc35af1d chore(library/vm): remove meta rb_map
We should use the non-meta rbmap that is implemented in Lean.
2018-06-14 17:34:43 -07:00
Leonardo de Moura
882fa6e71f fix(library/init/meta/expr): order does not match C++ implementation 2018-06-14 16:12:02 -07:00
Leonardo de Moura
73e067d361 feat(kernel): add expression literals 2018-06-14 14:55:14 -07:00
Leonardo de Moura
3e846e1fc9 chore(library): remove unnecessary inaccessible annotations 2018-06-14 11:33:00 -07:00
Leonardo de Moura
ba598ada1a fix(library/init/meta/expr): expose quote constructor 2018-06-12 17:55:27 -07:00
Leonardo de Moura
ee7bc150f2 chore(library/init/meta/expr): remove elaborated : bool parameter from expr 2018-06-06 09:47:01 -07:00
Leonardo de Moura
3a7229add3 chore(library/init): pexpr is now an opaque constant 2018-06-06 09:36:22 -07:00
Leonardo de Moura
e160154d14 fix(library/init/meta/name): duplicate 2018-06-06 08:47:28 -07:00
Leonardo de Moura
dda1f0ebaa chore(library/init/meta/interactive): remove more tactics 2018-06-06 08:46:48 -07:00
Leonardo de Moura
e4a168af91 chore(library/init/meta): remove goal tagging feature 2018-06-06 08:46:47 -07:00
Leonardo de Moura
50ce4e8ae9 chore(library/init/meta/interactive_base): remove Lean3 format macros 2018-06-05 16:29:26 -07:00
Leonardo de Moura
bd7138349a chore(library/init/meta/pexpr): remove pexpr primitives 2018-06-05 16:28:12 -07:00
Leonardo de Moura
ab481d7e7b chore(library/init/meta): remove unnecessary primitives 2018-06-05 16:13:22 -07:00
Leonardo de Moura
45202eca16 chore(library/init/meta): cleanup 2018-06-05 15:32:59 -07:00
Leonardo de Moura
3c1ccc9b74 refactor(kernel): use m_meta instead of m_trusted 2018-05-31 11:18:00 -07:00
Leonardo de Moura
80545832f4 chore(library): remove user attributes 2018-05-31 09:10:41 -07:00
Leonardo de Moura
1332fbabd6 feat(library,frontends): remove sorry macro
Lean4 will not have macros.
2018-05-24 14:00:30 -07:00
Leonardo de Moura
84c0580e05 fix(library/init/meta/tactic): monad_from_pure_bind is used to implement io 2018-05-21 15:45:56 -07:00
Leonardo de Moura
160b7e8847 refactor(library/init/meta/expr): local_const will have only one field
In Lean3, we supported two kinds of local constant:
context-less (inherited from Lean2) and context-based (type,
binder-info and pretty printing name are stored in the context).
The context-less was used in the kernel and a few modules we kept when
we moved from Lean2 to Lean3. Even if we keep the hybrind
representation, we should not expose the context-less to users.
2018-05-21 15:36:09 -07:00
Leonardo de Moura
d04f0b2022 chore(library/init/meta): remove old code 2018-05-21 15:30:12 -07:00
Leonardo de Moura
afd018d7cc chore(*): remove several tactics 2018-05-21 06:53:01 -07:00
Leonardo de Moura
0955962f65 chore(*): remove some unnecessary files and tactics 2018-05-21 06:29:50 -07:00