lean4-htt/src/Lean
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
..
Compiler doc: explain the borrow syntax (#4305) 2024-09-17 09:52:41 +00:00
Data feat: export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
DocString feat: more infrastructure for tactic documentation (#4490) 2024-06-21 12:49:30 +00:00
Elab feat: instance for Inhabited (TacticM α) (#5401) 2024-09-20 06:07:02 +00:00
Language fix: changing whitespace after module header may break subsequent commands (#5312) 2024-09-11 13:00:42 +00:00
Linter fix: unused variable false positive when combining alias and non-lexical use (#5335) 2024-09-19 10:51:14 +00:00
Meta feat: apply_rfl tactic: handle Eq, HEq, better error messages (#3714) 2024-09-20 08:25:10 +00:00
Parser fix: do not ban .. with a . on the next line (#4768) 2024-09-17 09:57:35 +00:00
ParserCompiler feat: reserved names (#3675) 2024-03-15 00:33:22 +00:00
PrettyPrinter chore: cleanup after export Bool.and/or/not/xor 2024-09-16 12:45:51 +10:00
Server feat: completion fallback (#5299) 2024-09-12 16:09:20 +00:00
Util refactor: remove the last use of Lean.(HashSet|HashMap) (#5362) 2024-09-18 18:20:51 +00:00
Widget feat: use incrementality for completion in tactic blocks (#5205) 2024-09-09 12:08:37 +00:00
AddDecl.lean fix: adapt kernel interruption to new cancellation system (#4584) 2024-07-01 14:52:42 +00:00
Attributes.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
AuxRecursor.lean refactor: IndGroupInst.brecOn (#4787) 2024-07-19 10:20:50 +00:00
BuiltinDocAttr.lean feat: more infrastructure for tactic documentation (#4490) 2024-06-21 12:49:30 +00:00
Class.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Compiler.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
CoreM.lean chore: shorten suggestion about diagnostics (#4882) 2024-07-31 17:56:43 +00:00
Data.lean chore: move Lean.Data.Parsec to Std.Internal.Parsec (#5115) 2024-08-21 15:26:17 +00:00
Declaration.lean refactor: use indVal.numNested or indVal.numTypeFormers where applicable (#4734) 2024-07-12 22:07:25 +00:00
DeclarationRange.lean feat: snapshot trees and language processors (#3014) 2024-03-14 13:40:08 +00:00
DocString.lean feat: more infrastructure for tactic documentation (#4490) 2024-06-21 12:49:30 +00:00
Elab.lean chore: upstream #time command (#5044) 2024-08-15 00:17:48 +00:00
Environment.lean fix: invalid namespace completions (#5322) 2024-09-13 12:23:03 +00:00
Eval.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Exception.lean chore: cleanup unused arguments (from linter) (#4621) 2024-07-07 21:20:06 +00:00
Expr.lean chore: use Expr.numObjs instead of lean_expr_size_shared (#5239) 2024-09-02 21:26:00 +00:00
HeadIndex.lean chore: fix linter errors (#4502) 2024-06-19 18:24:08 +00:00
Hygiene.lean chore: remove the coercion from String to Name (#3589) 2024-03-21 23:46:03 +00:00
ImportingFlag.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
InternalExceptionId.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
KeyedDeclsAttribute.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
LabelAttribute.lean fix: handle AttributeKinds in LabelAttributes correctly (#3698) 2024-08-29 17:57:14 +02:00
LazyInitExtension.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Level.lean chore: deprecate Lean.HashMap and Lean.HashSet (#4954) 2024-08-08 12:46:10 +00:00
Linter.lean feat: omit (#5000) 2024-08-21 13:22:34 +00:00
LoadDynlib.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
LocalContext.lean chore: upstream omega (#3367) 2024-02-19 00:19:55 +00:00
Log.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Message.lean feat: safe exponentiation (#4637) 2024-07-03 05:12:53 +00:00
Meta.lean feat: improve set_option diagnostics true (#4031) 2024-04-30 05:07:03 +00:00
MetavarContext.lean perf: maximize term sharing at instantiateMVarDeclMVars (#5226) 2024-09-01 23:00:48 +00:00
Modifiers.lean refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
MonadEnv.lean refactor: use indVal.numNested or indVal.numTypeFormers where applicable (#4734) 2024-07-12 22:07:25 +00:00
Parser.lean feat: more infrastructure for tactic documentation (#4490) 2024-06-21 12:49:30 +00:00
ParserCompiler.lean refactor: Offset.lean and related files (#3614) 2024-03-05 19:40:15 -08:00
PrettyPrinter.lean chore: use Expr.numObjs instead of lean_expr_size_shared (#5239) 2024-09-02 21:26:00 +00:00
ProjFns.lean fix: modify projection instance binder info (#5376) 2024-09-20 06:03:59 +00:00
ReducibilityAttrs.lean chore: fix linter errors (#4502) 2024-06-19 18:24:08 +00:00
Replay.lean chore: switch to Std.HashMap and Std.HashSet almost everywhere 2024-08-07 18:24:42 +02:00
ReservedNameAction.lean fix: FunInd: support structural recursion on reflexive types (#4327) 2024-06-05 07:54:48 +00:00
ResolveName.lean chore: cleanup unused arguments (from linter) (#4621) 2024-07-07 21:20:06 +00:00
Runtime.lean feat: link LibUV (#4963) 2024-08-12 12:33:24 +00:00
ScopedEnvExtension.lean feat: flexible reducibility attributes 2024-04-29 05:46:11 +02:00
Server.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Structure.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
SubExpr.lean fix: use correct expr positions when delaborating match patterns (#4034) 2024-05-01 12:02:10 +00:00
Syntax.lean refactor: move Synax.hasIdent, shake dependencies (#4766) 2024-07-16 21:19:26 +00:00
ToExpr.lean chore: upstream Zero and NeZero 2024-09-10 19:30:09 +10:00
Util.lean feat: theorem diagnostics (#4924) 2024-08-06 01:01:28 +00:00
Widget.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00