Commit graph

60 commits

Author SHA1 Message Date
Leonardo de Moura
ac43b82668 chore(library/init): remove [derive] uses
Trying to minimize the number of features we need to support in the new
frontend, and attributes we need to port to the new attribute manager.
2019-06-20 10:53:15 -07:00
Leonardo de Moura
697f69020f fix(library/init/lean/parser/parser): new registerBuiltinParserAttribute
It is still broken since we apply attributes before we compile code.

Recall that attributes such as `@[export]` and `@[extern]` must be applied before we
compile code.

On the other hand, any attribute `attrName`
```
@[attrName] def foo := ...
```
which creates auxiliary definitions that depend on `foo` must be applied
AFTER we generate code for `foo`. Otherwise, we will fail to compile the
auxiliary definition since we don't have code for `foo` yet.

I will fix the issue above by allowing attributes to specify when they
should be applied. I will start with only two options: before and after
code compilation. In the future, we may need more options (e.g., before
elaboration), but I don't see the need yet.

cc @kha
2019-06-19 09:52:56 -07:00
Leonardo de Moura
fd29b7e45d feat(util/io): add helper functions for consuming IO results in C++ 2019-06-05 13:53:38 -07:00
Leonardo de Moura
c46608ced5 feat(library/init/io): implement unsafeIO in Lean
Motivation: avoid closure allocation.
2019-05-11 16:28:11 -07:00
Leonardo de Moura
77c6aa6693 chore(library/init/io): mark unsafeIO as unsafe
@kha The previous declaration was fine from the logical point of
view. That is, nobody would be able to prove `false` using the opaque
constant `unsafeIO`. However, its runtime implementation breaks
referencial transparency, and counterintuitive behavior may happen if
it is not used carefully.
2019-05-11 15:46:45 -07:00
Leonardo de Moura
fd2a5dd45e feat(library/init/io): add IO.initializing 2019-05-10 11:26:49 -07:00
Leonardo de Moura
bca57afae7 fix(library/init/io): RefPointed must "depend" on \alpha 2019-05-07 09:26:28 -07:00
Leonardo de Moura
a43a40b7f5 chore(library/init): remove fix.lean
`partial def` is much more general
2019-03-27 13:11:00 -07:00
Leonardo de Moura
3936b2ba79 chore(library/init/io): we don't need fix anymore
`partial def` are much more general
2019-03-27 12:59:43 -07:00
Leonardo de Moura
d4aab31ada feat(library/init/io): IO.userError 2019-03-22 17:26:43 -07:00
Leonardo de Moura
a79b00d733 chore(runtime, stage0): update Ref primitive operation names 2019-03-21 16:43:54 -07:00
Leonardo de Moura
dfe15cf743 refactor(library/init): use get and set for State EState and Ref
TODO: use the same naming convention for array reads and writes.
2019-03-21 16:34:32 -07:00
Sebastian Ullrich
97e5aa2411 chore(library): s/Punit/PUnit/g etc 2019-03-21 15:06:45 -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
f8113a01eb chore(library): unit => Unit 2019-03-21 15:06:44 -07:00
Leonardo de Moura
62e6341014 chore(*): lowercase file 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
f7aeeaf237 exclude export/extern, translate constants.txt 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
36faa595f5 refactor(library/init): move inhabited (except ...) to except.lean 2019-03-18 16:48:58 -07:00
Leonardo de Moura
2610ace69d feat(library/init/io): remove init_io
In the Haskell proposal for top level mutable state
https://wiki.haskell.org/Top_level_mutable_state, they describe the
following problems with using the `IO` monad during initialization.

"A more serious problem is that there is nothing to prevent arbitrary
observable IO actions from appearing to the right of the arrow. If we
perform all actions before executing main, then import becomes a
side-effectful operation, rather than simply a way of bringing names
into scope; furthermore we must specify the order in which actions from
different modules are executed, which would appear to be difficult in
general. If we execute actions on demand (as the unsafePerformIO hack
does) then we are building an unsafe syntactic construct into the
language."

I believe this is not applicable to us. First, our imports are already
side-effectful since we update attributes and the order we import
modules already matters. Second, we have already a well-defined order
in which we import modules. Finally, all global constants are already
being initialized eagerly.

