Commit graph

363 commits

Author SHA1 Message Date
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
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
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
09e588269c feat: add MonadIO instance for CoreM 2020-08-18 13:25:49 -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
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
dab53c4986 feat: add [parserAttributeHook] attribute 2020-08-18 14:41:36 +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
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
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
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
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
bb261c51a6 fix: isDefEqQuick 2020-08-15 13:24:43 -07:00
Leonardo de Moura
0be9516bd8 fix: instantiate metavariables in alternative local decls 2020-08-15 08:18:00 -07:00
Leonardo de Moura
63c4ee0acf chore: cleanup 2020-08-15 08:07:46 -07:00
Leonardo de Moura
7eed45dd45 fix: generalize isNatValueTransition 2020-08-15 07:59:31 -07:00
Leonardo de Moura
6e958d6208 refactor: cleanup 2020-08-15 07:55:44 -07:00
Leonardo de Moura
4223bdf8aa feat: add expandNatValuePattern 2020-08-15 07:26:22 -07:00
Leonardo de Moura
5d56cc5505 refactor: DepElim
We go back to the original approach where we pattern matching
alternative variables as `FVar`s.
We fix the original problem we had by implementing a simple
unification procedure for alternative `FVar`s.
2020-08-14 19:03:22 -07:00
Leonardo de Moura
87d506cb90 feat: instantiate metavariables in LocalDecls 2020-08-14 19:02:38 -07:00
Leonardo de Moura
00d46e4a7d chore: preparing to refactor DepElim 2020-08-14 19:02:20 -07:00
Leonardo de Moura
55d9689a7b fix: finalizePatternDecls 2020-08-14 13:55:43 -07:00
Leonardo de Moura
c5316d5cf3 fix: missing withMVarContext 2020-08-14 12:52:51 -07:00
Leonardo de Moura
50abd28f6e feat: generalize "constructor transition" 2020-08-14 12:38:43 -07:00
Leonardo de Moura
e2109ceab6 fix: missing substitution
We should include the `majorFVarId -> ctor-application` substitution
in each subgoal.
2020-08-14 12:38:00 -07:00
Leonardo de Moura
b3894200f0 feat: expose constructorApp? and isConstructorApp? 2020-08-14 12:37:34 -07:00
Leonardo de Moura
d85a41a4d7 chore: reduce number of dependencies
@Kha Please try to avoid importing `Lean.Meta`, it is huge, and any
change there was forcing a bunch of files to be recompiled since
`Parser.Extension` depends on `Parenthesizer`
2020-08-14 10:59:00 -07:00
Leonardo de Moura
8e81c19162 fix: combine "complete" and constructor transitions 2020-08-14 10:50:48 -07:00