Commit graph

63 commits

Author SHA1 Message Date
Sebastian Ullrich
e726c64895 feat(frontends/lean/vm_elaborator): synthesize instance names 2019-01-16 19:12:40 +01:00
Leonardo de Moura
4f53e505b0 fix(library/compiler): we need to unfold auxiliary nested _match applications eagerly 2018-09-18 14:17:37 -07:00
Leonardo de Moura
fabfe32ca5 chore(*): remove unnecessary scoped_ext dependencies 2018-09-08 15:42:48 -07:00
Leonardo de Moura
dd03747d22 chore(kernel): univ_param vs lparam, level_param_names ==> names, and other inconsistencies 2018-09-03 13:05:42 -07:00
Sebastian Ullrich
39cdae50ee feat(library,frontends/lean): use mdata instead of hacky cache for position information in preterms 2018-09-02 18:08:41 -07:00
Leonardo de Moura
d334bb1fa7 chore(*): remove more stuff 2018-08-23 15:56:31 -07:00
Sebastian Ullrich
046b1890ad feat(src/frontends/lean/decl_util): ignore out_params when deciding whether to include an anonymous inst implicit section variable 2018-07-27 14:49:09 -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
bc57c66ae3 refactor(kernel/level): naming consistency 2018-06-22 10:29:56 -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
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
4836dd55b5 chore(frontends/lean): propogate position information
This is a huge HACK to get some position information.
2018-06-08 11:12:01 -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
75c63ec921 refactor(*): list<name> ==> obj_list<name> 2018-05-23 15:48:43 -07:00
Leonardo de Moura
f8e0916c64 feat(library/tactic, frontends/lean): replace a few mk_tagged_fresh_name with mk_unused_name 2018-02-21 15:04:19 -08:00
Leonardo de Moura
3fa487c153 fix(frontends/lean/decl_util): as-is annotation was leaking into elaborated terms
@kha This commit fixes the repro you sent me. Could you please check
whether it also fixes the original file?
2018-01-30 12:48:48 -08:00
Leonardo de Moura
8b835f9ab6 fix(frontends/lean): fixes #1890
It fixes the issue by propagating the correct information to the
equation compiler.

The fix may be a little bit hackish, but it is comapatible with
the approach we are already using: store `m_is_meta` flag in the equation
macro.

Disclaimer: we may still have other instances of this bug, since
the information may still be propagated incorrectly in other places.

I will not refactor this code right now nor accept any PR that
changes the current design. I am busy in other parts of the code
base and do not have time to do the context switch required for
implementing this kind of change and/or review the PR and make sure I'm
happy with it.
2017-12-17 09:42:06 -08:00
Leonardo de Moura
7c35a25169 fix(frontends/lean): do not generate equation lemma for match expressions occurring in by tac nested in regular definitions 2017-11-22 12:49:32 -08:00
Leonardo de Moura
fabf7f6380 perf(library/equations_compiler, library/compiler): expand auxiliary _match_idx definitions when generating byte code
We use the auxiliary procedure pull_nested_rec_fn to pull recursive
application in nested match expressions. This is needed because the
nested match expression is compiled before we process the recursive
procedure that contains it. This transformation may produce
performance problems if the recursive application does not depend on
the data being matched. Here is an example from the new test:

```
def tst : tree → nat
| (tree.leaf v) := v
| (tree.node v l r) :=
  match f v with
  | tt := tst l
  | ff := tst r
  end
```

pull_nested_rec_fn will convert it into

```
def tst : tree → nat
| (tree.leaf v)     := v
| (tree.node v l r) := tst._match_1 (f v) (tst l) (tst r)
```

Since our interpreter uses eager evaluation, both `(tst l)` and `(tst r)`
are executed. This commit fixes this issue by expanding `tst._match_1`
during code generation.
2017-11-09 11:14:57 -08:00
Leonardo de Moura
f36fca875c feag(frontends/lean): explicit delimiters in declaration parameters
Comment from parser.h

This commit makes sure that all declaration parameters must be surrounded with some kind of bracket. (e.g., '()', '{}', '[]').
The goal is to avoid counter-intuitive declarations such as:

              example p : false := trivial
              def main proof : false := trivial

which would be parsed as

              example (p : false) : _ := trivial

              def main (proof : false) : _ := trivial

where `_` in both cases is elaborated into `true`. This issue was raised by @gebner in the slack channel.

Remark: we still want implicit delimiters for lambda/pi expressions. That is, we want to write

               fun x : t, s
           or
               fun x, s

instead of

               fun (x : t), s
2017-09-15 10:07:09 -07:00
Leonardo de Moura
d428eca8a7 fix(library/equations_compiler,frontends/lean): private name support and alias generation for auxialiary declarations
fixes #1804

