Commit graph

20520 commits

Author SHA1 Message Date
Leonardo de Moura
e3b1ae514b fix: nontermination
This issue was reported by Simon Winwood at Zulip.
Here is the message

The following code doesn't terminate (in a reasonable amount of time)
```
def large_nat : Nat := (9223372036854775807 : Nat)
```
$ time lean --o=large-nat.olean large-nat.lean
2020-08-18 18:45:28 -07:00
Leonardo de Moura
d0c8da84d2 chore: update stage0 2020-08-18 18:18:23 -07:00
Leonardo de Moura
3478579dce chore: fix typo 2020-08-18 18:16:36 -07:00
Leonardo de Moura
b44ab93c58 refactor: implement CommandElabM using StateRefT 2020-08-18 18:04:49 -07:00
Leonardo de Moura
390aef535e chore: remove workaround 2020-08-18 17:22:51 -07:00
Leonardo de Moura
64f5ac37c1 fix: missing instance 2020-08-18 17:22:22 -07:00
Leonardo de Moura
4eef5a2fb6 fix: missing instance 2020-08-18 17:22:08 -07:00
Leonardo de Moura
58c4d8bfc0 refactor: add MonadStateOf
@Kha I tried to remove `MonadExceptOf` by adding `HasThrow` and
`HasCatch`, but this change impacts our ability to define polymorphic
methods such as `finally` which is parametrized by `[MonadExcept]`.
If we remove the `outParam` from `[MonadExcept]`, then we will need to
know the exception at `finally`, or add two instances `[HasCatch]` and
`[HasThrow]`. So, it seems it is more convenient to have
`[MonadExceptOf]` and `[MonadExcept]`. Thus, I applied this approach
to `[MonadState]`
2020-08-18 16:35:33 -07:00
Leonardo de Moura
e70ff5b773 refactor: simplify CoreM using StateRefT 2020-08-18 16:02:29 -07:00
Leonardo de Moura
b8044fdf97 chore: remove MonadExceptOf from MonadIO
@Kha we currently do not need this feature. We may add it back when needed.
2020-08-18 15:40:16 -07:00
Leonardo de Moura
9519479726 chore: fix test 2020-08-18 15:19:22 -07:00
Leonardo de Moura
647b917b49 test: HasGetAt helper class example 2020-08-18 15:16:02 -07:00
Leonardo de Moura
5605735137 feat: remove outparam from MonadState
We add helper classes with `outParam`.

@Kha This is similar to the `MonadExceptOf` modification.
Motivation: the new `StateRefT` (state monad implemented using
`IO.Ref`) makes is it quite cheap to have multiple states on the
stack. But, we need a mechanism for accessing the different states in
a convenient way.
Note that, I did not add a `MonadStateOf` class, but helper classes
such as `HasGet` which uses `outParam`. I will do the same for `MonadExcept`.

Summary:
- `get` gets the state on the top of the Monad stack
- `getThe σ` gets the state with type `σ`
- `modify f` modifies the state on the top of the Monad stack.
   We use `modify fun s => { s with ... }` quite often, and we cannot
   infer type of `s` here.
- `modifyThe σ f` allows us to select which state on the stack we are modifying.
- I didn't add `setThe`, since we usually can infer the state type at
  `set s`. In the whole codebase, we have only one instance where this
  is not true.
