Commit graph

87 commits

Author SHA1 Message Date
Leonardo de Moura
6858cb5fb6 chore: cleanup 2020-10-29 10:24:16 -07:00
Leonardo de Moura
4ba21ea10c chore: cleanup src/Array/Basic.lean 2020-10-28 19:35:42 -07:00
Leonardo de Moura
898a08a0c1 chore: avoid Has prefix in type classes
closes #203
2020-10-27 18:29:19 -07:00
Leonardo de Moura
97c93ec557 chore: prepare to rename 2020-10-27 18:09:03 -07:00
Leonardo de Moura
10c32fcf94 chore: HasToString => ToString 2020-10-27 16:11:48 -07:00
Leonardo de Moura
d6418299c7 chore: naming convention 2020-10-27 13:05:13 -07:00
Leonardo de Moura
13c2a8ff51 chore: remove #lang lean4 header 2020-10-25 09:54:07 -07:00
Leonardo de Moura
de66ca3943 feat: add helper functions for writing macros 2020-10-23 10:59:59 -07:00
Leonardo de Moura
a37e2ae46f refactor: simplify MonadFunctor 2020-10-22 17:05:34 -07:00
Leonardo de Moura
073bbeb676 chore: move to new frontend 2020-10-22 16:30:03 -07:00
Leonardo de Moura
19d7050847 chore: remove Lean.Name.Name.beq 2020-10-22 16:30:02 -07:00
Leonardo de Moura
311265d833 fix: Name.beq primitive name
@Kha I cannot change the name is one step. The problem is that stage0
contains only the function `l_Lean_Name_Name_beq___boxed`.
So, I have to add a function with the new name, update stage0, and
then delete the old one. Otherwise, the build breaks because
the interpreter will fail when we try to test whether two names are
equal or not. The summary is: we cannot change the Lean name for a
primitive in one step because it changes the name of the auxiliary
"boxed" definition used by the interpreter.
2020-10-22 16:30:02 -07:00
Leonardo de Moura
4f109e23c2 feat: return syntax object representing the whole file 2020-10-21 07:55:59 -07:00
Leonardo de Moura
54c1607b36 chore: export Name.eraseMacroScopes 2020-10-15 11:35:32 -07:00
Leonardo de Moura
c1dccb8154 feat: stx[i] as notation for stx.getArg i 2020-10-13 15:48:39 -07:00
Leonardo de Moura
9af0a0e18b feat: add withReader method
@Kha `withReader` is a well-behaved version of `adaptReader`. `adaptReader` is
too general, and it often produces counterintuitive elaboration
errors.

Here are two super annoying issues I hit all the time:
1- `adaptReader` + polymorphic code
```
def ex1 : ReaderT Nat IO Unit :=
adaptReader (fun x => x + 1) $
  IO.println "foo" -- 3 Errors here failed to synthesize `Monad ?m` and  `MonadIO ?m`, and don't know how to synthesize `Type → Type`
```

2- `adaptReader` and notation that requires the expected type
```
structure Context :=
(x y : Nat)

def ex2 : ReaderT Context IO Nat :=
adaptReader (fun s => { s with x := 10 }) $ -- Error at the structure instance
  ...
```
In the example above, I have to write `fun (s : Context) => ...` to
fix the problem.