Remark: now, all auxiliary definitions in a private declaration share
the same "private" prefix.
2017-09-11 16:46:56 -07:00
Leonardo de Moura
9afb53fad5 feat(kernel/expr): allow metavariables to have user-facing names
We need this feature for:
1) Defining nonlinear search patterns. Example: (?m <= ?m + 1)
2) Preprocessing recursive equations and support the pattern
refinement approach used in Agda. Example: in Agda, they accept
```
def append {A : Type} : Π (m n : nat), Vec A m -> Vec A n -> Vec A (m + n)
| m n nil            ys := ys
| m n (cons m' x xs) ys := cons x (append m' n xs ys)
```
These equations have to be refined. For example, `m` has to be
replaced with `0` (in the first equation), and `succ m'` in the
second. To implement this kind of refinement, we need to convert
the pattern variables (local constants) into metavariables during
elaboration. Then, the unassigned metavariables become local constants
again. This preprocessing step will fix some of the issues on #1594.
To completely fix #1594, we will need yet another preprocessing step
which will implement "complete transition" used in the equation
compiler before we start elim_match.cpp
2017-07-16 07:16:41 -07:00
Leonardo de Moura
748eb856c3 fix(frontends/lean): fixes #1649
This issue is yet another reason for refactoring how parameters are
represented in Lean.
2017-06-06 21:33:24 -07:00
Gabriel Ebner
6b956ad658 fix(frontends/lean): prevent endless loops 2017-05-23 11:14:30 -07:00
Gabriel Ebner
1468461c47 feat(frontends/lean): recover from many parser errors 2017-05-23 11:14:30 -07:00
Sebastian Ullrich
aefd312a98 feat(frontends/lean/decl_util): allow opt_param shorthand in all decls 2017-05-17 10:38:12 -07:00
Sebastian Ullrich
14425bd2d3 fix(frontends/lean/decl_util): double-elaboration of include params 2017-05-14 19:19:22 -07:00
Sebastian Ullrich
7a147eab12 fix(frontends/lean/decl_util): truly fix top-level do pattern names race 2017-03-30 06:04:00 +02:00
Sebastian Ullrich
e7f01b7490 fix(frontends/lean/decl_util): bad reset in scope destructor 2017-03-30 06:04:00 +02:00
Gabriel Ebner
5f872912e0 refactor(shell/lean): set exit status 1 iff at least one error was reported 2017-03-23 08:57:56 +01:00
Leonardo de Moura
a897fd3f17 fix(frontends/lean): pattern matching in the declaration header 2017-03-16 01:09:12 -07:00
Daniel Selsam
ce1ec69ea6 fix(frontends/lean/decl_utils.cpp): closes #1417 2017-03-06 10:54:22 -08:00
Leonardo de Moura
54f7bf9391 fix(frontends/lean, library/tactic): remove redundant error messages, and fix position of error messages
Summary:

We minimize the number of "'sorry' used warning messages".  We also
re-target the error to the main declaration. Example: foo._main ==> foo
We do not report for auxiliary declarations such as "_example" and
"foo.equations._eqn_1"

Get rid of the redundant error message "error : failed" for tactics.
We added "silent failures" in the tactic framework.

We do not store line/col information for tactics nested in notation
declarations.  Before this commit, we would have tactics such
as (tactic.save_info line col) nested inside of notation declarations.
2017-02-07 20:25:28 -08:00
Leonardo de Moura
4d3ff955d3 feat(frontends/lean): nicer syntax for default parameter values
See #1340
2017-01-30 15:54:26 -08:00
Leonardo de Moura
93c8e69313 chore(frontends/lean, library): cleanup anonymous instance management 2017-01-06 14:37:44 -08:00
Gabriel Ebner
a8df381d20 feat(*): parallel compilation 2016-11-29 11:12:40 -08:00
Leonardo de Moura
9b84db083d fix(frontends/lean): error localization bugs 2016-10-15 13:40:57 -07:00
Leonardo de Moura
a5029ab5d2 fix(frontends/lean): improve error localization 2016-10-15 10:43:33 -07:00
Leonardo de Moura
c745519e50 feat(frontends/lean/definition_cmds): generate equation lemmas for top-level definitions 2016-10-06 15:30:43 -07:00
Leonardo de Moura
148da46481 feat(frontends/lean): 'mutual' and 'meta' are now keywords 2016-09-24 10:44:40 -07:00
Leonardo de Moura
6d9a9b46f3 chore(frontends/lean): cleanup 2016-09-23 16:26:21 -07:00
Leonardo de Moura
f00e6c0a96 feat(frontends/lean): anonymous instances
The instance name is synthesized automatically.
2016-09-23 13:34:34 -07:00
Leonardo de Moura
c8e13cd391 feat(frontends/lean): minimize errors being reported 2016-09-23 09:20:31 -07:00
Leonardo de Moura
c668185a1e fix(frontends/lean/decl_util): bug add add_local_ref 2016-09-19 15:53:58 -07:00
Leonardo de Moura
f1a244b858 fix(frontends/lean/decl_util): bug at add_local_ref 2016-09-19 15:45:58 -07:00
Leonardo de Moura
9013dacd03 fix(frontends/lean/decl_util): bug at collect_implicit_locals 2016-09-16 22:35:33 -07:00
Leonardo de Moura
f8df2cd44f fix(frontends/lean/decl_util): section variables/parameters 2016-09-16 15:32:51 -07:00
Leonardo de Moura
194985f335 fix(frontends/lean/decl_util): bug when creating local ref 2016-09-15 18:47:02 -07:00
Leonardo de Moura
6c84a0a7b1 feat(frontends/lean): use new notation for declaring universes in constant and structure decls 2016-09-13 21:45:16 -07:00
Leonardo de Moura
ce53c035bc feat(frontends/lean/decl_util): use the same notation for declaring universes in mutual and single decls 2016-09-13 21:05:18 -07:00