Commit graph

26011 commits

Author SHA1 Message Date
Leonardo de Moura
892e9c63ec chore: update stage0 2020-12-01 16:43:17 -08:00
Leonardo de Moura
9d304df757 feat: heterogeneous Append experiment
@Kha This one required a bunch of manual fixes. The main issue is that
before we added the string interpolation feature, we created
`MessageData`s using `++` and coercions. For example, given
`(e : Expr)`, we would write
```
let msg : MessageData := "type: " ++ e
```
and rely on the coercions `String -> MessageData` and
`Expr -> MessageData`, and the instance `Append MessageData`.
However, heterogeneous operators "block" the expected type propagation downwards.
This kind of code is obsolete now since we can write a more compact
version using string interpolation
```
let msg := m!"type: {e}"
```
2020-12-01 16:32:41 -08:00
Leonardo de Moura
baabfc13e0 chore: remove occurrences of Append.append 2020-12-01 15:44:03 -08:00
Leonardo de Moura
e31b17484a feat: add instances from coe + homogeneous operator to heterogeneous operator
@Kha The new `rational.lean` test shows their usefulness. We just
define the monorphic version and a coercion, and get a bunch of `HAdd`
instances for free.
2020-12-01 15:30:10 -08:00
Leonardo de Moura
599c2f68ef chore: update stage0 2020-12-01 15:09:07 -08:00
Leonardo de Moura
2120883307 refactor: heterogeneous operators
@Kha I had some unexpected surprises, but it is a good change.
Here is the summary.

1- We could get rid of `a %ₙ b` and `ModN` class. We can use `HMod`
instead. It was a positive surprise since I didn't remember we had
this `ModN` class.

2- Coercions are never used in heterogeneous operators. This is
expected since `a * b` is now notation for `HMul.hMul a b`, and
`a` and `b` may have different types. I manually added instances such
as `HMul Nat Int Int`. However, I did not try to add generic instances
such as
```
instance [Coe a b] [Mul b] : HMul a b b where
  hMul x y := mul (coe x) y
```
I will try later.

3- Give `h : cs.size > 0`, I got a type error at
```
let idx : Fin cs.size := ⟨cs.size - 1, Nat.predLt h⟩
```
`Nat.predLt h` has type `Nat.pred cs.size < cs.size`
However, `Nat.pred cs.size` doesn't unify with `cs.size - 1`.
The problem is that we can't synthesize the `HSub` instance until
we apply the default instances.
It worked before because `isDefEq` would force the pending TC
problem `Sub Nat` to be resolved, and after that we would be able
to reduce `cs.size - 1` and establish that it is definitionally
equal to `Nat.pred cs.size`.
I considered two possible workarounds
a) `let idx : Fin cs.size := ⟨cs.size - (1:Nat), Nat.predLt h⟩`
b) `let idx : Fin cs.size := ⟨cs.size - 1, by exact Nat.predLt h⟩`
The first one works because we are not providing enough information
for synthesizing the `HSub` instance. The second works because it
postpones the elaboration of `Nat.predLt h`. The default instances
will be applied before we start applying tactics.

4- The `.` notation is affected too. For example, `(x + 1).toUInt8`
doesn't work since we don't know the type of `x+1` until we apply
default instances. I fixed it by using `(x + (1:Nat)).toUInt8`.
Another possible fix is `Nat.toUInt8 (x + 1)`.
Similarly, `(x+1).fold ...` doesn't work.

