Commit graph

58 commits

Author SHA1 Message Date
Sebastian Ullrich
428355cf02
chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Sebastian Ullrich
ff1d3138bf
refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Leonardo de Moura
b1e52f1475
chore: mark Meta.Context.config as private (#6051)
Motivation: we want to modify the internal representation and improve
`isDefEq` caching.
This PR is preparing the stage for future modifications.
2024-11-13 13:30:06 +11:00
Leonardo de Moura
1630d9b803
feat: universe constraint approximations (#3981)
We add a new configuration flag for `isDefEq`:
`Meta.Config.univApprox`.
When it is true, we approximate the solution for universe constraints
such as
- `u =?= max u ?v`, we use `?v := u`, and ignore the solution `?v := 0`.
- `max u v =?= max u ?w`, we use `?w := v`, and ignore the solution `?w
:= max u v`.

We only apply these approximations when there the contraints cannot be
postponed anymore. These approximations prevent error messages such as
```
error: stuck at solving universe constraint
  max u ?u.3430 =?= u
```
This kind of error seems to appear in several Mathlib files.

We currently do not use these approximations while synthesizing type
class instances.
2024-04-24 20:27:51 +00:00
Henrik Böving
23e49eb519 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Gabriel Ebner
e386d5941e refactor: replace ignoreLevelMVarDepth by levelAssignDepth 2022-12-19 20:14:17 +01:00
Gabriel Ebner
3a9152f007 chore: improve defeq traces 2022-08-15 08:55:25 -07:00
Leonardo de Moura
c210781af8 refactor: add doc strings, cleanup, and dotted notation friendly API
See #1346
2022-07-27 16:01:15 -07:00
Leonardo de Moura
a62949c49b refactor: add type LevelMVarId (and abbreviation LMarId)
Motivation: make sure we do not mixup metavariable ids for
expression and universe level.

cc @bollu
2022-07-24 17:21:45 -07:00
Gabriel Ebner
3176943750 refactor: use computed fields for Level 2022-07-11 14:19:41 -07:00
Leonardo de Moura
88fc0b2503 fix: isAssigned-like functions should set usedAssignment 2022-07-04 06:20:37 -07:00
Leonardo de Moura
12e2a79170 chore: fix codebase after removing auto pure 2022-02-03 18:08:14 -08:00
Leonardo de Moura
7b6732a137 refactor: ExprDefEq.lean and LevelDefEq.lean are now implementation only files
We use the export/extern idiom to define `isLevelDefEqAux`, and then
define the `isDefEq` user facing functions at `Meta/Basic.lean`.
2021-12-06 09:57:00 -08:00
Leonardo de Moura
9e980b2a78 fix: bug at decAux?
We are getting a few "stuck at universe constraint" errors after the
fix. We may need to add some kind of approximation in the future.
2021-09-20 07:12:57 -07:00
Leonardo de Moura
d0d7799a7b doc: document (and rename) the new configuration option ignoreLevelMVarDepth 2021-08-18 20:38:18 -07:00
Leonardo de Moura
99e8a98f06 feat: allow universes metavariables from any depth to be assigned when ignoreLevelDepth is true
We set `ignoreLevelDepth` to true during type class resolution.
2021-08-18 20:20:51 -07:00
Leonardo de Moura
16d803c0b3 chore: update comment 2021-07-28 17:18:41 -07:00
Leonardo de Moura
818efe719e fix: fixes #533 2021-06-29 15:20:46 -07:00
Leonardo de Moura
c9db8619f1 fix: fixes #456 2021-05-11 21:07:21 -07:00
Leonardo de Moura
675bebb446 fix: isLevelDefEq missing case 2021-04-25 10:27:14 -07:00
Leonardo de Moura
dbc84c502c chore: make sure we don't lift methods over binders 2021-04-15 12:06:46 -07:00
Leonardo de Moura
2694e7798a refactor: add MonadBacktrack
The new class specifies an interface for saving and restoring the
backtrackable part of the state.
This commit also fixes a few issues.

- `commitWhen` at `LevelDefEq` was defining a checkpoint for
  the `isDefEq` methods, and it affects how postponed universe
  constraints are handled. However, the name suggests it is
  similar to `commitWhenSome?`, and consequently it was used
  in other places that had nothing to do with `isDefEq`.
  So, I renamed it, and provided the generic `commitWhen` at the new
  `MonadBacktrack.lean` file.

- We were restoring more state then needed in a few places.
  For example, we were discarding all caches.

- At `SyntheticMVars.lean`, we were using the `Meta.commitWhenSome?`
  method which does not restore the `Term.State`.
2021-04-11 19:10:41 -07:00
Leonardo de Moura
865316bbf9 feat: improve error message when stuck solving universe constraints
closes #343
2021-03-11 17:46:44 -08:00
Leonardo de Moura
be841a7cad chore: throwError! => throwError, throwErrorAt! => throwErrorAt
@Kha I marked the corresponding methods as `protected`.
I currently can't stand `throw_error`, and I am optimistic about
server highlighting feature you are working on :)
2021-03-11 11:59:45 -08:00
Leonardo de Moura
68143ca8ba chore: trace[...]! ==> trace[...]
@Kha I think this one is a good change, there is no real reason for
using the `!` suffix here.
2021-03-10 18:44:43 -08:00
Leonardo de Moura
30ba56126b fix: missing case
Lean should not get stuck at universe constraints such as `?u =?= ?u + 1`.
2021-03-10 14:48:02 -08:00
Leonardo de Moura
a3923eecc8 feat: filter duplicate universe constraints at error message 2021-03-10 14:40:25 -08:00
Leonardo de Moura
847f95021a fix: losing postponed universe constraints
This bug was exposed by #342
2021-03-10 14:18:03 -08:00
Leonardo de Moura
21812541ea fix: solve method at isLevelDefEq
closes #283
2021-01-20 08:36:26 -08:00
Leonardo de Moura
6a89a811ce chore: cleanup 2021-01-20 08:36:26 -08:00
Leonardo de Moura
63ab55289e chore: remove "liftable methods"
The new frontend "auto lifting" feature makes them obsolete.
2020-12-09 15:06:07 -08:00
Leonardo de Moura
05fc1e8bbf feat: optional name for unification hints 2020-11-29 08:05:26 -08:00
Leonardo de Moura
645c1034a0 chore: reduce compilation time 2020-11-23 16:18:55 -08:00
Leonardo de Moura
db5fe843de chore: add expandInterpolatedStr helper function, rename msg! => m! 2020-11-14 13:52:52 -08:00
Leonardo de Moura
a80c7ff882 feat: add mkLevelMax' and mkLevelIMax' 2020-11-14 08:11:49 -08:00
Leonardo de Moura
bf242f434d fix: missing case 2020-11-14 07:14:25 -08:00
Leonardo de Moura
2d2d39c78e chore: use mut 2020-11-07 17:32:13 -08:00
Leonardo de Moura
79609938a8 feat: allow universe constraints to be postponed longer
Before this commit, each `isDefEq u v` invocation would fail if there
were pending universe level constraints. This commit, moves the
postponed universe constraints back to the `MetaM` state.
It also adds the combinator
```lean
withoutPostponingUniverseConstraints x
```
which executes `x` and throws an error if there are pending universe
constraints. We use the combinator at `elabApp` and `elabBinders`.
Without this commit, we would fail to elaborate simple terms such as
```lean
  Functor.map Prod.fst (x s)
```
because after elaborating `Prod.fst` and trying to ensure its type
match the expected one, we would be stuck at the universe constraint:
```
  u =?= max u ?v
```

Another benefit of the new approach is better error messages. Instead
of getting a mysterious type mismatch constraint, we get a list of
universe contraints the system is stuck at.

cc @Kha
2020-10-26 15:50:05 -07:00
Leonardo de Moura
5481999560 chore: cleanup 2020-10-26 14:25:38 -07:00
Leonardo de Moura
13c2a8ff51 chore: remove #lang lean4 header 2020-10-25 09:54:07 -07:00
Leonardo de Moura
1b6d1a83c7 chore: move to new frontend 2020-10-20 09:33:50 -07:00
Leonardo de Moura
ef18b0ab49 chore: use [builtinInit] 2020-10-19 14:58:38 -07:00
Leonardo de Moura
f2835207a8 refactor: move isDefEqGuarded helper 2020-09-16 10:15:47 -07:00
Leonardo de Moura
e181c1adee refactor: add DefEqM
The idea is to make clear that the field `posponed` is transient
state. It is only used during `isDefEq`.
The refactoring was motivated by a bug I found where the `posponed`
constraints were not being handled correctly. For example,
the `check (e : Expr)` method was returning `true`, but leaving pending
universe constraints at `postponed`.

cc @Kha
2020-09-12 16:42:16 -07:00
Leonardo de Moura
0967ad7e91 feat: extend/cleanup isLevelDefEqAux
`tests/lean/run/toExpr.lean` could not be processed by the new
frontend without these extensions.
2020-09-12 15:38:48 -07:00
Leonardo de Moura
813a964767 refactor: move polymorphic Meta methods back to Meta namespace 2020-08-25 14:57:58 -07:00
Leonardo de Moura
cf0149a1a7 refactor: use MonadControlT 2020-08-25 13:54:42 -07:00
Leonardo de Moura
49f5e4db20 refactor: cleanup 2020-08-24 17:47:27 -07:00
Leonardo de Moura
eaed6ba6a3 refactor: polymorphic MetaM combinators 2020-08-24 17:03:54 -07:00
Leonardo de Moura
ac565de96c refactor: add MonadMetaM class 2020-08-24 12:17:47 -07:00