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 refactor: ArgsPacker (#3621) 2024-03-14 14:59:40 +00:00
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 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
ACLt.lean fix: loose bound variables at ACLt (#3819) 2024-04-01 20:26:20 +00:00
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 chore: bool and prop lemmas for Mathlib compatibility and improved confluence (#3508) 2024-03-04 23:56:30 +00:00
Closure.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
Coe.lean refactor: Offset.lean and related files (#3614) 2024-03-05 19:40:15 -08:00
CoeAttr.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
CollectFVars.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
CollectMVars.lean chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
CompletionName.lean refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
CongrTheorems.lean fix: cleanup type annotations in congruence theorems (#4185) 2024-05-15 23:50:35 +00:00
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 chore: missing registerTraceClass (#4369) 2024-06-06 00:53:16 +00:00
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 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Eqns.lean refactor: put new eqns options into backward namespace (#5207) 2024-08-29 17:03:51 +00:00
Eval.lean feat: propagate maxHeartbeats to kernel (#4113) 2024-05-09 17:44:19 +00:00
ExprDefEq.lean feat: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
ExprLens.lean chore: code convention (#4009) 2024-04-28 15:49:55 +00:00
ExprTraverse.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
ForEachExpr.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
FunInfo.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
GeneralizeTelescope.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
GeneralizeVars.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
GetUnfoldableConst.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
GlobalInstances.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
IndPredBelow.lean fix: recursion over predicates: add some whnf sprinkles (#5136) 2024-08-29 16:55:54 +00:00
Inductive.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
InferType.lean feat: structural mutual recursion (#4575) 2024-07-08 14:39:50 +00:00
Injective.lean fix: revert "monadic generalization of FindExpr" (#4125) 2024-05-10 20:36:08 +00:00
Instances.lean fix: modify projection instance binder info (#5376) 2024-09-20 06:03:59 +00:00
Iterator.lean chore: address copyright inconsistencies (#3448) 2024-02-22 06:23:50 -08:00
KAbstract.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
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 feat: universe constraint approximations (#3981) 2024-04-24 20:27:51 +00:00
LitValues.lean feat: simprocs for #[1,2,3,4,5][2] (#4765) 2024-07-17 03:05:17 +00:00
Match.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
MatchUtil.lean fix: regression on match expressions with builtin literals (#3521) 2024-02-27 18:49:44 +00:00
NatInstTesters.lean feat: shorten auto-generated instance names (#3089) 2024-04-13 18:08:50 +00:00
Offset.lean feat: safe exponentiation (#4637) 2024-07-03 05:12:53 +00:00
PPGoal.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
PProdN.lean refactor: Introduce PProdN module (#4807) 2024-07-22 11:56:50 +00:00
RecursorInfo.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Reduce.lean fix: fold raw Nat literals at dsimp (#3624) 2024-03-06 18:29:20 +00:00
ReduceEval.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
SizeOf.lean refactor: use indVal.numNested or indVal.numTypeFormers where applicable (#4734) 2024-07-12 22:07:25 +00:00
Structure.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
SynthInstance.lean chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
Tactic.lean feat: add grind_norm simp attribute for grind tactic 2024-05-14 19:52:25 +02:00
Transform.lean feat: let unfold do zeta-delta reduction of local definitions (#4834) 2024-09-07 21:48:08 +00:00
TransparencyMode.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
UnificationHint.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
WHNF.lean feat: safe exponentiation (#4637) 2024-07-03 05:12:53 +00:00