Commit graph

21403 commits

Author SHA1 Message Date
Leonardo de Moura
43ce35985b chore: fix test 2020-10-05 16:47:34 -07:00
Leonardo de Moura
54e10776d4 feat: improve error messages for do notation
@Kha we are getting better error message, but we need to figure out a
way to suppress error messages that come from the "plumbing".
For example, in the following example.
```
def f4 (b : Bool) (n : Nat) (v : Vector Nat n) : Vector Nat (n+1) := do
if b then
  v := Vector.cons 1 v
Vector.cons 1 v
```
We get the nice "invalid reassignment" error at `v := ...`, but
we also get the nasty
```
error: application type mismatch
  jp✝ v
argument
  v
has type
  Vector Nat (n + 1)
but is expected to have type
  Vector Nat n
failed to synthesize instance
  CoeT (Vector Nat (n + 1)) v (Vector Nat n)
```
Where `jp✝` is a joinpoint created by the do-notation macro expander.
I thought about using `withoutErrToSorry` when elaborating the expanded
`do` term.
We may also try to add more helper hints such as `ensureTypeOf!` and
use them around "plumbing" code (e.g., "joinpoint goto"s)
2020-10-05 16:33:59 -07:00
Leonardo de Moura
eafd9bc0ad feat: expand for x in xs notation 2020-10-05 15:37:34 -07:00
Leonardo de Moura
ac16393ae9 chore: add break and continue keywords 2020-10-05 15:37:01 -07:00
Leonardo de Moura
98dbe45ab8 chore: remove Monad List instance
@Kha The new `do` notation works for pure code too.
It automatically inserts `Id` if the expected type is not a monad.
This works great when we are not conflating data and control.
After deleting `Monad List`, we will be able to write functions such as
```lean
def mapWhen (p : Nat → Bool) (f : Nat → Nat) (xs : List Nat) : List Nat := do
for x in xs do
  if p x then
    x := f x
```
without adding `Id.run` before the `do`.
2020-10-05 13:27:18 -07:00
Leonardo de Moura
7a0cbdbe04 test: shadowing in do blocks 2020-10-05 11:51:17 -07:00
Leonardo de Moura
60edde82b0 fix: special support for Id 2020-10-05 11:50:07 -07:00
Leonardo de Moura
a6063a5560 chore: fix tests 2020-10-05 11:28:52 -07:00
Leonardo de Moura
fb83e8e79b feat: allow any variable to be reassigned 2020-10-05 11:25:19 -07:00
Leonardo de Moura
5adb04b10e chore: add helper instance 2020-10-05 11:24:35 -07:00
Leonardo de Moura
82e11c401d fix: #eval was not capturing dbgTrace! output in pure code
In the following example, the output produced by `dbgTrace!` was not
being captured. It could break the lean server. At least, it broke the lean4-mode.
```lean
def f (x : Nat) : Nat :=
dbgTrace! ">>> " ++ toString x;
x + 1

eval f 10
```

