Commit graph

28 commits

Author SHA1 Message Date
Leonardo de Moura
b1d5a4284d feat(library/init/lean): address issue raised in the previous commit
We also changed the type of `addImportedFn` to `Array (Array α) → IO σ`.
This modification avoids the `unsafeIO` hack at `parser.lean`.
2019-07-18 13:20:46 -07:00
Leonardo de Moura
4e572b5e05 refactor(library/init/lean/scopes): move ScopeManager to separate file 2019-07-17 19:09:15 -07:00
Leonardo de Moura
a8c36d4c29 feat(library/init/lean/syntax): remove MacroScopes
We are going to use a simpler approach to help users writing hygienic
macros. Suppose we have a syntax quotation such as
```
`(let x := %%a;
  ite x x %%b)
```
We will parse this quotation, and during elaboration, we must create
code (i.e., an `Expr`) such that given `a` and `b`, it constructs
a (new) syntax object, and we want to guarantee that there is no accidental name capture.
So, given the syntax object `S` representing the quotation above, we
first pre-resolve the identifiers in `S`. In this step, we annotate the
identifier `ite` with the global declaration `_root_.ite`.
Then, we create a fresh identifier for each identifier, but we would
preserve the pre-resolved information.
Assume the monadic action `mkFresh <id>` creates a fresh identifier with
prefix `<id>`, and `mkFreshWithPreresolved <id> <pre-list>` creates a
fresh identifier with prefix <id> and pre-resolved list `<pre-list>`.
Then, the quotation above would be transformed into:
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
`(let %%x := %%a;
 %%ite %%x %%x %%b)
```
Here, the new quotation is just syntax sugar for a sequence of `Syntax`
constructor applications. Now, whenever we want to create a syntax
object using the quotation above, we guarantee there is no accidental
name capture because we are creating a fresh identifier for all
identifiers in the quotation. Global references are preserved using the
field preresolved that we already have.
It is straightforward to implement the transformation above using a
mapping. Note that if we use the same mapping to elaborate two different
quotations, we are essentially saying they share the same scope.
For example, suppose we have
```
let c := `(ite x x %%b);
`(let x := %%a; %%c)
```
If we use the same mapping, we produce
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
`(let %%x := %%a; %%c)
```
If we create a new mapping when compiling each quotation, we get
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
let x1 := mkFresh `x;
`(let %%x1 := %%a; %%c)
```
which is probably not what the user wants.
We can provide a simple notation for users specifying which behavior
they want. The default may be super simple. Example: we have a new mapping (aka scope) per declaration.
The approach above is simple and efficient. It is also great for
users that want to create syntax objects during the elaboration phase
and want to avoid name capture.
2019-07-15 10:00:27 -07:00
Leonardo de Moura
ea6eee516b chore(frontends/lean): use => instead of := in match-expressions
Motivation: use same separator used in lambda expressions as in
other programming languages.
2019-07-04 11:38:38 -07:00
Leonardo de Moura
a02443d23d chore(frontends/lean): fun x, e ==> fun x => e 2019-07-02 13:22:11 -07:00
Leonardo de Moura
91e1d30cf8 feat(frontends/lean/builtin_exprs): use ; in do-notation 2019-06-27 18:00:43 -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
16d423dab6 feat(frontends/lean): switch to [extern] implemented in Lean
This commit also changes how we represent attribute parameters as
Syntax objects.
2019-06-26 10:57:33 -07:00
Leonardo de Moura
64ee4e01a8 refactor(library/init/lean/attributes): split getParam into getParam and afterSet 2019-06-26 10:09:57 -07:00
Leonardo de Moura
1ff6ee3155 feat(library/init/lean/attributes): allow getParam at ParametricAttribute registration to update environment 2019-06-25 09:15:55 -07:00
Leonardo de Moura
5d27fd279b feat(library/init/lean/attributes): add EnumAttributes 2019-06-24 15:48:12 -07:00
Leonardo de Moura
e0ddacfd3e feat(library/init/lean/attributes,frontends/lean): allow attributes to specify when they should be applied 2019-06-20 09:17:03 -07:00
Leonardo de Moura
e86e6af049 feat(library/init/lean/attributes): add applicationTime field and remove unnecessary parameters 2019-06-20 08:48:26 -07:00
Leonardo de Moura
451ab72eea fix(library/init/lean/attributes): typo 2019-06-19 10:21:40 -07:00
Leonardo de Moura
dbe7078e80 feat(library/init/lean/attributes): add ParametricAttribute.setParam 2019-06-18 17:24:16 -07:00
Leonardo de Moura
89738ac344 feat(library/init/lean/attributes): add ParametricAttribute 2019-06-18 12:49:53 -07:00
Leonardo de Moura
e05cdc2b08 feat(library/init/lean/compiler): declare function inlining attributes in Lean
Remark: they are not active yet since we haven't removed the ones
defined in C++ yet.
2019-06-06 11:05:54 -07:00
Leonardo de Moura
c8a972c57b fix(library/init/lean/attributes): typos at @[export] 2019-06-06 10:41:17 -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
280e7bb006 feat(library/init/lean/attributes): add TagAttributes
`TagAttribute`s are implemented on top of the low level Attribute API,
and `PersistentEnvExtension`.
This is just the first attribute on a series of attributes we are
going to implement using Lean itself.
2019-06-05 21:54:28 -07:00
Leonardo de Moura
fb77d71d23 feat(library/init/lean/attributes): export attribute API 2019-06-05 16:55:47 -07:00
Leonardo de Moura
7909d86e5d feat(library/init/lean): Syntax objects with new SyntaxNodeKind and Substring, and arrays instead of lists
We can use `SyntaxNodeKind.id : Nat` to implement maps from kind to
values using arrays.
2019-06-05 15:35:51 -07:00
Leonardo de Moura
55626ba60d chore(library/init/lean): disable new frontend for now
We are going to start making drastic changes in the parser,
elaborator, attributes, etc. Examples:
- No View objects. I am going to implement match_syntax.
- No RecT in the parser. I am going to implement parser extensions
using an approach similar to the one I used to implement environment
extensions.
- No Parsec. I will use an approach similar to the one used in the
experiment https://github.com/leanprover/lean4/tree/master/tests/playground/parser

It is easier to perform these changes with the new frontend disabled.
I will slowly re-active it as I apply the changes.

cc @kha
2019-06-05 15:26:43 -07:00
Leonardo de Moura
642992eeca chore(library/init/lean/attributes): missing @[export] 2019-06-05 13:30:26 -07:00
Leonardo de Moura
fd9c8a4c82 feat(library/init/lean/attributes): add pushScope/popScope, missing APIs, and @[export] 2019-06-05 13:17:25 -07:00
Leonardo de Moura
67a4ebbde6 feat(library/init/lean/attributes): low level attribute registration, and frontend attribute actions
Remark: the attribute actions used by the frontend are all in IO.
These actions access attributes by name, and need access to the IO.ref
that contains all registered attributes in the system.
2019-06-05 09:15:35 -07:00
Leonardo de Moura
583f38d1e5 feat(library/init/lean/attributes): attribute API for implementing the new frontend 2019-06-05 07:02:06 -07:00
Leonardo de Moura
c480f1f95c refactor(library/init/lean/environment): move scope management to attributes.lean 2019-06-04 16:50:29 -07:00