Commit graph

5196 commits

Author SHA1 Message Date
Leonardo de Moura
cbf2b6c0db feat: change synthinstance threshold
Before this commit, the threshold was the amount of "fuel".
Now, it is the maximum number of instances used to solve a TC problem.
We have two thresholds
- `maxInstSize`: default 128
- `maxCoeSize`: default 16. It is similar to `maxInstSize`, but used for automatic coercions.

cc @Kha
2020-12-07 10:45:08 -08:00
Leonardo de Moura
906cb81319 feat: improve inferAppType
See comment at `Expr.instantiateRevRange`
2020-12-06 19:01:23 -08:00
Leonardo de Moura
32325838a3 chore: fix test 2020-12-06 19:00:24 -08:00
Leonardo de Moura
91dec25a35 fix: bug at runST and runEST 2020-12-06 18:52:28 -08:00
Leonardo de Moura
44d0fe993a feat: ensure scoped instances cannot be used outside namespaces 2020-12-05 16:26:31 -08:00
Leonardo de Moura
dcf5f855dd test: scoped and local instances 2020-12-05 16:10:27 -08:00
Leonardo de Moura
4fa107c6a3 test: add test for issue fixed in previous commit 2020-12-05 15:50:24 -08:00
Leonardo de Moura
1af03901da feat: scoped and local unification hints 2020-12-05 14:34:14 -08:00
Leonardo de Moura
f000aa0155 test: scoped parser after open 2020-12-05 08:35:30 -08:00
Leonardo de Moura
d43a65aed0 feat: elaboarate local syntax, infix and notation commands 2020-12-05 08:05:40 -08:00
Leonardo de Moura
2463371a25 chore: fix test 2020-12-04 18:13:36 -08:00
Leonardo de Moura
8dbbe37d38 chore: fix test 2020-12-04 16:22:45 -08:00
Leonardo de Moura
54723409c3 test: scoped parsers 2020-12-04 16:22:45 -08:00
Sebastian Ullrich
d7f27a140e feat: antiquotation scopes 2020-12-04 19:24:32 +01:00
Leonardo de Moura
2408b5c6b5 feat: basic support for scoped attributes 2020-12-03 10:39:59 -08:00
Sebastian Ullrich
21f4257da5 feat: name resolution during parsing 2020-12-03 17:46:13 +01:00
Leonardo de Moura
d1f4d4f57e feat: scientific notation 2020-12-03 07:49:20 -08:00
Leonardo de Moura
85c9ab072c feat: elaborate and delaborate decimals 2020-12-02 15:31:06 -08:00
Leonardo de Moura
469de09280 fix: bug at isDefEq
The new test contains a minimal example that triggers the bug.
2020-12-02 13:27:21 -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
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
Sebastian Ullrich
0242b0e1eb fix: test 2020-12-01 12:05:54 -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
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
f4eb6a4e27 test: heterogeneous + and * 2020-11-30 17:05:57 -08:00
Leonardo de Moura
b6f242434d fix: fixes #229 2020-11-30 11:51:13 -08:00
Sebastian Ullrich
f6816a0ffa refactor: move & split Lean.Delaborator 2020-11-30 13:52:46 +01: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
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
390eea3750 feat: use One and Zero classes when expanding numeric literals 2020-11-29 16:23:52 -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
cb3a2f7947 test: add coercion pullback example from "Hints in Unification" 2020-11-29 08:46:45 -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
05fc1e8bbf feat: optional name for unification hints 2020-11-29 08:05:26 -08: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
249d79218c test: CoeFun 2020-11-28 17:46:00 -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
e21b4a6399 feat: nicer syntax for unification hints 2020-11-27 19:18:18 -08:00
Leonardo de Moura
ebba9d119d feat: unification hints 2020-11-27 18:12:49 -08:00
Wojciech Nawrocki
b1e6edefde fix: redirect child I/O to null on Process.Stdio.null
And don't use errno for Win32 API errors.
2020-11-27 13:17:32 -08:00
Leonardo de Moura
3f720d778c fix: unnecessary unfolding 2020-11-27 13:08:18 -08:00
Leonardo de Moura
f2ae695e14 test: propagateExpectedType 2020-11-27 12:17:23 -08:00
Leonardo de Moura
58f1f512f1 feat: simplify heuristics at propagateExpectedType 2020-11-27 12:13:29 -08:00
Leonardo de Moura
93cc8a6403 chore: fix test
It was working for the wrong reasons
2020-11-27 09:00:11 -08:00
Leonardo de Moura
fcc382df08 fix: improve Offset.lean
It did not support for assigned metavariables.
2020-11-27 08:40:43 -08:00