Commit graph

12736 commits

Author SHA1 Message Date
Leonardo de Moura
9bc07254a1 feat: add support for CoeSort 2020-01-29 02:34:35 -08:00
Leonardo de Moura
6a046a11c2 chore: remove coeSortBool
It is interacting with new `Coe`.
We can add it back at `Coe.lean` after we remove `HasCoe.lean`
2020-01-28 19:07:02 -08:00
Leonardo de Moura
c33cd11be1 feat: add CoeHead and CoeTail to minimize nontermination
The adventure continues.

cc @Kha @dselsam
2020-01-28 18:20:58 -08:00
Leonardo de Moura
55bb0805b2 feat: handle attribute inferTCGoalsLR 2020-01-28 18:01:35 -08:00
Leonardo de Moura
f2a32e5985 feat: tag coeFunTrans and coeSortTrans with [inferTCGoalsLR] 2020-01-28 17:19:21 -08:00
Leonardo de Moura
8c34ccf829 feat: add attribute inferTCGoalsLR
@Kha I didn't find any workaround for the instance

```lean
instance coeFunTrans {α : Sort u} {β : Sort v} {γ : Sort w} (a : α) [CoeT α a β] [CoeFun β (coe a) γ] : CoeFun α a γ :=
```

`γ` is an output param. Thus, it is just a metavariable, and if we use
the default order, the subgoal `CoeFun ?β (coe ?a) ?γ` is really bad.
We need to go from left to right here.
2020-01-28 17:08:51 -08:00
Leonardo de Moura
a7de10a74a feat: add support for CoeFun in the new elaborator
cc @kha
2020-01-28 16:50:53 -08:00
Leonardo de Moura
4aa710d4a6 feat: add bridge Coe + HasNat transitivity instance
cc @kha @dselsam
2020-01-28 16:17:14 -08:00
Leonardo de Moura
2a89bcd931 feat: use Coe in the new frontend 2020-01-28 15:51:36 -08:00
Leonardo de Moura
d3cb5b832c fix: handle delayed assignments at isDefEqQuick 2020-01-28 15:09:16 -08:00
Leonardo de Moura
2df230e7a8 feat: missing instance 2020-01-28 14:09:04 -08:00
Leonardo de Moura
e9e4dfe1ff feat: add new Coe.lean 2020-01-28 13:10:30 -08:00
Leonardo de Moura
2efdeda903 fix: bug at preprocessArgs 2020-01-28 12:56:01 -08:00
Leonardo de Moura
9eb1723680 fix: outParam support 2020-01-28 11:13:32 -08:00
Leonardo de Moura
ef51d6c2ab chore: improve error message 2020-01-28 10:56:14 -08:00
Leonardo de Moura
7809274c3a chore: Coe.lean ==> HasCoe.lean 2020-01-28 08:55:22 -08:00
Leonardo de Moura
ef105ba49d chore: remove coe functions
They will be used in the new `Coe` file
2020-01-28 08:49:02 -08:00
Leonardo de Moura
5ca71f48ca chore: make sure Quotation.lean does not depend on old coe 2020-01-28 08:39:36 -08:00
Leonardo de Moura
22c42ec1d8 chore: remove unnecessary method 2020-01-28 08:24:35 -08:00
Leonardo de Moura
f0f522a6d6 chore: prepare to rename old coe primitives 2020-01-28 08:18:56 -08:00
Sebastian Ullrich
244382f49c chore: reintroduce accidentally dropped withMacroExpansion 2020-01-27 16:43:18 +01:00
Sebastian Ullrich
88b09315f1 chore: better error message on missing import
The macOS CI build rarely, randomly fails with a "failed to lock file" message.
This commit will not fix this error, but at least should make it clearer whether
the file actually cannot be locked or is just missing.

/cc @leodemoura
2020-01-27 13:09:01 +01:00
Sebastian Ullrich
c805eb87e6 refactor: elabAnoymousCtor: align more closely to the paper 2020-01-27 10:35:16 +01:00
Leonardo de Moura
145bd50903 feat: disallow patterns with choice nodes
@Kha Patterns with nested "choice" nodes produce counterintuitive
behavior, and hard to understand errors. They only work when we have
the exact same overloads at macro definition and application time.

Here is a funky example
```
syntax [myAdd] term "++":65 term:65 : term    -- overloads "++"
/- The following `macro_rules` manages to eliminate "choice" node by using the
   explicitly provided node kind. -/
macro_rules [myAdd] `($a ++ $b) => `($a + $b)

check (1:Nat) ++ 2 -- works as expected

syntax "FOO!" term : term

/- Before this commit, the following pattern was accepted,
   and it contained a "choice" node for `++`. It is a `myAdd` or
   `HasAppend.append`.

   Now, this kind of pattern is rejected since it contains a nested
   "choice" -/
macro_rules `(FOO! $a ++ $b) => `($a ++ $b)

/- Before this commit, the following command worked because
   it contained a "choice" node similar to the one at macro definition
   time. -/
check FOO! [1, 2] ++ [2, 3]

-- Now, we have 3 overloads for "++".
syntax [myAppend] term "++":65 term:65 : term

-- The `macro_rules` fails here.
```

