Commit graph

1274 commits

Author SHA1 Message Date
Leonardo de Moura
d85836a387 chore: mark TODO 2020-08-23 19:55:53 -07:00
Leonardo de Moura
6180ba6d7d chore: rename ST.Ref primitives 2020-08-23 12:28:14 -07:00
Leonardo de Moura
77b9445544 feat: real ST monad
@Kha: the new `ST` (and `EST`) are escapable like the Haskell ST monad.
It makes `StateRefT` much more useful because we can now run it from pure
code.
2020-08-23 12:15:32 -07:00
Leonardo de Moura
37571edce5 fix: remove unnecessary dependencies 2020-08-22 15:15:10 -07:00
Leonardo de Moura
916b395d1b chore: cleanup 2020-08-21 09:29:09 -07:00
Leonardo de Moura
05a0e7f6d0 refactor: build all main monads on top of ECoreM 2020-08-20 18:36:04 -07:00
Leonardo de Moura
fad6235abb feat: give a name to EIO Empty
@Kha I am calling it `ST` for lack of a better name. It makes some
sense since only the `IO.Ref` operations are in `EIO Empty` :)
That being said, it may confuse Haskell users.

BTW, I had to give the name to avoid a nontermination in the TC
procedure when using
```lean
instance EIOEmpty.monadLift {ε} : HasMonadLift (EIO Empty) (EIO ε) :=
{ monadLift := fun α => fromEmptyEIO }
```
2020-08-20 15:47:27 -07:00
Leonardo de Moura
eebc611391 chore: remove unnecessary workaround 2020-08-20 13:15:11 -07:00
Leonardo de Moura
968457ac1c feat: make sure StateRefT can be used with any base EIO Exception 2020-08-20 13:11:12 -07:00
Leonardo de Moura
d36ccb166c feat: use EIO Empty instead of IO at IO.Ref primitives 2020-08-20 12:54:15 -07:00
Leonardo de Moura
c55376a1ba chore: more conventional MonadIO 2020-08-20 11:13:10 -07:00
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
Leonardo de Moura
b5ed59ef61 chore: missing [inline] 2020-08-19 17:10:52 -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
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
Leonardo de Moura
9158ba60ea feat: add IO.toEIO 2020-08-19 09:43:26 -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
1e496fb32d feat: helper instance 2020-08-18 13:26:14 -07:00
Leonardo de Moura
aa2f834c0f feat: add mkMonadIO and modifyGet 2020-08-18 13:25:15 -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
b4b60dc326 feat: add List.filterMapM 2020-08-14 10:50:48 -07:00
Leonardo de Moura
bd8e2d305f feat: add Array.filterMap 2020-08-14 10:50:48 -07:00
Leonardo de Moura
81ae6a734b feat: mark List.toArray with [matchPattern] 2020-08-13 14:25:47 -07:00
Leonardo de Moura
6c234daad7 chore: MonadExceptCore => MonadExceptOf 2020-08-13 09:28:23 -07:00
Wojciech Nawrocki
55655869b7 feat: default to binary file mode on Windows 2020-08-13 09:21:35 -07:00
Leonardo de Moura
d7add53229 feat: add MonadExceptCore 2020-08-13 09:19:26 -07:00
Sebastian Ullrich
b2714d36ef fix: String: take/drop characters, not bytes 2020-08-11 18:24:47 -07:00
Leonardo de Moura
f1c7665a93 feat: validate patterns, and collect pattern variables 2020-08-11 18:19:29 -07:00
Leonardo de Moura
5a09883cc7 chore: add namedPattern 2020-08-11 15:04:09 -07:00
Leonardo de Moura
61f8b4ef07 feat: add support for maximum recursion depth checks at MacroM 2020-08-10 16:50:12 -07:00
Leonardo de Moura
aefc9a473f feat: add auxiliary definitions for compiling array literals in pattern matching expressions 2020-08-07 09:23:33 -07:00
Sebastian Ullrich
c5d226ba36 feat: HasBeq for Syntax, Substring 2020-08-06 09:26:49 -07:00
Sebastian Ullrich
0f7f49aa06 feat: dbgTraceVal 2020-08-06 09:26:48 -07:00
Leonardo de Moura
447000a797 fix: >>= associativity 2020-08-03 14:00:19 -07:00
Sebastian Ullrich
719819bf49 fix: finally shouldn't call finalizer when finalizer throws 2020-07-10 07:42:26 -07:00
Sebastian Ullrich
b40ef65b39 feat: add IO.eprint(ln) for printing to stderr
Most useful when stdout is being consumed by another program
2020-07-06 09:22:47 -07:00
Leonardo de Moura
cbb14673ef chore: move RBTree and RBMap to Std 2020-06-25 13:26:16 -07:00
Leonardo de Moura
11ed7c6195 chore: move PersistentArray to Std 2020-06-25 13:02:21 -07:00
Leonardo de Moura
02aa8498cd chore: move AssocList to Std 2020-06-25 12:52:23 -07:00