The two problems above happen in the old and new frontends. However,
there is a new problem specific for the new frontend. In the new
frontend, a `do` is only elaborated when the expected type is known.
So, `adaptReader (fun ctx => ...) do ...` seldom works :(

As I said above, the issue is that `adaptReader` is too general. Its
type is
```
  {ρ ρ' : Type u_1} → {m m' : Type u_1 → Type u_2} → [MonadReaderAdapter ρ ρ' m m'] → {α : Type u_1} → (ρ' → ρ) → m α → m' α
```

`withReader` is a simpler version of `adaptReader`
```
withReader : {ρ : Type u_1} → {m : Type u_1 → Type u_2} → [MonadWithReader ρ m] → {α : Type u_1} → (ρ → ρ) → m α → m α
```
It doesn't have any of the problems above. Moreover, I managed to replace
every single instance of `adaptReader` with `withReader` at the stdlib
and tests. We don't need the `adaptReader` generality.
2020-10-13 15:00:17 -07:00
Leonardo de Moura
7c6b10012b chore: add helper function 2020-10-11 19:58:07 -07:00
Leonardo de Moura
8555cbaace fix: export command for new frontend 2020-10-11 19:44:43 -07:00
Leonardo de Moura
3bd75d51d5 feat: add ParserDescr.noWs 2020-10-09 16:26:49 -07:00
Leonardo de Moura
7013ea4098 feat: add interpolatedStr to ParserDescr and Syntax 2020-10-09 14:04:53 -07:00
Leonardo de Moura
36696d726d feat: add String Interpolation 2020-10-09 13:40:35 -07:00
Leonardo de Moura
3f4499be08 feat: allow trailing ; at doSeqBracketed 2020-09-26 14:20:47 -07:00
Sebastian Ullrich
eae32b08a6 fix: pretty printing multiple universe levels
Fixes #190
2020-09-25 20:06:18 +02:00
Leonardo de Moura
241eabfc41 fix: non termination on ill-formed string literals 2020-09-20 17:05:18 -07:00
Leonardo de Moura
f679b7d803 feat: add notFollowedBy to syntax 2020-09-19 15:43:44 -07:00
Leonardo de Moura
3e9b2a0b08 feat: add expandMacro? and expandMacros methods to MacroM 2020-09-19 13:02:27 -07:00
Leonardo de Moura
f4aabaecae refactor: move Lean.quote to LeanInit
cc @Kha
2020-09-17 08:15:58 -07:00
Leonardo de Moura
34291e2151 feat: add Name.simpMacroScopes
@Kha We currently have a few macros that create binder names
such as `x`. These macros rely on the hygienic framework. This part is
great. Before this commit we were simply erasing the macro
scopes when creating the actual binders at `Expr.lean`.
The result produced expressions that were hard to debug.
For example, consider the following scenario

1- Macro creates a few binder names using ``x <- `(x)``
2- We create a lambda expression `t` with these binder names.
3- Then, we use `lambdaTelescope t fun xs body => ...`
   Now, if we trace `xs` and `body`, we get `#[x, x, ... x]` and
   we can't distinguish the different `x`s in `body`.
   So, it is really hard to debug anything using the traces.

This commit adds `Name.simpMacroScopes` for simplying "macro scoped"
names. Example: given `x._@.Init.Data.List.Basic._hyg.2.5`, it
produces `x.2.5`. I exported this function, and used it in the old
pretty printer.

I have considered modifying `lambdaTelescope` to make sure it creates
unused names. I think this option is bad because it introduces
overhead, and in a few places we want to preserve the binder names.

I have also considered replacing the `let x := x.eraseMacroScopes` at
`Expr.lean` with `let x := x.simpMacroScopes`. I think this option is
bad since we are destroying scoping information and will not be able
to distiguish which variables have macro scopes when processing
tactics.

Anyway, the solution in this commit is good for this week, but we
should discuss a more permanent solution next week.
2020-09-08 18:22:44 -07:00
Leonardo de Moura
1103806ff4 refactor: HasMonadLift ==> MonadLift 2020-08-25 13:54:41 -07:00
Leonardo de Moura
b672f0820b chore: remove workarounds 2020-08-23 19:56:01 -07:00
Leonardo de Moura
6fc935f6d1 refactor: add MonadNameGenerator 2020-08-23 19:56:01 -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
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
f1c7665a93 feat: validate patterns, and collect pattern variables 2020-08-11 18:19:29 -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
c6e7ea8fd5 feat: add ParserDescr.parser constructor for embedding parser definitions into parser descriptions 2020-06-16 14:06:46 -07:00
Leonardo de Moura
f61e4ffbbd chore: ParserDescr.parser ==> ParserDescr.cat 2020-06-16 13:40:16 -07:00
Leonardo de Moura
1477d23546 feat: remove ParserDescr.prec and update ParserDescr.trailingNode/ParserDescr.node 2020-06-10 14:57:55 -07:00
Leonardo de Moura
8972c7e666 feat: revised syntax commands 2020-06-08 16:12:06 -07:00
Leonardo de Moura
1554f7f99a fix: ParserDescr
This commit also adds the new constructor `ParserDescr.rblLt`
2020-06-08 16:12:05 -07:00
Leonardo de Moura
dbe4aa447e chore: explicit lbp at ParserDescr.symbol 2020-05-27 16:12:53 -07:00
Leonardo de Moura
bd58048449 chore: { <source> with ... } syntax 2020-05-20 15:08:43 -07:00
Sebastian Ullrich
b28eedbd98 refactor: make all fields of SourceInfo optional 2020-05-20 11:54:53 -07:00
Leonardo de Moura
33a10130cf chore: fix stdlib 2020-05-12 15:02:03 -07:00
Sebastian Ullrich
b6fc9428f1 fix: support Windows newlines and '\r' escape 2020-03-27 13:21:21 -07:00
Leonardo de Moura
0c13445da6 fix: mkStructView
Reamrk: `1.2` is a numLit
2020-02-18 20:22:04 -08:00
Sebastian Ullrich
25f764daad feat: antiquotation escapes 2020-02-18 10:57:12 -08:00
Leonardo de Moura
da3bf54ec7 feat: elaborate autoParams
cc @Kha
2020-02-13 16:24:50 -08:00