Commit graph

7042 commits

Author SHA1 Message Date
Leonardo de Moura
f4ccb78014 feat: improve tryPureCoe? and document its limitations 2020-10-06 17:41:45 -07:00
Leonardo de Moura
608ae62aef chore: use pure
We are planning to change the meaning of `return`
2020-10-06 15:53:53 -07:00
Leonardo de Moura
cda4de474b fix: weird error message in do notation
cc @Kha
2020-10-06 15:12:55 -07:00
Leonardo de Moura
db1b110f7e fix: use let* to avoid bad error messages in do notation
cc @Kha
2020-10-06 15:01:05 -07:00
Leonardo de Moura
82dad3c86f feat: add Code.returnAction 2020-10-06 13:19:55 -07:00
Leonardo de Moura
5110b1212d test: do notation error messages 2020-10-06 11:35:44 -07:00
Leonardo de Moura
13591e59d5 chore: improve regular 'for' error message 2020-10-06 11:30:14 -07:00
Leonardo de Moura
760b658d19 chore: suppress extraMsg in type mismatch errors 2020-10-06 10:58:50 -07:00
Leonardo de Moura
0ce6ac4267 chore: fix error messages 2020-10-06 10:52:04 -07:00
Leonardo de Moura
7f5b454382 chore: improve for type mismatch error message 2020-10-06 10:50:03 -07:00
Leonardo de Moura
5cabc917f5 chore: improve error message 2020-10-06 10:45:12 -07:00
Leonardo de Moura
74e5bf2539 feat: add elabEnsureExpectedType 2020-10-06 09:39:16 -07:00
Leonardo de Moura
3a426d96e7 feat: custom error message header at elabTermEnsuringType
This commit also improves `ensureTypeOf!` primitive.
2020-10-06 09:27:13 -07:00
Leonardo de Moura
653f1406d6 chore: remove workaround 2020-10-06 08:28:41 -07:00
Leonardo de Moura
e635196f32 chore: fix test
I added a temporary workaround. I will remove it later.
2020-10-06 08:28:13 -07:00
Leonardo de Moura
0447966b72 chore: adjust elaborator to new syntax 2020-10-06 06:53:12 -07:00
Leonardo de Moura
5f28f2badc test: add another do notation test 2020-10-05 19:19:18 -07:00
Leonardo de Moura
eac3ca9286 feat: let rec in do notation 2020-10-05 19:10:06 -07:00
Leonardo de Moura
520a5f566a fix: local name resolution
Local name resolution was incorrect when identifier had macro scopes
and projections were used.

cc @Kha
2020-10-05 17:32:46 -07:00
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
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
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
7325dcd630 feat: use do at for-in and unless notations 2020-10-05 09:43:11 -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
21d90afa43 feat: add ForInStep type 2020-10-03 15:16:45 -07:00
Leonardo de Moura
a84b3ac8de chore: fix old elabDo and test 2020-10-03 08:36:22 -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
946f5537ee fix: pullExitPoints 2020-10-01 16:12:58 -07:00
Leonardo de Moura
4b6d308bc2 feat: add elabTypeOf and elabEnsureTypeOf 2020-10-01 14:56:46 -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
Leonardo de Moura
94c7945bd3 feat: do code blocks
WIP
2020-09-30 19:20:16 -07:00
Leonardo de Moura
c10e92b348 chore: add temporary workarounds 2020-09-30 07:05:46 -07:00
Leonardo de Moura
72f969e9dd test: new frontend 2020-09-29 18:22:34 -07:00
Leonardo de Moura
0fe705f3a1 feat: improve error messages for unassigned metavariables
cc @Kha
2020-09-29 17:18:03 -07:00
Sebastian Ullrich
16c71e6a26 fix: IO.Process.output 2020-09-29 08:01:10 -07:00
Sebastian Ullrich
19dcbdcec9 fix: do not format Syntax in Messages eagerly 2020-09-29 07:59:22 -07:00
Sebastian Ullrich
d51101b884 feat: sanitize Syntax in messages
Fixes #182
2020-09-29 07:59:22 -07:00
Sebastian Ullrich
af8dc5eeab feat: pretty print Syntax in messages 2020-09-29 07:59:22 -07:00
Sebastian Ullrich
6ad47878ef chore: improve error message using (<- ...) outside of do 2020-09-29 07:59:22 -07:00
Leonardo de Moura
49c5c5c08a fix: horrible error message due to constApprox := true
The new test `typeMismatch.lean` contains two examples where the error
message was dreadful.
2020-09-29 07:54:48 -07:00
Leonardo de Moura
d6db541366 chore: cleanup 2020-09-28 19:05:48 -07:00
Leonardo de Moura
4fae8588fd test: optional ';' 2020-09-28 17:11:00 -07:00
Leonardo de Moura
65834b95ff chore: fix test 2020-09-28 17:11:00 -07:00
Leonardo de Moura
e10edde5cd feat: optional ; in terms 2020-09-28 17:10:59 -07:00