Commit graph

13763 commits

Author SHA1 Message Date
Leonardo de Moura
4e736bcca0 feat: use trick to inform compiler that a builtin doesn't throw exceptions 2020-08-20 11:05:11 -07:00
Leonardo de Moura
c0dbf60830 feat: remove IO.ref.reset
`reset` was used to implement a "buggy" `IO.ref.modify`.
```lean
@[inline] def Ref.modify {α : Type} (r : Ref α) (f : α → α) : m Unit := do
v ← r.get;
r.reset;
r.set (f v)
```
`IO.Ref.reset` will store a nullptr in `r`.
Now, suppose another thread tries to read this reference,
it will get an `IO.error`.
It is not a crash, but it is really weird behavior.
2020-08-20 10:07:15 -07:00
Sebastian Ullrich
ea266e48ab feat: unicodeSymbol.formatter: prefer symbol used in syntax tree 2020-08-20 18:57:08 +02:00
Sebastian Ullrich
95742ca17b fix: parenthesizer: take minimum of successive precedence checks for contPrec as well
Otherwise, we would parenthesize `1 + 2 + 3` as `(1 + 2) + 3` since in
```
@[builtinTermParser] def add   := tparser! infixL " + "  65
```
there is an additional `checkPrec 1024` implied by `tparser!`. Now `contPrec` of this parser is (min 1024 65 = 65).
2020-08-20 18:36:04 +02:00
Sebastian Ullrich
c2fbb3d307 fix: parenthesizer: parenthesize only because of subsequent parser if in same syntax category
Otherwise, we would parenthesize `... : α → β := ...` as `... : (α → β) := ...` since in
```
def declValSimple    := parser! " := " >> termParser
```
there is an implicit `checkPrec 1024` from `parser!`.
2020-08-20 18:36:04 +02:00
Sebastian Ullrich
4f5d1cf369 chore: finish formatter refactoring 2020-08-20 15:47:43 +02:00
Sebastian Ullrich
aa452b795d refactor: make formatter precompiled as well 2020-08-20 15:29:33 +02:00
Sebastian Ullrich
68b9a8e1d1 refactor: move parenthesizer compiler into separate file, generalize 2020-08-20 13:22:57 +02:00
Sebastian Ullrich
9fa6795a73 feat: add [combinatorFormatter] attribute 2020-08-20 11:21:01 +02:00
Leonardo de Moura
b5ed59ef61 chore: missing [inline] 2020-08-19 17:10:52 -07:00
Leonardo de Moura
68a4c145f7 refactor: implement attribute hooks using CoreM
We were using a mix of `IO` and `Except`
2020-08-19 14:44:54 -07:00
Leonardo de Moura
61d1846334 feat: add adaptTheReader 2020-08-19 10:23:11 -07:00
Leonardo de Moura
e28f68936d feat: add MonadReaderOf 2020-08-19 10:14:36 -07:00
Leonardo de Moura
57ed29e814 revert: panic! changes
@Kha I am reverting this change for now.
I understand that the "default-value" approach is bad for debugging,
and it does not produce good error messages, but at least the frontend
will not "panic" when users add a bad macro.

After we switch to the new frontend, we can have a monadic `getArg`
and `getArgs` in the Elab and Macro monads which produces an
"unexpected syntax" error message. I say we wait for the new frontend
because we will be able to write `(<- s.getArg)` inside of
expressions.
2020-08-19 09:57:58 -07:00
Sebastian Ullrich
1840b4b1ff fix: pretty printer with new syntax 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
203e5f76bd fix: bug found by getArg panic 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
4768ac2fbc chore: make Syntax.getArg(s) panic 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
eb5a171764 feat: adjust semantics to new syntax 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
6cbfe2359b chore: remove old syntax 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
3091bd71e7 feat: unwrap basic token parsers 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
3bddb90bd0 refactor: move isQuot/isAntiquot 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
d4952dc40b feat: use insideQuot parsers 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
ed7edf5661 feat: add checkInsideQuot/checkOutsideQuot/toggleInsideQuot parsers
One use case is to obtain fine-grained control over at what stage changed syntax is activated
2020-08-19 09:56:23 -07:00
Leonardo de Moura
40ec0b7ae4 feat: add helper functions and generalize 2020-08-19 09:53:45 -07:00
Leonardo de Moura
9158ba60ea feat: add IO.toEIO 2020-08-19 09:43:26 -07:00
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
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
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
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