lean4-htt/src/Lean/Meta
Joachim Breitner fc963ffceb
feat: apply_rfl tactic: handle Eq, HEq, better error messages (#3714)
This implements the first half of #3302: It improves the extensible
`apply_rfl` tactic (the one that looks at `refl` attributes, part of
the `rfl` macro) to

* Check itself and ahead of time that the lhs and rhs are defEq, and
give
a nice consistent error message when they don't (instead of just passing
on
  the less helpful error message from `apply Foo.refl`), and using the 
machinery that `apply` uses to elaborate expressions to highlight diffs
  in implicit arguments.

* Also handle `Eq` and `HEq` (built in) and `Iff` (using the attribute)

Care is taken that, as before, the current transparency setting affects
comparing the lhs and rhs, but not the reduction of the relation

So before we had

```lean
opaque P : Nat → Nat → Prop
@[refl] axiom P.refl (n : Nat) : P n n

/--
error: tactic 'apply' failed, failed to unify
  P ?n ?n
with
  P 42 23
⊢ P 42 23
-/
#guard_msgs in
example : P 42 23 := by apply_rfl

opaque withImplicitNat {n : Nat} : Nat

/--
error: tactic 'apply' failed, failed to unify
  P ?n ?n
with
  P withImplicitNat withImplicitNat
⊢ P withImplicitNat withImplicitNat
-/
#guard_msgs in
example : P (@withImplicitNat 42) (@withImplicitNat 23) := by apply_rfl
```

and with this PR the messages we get are

```
error: tactic 'apply_rfl' failed, The lhs
  42
is not definitionally equal to rhs
  23
⊢ P 42 23
```
resp.
```
error: tactic 'apply_rfl' failed, The lhs
  @withImplicitNat 42
is not definitionally equal to rhs
  @withImplicitNat 23
⊢ P withImplicitNat withImplicitNat
```

A test file checks the various failure modes and error messages.

I believe this `apply_rfl` can serve as the only implementation of
`rfl`, which would then complete #3302, and actually expose these
improved
error messages to the user. But as that seems to require a
non-trivial bootstrapping dance, it’ll be separate.
2024-09-20 08:25:10 +00:00
..
ArgsPacker
Constructions refactor: Introduce PProdN module (#4807) 2024-07-22 11:56:50 +00:00
Match feat: FunInd: more equalities in context, more careful cleanup (#5364) 2024-09-16 12:30:12 +00:00
Tactic feat: apply_rfl tactic: handle Eq, HEq, better error messages (#3714) 2024-09-20 08:25:10 +00:00
AbstractMVars.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
AbstractNestedProofs.lean
ACLt.lean
AppBuilder.lean refactor: Introduce PProdN module (#4807) 2024-07-22 11:56:50 +00:00
ArgsPacker.lean refactor: Introduce PProdN module (#4807) 2024-07-22 11:56:50 +00:00
Basic.lean doc: mention that inferType does not ensure type correctness (#5087) 2024-09-07 20:46:53 +00:00
Canonicalizer.lean chore: deprecate Lean.HashMap and Lean.HashSet (#4954) 2024-08-08 12:46:10 +00:00
Check.lean feat: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
CheckTactic.lean
Closure.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
Coe.lean
CoeAttr.lean
CollectFVars.lean
CollectMVars.lean chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
CompletionName.lean
CongrTheorems.lean
Constructions.lean refactor: Split Constructions module (#4656) 2024-07-05 08:25:44 +00:00
CtorRecognizer.lean feat: allow users to disable simpCtorEq simproc (#5167) 2024-08-26 13:51:21 +00:00
DecLevel.lean
Diagnostics.lean chore: wrap diagnostic results in MessageData.traces (#4897) 2024-08-06 19:10:51 +00:00
DiscrTree.lean feat: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
DiscrTreeTypes.lean
Eqns.lean refactor: put new eqns options into backward namespace (#5207) 2024-08-29 17:03:51 +00:00
Eval.lean
ExprDefEq.lean feat: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
ExprLens.lean
ExprTraverse.lean
ForEachExpr.lean
FunInfo.lean
GeneralizeTelescope.lean
GeneralizeVars.lean
GetUnfoldableConst.lean
GlobalInstances.lean
IndPredBelow.lean fix: recursion over predicates: add some whnf sprinkles (#5136) 2024-08-29 16:55:54 +00:00
Inductive.lean
InferType.lean feat: structural mutual recursion (#4575) 2024-07-08 14:39:50 +00:00
Injective.lean
Instances.lean fix: modify projection instance binder info (#5376) 2024-09-20 06:03:59 +00:00
Iterator.lean
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: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
LevelDefEq.lean
LitValues.lean feat: simprocs for #[1,2,3,4,5][2] (#4765) 2024-07-17 03:05:17 +00:00
Match.lean
MatchUtil.lean
NatInstTesters.lean
Offset.lean
PPGoal.lean
PProdN.lean refactor: Introduce PProdN module (#4807) 2024-07-22 11:56:50 +00:00
RecursorInfo.lean
Reduce.lean
ReduceEval.lean
SizeOf.lean refactor: use indVal.numNested or indVal.numTypeFormers where applicable (#4734) 2024-07-12 22:07:25 +00:00
Structure.lean
SynthInstance.lean chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
Tactic.lean
Transform.lean feat: let unfold do zeta-delta reduction of local definitions (#4834) 2024-09-07 21:48:08 +00:00
TransparencyMode.lean
UnificationHint.lean
WHNF.lean