Commit graph

726 commits

Author SHA1 Message Date
Leonardo de Moura
2ebf8ab8f1 chore(*): unnecessary #includes 2018-05-18 13:19:22 -07:00
Sebastian Ullrich
696ba77b53 feat(frontends/lean/elaborator): anonymous constructor notation for ginductives 2018-05-17 14:14:00 +02:00
Leonardo de Moura
0556412f8d refactor(*): add runtime folder
@kha The runtime folder includes what is needed to link a
standalone Lean program. It is still contains some unnecessary files.
We will be able to remove them after we release Lean4.
2018-05-14 14:23:56 -07:00
Leonardo de Moura
b0641ba770 feat(frontends/lean/elaborator): add support for definitions such as monad_run.run
cc @Kha
2018-05-08 17:14:52 -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
efb9fb0802 chore(kernel): remove opportunistic hash consing support
It just adds extra complexity and is in conflict for our plans for
Lean4. Moreover, in our experiments it impacts negatively on
performance: master and lean4 branches. The negative impact has been
confirmed by @kha too.
2018-04-12 16:43:10 -07:00
Leonardo de Moura
c08a3bc557 refactor(library/typed_expr): move typed_expr to frontends/lean 2018-04-09 15:25:40 -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
Leonardo de Moura
bdea7d420d chore(*): type_context ==> type_context_old 2018-03-05 12:38:24 -08:00
Sebastian Ullrich
76843717c4 chore(frontends/lean/elaborator): style 2018-02-28 12:49:22 +01:00
Sebastian Ullrich
f3ca420b64 feat(frontends/lean/elaborator): hide opt/auto param types when elaborating structure field values 2018-02-28 12:49:22 +01:00
Leonardo de Moura
5607884787 feat(library/tactic): use new cache
Remark: so far, caching, in the tactic framework, only makes a difference for the `simp` tactic.
This is not surprising since the simplifier tries to apply rewriting
lemmas over and over again.
2018-02-21 15:04:20 -08:00
Leonardo de Moura
8a93d2770e feat(library/equations_compiler): add new cache support to equation compiler 2018-02-21 15:04:20 -08:00
Leonardo de Moura
9d9ac16e7a feat(library): add implementation of abstract_context_cache 2018-02-21 15:04:20 -08:00
Leonardo de Moura
7762dc381a feat(library/type_context): use context_cache interface 2018-02-21 15:04:20 -08:00
Leonardo de Moura
78d8ff8031 feat(*): add reset_thread_local 2018-02-21 15:04:19 -08:00
Sebastian Ullrich
782af7e5d6 chore(library/vm/interaction_state): do not profile calls into Lean other than tactic execution
Otherwise, we produce a message for e.g. every single interactive tactic parameter
2018-02-19 09:13:24 -08:00
Sebastian Ullrich
9c5df7875a perf(frontends/lean/elaborator): visit_structure_instance_fn: delay building error message 2018-02-19 09:13:24 -08:00
Leonardo de Moura
56dba5b98a fix(frontends/lean/elaborator): fixes #1930
@kha the following idiom is not safe
```
   while (is_pi(t)) {
      t = whnf(binding_body(t));
   }
```
`whnf(e)` assumes that `e` does not have dangling deBruijn variables.
We should use (the more expensive):
```
   while (is_pi(t)) {
      t = whnf(instantiate(binding_body(t), locals.push_local_from_binding(t)));
   }
```
BTW, this problem is not related to the assertion violation at #1930
I just stumbled on it when fixing the violation.
2018-02-19 08:51:26 -08:00
Sebastian Ullrich
affe3463ab fix(frontends/lean/elaborator): fix assertion error: accidental mutation of a variable 2018-02-08 14:07:08 +01:00
Sebastian Ullrich
5736fda1ee chore(frontends/lean/elaborator): do not name mvars from { .. } catchall
We already use the same names for the field mvars, which can be confusing during debugging
2018-02-08 14:04:33 +01:00
Nuno Lopes
c1a768b7a7 fix(msvc): further work on MSVC port
only 7 files left
2018-02-06 10:11:10 -08:00
Sebastian Ullrich
4d5bd6d03c fix(frontends/lean/elaborator): fix build 2018-02-02 20:53:24 +01:00
Sebastian Ullrich
703d12d594 feat(frontends/lean/elaborator): do not execute tactics after error recovery 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
b3262d53b4 feat(frontends/lean/elaborator): structure notation: fall back to inferring superclasses 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
9f25cf665e feat(frontends/lean/elaborator): structure instance notation: allow implicit fields 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
6eeb90c8fb chore(frontends/lean/elaborator): remove confusing assign_mvar method 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
040748419f refactor(frontends/lean/elaborator): refactor and document structure instance notation code 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
6ab13a433d chore(library/type_context): should not have an implicit constructor, copy constructor, or assignment operator 2018-02-02 08:58:53 -08:00
Sebastian Ullrich
9f60fd5492 feat(frontends/lean/elaborator): ignore more sorry-containing type mismatch messages 2018-02-02 08:58:52 -08:00
Sebastian Ullrich
009cff6f79 feat(frontends/lean/elaborator): prefer taking subobjects from structure notation sources as a whole
This guarantees definitional equality on the field as witnessed by the test
2018-02-02 08:58:52 -08:00
Leonardo de Moura
b063edb6c7 chore(frontends/lean/elaborator): remove dead code 2018-02-02 08:49:10 -08:00
Leonardo de Moura
ec1a490a15 chore(*): annotate candidates for thread local cache reset 2018-02-01 14:59:37 -08:00
Leonardo de Moura
c5df94ed17 feat(library/tactic): add support for auto params at simp tactic 2018-01-11 16:47:22 -08:00
Leonardo de Moura
e0bdb10ab4 fix(library/type_context): clenaup whnf_head_pred
The code had a few leftovers from the old `whnf_pred` method.
We don't use `whnf_pred` anymore.
2018-01-08 11:31:03 -08:00
Leonardo de Moura
e9650d835d chore(library/type_context): cleanup metavar method names
This commit also fixes some corner case bugs at is_def_eq
2018-01-03 13:49:42 -08:00
Leonardo de Moura
8621be6335 fix(frontends/lean): closes #1898 2018-01-02 12:33:00 -08:00
Leonardo de Moura
f0352d31a1 feat(library/type_context, library): inout ==> out modifier in type class declarations
@kha: I decided to implement this change before I start the
type_context modifications. The change did not affect the corelib and
test suite much. The only annoying problem is that `out` cannot be
used to name locals anymore.
2017-12-15 14:46:47 -08:00
Leonardo de Moura
ef784ce7b8 fix(library/tactic/simp_lemmas): auto_params when adding simp lemmas 2017-12-09 09:47:39 -08:00
Sebastian Ullrich
18cf63e37f fix(frontends/lean/elaborator): avoid assertion error on delayed abstraction in structure notation 2017-11-24 21:27:55 +01:00
Sebastian Ullrich
30cfc6cf0b feat(frontends/lean/{parser,elaborator}): structure instance patterns 2017-11-22 12:16:28 -08:00
Sebastian Ullrich
06a316ad30 fix(frontends/lean/elaborator): type of '..' placeholders
Fixes #1870
2017-11-19 18:57:18 +01:00
Sebastian Ullrich
0aacccd8c9 feat(frontends/lean): change structure update notation
`{s with ...}` is now `{..., ..s}`, which more clearly expresses that the
result type is not necessarily equal to the type of `s` (in absence of an
expected type and a structure name, we still default to the type of `s`).