cc @Kha
2020-10-05 10:22:04 -07:00
Leonardo de Moura
d7d7e16f96 chore: Id missing instances 2020-10-05 09:55:19 -07:00
Leonardo de Moura
ebc166585a chore: update stage0 2020-10-05 09:46:42 -07:00
Leonardo de Moura
7325dcd630 feat: use do at for-in and unless notations 2020-10-05 09:43:11 -07:00
Leonardo de Moura
666398bf96 chore: update stage0 2020-10-05 09:37:21 -07:00
Leonardo de Moura
9a551d9219 feat: add withForbidden and withoutForbidden parser combinators 2020-10-05 09:36:28 -07:00
Leonardo de Moura
fa4d6d24eb feat: use toString at dbgTrace! 2020-10-05 09:27:42 -07:00
Leonardo de Moura
6e7a883b21 fix: make sure all joinpoints have at least 1 argument 2020-10-04 18:07:00 -07:00
Leonardo de Moura
d8c2d0b551 fix: CodeBlock concatenation 2020-10-04 17:59:56 -07:00
Leonardo de Moura
0caa17889f feat: remove old elabDo
Remark: we still have a few WIP
2020-10-04 17:14:36 -07:00
Leonardo de Moura
4a2a2758ec chore: adjust test 2020-10-04 16:19:50 -07:00
Leonardo de Moura
9810b405d9 feat: add CodeBlock to Syntax converter 2020-10-04 16:19:09 -07:00
Leonardo de Moura
b4289d5c5d feat: add DoResult 2020-10-03 15:38:30 -07:00
Leonardo de Moura
e47e9c8be3 chore: remove unnecessary withNewVars 2020-10-03 15:24:35 -07:00
Leonardo de Moura
21d90afa43 feat: add ForInStep type 2020-10-03 15:16:45 -07:00
Leonardo de Moura
251ac73df4 feat: add missing code to new elabDo
WIP
2020-10-03 14:59:28 -07:00
Leonardo de Moura
a84b3ac8de chore: fix old elabDo and test 2020-10-03 08:36:22 -07:00
Leonardo de Moura
ef741d343d chore: update stage0 2020-10-03 08:36:08 -07:00
Leonardo de Moura
4e7fd4b4bf chore: add doSeqIndent kind 2020-10-03 08:22:02 -07:00
Leonardo de Moura
ee830ec293 chore: update stage0 2020-10-03 07:35:03 -07:00
Leonardo de Moura
a5daaee3ed chore: do syntax adjustments 2020-10-03 07:33:18 -07:00
Leonardo de Moura
3caa683626 chore: add unless to keyword list 2020-10-02 19:16:14 -07:00
Leonardo de Moura
d3d245c711 feat: ToCodeBlock skeleton 2020-10-02 19:02:47 -07:00
Leonardo de Moura
96f5c51a3e fix: doElem issues 2020-10-02 18:58:43 -07:00
Leonardo de Moura
887a09cb97 chore: update stage0 2020-10-02 18:11:16 -07:00
Leonardo de Moura
c40ec0128d fix: return value is optional 2020-10-02 18:09:42 -07:00
Leonardo de Moura
137b9efd42 chore: remove leftover 2020-10-02 15:51:03 -07:00
Leonardo de Moura
e8edd810de chore: update stage0 2020-10-02 15:48:46 -07:00
Leonardo de Moura
35e401e915 chore: naming consistency 2020-10-02 15:47:12 -07:00
Leonardo de Moura
40640b85bd fix: doSeqBracketed parser
It was failing to parse
```
def f2 (x : Nat) : IO Nat := do {
  let y := 1;
  if x > 0 then
    y := y + 1;
  IO.println y
}
```

cc @Kha
2020-10-02 15:05:22 -07:00
Leonardo de Moura
04eda60451 chore: update stage0 2020-10-02 13:17:50 -07:00
Leonardo de Moura
379e34a910 feat: do reassignment parsers 2020-10-02 13:16:55 -07:00
Leonardo de Moura
703adc9a0a chore: remove leftover 2020-10-01 18:47:35 -07:00
Leonardo de Moura
299bc54af0 chore: improve error message 2020-10-01 18:47:22 -07:00
Leonardo de Moura
946f5537ee fix: pullExitPoints 2020-10-01 16:12:58 -07:00
Leonardo de Moura
4a57eace89 chore: remove expandDo builtin macro 2020-10-01 16:12:19 -07:00
Leonardo de Moura
4b6d308bc2 feat: add elabTypeOf and elabEnsureTypeOf 2020-10-01 14:56:46 -07:00
Leonardo de Moura
b3acffe944 chore: update stage0 2020-10-01 14:33:31 -07:00
Leonardo de Moura
6db45891e2 feat: add typeOf! and ensureTypeOf! parsers 2020-10-01 14:33:04 -07:00
Leonardo de Moura
d0ade7ff08 feat: extend doBlock expander
- Add support for `if h:c then t else e`, `h` may shadow reassignable
variables

- Pattern variables in `match` alternatives may shadow reassignable
variables

- A single declaration/reassignment in a `do` block may
declare/reassign multiple variables. Example: `let (x, y) := t`
2020-10-01 10:40:55 -07:00