2020-08-18 15:15:31 -07:00
Leonardo de Moura
f01d45a6c1 feat: add StateRef 2020-08-18 13:54:51 -07:00
Leonardo de Moura
53cbc744c7 fix: missing instance 2020-08-18 13:42:48 -07:00
Leonardo de Moura
1e496fb32d feat: helper instance 2020-08-18 13:26:14 -07:00
Leonardo de Moura
09e588269c feat: add MonadIO instance for CoreM 2020-08-18 13:25:49 -07:00
Leonardo de Moura
aa2f834c0f feat: add mkMonadIO and modifyGet 2020-08-18 13:25:15 -07:00
Leonardo de Moura
a69178ea9f feat: add MonadTracer instance 2020-08-18 13:24:32 -07:00
Leonardo de Moura
b142c608fe feat: add CoreM 2020-08-18 09:45:16 -07:00
Sebastian Ullrich
20c5f4cde9 chore: update stage0 2020-08-18 16:03:31 +02:00
Sebastian Ullrich
eeaf20080c refactor: register parenthesizer compiler as hook
/cc @leodemoura
2020-08-18 16:02:33 +02:00
Sebastian Ullrich
58e7af0d7f chore: simplify parser attribute hook registration
It is unlikely to be needed outside the stdlib
2020-08-18 15:52:23 +02:00
Sebastian Ullrich
694a8cb28c chore: update stage0 2020-08-18 15:18:28 +02:00
Sebastian Ullrich
dab53c4986 feat: add [parserAttributeHook] attribute 2020-08-18 14:41:36 +02:00
Sebastian Ullrich
5e48d2bb7d chore: update cross benches 2020-08-18 11:44:29 +02:00
Leonardo de Moura
d059d28c22 fix: anonymous constructor elaborator 2020-08-17 17:32:11 -07:00
Leonardo de Moura
0cda65057e fix: addCtorFields 2020-08-17 17:25:42 -07:00
Leonardo de Moura
f7f77241a1 chore: fix test 2020-08-17 17:14:28 -07:00
Leonardo de Moura
07dd5c9daf fix: withFields 2020-08-17 17:12:59 -07:00
Leonardo de Moura
2ce8479303 refactor: DepElim.lean ==> Match.lean 2020-08-17 16:34:39 -07:00
Leonardo de Moura
81a19c8554 feat: structure instances with .. in patterns 2020-08-17 16:23:49 -07:00
Leonardo de Moura
b47f530db5 chore: remove debugging code 2020-08-17 16:23:11 -07:00
Leonardo de Moura
7c87b8f256 feat: add Expr.occurs 2020-08-17 16:20:57 -07:00
Leonardo de Moura
9b085b97c4 feat: let+equations macro 2020-08-17 10:15:43 -07:00
Leonardo de Moura
f335cb3304 test: let+pattern 2020-08-17 09:28:25 -07:00
Leonardo de Moura
3342ba08d2 feat: implement let elaborators without using match_syntax
@Kha I had to do this because of the `ident` vs `Term.id` recurrent
issue. `match_syntax` fails if a `Term.id` is used at `Term.letIdDecl`
where an `ident` is expected.
We should try to remove `Term.id` in the future.
2020-08-17 09:27:54 -07:00
Leonardo de Moura
1ba3925740 feat: new let-expression syntax
see 0064f7d2b9
2020-08-17 07:51:08 -07:00
Leonardo de Moura
ae2e00ae96 chore: update stage0 2020-08-17 06:29:24 -07:00
Leonardo de Moura
5d945dba2d test: match-expression 2020-08-16 15:50:22 -07:00
Leonardo de Moura
0064f7d2b9 chore: add let+patterns case
@Kha the patterns at `Binders.lean` for let-expressions are not matched correctly by
`match_syntax`. The problem is that we "reuse" kinds here:
```lean
def letIdDecl   : Parser := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl $ try (letIdLhs >> " := ") >> termParser
def letPatDecl  : Parser := node `Lean.Parser.Term.letDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl : Parser := node `Lean.Parser.Term.letDecl $ letIdLhs >> matchAlts false
def letDecl              := letIdDecl <|> letPatDecl <|> letEqnsDecl
```
This is a bad hack for implementing the `where` macro. I will remove it, and rewrite the code above as
```lean
def letIdDecl   := parser! try (letIdLhs >> " := ") >> termParser
def letPatDecl  := parser! try (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl := parser! letIdLhs >> matchAlts false
def letDecl     := parser! letIdDecl <|> letPatDecl <|> letEqnsDecl
```
Remark: we need the `letDecl` kind to be able to implement the `where`
macro.
I will do it tomorrow because it is a staging nightmare.
2020-08-16 15:41:53 -07:00
Leonardo de Moura
fdd8978bfe fix: structure instance in patterns
TODO: the structure instance `..` is not being handled correctly in
patterns. We must create new pattern variables for the missing fields.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2020-08-16 15:03:49 -07:00
Leonardo de Moura
bedb9d1fb6 fix: postponeElabTerm
This bug was introduced by the `ref`-plumbing refactoring.
2020-08-16 14:47:52 -07:00
Leonardo de Moura
7ea0d5394d feat: add withMacroExpansion 2020-08-16 14:28:07 -07:00
Leonardo de Moura
a97f8cb8e4 fix: nontermination at DepElim 2020-08-16 11:07:44 -07:00
Leonardo de Moura
8a7edf03ca feat: add commitWhenSome? 2020-08-16 10:55:15 -07:00
Leonardo de Moura
58f4b280ca feat: elaborate nomatch 2020-08-16 08:26:04 -07:00
Leonardo de Moura
655104d8df fix: use constructor transition when we have an empty set of alternatives 2020-08-16 08:25:38 -07:00
Leonardo de Moura
b616e8d07a test: do issue
This is the example triggered a panic message in the new frontend when
we were encoding `do a; b` as `a *> b`.
See 7cdf917c9
2020-08-15 16:07:01 -07:00
Leonardo de Moura
4f145c744e test: match-expr 2020-08-15 16:03:31 -07:00