Multiple fallback sources can be given: `{..., ..s, ..t}` will fall back to
searching a field in `s`, then in `t`. The last component can also be `..`,
which will replace any missing fields with a placeholder.

The old notation will be removed in the future.
2017-11-17 16:40:47 -08:00
Sebastian Ullrich
e7e05a3ad0 feat(frontends/lean): add aliasing patterns id@pat 2017-11-17 16:35:21 -08:00
Leonardo de Moura
d88a6f663e fix(frontends/lean/elaborator): implicit arguments after auto_param arguments
Function applications `(f ...)` were not being elaborated correctly when
`f` has implicit parameters occurring after auto_params.
The new test exposes the problem.

This bug was found when developing the red black tree module.

This commit also fixes the following bugs:

- Invoke type class resolution again after tactic execution at
  synthesize method. Reason: metavariables occurring in type
  class instances may have been synthesized by tactics.

- mctx.assign optimization at invoke_tactic was incorrect
  when the metavariable was assigned by typing rules.
2017-11-14 17:22:12 -08:00
Sebastian Ullrich
191065d963 fix(frontends/lean/elaborator): change assertion into type mismatch error
Fixes #1859
2017-11-06 10:51:37 +01:00
Sebastian Ullrich
032e0701e0 fix(frontends/lean/elaborator): non-recursive local shouldn't shadow projection 2017-10-23 12:12:06 -07:00
Sebastian Ullrich
d82df26ff0 fix(frontends/lean/elaborator): go back to ignoring implicit args in quote patterns 2017-09-11 09:33:38 -07:00
Sebastian Ullrich
0bf96e5752 fix(frontends/lean/elaborator): revert dubious workaround of mine
Synthesizing an expr placeholder in an elaborated term doesn't make much sense
2017-09-08 13:23:16 +02:00
Gabriel Ebner
5f8cf45073 feat(frontends/lean/elaborator): apply to-sort coercion also in arguments 2017-09-06 14:15:30 +02:00