Commit graph

1336 commits

Author SHA1 Message Date
Leonardo de Moura
f809758dd3 refactor(kernel/expr): remove extra field 2018-06-22 14:35:32 -07:00
Leonardo de Moura
e9f843ddf6 refactor(kernel/expr): remove mlocal_* functions
The constructors `mvar` and `fvar` have different memory layouts.
2018-06-22 14:25:31 -07:00
Leonardo de Moura
1371c636e5 refactor(kernel/expr): remove pp_name from metavariables 2018-06-22 13:12:42 -07:00
Leonardo de Moura
3729c7ffb2 chore(kernel/expr): remove some old/legacy functions 2018-06-22 12:52:14 -07:00
Leonardo de Moura
1063905d07 chore(kernel/expr): reorder constructors and fix typo 2018-06-22 12:39:16 -07:00
Leonardo de Moura
d0a54aceb6 refactor(kernel): remove unnecessary expr_kind printer 2018-06-22 12:35:38 -07:00
Leonardo de Moura
bc57c66ae3 refactor(kernel/level): naming consistency 2018-06-22 10:29:56 -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
01ea596aea refactor(kernel/expr): implement expr using runtime/object 2018-06-21 16:05:33 -07:00
Leonardo de Moura
c1de8e7ca7 chore(kernel/expr): make sure we can compile with g++ 4.9 2018-06-21 09:00:58 -07:00
Leonardo de Moura
96a9c7db78 feat(kernel/expr): add helper functions for computing scalar data offsets 2018-06-20 16:03:03 -07:00
Leonardo de Moura
bc82208591 chore(kernel/expr): move literal 2018-06-20 15:39:19 -07:00
Leonardo de Moura
fd5bfc7dfe refactor(kernel): simplify binder_info
Now, it is an enumeration type like its Lean counterpart.
2018-06-20 15:31:40 -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
2b9eea3c86 chore(kernel/old_type_checker): copy&paste reduce_proj and infer_proj to old_type_checker
Remark: `old_type_checker` will be deleted in the future.
This commit is just to make sure we can compile legacy code.
2018-06-19 17:26:58 -07:00
Leonardo de Moura
1a3dd6df43 feat(kernel): add reduce_proj and infer_proj 2018-06-19 16:40:00 -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
0847571ea6 feat(kernel): add mdata constructor 2018-06-18 13:36:22 -07:00
Leonardo de Moura
13c532d0d4 fix(*): truncation bugs
- Lean strings (like std::string) may contain null characters. The
  codebase was ignoring this issue.

- We now have a wrapper `string_ref` for wrapping Lean string objects in
  C++. This wrapper also implements correctly the coercions std::string <-> string_ref.
  Remark: I also found a few places where the code relies on the
  following property which is not true
  Forall s : std::string, std::string(s.c_str()) == s

- `name` object wrapper was assuming that all numerals were small
  `nat` values. This is true in most cases, but the system would
  crash when processing if it is a big number.

- The commit tries to make sure runtime/util/kernel are correct.
  Modules that will be deleted contain many `TODO` comments
  indicating they may crash and/or produce incorrect results
  when strings contain null characters and numerals are big.

cc @kha

@kha: I thought about using `string` instead of `string_ref`.
We consistently use `std::string`. So, it should be fine, but I
was concerned about code readability.

After we bootstrap Lean4, we will be able to delete `lean::list`
template, and rename `lean::list_ref` to `lean::list`.

