Commit graph

24104 commits

Author SHA1 Message Date
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
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
d629c76f9e chore: more heterogeneous operators support 2020-12-01 12:39:45 -08:00
Sebastian Ullrich
3aad1348ff chore: add back removed prefix operators as non-builtins 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
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
27292c4f60 chore: prepare to change OfNat type class 2020-12-01 06:59:16 -08: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
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
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
6cef5f17b7 chore: prepare moving Lean.Delaborator into Lean.PrettyPrinter 2020-11-30 13:39:18 +01:00
Leonardo de Moura
72215c7144 feat: add TransparencyMode.instances 2020-11-29 18:12:33 -08:00
Leonardo de Moura
d734a2605b chore: adjust stdlib 2020-11-29 17:01:56 -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
Leonardo de Moura
390eea3750 feat: use One and Zero classes when expanding numeric literals 2020-11-29 16:23:52 -08:00
Leonardo de Moura
89961a608e fix: missing withDeclName 2020-11-29 16:22:11 -08:00
Leonardo de Moura
da15bc27c6 feat: add Zero and One classes 2020-11-29 16:02:34 -08:00
Leonardo de Moura
e562959682 feat: add support for auto bound implicits to the structure command 2020-11-29 14:39:51 -08:00
Leonardo de Moura
dfd1f23030 fix: avoid unnecessary page allocation
When import objects deleted by other threads, we may add elements to
`p` free list.
2020-11-29 13:33:59 -08:00
Leonardo de Moura
6dd3616298 fix: import pending objects *before* moving segments
@Kha I stopped getting the assertion violation after this fix.
There is another unrelated issue that I will fix in a separate commit.
2020-11-29 13:26:10 -08:00
Sebastian Ullrich
a22d234e93 fix: Thunk.get: mark result as MT before storing it in the task object 2020-11-29 18:59:39 +01:00
Sebastian Ullrich
65c1bc8952 fix: gen_constants_cpp.py: mark constants as persistent 2020-11-29 18:59:39 +01:00
Leonardo de Moura
9e860672ad chore: helper trace message 2020-11-29 08:46:34 -08:00
Leonardo de Moura
df665eb8fc fix: notation 2020-11-29 08:28:01 -08:00
Leonardo de Moura
e9069b6965 feat: expand optional priority at notation and mixfix commands 2020-11-29 08:22:47 -08:00
Leonardo de Moura
ee5679c77c chore: prepare to add optional priorities to the notation and mixfix commands 2020-11-29 08:05:26 -08:00
Leonardo de Moura
05fc1e8bbf feat: optional name for unification hints 2020-11-29 08:05:26 -08:00
Sebastian Ullrich
f649f24014 fix: compilation on Windows 2020-11-29 14:08:53 +01:00
Sebastian Ullrich
c0f94c902e fix: memory leak in interpreter 2020-11-29 14:08:53 +01:00
Leonardo de Moura
2ffd929227 feat: improve unification hints
The constraints don't need to be in the same universe anymore.
The new test demonstrates why this is useful.
2020-11-28 19:03:21 -08:00
Leonardo de Moura
16003871e4 feat: add helper instance 2020-11-28 19:01:54 -08:00
Leonardo de Moura
5ead7bfc81 feat: add [elabWithoutExpectedType] attribute 2020-11-28 13:23:37 -08:00
Leonardo de Moura
470717ba67 feat: autoBoundImplicit for universes 2020-11-28 12:45:57 -08:00
Leonardo de Moura
5a396a4872 feat: insert auto bound implicit arguments before explicitly provided ones
cc @Kha
2020-11-28 12:45:57 -08:00
Leonardo de Moura
0b8b30ef9e fix: CoeFun and CoeSort perf issue 2020-11-28 12:45:57 -08:00
Leonardo de Moura
4fc32d114f chore: "unbound implicit" => "auto bound implicit" 2020-11-28 12:45:57 -08:00
Leonardo de Moura
b6f2ed9e78 feat: add instances for converting CoeFun and CoeSort into Coe 2020-11-28 12:45:57 -08:00
Sebastian Ullrich
99383d97e1 feat: measure interpreter time & fix enabling interpreter traces 2020-11-28 17:36:20 +01:00