Their ACIO proposal (`init_io` in our implementation) is too restrictive
for what we want to do. For example, to implement an environment
extension mechanism like we have discussed, we would also need `io.ref.write` and
`io.ref.read`. I imagine, we would have a global table, and `register`
would update this table. These extra actions do not satisfy the ACIO restrictions
described in the Haskell proposal. From their document:
"AC stands for Affine Central.
An IO action u is affine if its effect is not indirectly observable, hence need not be performed if the result is unneeded. That is, if u >> v === v for all actions v.
It is central if its effect commutes with every other IO action. That is, if do { x <- u; y <- v; w } === do { y <- v; x <- u; w } for all actions v and w."
It feels like we would have to keep fighting with the ACIO
restrictions. As I said above, our initialization order is well
defined. So, we must document the `[init]` feature and tell users they
should be aware that the `import` is important for initialization
purposes, and that their initialization actions should be
affine central whenever possible.
2019-03-18 15:33:29 -07:00
Leonardo de Moura
15d89b24a3 feat(library/compiler): [init] attribute
TODO: use attribute when emitting code in the backends.
2019-03-18 15:33:29 -07:00
Leonardo de Moura
c4e755c8d3 feat(library/init/io): add init_io and mk_global_ref 2019-03-18 15:33:29 -07:00
Leonardo de Moura
1da4782483 feat(runtime, library/init/io): add io.ref 2019-03-16 22:16:28 -07:00
Leonardo de Moura
9984d28bb2 fix(library/init/lean/frontend): make sure new frontend works with new io monad 2019-03-16 18:24:53 -07:00
Leonardo de Moura
b1c187f717 feat(library/compiler): allow io unit as main function result type
When `io unit` is used, we use `return 0` for `result.ok`, and `return
1` for `result.except`.
2019-03-16 16:05:45 -07:00
Leonardo de Moura
6d0ec3a8c9 refactor(library/init/io): implement io monad using estate monad 2019-03-16 15:34:58 -07:00
Leonardo de Moura
0b7d987699 feat(frontends/lean, library/init/lean): opaque constants
@kha I have added support for opaque constants to the old C++ frontend,
and made sure the new frontend can still parse `library/init/core.lean`.
The kernel should enforce that opaque constants are really opaque, and
the following example should fail
```
constant x : nat := 0
theorem foo : x = 0 := rfl
```
If it doesn't, it is a bug.

Here are some remaining issues:
1- `environment.mk_empty` is currently an axiom because we cannot create
an inhabitant of an opaque type. A possible solution is to use
`option environment` instead of `environment`.

2- There is no support for opaque constants in the new
frontend. However, I modified it to handle axioms, and fixed the literal
values with decl_cmd_kind. I tried to mark some of my changes with
comments, but it is probably much easier for you to just check the
commit change list.

3- I did not add any support for automatically constructing `e`
at `constant x : t := e`. I think we can do this later
after we replace the old frontend with the new one. BTW, it took only a
few minutes to provide the inhabitants manually.
2019-03-15 17:41:44 -07:00
Leonardo de Moura
ecdb9d6df0 feat(library/init, frontends/lean): add abbreviation for abbreviation 2019-03-15 16:01:25 -07:00
Leonardo de Moura
0888dee25e chore(*): meta ==> unsafe 2019-03-15 15:04:40 -07:00
Leonardo de Moura
39dd079e37 feat(runtime): low tech allocation profiler
```
@[extern 4 "lean_io_allocprof"]
constant allocprof {α : Type} (msg : @& string) (fn : io α) : io α
```
2019-03-14 15:15:29 -07:00
Leonardo de Moura
77dc3f3d32 feat(library/init/io): use fix to implement iterate 2019-03-12 18:06:23 -07:00
Sebastian Ullrich
e0bbc094ad chore(library/init): remove coroutines from stdlib 2019-03-08 15:34:17 +01:00
Sebastian Ullrich
85bc52b9f2 feat(library/init/lean/frontend): profile frontend 2019-03-06 11:08:38 +01:00
Leonardo de Moura
20c877b277 chore(library/init/io): add inline 2019-02-22 09:55:36 -08:00
Leonardo de Moura
b722885137 feat(library/init/io): add unsafe_io and timeit 2019-02-13 16:59:24 -08:00
Leonardo de Moura
e10240fe5c refactor(runtime/io): use extern "C" for io primitives 2019-02-13 11:21:29 -08:00
Leonardo de Moura
73d590f1fb feat(library/init/io): use extern attribute 2019-02-11 16:56:54 -08:00
Leonardo de Moura
dfdf42ce34 chore(library/init/io): minimize io interface
We are moving to new compiler stack.
2018-11-14 13:59:25 -08:00
Leonardo de Moura
c599d78639 feat(library/init/io): implement io.iterate in Lean
cc @kha
2018-11-14 13:43:02 -08:00
Leonardo de Moura
8d47d2a026 chore(library/vm,library/init/meta): remove vm_format, and some obsolete meta objects 2018-10-23 11:32:56 -07:00
Leonardo de Moura
4cb6b1f9d5 chore(library/tactic): reduce dependencies 2018-10-23 11:32:56 -07:00
Sebastian Ullrich
0563c60b1a feat(library/init/lean/elaborator): add coroutine, use it to implement section/namespace elaborators (they don't do anything yet except for checking the end name) 2018-10-02 14:55:28 -07:00
Sebastian Ullrich
6f68a0d1eb feat(library/init/lean/parser/basic): check for conflicting tokens 2018-09-20 09:40:21 -07:00
Leonardo de Moura
5ff9e24b17 feat(library/init/control): do not use unnecessary structures
It confuses the compiler.
2018-09-20 08:39:25 -07:00
Leonardo de Moura
afd54039ab chore(library): remove >>, we should use *> 2018-09-12 17:31:21 -07:00
Leonardo de Moura
9e305a5f26 chore(library): remove return, we should use pure 2018-09-12 16:51:11 -07:00
Leonardo de Moura
da2de33245 fix(library/init/io): move coroutine_io implementation to io 2018-09-06 18:09:32 -07:00
Leonardo de Moura
c7cf75508d feat(init/control/coroutine): avoid mutual inductive
Reason: we want to delete the inductive compiler.
2018-08-23 10:49:40 -07:00