This commit fixes this weird behavior by disallowing "choice" nodes in
patterns.
2020-01-26 15:13:14 -08:00
Leonardo de Moura
8525584a78 refactor: naming consistency ensure List and Array have similar find* methods
`find?`     -> takes predicate
`findSome?` -> takes a function (A -> Option B)
2020-01-26 15:13:05 -08:00
Leonardo de Moura
5ff63c2bc6 choice: better error message 2020-01-26 13:58:51 -08:00
Leonardo de Moura
17d5453827 fix: elabTerm must be part of observing 2020-01-26 13:55:21 -08:00
Leonardo de Moura
7133d3fc84 feat: handle explicit node kinds in macro_rules, and handle choice kind 2020-01-26 09:39:46 -08:00
Leonardo de Moura
02d31fb619 feat: allow user to specify intended syntax node kind at macro_rules 2020-01-26 08:43:05 -08:00
Leonardo de Moura
e52c4291cc feat: allow macro_rules block with different syntax node kinds 2020-01-26 08:39:40 -08:00
Leonardo de Moura
6a0208630e feat: add sanity checking at macro_rules 2020-01-25 20:31:58 -08:00
Leonardo de Moura
f5630ae054 chore: remove let_core 2020-01-25 20:17:25 -08:00
Leonardo de Moura
1512ccfdc8 chore: reacticate where elaboration 2020-01-25 20:11:42 -08:00
Leonardo de Moura
74bac15c6f chore: make sure letDecl is a node
This is useful when defining notation such as `where`.
Moreover, it allows us to write `$d:letDecl`, but `$d` never matches
a `letDecl`
2020-01-25 19:56:53 -08:00
Leonardo de Moura
5b8e713150 chore: minor 2020-01-25 19:35:18 -08:00
Leonardo de Moura
9f816277fc feat: make sure letSimpleDecl and letPatDecl have the same #args 2020-01-25 19:08:16 -08:00
Leonardo de Moura
051fd530e0 chore: handle new let at toPreterm 2020-01-25 18:33:36 -08:00
Leonardo de Moura
ca690a5571 chore: re-enable let elaborator 2020-01-25 18:24:03 -08:00
Leonardo de Moura
32b36f0ea3 feat: update macro_rules 2020-01-25 18:19:16 -08:00
Leonardo de Moura
71ba6205c3 feat: improve matchAlt syntax 2020-01-25 18:00:30 -08:00
Leonardo de Moura
ca8d6028a1 chore: simplify let decl again 2020-01-25 16:54:26 -08:00
Leonardo de Moura
110191abc8 fix: let syntax 2020-01-25 16:41:29 -08:00
Leonardo de Moura
19e4c30542 feat: elaborate new let decl
We can now write
```lean
syntax "case!" ident ":" term "with" term "," term : term
macro_rules
| `(case! $h : $c with $t, $e) => `(let $h := $c; cond $h $t $e)
```

Before the series of commits to change `let` syntax, the
quasiquotation `(let $h := $c; cond $h $t $e)
produced the weird error message "`;` expected" at ":=".
The problem was that $h was matching the now deleted "nonterminal"
```lean
def letIdDecl         := parser! try (letIdLhs >> " := ") >> termParser
```
This was not a bug, but a side-effect on how the `let` syntax was
declared.

cc @kha
2020-01-25 16:32:21 -08:00
Leonardo de Moura
eb8e7b9f3d feat: add new let syntax
It avoids hidden nonterminals, and store the equation case as a
separate rule. It would be great if we could have 3 independent rules,
but this is not possible because `longestMatch` would return a choice
for terms as simple as `let x := v; ...` The problem is that it is
both a `letSimpleDecl` and a `letPatDecl`. We resolve the ambiguity at
the parsing level using `<|>`.

cc @Kha
2020-01-25 16:15:30 -08:00
Leonardo de Moura
b708407b7b chore: implement Quotation.lean using let_core, disable let syntax 2020-01-25 15:34:24 -08:00
Leonardo de Moura
993ae96fb7 chore: elaborate let_core 2020-01-25 15:21:47 -08:00
Leonardo de Moura
5796eba368 chore: add elabLetDeclAux 2020-01-25 15:14:28 -08:00
Leonardo de Moura
58833e6f79 chore: add let_core
We want to change the representation of `let` terms.
`let_core` is a temporary syntax for helping us with the translation.
2020-01-25 15:08:36 -08:00
Leonardo de Moura
bdb9f4c86e feat: allow raw identifiers to be used where terms are expected
@Kha this commit fix another example of weird error message I have
experienced in the last few days.

The macro
```lean
syntax "case!" ident ":" term "with" term "," term : term
macro_rules
| `(case! $h : $cond with $t, $e) =>
  `((fun $h => cond $h $t $e) $cond)
```
is accepted, but as in `fun` binders, we get a weird error when
trying to elaborate an instance of the macro.
Example:
```lean
check case! h : 0 == 0 with h, not h
```
2020-01-25 14:55:32 -08:00
Leonardo de Moura
7b6caba457 feat: add `ident as a valid elaboration kind 2020-01-25 14:55:32 -08:00