5- The following code failed to be elaborated
```
indent (push s!"{ss'}\n") (some (0 - Format.getIndent (← getOptions)))
```
It was working before, but it relied on how the expected type is
propagated. The elaborator process
```
some (0 - Format.getIndent (← getOptions))
```
with expected type `(Option Int)`. So, the `-` is interpreted as
`Int.sub` although `Format.getIndent (← getOptions)` has type `Nat`.
In the new `HSub`, the expected type doesn't really influence TC
resolution since it is an `outparam`. So, we failed with the error
failed to synthesize `HSub Nat Nat Int`.
One possible fix was to add the instance `HSub Nat Nat Int` with
`Int.sub`, but I used the following fix
```
some ((0 : Int) - Format.getIndent (← getOptions))
```
which makes it clear that we want the `Int.sub` operator instead of
`Nat.sub`.
2020-12-01 14:02:46 -08:00
Leonardo de Moura
574aa62fa8 chore: update stage0 2020-12-01 12:42:00 -08:00
Leonardo de Moura
d629c76f9e chore: more heterogeneous operators support 2020-12-01 12:39:45 -08:00
Sebastian Ullrich
0242b0e1eb fix: test 2020-12-01 12:05:54 -08:00
Sebastian Ullrich
3aad1348ff chore: add back removed prefix operators as non-builtins 2020-12-01 12:01:23 -08:00
Sebastian Ullrich
5c047e392f chore: update stage0 2020-12-01 12:01:23 -08:00
Sebastian Ullrich
32618b0398 chore: remove built-in prefix operators
To reappear soon
2020-12-01 11:57:20 -08:00
Sebastian Ullrich
5b2b2d8069 chore: declare ASCII notations first 2020-12-01 11:57:20 -08:00
Sebastian Ullrich
1f9e8bc93d fix: <&> 2020-12-01 11:57:20 -08:00
Sebastian Ullrich
07f25a19db chore: remove obsolete builtin delaborators 2020-12-01 11:57:20 -08:00
Sebastian Ullrich
d18596d4ca feat: add Unexpander for delaborating without importing Lean, use for simple notations
/cc @leodemoura
2020-12-01 11:57:20 -08:00
Sebastian Ullrich
4843f933fa feat: mkAntiquotNode 2020-12-01 11:57:20 -08:00
Sebastian Ullrich
39edb949c1 feat: allow KeyedDeclsAttribute without built-in attribute 2020-12-01 11:57:20 -08:00
Leonardo de Moura
a1f6fc8382 chore: update stage0 2020-12-01 11:56:11 -08:00
Leonardo de Moura
e213a7ecca feat: add support for heterogeneous operators at Offset.lean 2020-12-01 11:53:44 -08:00
Leonardo de Moura
1e84fa1eed refactor: more general OfNat, remove One and Zero classes 2020-12-01 07:49:52 -08:00
Leonardo de Moura
a2da8b86fa chore: update stage0 2020-12-01 07:01:52 -08:00
Leonardo de Moura
27292c4f60 chore: prepare to change OfNat type class 2020-12-01 06:59:16 -08:00
Sebastian Ullrich
8cc6ec1cb7 chore: Nix: Lean shell quoting 2020-12-01 15:55:41 +01:00
Sebastian Ullrich
5adaecc00e doc: Nix: more about nix develop 2020-12-01 15:55:41 +01:00
Leonardo de Moura
5233ff6db7 feat: very lazy synthesizeUsingDefault
Stop as soon as we succeed applying a default instance.
2020-11-30 17:57:35 -08:00
Leonardo de Moura
6a3fff5c66 fix: condition 2020-11-30 17:10:25 -08:00
Leonardo de Moura
f4eb6a4e27 test: heterogeneous + and * 2020-11-30 17:05:57 -08:00
Leonardo de Moura
085c7e59ba feat: apply default instances using priorities 2020-11-30 16:43:12 -08:00
Leonardo de Moura
a7563a0ec2 feat: forIn for RBTree and RBMap 2020-11-30 16:42:47 -08:00
Leonardo de Moura
8c712cd145 chore: update stage0 2020-11-30 15:58:29 -08:00
Leonardo de Moura
b437cfd9a3 feat: add [defaultInstance] priorities 2020-11-30 15:57:40 -08:00
Leonardo de Moura
b6f242434d fix: fixes #229 2020-11-30 11:51:13 -08:00
Sebastian Ullrich
6d9fcd1d07 fix: renamed references 2020-11-30 14:41:10 +01:00
Sebastian Ullrich
f6816a0ffa refactor: move & split Lean.Delaborator 2020-11-30 13:52:46 +01:00
Sebastian Ullrich
816185373a chore: update stage0 2020-11-30 13:41:17 +01:00
Sebastian Ullrich
6cef5f17b7 chore: prepare moving Lean.Delaborator into Lean.PrettyPrinter 2020-11-30 13:39:18 +01:00
Sebastian Ullrich
78379de8e6 chore: go back to LLVM 10
3% slower on stdlib: http://speedcenter.informatik.kit.edu/velcom/run-detail/9012094e-6524-4e99-8397-1b17b6a10ae5
failure on macOS: https://hydra.nixos.org/build/130586121
2020-11-30 12:32:53 +01:00
Sebastian Ullrich
f850354ee1 chore: turn LLVM up to 11 2020-11-30 11:46:32 +01:00
Sebastian Ullrich
039955a4c5 chore: update nixpkgs 2020-11-30 11:46:32 +01:00
Leonardo de Moura
cde53c67e6 chore: fix docs 2020-11-29 20:09:32 -08:00
Leonardo de Moura
4ef7d83445 test: bundled structures 2020-11-29 18:58:42 -08:00
Leonardo de Moura
b66dd397f8 test: CommGroup example 2020-11-29 18:21:59 -08:00
Leonardo de Moura
51e0d88e38 chore: update stage0 2020-11-29 18:17:53 -08:00
Leonardo de Moura
72215c7144 feat: add TransparencyMode.instances 2020-11-29 18:12:33 -08:00
Leonardo de Moura
482f44deda test: basic algebra classes 2020-11-29 17:26:30 -08:00
Leonardo de Moura
384ba49d8e chore: fix tests 2020-11-29 17:05:43 -08:00
Leonardo de Moura
d734a2605b chore: adjust stdlib 2020-11-29 17:01:56 -08:00
Leonardo de Moura
9561ec8ece chore: update stage0 2020-11-29 16:54:09 -08:00
Leonardo de Moura
40e51270f5 feat: add withReducible <tacticSeq>
Use `try (withReducible rfl)` after `rw` and `erw`
2020-11-29 16:52:30 -08:00