Commit graph

553 commits

Author SHA1 Message Date
Leonardo de Moura
f5725abb57 refactor(library/init/lean/environment): cleanup and improve 2019-05-10 15:54:29 -07:00
Leonardo de Moura
251890b490 feat(library/init/control/combinators): add Nat.mfold and rename Nat.for => Nat.fold 2019-05-10 10:47:57 -07:00
Leonardo de Moura
18aa7de408 feat(library/init/data): add ByteArray 2019-05-08 16:43:00 -07:00
Leonardo de Moura
b717177a1a chore(library/init/data/array/basic): make sure Array.*foldl and List.*foldl have similar signatures 2019-05-07 15:23:03 -07:00
Leonardo de Moura
4e5121fb5b chore(library/init/data/array/basic): more general miterate2 mfold2 iterate2 fold2 2019-05-07 15:06:11 -07:00
Leonardo de Moura
4b4ff9bf69 feat(library/init/data/array/basic): add Array.mfor 2019-05-06 18:21:29 -07:00
Leonardo de Moura
0d1a0c8b6e chore(library): toBool ==> decide
We want to define a type class similar to Haskell's `ToBool`.
2019-05-06 14:02:15 -07:00
Leonardo de Moura
c1fecc8939 feat(library/init/data/array/basic): add anyM and allM 2019-05-06 13:47:36 -07:00
Leonardo de Moura
ac747c5f6e feat(library/init/data/rbmap): add erase 2019-05-04 15:58:30 -07:00
Leonardo de Moura
8db0474571 feat(library/init/data/random): random numbers
It is useful for creating tests.
2019-05-04 15:57:42 -07:00
Leonardo de Moura
626e8fb27f chore(library/init/data/rbmap/basic): use [specialize] instead of [inline]
`RBMap.insert` is not that small.
2019-05-03 21:09:49 -07:00
Sebastian Ullrich
c77970a00f refactor(library): remove now-redundant parentheses 2019-05-03 13:57:21 +02:00
Leonardo de Moura
3628b39cb6 feat(library/init/lean/compiler): add simpcase transformation 2019-05-02 12:40:37 -07:00
Leonardo de Moura
81d11db5d2 chore(runtime/object): rename runtime primitives 2019-05-02 10:55:29 -07:00
Leonardo de Moura
4c9a488446 chore(library/init/data/array): naming convention
@kha Trying again :)
I started using the prefix `f` for the `Fin` version (e.g., `fswap` and
`fswapAt`). So, it seemed natural to use the prefix `f` for the `Fin`
versions of `get` and `set`.
BTW, is it too crazy to use `a[i]` (without spaces) as notation for
`a.get i`? The constraint is to make sure `f a [i]` is not ambiguous.
That is, `f a[i]` is `f (a.get i)` and `f a [i]` is `f a (i::nil)`.
This is doable with the new parser.

Then, we could have `a[i]` as notation for `a.fget i` if `i` is a `Fin`,
and `a.get i` if `i` is `Nat`.
Similarly, `a[i := v]` would be notation for `a.fset i v` if `i` is
`Fin`, and `a.set i` if `i` is `Nat`.

It would also be awesome to have
```
let a[i] := v in
e
```
as notation for
```
let a := a[i := v] in
```
2019-05-02 10:23:53 -07:00
Leonardo de Moura
970941db2c feat(library/init/data/array/basic): add Array.filter 2019-05-02 09:51:08 -07:00
Leonardo de Moura
5a83a2d7bb feat(library/init/data/array/basic): add swapAt 2019-05-02 07:46:11 -07:00
Leonardo de Moura
94fe3c18d0 fix(library/init/data/rbtree/basic): add HasInsert instance
It is useful for defining finite trees
2019-05-01 21:19:07 -07:00
Leonardo de Moura
e52e787ad5 fix(library/init/lean/compiler/pushproj): bug and cleanup 2019-05-01 21:01:03 -07:00
Leonardo de Moura
2991b966e5 featg(library/init/lean/compiler): add pushproj 2019-05-01 17:38:44 -07:00
Leonardo de Moura
1707628b6b feat(library/init/data/array/basic): Array.reverse 2019-05-01 17:38:44 -07:00
Leonardo de Moura
af1d521706 feat(library/init/data/array/basic): add Array.swap 2019-05-01 17:38:44 -07:00
Leonardo de Moura
711fab451b refactor(library/init/data/array): Array.foldl argument order 2019-04-29 10:48:33 -07:00
Leonardo de Moura
63442ebde7 feat(library/init/data/array/basic): add iterate₂ and foldl₂ 2019-04-29 10:48:33 -07:00
Leonardo de Moura
df84868ab4 feat(library/init/data/array/basic): array helper functions 2019-04-28 10:10:24 -07:00
Leonardo de Moura
03f42fda34 refactor(library/init/data/rbmap/basic): use [inline] instead of auxiliary "corpse" 2019-04-27 08:10:26 -07:00
Leonardo de Moura
c6d0083456 fear(library/init/data/array/basic): add Array.modify 2019-04-26 14:41:17 -07:00
Leonardo de Moura
7c0f3aef5b feat(library/init/data/rbmap/basic): add RBMap.empty 2019-04-23 09:14:54 -07:00
Leonardo de Moura
b1503f2c56 perf(library/init/data/array/basic): remove inefficient mforeachAux and add new hmmap and hmap
The `mforeachAux` function was keeping two references to the array
because it was implemented using `miterate a ⟨a, rfl⟩ ...`
Thus, we would have to allocate a new array even if `a` was not shared.

