-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: change apply_rfl tactic so that it does not operate on = #3784
Conversation
Mathlib CI status (docs):
|
I guess this should be considered as quicker / hackier alternative to #3714. |
src/Lean/Meta/Tactic/Rfl.lean
Outdated
-/ | ||
def _root_.Lean.MVarId.applyRfl (goal : MVarId) : MetaM Unit := do | ||
def _root_.Lean.MVarId.applyRfl (goal : MVarId) (failOnEq : Bool := false) : MetaM Unit := do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a use case for failOnEq := false
?
It seems we have
- End users calling
rfl
. They don’t need it. - Tactics or Meta use that wants to work on Eq only. They can use
eq_refl
orwith_reducible eq_refl
resp.MVarId.refl
orwithReducible MVarId.refl
as suitable.
Who wants to use MVarId.applyRfl
, wants to handle more than Eq, but also wants to handle Eq, and can’t go via the rfl
tactic?
(Also note that .applyRfl
still behaves different than the rfl
tactic. All very confusing.)
Preventing users from registering Eq.refl
is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can grep mathlib myself…
There is
def rflTac : TacticM Unit :=
withMainContext do liftMetaFinishingTactic (·.applyRfl)
which is corresponds to
src/Lean/Elab/Tactic/Rfl.lean: | `(tactic| apply_rfl) => withMainContext do liftMetaFinishingTactic (·.applyRfl)
in core.
It is used in
attribute [aesop safe tactic (rule_sets := [CategoryTheory])] Mathlib.Tactic.rflTac
Then there is
/-- See if the term is `a = b` and the goal is `a ∼ b` or `b ∼ a`, with `∼` reflexive. -/
@[gcongr_forward] def exactRefl : ForwardExt where
eval h goal := do
let m ← mkFreshExprMVar none
goal.assignIfDefeq (← mkAppOptM ``Eq.subst #[h, m])
goal.applyRfl
in Mathlib/Tactic/GCongr/Core.lean
. I’m not entirely sure, but it seems that here you don’t want to handle also Eq.
There is also
withReducible (← mkFreshExprMVar r.result.eNew).mvarId!.applyRfl
in Mathlib/Tactic/Rewrites.lean
. Upstreamed and fixed with #3783.
And finally in rw_search
we have
/-- Check whether a goal can be solved by `rfl`, and fill in the `SearchNode.rfl?` field. -/
def compute_rfl? (n : SearchNode) : MetaM SearchNode := withMCtx n.mctx do
if (← try? n.goal.applyRfl).isSome then
and I wonder if that really wants to use applyRfl
, and not .refl
instead.
Hyrum’s law is strong again :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this last one does want to use applyRfl
, or at least there are test cases that expect it, so they can discharge Iff
goals...
So when this PR lands, it will again break rw_search
, and I'll patch it up to try .refl
and then .applyRfl
....
Previously:
If the
rfl
macro was going to fail, it would:eq_refl
, which is implemented byLean.Elab.Tactic.evalRefl
, and callLean.MVarId.refl
which would:.default
or.all
transparency mode)IsDefEq
apply_rfl
tactic, which is implemented byLean.Elab.Tactic.Rfl.evalApplyRfl
, and callLean.MVarId.applyRefl
which would look for lemmas labelled@[refl]
, and unfortunately in Mathlib findEq.refl
, so try applying that (resulting in anotherIsDefEq
)Lean.Elab.Tactic.Rfl
was imported, it would again expand toapply_rfl
.Now:
eq_refl
.@[refl]
attribute will rejectEq.refl
, andMVarId.applyRefl
will fail when applied to equality goals.