lean4-htt/src/Lean/Meta
Kyle Miller 3f98f6bc07
feat: structure instance notation elaboration improvements (#7717)
This PR changes how `{...}`/`where` notation ("structure instance
notation") elaborates. The notation now tries to simulate a flat
representation as much as possible, without exposing the details of
subobjects. Features:
- When fields are elaborated, their expected types now have a couple
reductions applied. For all projections and constructors associated to
the structure and its parents, projections of constructors are reduced
and constructors of projections are eta reduced, and also implementation
detail local variables are zeta reduced in propositions (so tactic
proofs should never see them anymore). Furthermore, field values are
beta reduced automatically in successive field types. The example in
[mathlib4#12129](https://github.com/leanprover-community/mathlib4/issues/12129#issuecomment-2056134533)
now shows a goal of `0 = 0` rather than `{ toFun := fun x => x }.toFun 0
= 0`.
- All parents can now be used as field names, not just the subobject
parents. These are like additional sources but with three constraints:
every field of the value must be used, the fields must not overlap with
other provided fields, and every field of the specified parent must be
provided for. Similar to sources, the values are hoisted to `let`s if
they are not already variables, to avoid multiple evaluation. They are
implementation detail local variables, so they get unfolded for
successive fields.
- All class parents are now used to fill in missing fields, not just the
subobject parents. Closes #6046. Rules: (1) only those parents whose
fields are a subset of the remaining fields are considered, (2) parents
are considered only before any fields are elaborated, and (3) only those
parents whose type can be computed are considered (this can happen if a
parent depends on another parent, which is possible since #7302).
- Default values and autoparams now respect the resolution order
completely: each field has at most one default value definition that can
provide for it. The algorithm that tries to unstick default values by
walking up the subobject hierarchy has been removed. If there are
applications of default value priorities, we might consider it in a
future release.
- The resulting constructors are now fully packed. This is implemented
by doing structure eta reduction of the elaborated expressions.
- "Magic field definitions" (as reported [on
Zulip](https://leanprover.zulipchat.com/#narrow/channel/113489-new-members/topic/Where.20is.20sSup.20defined.20on.20submodules.3F/near/499578795))
have been eliminated. This was where fields were being solved for by
unification, tricking the default value system into thinking they had
actually been provided. Now the default value system keeps track of
which fields it has actually solved for, and which fields the user did
not provide. Explicit structure fields (the default kind) without any
explicit value definition will result in an error. If it was solved for
by unification, the error message will include the inferred value, like
"field 'f' must be explicitly provided, its synthesized value is v"
- When the notation is used in patterns, it now no longer inserts fields
using class parents, and it no longer applies autoparams or default
values. The motivation is that one expects patterns to match only the
given fields. This is still imperfect, since fields might be solved for
indirectly.
- Elaboration now attempts error recovery. Extraneous fields log errors
and are ignored, missing fields are filled with `sorry`.

This is a breaking change, but generally the mitigation is to remove
`dsimp only` from the beginnings of proofs. Sometimes "magic fields"
need to be provided — four possible mitigations are (1) to provide the
field, (2) to provide `_` for the value of the field, (3) to add `..` to
the structure instance notation, (4) or decide to modify the `structure`
command to make the field implicit. Lastly, sometimes parent instances
don't apply when they should. This could be because some of the provided
fields overlap with the class, or it could be that the parent depends on
some of the fields for synthesis — and as parents are only considered
before any fields are elaborated, such parents might not be possible to
use — we will look into refining this further.

There is also a change to elaboration: now the `afterTypeChecking`
attributes are run with all `structure` data set up (e.g. the list of
parents, along with all parent projections in the environment). This is
necessary since attributes like `@[ext]` use structure instance
notation, and the notation needs all this data to be set up now.
2025-03-30 17:40:36 +00:00
..
ArgsPacker chore: fix spelling mistakes in src/Lean/Meta/ (#5436) 2024-09-23 23:09:14 +00:00
Constructions feat: align lemmas about List.getLast(!?) with Array/Vector.back(!?) (#7205) 2025-02-24 11:48:43 +00:00
Match feat: deprecate Array.mkArray in favour of Array.replicate 2025-03-24 08:25:00 +01:00
Tactic fix: markNestedProofs in grind (#7726) 2025-03-29 22:02:51 +00:00
AbstractMVars.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
AbstractNestedProofs.lean fix: abstractNestedProofs (#7728) 2025-03-29 23:58:09 +00:00
ACLt.lean fix: isDefEq, whnf, simp caching and configuration (#6053) 2024-11-18 01:17:26 +00:00
AppBuilder.lean perf: Environment blocker removals from async-proofs branch (#7483) 2025-03-14 13:37:01 +00:00
ArgsPacker.lean feat: identify more fixed parameters (#7166) 2025-03-04 22:26:20 +00:00
Basic.lean fix: report replay kernel errors as standard diagnostics (#7471) 2025-03-13 18:45:46 +00:00
BinderNameHint.lean feat: binderNameHint in congr (#7053) 2025-02-13 09:38:42 +00:00
Canonicalizer.lean chore: remove the old Lean.Data.HashMap implementation (#7519) 2025-03-20 23:49:55 +00:00
Check.lean perf: Environment blocker removals from async-proofs branch (#7483) 2025-03-14 13:37:01 +00:00
CheckTactic.lean
Closure.lean fix: process delayed assignment metavariables correctly in Lean.Meta.Closure (#6414) 2024-12-19 20:15:49 +00:00
Coe.lean doc: docstring review for monads and transformers (#7548) 2025-03-20 12:18:46 +00:00
CoeAttr.lean
CollectFVars.lean feat: change Array.get to take a Nat and a proof (#6032) 2024-11-12 03:30:46 +00:00
CollectMVars.lean chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
CompletionName.lean chore: fix spelling mistakes in src/Lean/Meta/ (#5436) 2024-09-23 23:09:14 +00:00
CongrTheorems.lean feat: elaborate theorem bodies in parallel (#7084) 2025-03-14 07:50:42 +00:00
Constructions.lean
CtorRecognizer.lean fix: have Lean.Meta.isConstructorApp'? be aware of n + k Nat offsets (#6270) 2024-12-01 18:04:32 +00:00
DecLevel.lean
Diagnostics.lean fix: add workaround for MessageData limitations (#6669) 2025-01-16 16:58:20 +00:00
DiscrTree.lean feat: allow line-wrapping when printing DiscrTree.Keys (#7200) 2025-02-24 07:52:47 +00:00
DiscrTreeTypes.lean
Eqns.lean perf: remove more async blockers (#7497) 2025-03-15 11:07:04 +00:00
Eval.lean perf: async optimizations for Init.Data.BitVec.Lemmas (#7546) 2025-03-18 12:56:16 +00:00
ExprDefEq.lean feat: zetaUnused option (implementation) (#6755) 2025-01-26 11:14:12 +00:00
ExprLens.lean
ExprTraverse.lean
ForEachExpr.lean chore: avoid runtime array bounds checks (#6134) 2024-11-21 05:04:52 +00:00
FunInfo.lean feat: refactor of find functions on List/Array/Vector (#6833) 2025-01-30 01:14:21 +00:00
GeneralizeTelescope.lean feat: change Array.get to take a Nat and a proof (#6032) 2024-11-12 03:30:46 +00:00
GeneralizeVars.lean
GetUnfoldableConst.lean perf: async optimizations for Init.Data.BitVec.Lemmas (#7546) 2025-03-18 12:56:16 +00:00
GlobalInstances.lean
IndPredBelow.lean feat: deprecate Array.mkArray in favour of Array.replicate 2025-03-24 08:25:00 +01:00
Inductive.lean
InferType.lean perf: Environment blocker removals from async-proofs branch (#7483) 2025-03-14 13:37:01 +00:00
Injective.lean feat: change Array.get to take a Nat and a proof (#6032) 2024-11-12 03:30:46 +00:00
Instances.lean fix: isDefEq, whnf, simp caching and configuration (#6053) 2024-11-18 01:17:26 +00:00
IntInstTesters.lean feat: divisibility constraint normalizer (#7092) 2025-02-15 04:20:40 +00:00
Iterator.lean chore: fix spelling mistakes in src/Lean/Meta/ (#5436) 2024-09-23 23:09:14 +00:00
KAbstract.lean
KExprMap.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
LazyDiscrTree.lean feat: cleanup of get and back functions on List/Array (#7059) 2025-02-17 01:43:45 +00:00
LevelDefEq.lean chore: mark Meta.Context.config as private (#6051) 2024-11-13 13:30:06 +11:00
LitValues.lean doc: Char docstring proofreading (#7198) 2025-03-08 22:17:01 +00:00
Match.lean
MatchUtil.lean
NatInstTesters.lean feat: Nat divisibility constraints in cutsat (#7495) 2025-03-15 03:46:47 +00:00
Offset.lean chore: cleanup imports (#5825) 2024-10-23 23:51:13 +00:00
PPGoal.lean fix: have Lean.Meta.ppGoal use hard newlines (#5640) 2024-10-08 17:36:08 +00:00
PProdN.lean feat: partial_fixpoint: partial functions with equations (#6355) 2025-01-21 09:54:30 +00:00
RecursorInfo.lean feat: refactor of find functions on List/Array/Vector (#6833) 2025-01-30 01:14:21 +00:00
Reduce.lean refactor: more idiomatic syntax for if h: (#5567) 2024-10-01 15:23:54 +00:00
ReduceEval.lean
SizeOf.lean feat: deprecate Array.mkArray in favour of Array.replicate 2025-03-24 08:25:00 +01:00
Sorry.lean feat: labeled and unique sorries (#5757) 2024-12-11 23:53:02 +00:00
Structure.lean feat: structure instance notation elaboration improvements (#7717) 2025-03-30 17:40:36 +00:00
SynthInstance.lean feat: cleanup of get and back functions on List/Array (#7059) 2025-02-17 01:43:45 +00:00
Tactic.lean feat: cutsat preparations (#7097) 2025-02-16 02:52:14 +00:00
Transform.lean feat: grind preprocessing and Expr internalization (#6413) 2024-12-19 00:16:48 +00:00
TransparencyMode.lean
UnificationHint.lean fix: isDefEq, whnf, simp caching and configuration (#6053) 2024-11-18 01:17:26 +00:00
WHNF.lean feat: zeta and zetaDelta options in grind (#7723) 2025-03-29 20:07:53 +00:00