Commit graph

27 commits

Author SHA1 Message Date
Leonardo de Moura
a02443d23d chore(frontends/lean): fun x, e ==> fun x => e 2019-07-02 13:22:11 -07:00
Leonardo de Moura
6841e47aa4 chore(frontends/lean/builtin_exprs): remove support for (<infix>) and (<infix> <expr>) notations
In Lean 4, we will support the more general

`a + ·` ==> `fun x, a + x`
`· + b` ==> `fun x, x + b`
`· + ·` ==> `fun x y, x + y`
`f · y` ==> `fun x, f a y`
`g · · b` ==> `fun x y, g x y b`
2019-07-02 08:06:06 -07:00
Leonardo de Moura
ab487ea4ac feat(frontends/lean): allow ; instead of in in let-decls 2019-06-27 17:12:03 -07:00
Leonardo de Moura
373011bc20 chore(library/init/lean/format): export group 2019-06-07 10:35:04 -07:00
Leonardo de Moura
452485a706 chore(library/init/lean/format): export functions 2019-06-07 10:10:13 -07:00
Leonardo de Moura
44cba2fb3d chore(library/init/lean/attributes): add Inhabited instance and improve stats 2019-06-06 10:39:40 -07:00
Leonardo de Moura
c09df2d8c3 feat(library/init/lean/compiler/ir): use Array instead of List
The idea is to use the same approach we have used at `tests/playground/parser/syntax.lean`
2019-04-29 10:48:33 -07:00
Leonardo de Moura
807c9bff6d refactor(library/init): HasToFormat ==> HasFormat, toFormat ==> format 2019-04-28 09:16:47 -07:00
Leonardo de Moura
13d2398fb3 feat(library/init/lean/compiler/ir): formatter 2019-04-27 17:55:27 -07:00
Leonardo de Moura
b66f5dcf5c chore(library/init): avoid wf_term_hack 2019-03-27 12:12:21 -07:00
Leonardo de Moura
5b08bf18c5 feat(library/init/lean): improving options
@kha It will be awesome to automate the following idiom with a macro :)
```
def defIndent  := 4
def getIndent (o : Options) : Nat   := o.get `format.indent defIndent
@[init] def indentOption : IO Unit :=
registerOption `format.indent { defValue := defIndent, group := "format", descr := "indentation" }
```
2019-03-24 09:30:20 -07:00
Leonardo de Moura
1fe3f14ad0 chore(*): Uint => UInt, Usize => USize 2019-03-21 15:06:44 -07:00
Leonardo de Moura
2be87ecd92 chore(library/init): Bool.tt => Bool.true and Bool.ff => Bool.false 2019-03-21 15:06:44 -07:00
Leonardo de Moura
04e20623e6 chore(*): use lowercase dir names 2019-03-21 15:06:44 -07:00
Leonardo de Moura
67fb78bb47 chore(*): renaming files 2019-03-21 15:06:44 -07:00
Sebastian Ullrich
beda5f5f43 chore(library): capitalize types and namespaces 2019-03-21 15:06:43 -07:00
Sebastian Ullrich
b939162168 chore(library): switch from snake_case to camelCase 2019-03-21 15:06:43 -07:00
Leonardo de Moura
261dc999d0 refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion
@kha I was working in the new declaration type and using tasks there.
Since we don't have tasks yet in Lean, I decided to start refactoring
the `thunk` type. I defined it as:

```
-- TODO(Leo): mark as opaque, it is implemented by the new runtime
structure thunk (α : Type u) : Type u :=
(fn : unit → α)

def thunk.pure {α : Type u} (a : α) : thunk α :=
⟨λ _, a⟩

def thunk.get {α : Type u} (t : thunk α) : α :=
t.fn ()
```

The idea is to use the runtime primitives to implement them.
Then, I realized the support for `thunk`s in the elaborator are quite
hacky. Given `f x`, if `f`'s domain has type `thunk A`, we elaborate
`f x` as `f (fun _, x)` even if `x` has type `thunk A`.
This is quite bad, for example, suppose we have
```
def f (x : thunk A) := ...
```
Then, the following definition is type incorrect.
```
def g (x : thunk A) := f x
```
and we are forced to write
```
def g (x : thunk A) := f (x ())
```
The term `f (x ())` will be elaborated as `f (fun _, x ())` and an
unnecessary closure is created at runtime.

This mechanism inherited from Lean 3 is also incompatible with the
new thunk definition. Given `x : thunk A`, I want to write `x.get`
to retrieve the value instead of `x ()` as in Lean 3.
However, `x.get` expands into the nonsensical `(fun _, x).get`.

So, I decided to view the mapping `A` to `thunk A` as a "coercion".
I used double quotes, because it is a macro instead of a function.
If it were a coercion, then we would be using `thunk.pure` to coerce
values but this is not we want most of the time.
For example, given `f : thunk A -> B` and a term `t : A`, when we write
`f t`, we want it to be converted into `f (fun _, t)` instead of
`f (thunk.pure t)` which would eagerly compute `t`. The transformation
`t` into `fun _, t` is syntactic.
We cannot implement it using type classes. I implemented it as
a hard-coded extra case like the one from `Prop` to `bool`.
We can also add a coercion from `thunk A` to `A` to avoid the `.get`.

That being said, I had a few breakages in the code base since we only
use coercions when the given and expected type do not contain
metavariables.
2018-08-21 15:27:51 -07:00
Sebastian Ullrich
68936e3f80 fix(library/init/lean/format): ensure to_fmt (f : format) = f 2018-07-16 18:14:01 +02:00
Leonardo de Moura
224fdc7a78 refactor(library/init/lean/ir): platform dependent IR
Motivation: in 64-bit machines, we can store boxed uint32 values as a
tagged pointer. In 32-bit machines, we need to allocated an object (like
Haskell) to store the uint32 value. So, the generated bytecode is quite
different in each platform.

This change also allow us to simplify the IR. Example: we don't need the
type `sizet` anymore.

Impact: To be able to bootstrap in both platforms,
we will have to store two versions of the generated code: 32 and 64
versions. In principle, we only need to store the 64-bit version,
and use cross-compilation to build the 32-bit version.
2018-05-10 13:15:02 -07:00
Leonardo de Moura
0a9bd8caa8 chore(library/init/lean/ir): improve sizet syntax 2018-05-07 18:07:04 -07:00
Leonardo de Moura
6e2ebb5fab feat(library/init/lean/ir): add IR instruction parser 2018-05-01 17:45:50 -07:00
Leonardo de Moura
7361dc7b96 chore(library/init/lean): join_with ==> join_sep 2018-05-01 17:14:49 -07:00
Leonardo de Moura
4aafa82a9c feat(library/init/lean/ir/format): IR => format 2018-05-01 13:39:57 -07:00
Leonardo de Moura
3c317a30db chore(library/init/lean/parser): remove sorry warnings and init/meta dependencies 2018-04-30 13:38:25 -07:00
Leonardo de Moura
0405a67a70 feat(library/init): add wf_term_hack (unsound) axiom
We use the axiom instead of `sorry` to avoid a tsunami of warnings.
2018-04-30 11:06:51 -07:00
Leonardo de Moura
6ef4806fca feat(library/init/lean/format): add lean.format 2018-04-29 14:36:49 -07:00