I am going to add `pair_ref` for wrapping Lean pair objects.
If we use `lean::string` instead of `lean::string_ref`, then
we should also use `lean::pair` instead of `lean::pair_ref`.
But, there is a problem in this case since we have
https://github.com/leanprover/lean4/blob/master/src/util/pair.h#L13
:(
2018-06-15 16:05:11 -07:00
Leonardo de Moura
c8a13a9ada refactor(*): name convention obj_list => list_ref
Remark: we use the `_ref` suffix for Lean object smart pointers
when the name clashes with an existing name.
2018-06-15 16:05:11 -07:00
Leonardo de Moura
fe2d416cde fix(runtime,util,kernel): should not use strcmp to compare Lean string objects
Reason:
- UTF8 encoding
- Lean strings may contain null char. That is, null char is not an end
  of string delimiter like in C. Lean string objects are similar to std::string
2018-06-15 16:05:11 -07:00
Leonardo de Moura
af8853829e fix(kernel/expr): bug at literal::kind 2018-06-14 16:18:15 -07:00
Leonardo de Moura
7d40bb5db1 fix(kernel/expr): literal RC issue 2018-06-14 15:36:12 -07:00
Leonardo de Moura
ef38890784 fix(kernel/expr): missing case 2018-06-14 15:28:12 -07:00
Leonardo de Moura
78192972e9 chore(kernel): expr_kind::Meta ==> expr_kind::MVar 2018-06-14 15:13:45 -07:00
Leonardo de Moura
73e067d361 feat(kernel): add expression literals 2018-06-14 14:55:14 -07:00
Leonardo de Moura
4c370e4558 refactor(kernel/expr): fix binder_info 2018-06-13 12:20:58 -07:00
Leonardo de Moura
335c58f8a7 feat(kernel): add expr_kind::Quote
This is a temporary expr constructor. We need it to be able to eliminate
expr_macro, and then define expr using runtime/object
2018-06-12 17:40:00 -07:00
Leonardo de Moura
e590ebf54d feat(kernel/inductive): initialize m_elim_level 2018-06-12 15:17:52 -07:00
Leonardo de Moura
a7d08d2f3d feat(kernel/inductive/inductive): dependent elimination for inductive predicates
In Lean4, we will not generate non dependent recursors for inductive
predicates. The main goal is to make the shape of the automatically
generated recursors more uniform. The non uniform representation is
leftover from Lean2. In Lean2, we wanted to support different kernels
with different features. For example: we could create proof relevant
kernels, no impredicative universe, etc.
Recall that, in a kernel with an impredicative Prop and no proof
irrelevance, inductive predicates without dependent elimination are
weaker that inductive predicates with dependent elimination.
When proof irrelevance is enabled, we can generate the dependent
recursor from the non dependent one. Actually, the module drec.cpp
generates the dependent recursor.
Now, we only support one kind of kernel, and it doesn't make sense
anymore to generate non dependent recursors for inductive predicates.
This would only produce an unnecessary asymmetry on the inductive
datatype module.

Remark: we had to create non dependent recursors to help the elaborator.
This can be avoid if we improve the elaborator. I will do that in the
new elaborator implemented in Lean.

Remark: equation lemmas are broken for definitions that pattern match on
nested inductive datatypes. The problem is the super messy
`prove_eq_rec_invertible_aux` function. This function will not be needed
after I finish the new inductive datatype support in the kernel.

cc @kha
2018-06-12 13:03:26 -07:00
Leonardo de Moura
effefb8b03 chore(kernel/inductive): style 2018-06-12 13:03:25 -07:00
Leonardo de Moura
5088252aa8 feat(kernel): add proper constructor struct 2018-06-12 13:03:25 -07:00
Leonardo de Moura
c3c6c4afc3 feat(kernel/inductive): add check_inductive_types 2018-06-12 13:03:25 -07:00
Leonardo de Moura
b2bebbf75d chore(kernel): check_no_mlocal ==> check_no_metavar_no_fvar 2018-06-12 13:03:25 -07:00
Leonardo de Moura
a632df3211 refactor(kernel/inductive): do not use ginductive inductive declaration format
The format used by ginductive is more compact, but it forces the kernel
to implement the `infer_implicit_params`. It would also create problems
when we make inductive_decls a special case of declaration
2018-06-11 12:52:44 -07:00
Leonardo de Moura
7655d5f328 refactor(kernel): has_local ==> has_fvar 2018-06-11 10:46:05 -07:00
Leonardo de Moura
4ff710b709 fix(kernel/old_type_checker): assertion violation 2018-06-11 10:40:09 -07:00
Leonardo de Moura
d2efeca70c chore(kernel/instantiate): use new function names 2018-06-11 10:18:01 -07:00
Leonardo de Moura
50e50408eb feat(kernel): type checker with local_ctx 2018-06-11 09:59:49 -07:00
Leonardo de Moura
26b47c2852 chore(kernel/old_type_checker): cleanup 2018-06-11 08:57:22 -07:00
Leonardo de Moura
bf165e0f51 fix(kernel/quot): assertion violation 2018-06-09 08:50:32 -07:00
Leonardo de Moura
c632123fd1 chore(kernel/quot): avoid legacy code 2018-06-09 07:54:45 -07:00
Leonardo de Moura
d5c24806e7 feat(kernel/local_ctx): add methods for replacing legacy Pi/Fun 2018-06-09 07:45:16 -07:00
Leonardo de Moura
a6250840d5 chore(kernel): rename some expr functions 2018-06-09 07:18:24 -07:00
Leonardo de Moura
1612aca0b2 chore(kernel): rename expr kinds 2018-06-09 06:50:14 -07:00
Leonardo de Moura
62788a9ca3 refactor(kernel): fix terminology: "free_var" is actually a loose bound variable
We represent free variables uisng local constants.
We will fix this terminology too.
2018-06-08 13:25:36 -07:00
Leonardo de Moura
818170d780 refactor(kernel): remove tag from kernel expressions
We are temporarily storing position information in a global table.
2018-06-08 10:29:22 -07:00
Leonardo de Moura
2a79da1ab6 refactor(kernel): move formatting stuff out of the kernel 2018-06-07 16:28:54 -07:00
Leonardo de Moura
8ae1e51b6d feat(kernel): distinguish kernel_exceptions using different classes 2018-06-07 16:28:54 -07:00
Leonardo de Moura
e90585737f refactor(*): use C++11 std::current_exception and std::rethrow_exception
With these new C++11 APIs, we can delete the `clone` and `rethrow`
methods from our exception classes.
2018-06-07 16:28:54 -07:00