Commit graph

26011 commits

Author SHA1 Message Date
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
Leonardo de Moura
e90efdcabf chore: update stage0 2020-08-15 15:59:30 -07:00
Leonardo de Moura
b03589757a chore: update stage0 2020-08-15 15:56:09 -07:00
Leonardo de Moura
7cdf917c97 fix: compiler do a; b as a >>= fun _ => b
Consider the following example
```lean
def div!: Nat → Nat → Nat
| x, 0 => panic! "division by zero"
| x, y => x/y

def weird (x : Nat) : MetaM Nat :=
unless (x > 0) (throwOther "x == 0") *>
let y := div! 10 x;
pure y
```
If we execute `weird 0`, it produces a "division by zero" panic
message.
This is a simple version of a much bigger function in the new
frontend.
This is not due to a bug in the compiler.
It produces the panic message because of the `do`-encoding
refactoring. Recall that, a few months ago,
we started to compile `do a; b` as `a *> b` (i.e., `seqRight a b`).
Thus, the example above is
`seqRight action1 (let y := div! 10 x; pure y)`
where `action1` is the `unless ...`.
In A-normal form, this is equivalent to

```lean
let y:= div! 10 x;
let action2 := pure y;
seqRight action1 action2
```
Thus, we execute `div! 10 x` before we even execute the `seqRight`.
This is counterintuitive and demonstrates once again how impure
features such as `panic!` are dangerous.

This commit reverts the `do`-encoding refactoring, and encodes
`do a; b` as `a >>= fun _ b` as we did in Lean3.

cc @Kha
2020-08-15 15:51:00 -07:00
Leonardo de Moura
e32ebc62c0 fix: tryPostponeIfMVar
Must not postpone if there is a term `t` (which is not a metavariable)
assigned to the metavariable `e.getAppFn`.
2020-08-15 14:36:16 -07:00
Leonardo de Moura
2295c315aa feat: add elabTermEnsuringType
This commit also fixes a match-expression error location issue.
2020-08-15 13:49:10 -07:00
Leonardo de Moura
e9748dd0f9 test: match equality proofs 2020-08-15 13:35:16 -07:00
Leonardo de Moura
bb261c51a6 fix: isDefEqQuick 2020-08-15 13:24:43 -07:00
Leonardo de Moura
34d9879061 test: add new tests 2020-08-15 13:14:16 -07:00
Leonardo de Moura
9a2f10c592 chore: update stage0 2020-08-15 08:20:12 -07:00