Another issue is that when invoking `x ← f i v`, the array would still
have a reference to `v`, and consequently `RC(v) > 1`, and `f` would not
be able to perform destructive updates to `v` or reuse its memory cell.

Thus, I removed `mforeach` (we only used it to implement `hmap`: the
homogeneous map), and implemented a new `hmap` which makes sure
destructive updates can be performed modulo the issue with float `let`
inwards I described in the previous commit.

@kha I found the problem described in the previous commit when I was
using `Array.hmap`. If we use `Array`s to implement `Syntax` as we discussed,
then a `hmap` that does not prevent destructive updates from happening is
a must-have. Otherwise, any benefit we get from using `Array`s instead
of `List`s is gone.
2019-04-19 14:52:52 -07:00
Leonardo de Moura
549b07a815 chore(library/init/data/array/basic): missing [inline] 2019-04-19 14:52:52 -07:00
Leonardo de Moura
62b8954ec4 chore(library/init/data/array/basic): heterogeneous Array.mmap 2019-04-19 14:52:52 -07:00
Leonardo de Moura
52b72c85bf fix(library/init/data/array/basic): typo 2019-04-12 09:03:20 -07:00
Leonardo de Moura
804ff74350 feat(library/init/data/array/basic): add Array.back 2019-04-10 08:56:42 -07:00
Leonardo de Moura
0a1b751efd chore(library/init/data/string/basic): naming consistency 2019-04-09 08:18:29 -07:00
Leonardo de Moura
9c81cd7f1d feat(library/init/data/array/basic): add Array.extract 2019-04-07 13:08:23 -07:00
Leonardo de Moura
8d2d43beb2 feat(library/init/data/array/basic): add shrink 2019-04-07 12:42:56 -07:00
Leonardo de Moura
4d3689ea33 feat(library/init/data/array/basic): add new array functions
@kha I renamed the homogeneous `map` to `hmap`, and added the
heterogeneous one as `map`. As soon as we add user-defined rewriting
rules, we will be able to replace `map` with `hmap` whenever the types
are the same.
2019-04-06 19:25:32 -07:00
Leonardo de Moura
e09374afa6 perf(library/init/data/hashmap/basic): reuse AssocList memory cells when expanding hashtable 2019-04-03 10:49:46 -07:00
Leonardo de Moura
273a0775d6 perf(library/init/data/array): mkArray in Lean doesn't seem to buy us anything
The primitive implementation combines all `inc`'s into a single one.
2019-04-03 10:27:58 -07:00
Leonardo de Moura
a18c88a727 perf(library/init/data/hashmap/basic): add [inline] to reinsertAux 2019-04-03 09:52:34 -07:00
Leonardo de Moura
d9be0290ae perf(library/init/data/hashmap/basic): missing @[inline]
This commit adds the auxiliary function `expand` to break a nasty
interaction between code specialization, erasure and memory reuse.

Suppose we have
```lean
let  new_array := array.update array i v in
have pr : <some property that mentions array>, from <proof>,
f  new_array pr
```
Suppose `f` is not marked with `[specialize]`. Then, `pr` is erased and we get:

```lean
let  new_array := array.update array i v in
f  new_array box(0)
```
If `RC(array) == 1`, then the update performs a destructive update, and
we are happy.

Now, assume that `f` is marked with `[specialize]`.
Moreover, function specialization occurs before erasure since we want to
be able to use the to-be-implemented user-defined rewriting rules after specialization.
When we specialize `f` we compute a closure of its dependencies, and one of them is array because of `pr`.
Thus, we get
```lean
let  new_array := array.update array i v in
f_spec new_array array
```
after specialization and erasure, but now, we don't perfom the destructive update.

BTW, I assumed we should be able to reduce the arity of `f_spec` after
erasure since the parameter `array` be dead after it. However, I found the following TODO:
https://github.com/leanprover/lean4/blob/master/src/library/compiler/reduce_arity.cpp#L50
2019-04-03 09:38:03 -07:00
Leonardo de Moura
1815331828 perf(library/init/data): add @[specialize] to RBMap and RBTree functions that depend on lt : a -> a -> Bool
A few commits ago, a few `RBMap` and `RBTree` functions had
the parameters `(lt : a -> a -> Prop) [DecidableRel lt]` instead of
`(lt : a -> a -> Bool)`. Recall that the compiler automatically specializes
functions with arguments of the form `[ ... ]`. Thus, after we moved to
`(lt : a -> a -> Bool)` we have to include `@[specialize]` to force the
compiler to specialize.
2019-04-03 09:16:34 -07:00
Leonardo de Moura
a883042dc8 chore(library/init): fold functions argument order consistency 2019-04-03 07:42:14 -07:00
Leonardo de Moura
c43374d296 refactor(library/init/data/hashmap): use AssocList and HasBeq 2019-04-03 05:55:08 -07:00
Leonardo de Moura
568b598729 fix(library/init/data/array/basic): incorrect borrow annotation 2019-04-03 05:50:53 -07:00
Leonardo de Moura
19856c4ca7 chore(library/init/data/hashmap/default): missing file 2019-04-03 05:50:19 -07:00
Leonardo de Moura
01b3eb2b05 feat(library/init/data/assoclist): add AssocList 2019-04-03 04:35:52 -07:00
Leonardo de Moura
ee050431e0 feat(runtime): add primitive hash functions 2019-04-03 04:01:36 -07:00
Leonardo de Moura
dc6c1e329f refactor(library/init/data/rbmap): use Bool instead of Prop 2019-04-03 02:54:34 -07:00
Leonardo de Moura
beb946d132 chore(library/init/data/int/basic): remove weird notation, dead code, and fix camelCase conversion issues 2019-04-03 02:54:34 -07:00