Commit graph

63 commits

Author SHA1 Message Date
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
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
c6d0083456 fear(library/init/data/array/basic): add Array.modify 2019-04-26 14:41:17 -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
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
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
568b598729 fix(library/init/data/array/basic): incorrect borrow annotation 2019-04-03 05:50:53 -07:00
Leonardo de Moura
5e1a3a7e6a feat(library/init/data/array/basic): make sure we reduce List.length too at List.toArray 2019-04-01 10:54:45 -07:00
Leonardo de Moura
e58949e938 chore(library/init/control/id): rename id monad to Id 2019-03-29 16:45:52 -07:00
Leonardo de Moura
c134617ee3 fix(library/init/data/array/basic): mkEmpty 2019-03-29 11:20:45 -07:00
Leonardo de Moura
49551036ed refactor(library/init): minor changes
Old `Nat.repeat` => `Nat.for`
Old `Nat.mrepeat` => `Nat.mfor`
New `Nat.repeat` has type
```
def repeat {α : Type u} (f : α → α) (n : Nat) (a : α) : α :=
``
`List.repeat` => `List.replicate` (like in Haskell)
Avoid weird `ℕ` in List library
2019-03-29 10:39:00 -07:00
Leonardo de Moura
229e4a25b3 refactor(library/init/array): implement mkArray in Lean, add allow mkEmpty to set initial capacity 2019-03-29 10:19:21 -07:00
Sebastian Ullrich
c8e11d289f feat(library/init/data/array/basic): new Array operations from syntax-array experiment 2019-03-29 16:02:08 +01:00
Sebastian Ullrich
a86b852d1c chore(library/init/data/array/basic): use same foldl signature as other types 2019-03-29 14:34:42 +01:00
Leonardo de Moura
895bf2c91d feat(library/equations_compiler/partial_rec): try assumption if inhabitant could not be found 2019-03-27 12:24:24 -07:00
Leonardo de Moura
87b066b87e refactor(library/init): move function.lean definitions to core.lean 2019-03-22 09:33:10 -07:00
Leonardo de Moura
452d5107ac chore(library/init/data/array): naming convention
The array read and write operations are now called:

- "Comfortable" version (with runtime bound checks):
  `Array.get` and `Array.set` like OCaml.
   It is also consistent with `Ref.get` and `Ref.put`,
   and `get` and `set` for `MonadState`.

- `Fin` version (without runtime bound checks):
  `Array.index` and `Array.update` like in F*.

- `USize` version (without runtime bound checks and unboxing):
  `Array.idx` and `Array.updt`.

cc @kha
2019-03-21 18:03:29 -07:00
Leonardo de Moura
4a08d6715a chore(library/init/data/array): add HasEmptyc instance 2019-03-21 17:06:56 -07:00
Leonardo de Moura
3befc219c9 chore(library/init): Empty => empty when it is a function 2019-03-21 17:03:15 -07:00
Leonardo de Moura
1fe3f14ad0 chore(*): Uint => UInt, Usize => USize 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
2ea0baeb99 chore(library): use lowercase in imports 2019-03-21 15:06:44 -07:00
Leonardo de Moura
675003318e chore(*): small fixes 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
402034df1f chore(library/init/data): move usize to uint 2019-03-09 10:32:23 -08:00
Leonardo de Moura
9e0b28d8ce feat(library/init/data/array/basic): improve 2019-02-16 16:08:10 -08:00
Leonardo de Moura
3c73c43ab2 feat(runtime,library/init/data/array/basic): add builtin support for arrays 2019-02-16 15:27:23 -08:00
Leonardo de Moura
d85c30fde1 perf(library/init/data): mark usize, uint16, uint32 and uint64 as [irreducible]
Without these annotations, Lean will timeout when trying to synthesize
the type class instance `decidable_eq uint32`. The type class resolution
problem will produce the unification problem:
```
decidable (@eq uint32 a b) =?= decidable (@eq usize ?x ?y)
```
which Lean tries to solve by assigning `?x := a`.
During the assignment, the types of `?x` and `a` are unified with "full
force". Thus, we get the constraint
```
usize_sz =?= uint32_sz
```
which will take forever to be solved when peforming the computation in
unary arithmetic.

Remark: this commit also makes sure that `type_context` will not unfold
irreducible definitions when trying to unify/match the types.

The new test `type_class_performance1.lean` exposes the problem fixed
by this commit.
2018-05-07 18:07:04 -07:00
Leonardo de Moura
11a8a7c4f3 feat(library/init): use usize instead of uint32 in the low level array access primitives 2018-05-04 10:40:14 -07:00
Leonardo de Moura
af4f831a9f feat(library/init/data/hashmap): hash function produces an uint32 instead of nat
Most efficient hash functions use uint32/uint64 and produce values
that do not fit in out small nat representation. Thus, GMP big numbers
would have to be created.
2018-05-03 17:56:10 -07:00
Leonardo de Moura
acade175b6 feat(library/init/data/array): store dimension in the array
The array dimension is now stored inside the array.
The main motivation is that it reflects the actual runtime implementation.
We need to store the array size to be able to GC it.
So, it feels silly to have the array size stored in each array object,
but we cannot use this information.
For example, in the `hashmap` we implemented the bucket array using
`array`, and we store the `size` of the array.
Same for the Lean3 `buffer` object.
The `buffer` object doesn't even need to exist.
The actual `array` implementation is the `buffer`
2018-05-03 15:43:03 -07:00