-
Notifications
You must be signed in to change notification settings - Fork 465
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
conv’s arg fails with subsingleton parameters #4394
Comments
I was curious so had a deeper look. This might be a fix: diff --git a/src/Lean/Elab/Tactic/Conv/Congr.lean b/src/Lean/Elab/Tactic/Conv/Congr.lean
index 9060bd91d6..de4dee1bc5 100644
--- a/src/Lean/Elab/Tactic/Conv/Congr.lean
+++ b/src/Lean/Elab/Tactic/Conv/Congr.lean
@@ -75,20 +75,28 @@ def congr (mvarId : MVarId) (addImplicitArgs := false) (nameSubgoals := true) :
@[builtin_tactic Lean.Parser.Tactic.Conv.congr] def evalCongr : Tactic := fun _ => do
replaceMainGoal <| List.filterMap id (← congr (← getMainGoal))
+-- mvarIds is the list of goals produced by congr. We only want to change the one at position `i`
+-- so this closes all other equality goals with `rfl.`. There are non-equality goals produced
+-- by `congr` (e.g. dependent instances), thes are kept as goals.
private def selectIdx (tacticName : String) (mvarIds : List (Option MVarId)) (i : Int) :
TacticM Unit := do
if i >= 0 then
let i := i.toNat
if h : i < mvarIds.length then
+ let mut otherGoals := #[]
for mvarId? in mvarIds, j in [:mvarIds.length] do
match mvarId? with
| none => pure ()
| some mvarId =>
if i != j then
- mvarId.refl
+ if (← mvarId.getType').isEq then
+ mvarId.refl
+ else
+ -- If its not an equality, it's likely a class constraint, to be left open
+ otherGoals := otherGoals.push mvarId
match mvarIds[i] with
| none => throwError "cannot select argument"
- | some mvarId => replaceMainGoal [mvarId]
+ | some mvarId => replaceMainGoal (mvarId :: otherGoals.toList)
return ()
throwError "invalid '{tacticName}' conv tactic, application has only {mvarIds.length} (nondependent) argument(s)" But while testing it I found this:
Why does this behave differently than the import Lean
open Lean Elab Meta Tactic
opaque foo (p : Prop) [Decidable p] : Prop
class PropClass (n : Nat) : Prop where
opaque P1 (n : Nat) [PropClass n] : Prop
class TypeClass (n : Nat) : Type where
opaque P2 (n : Nat) [TypeClass n] : Prop
/--
info: thm for foo: ∀ (p p_1 : Prop), p = p_1 → ∀ {inst : Decidable p} {inst_1 : Decidable p_1}, foo p = foo p_1
kinds: #[Lean.Meta.CongrArgKind.eq, Lean.Meta.CongrArgKind.subsingletonInst]
---
info: thm for P1: ∀ (n n_1 : Nat) (e_n : n = n_1) [inst : PropClass n], P1 n = P1 n_1
kinds: #[Lean.Meta.CongrArgKind.eq, Lean.Meta.CongrArgKind.cast]
---
info: thm for P2: ∀ (n : Nat) [inst : TypeClass n], P2 n = P2 n
kinds: #[Lean.Meta.CongrArgKind.fixed, Lean.Meta.CongrArgKind.fixed]
-/
#guard_msgs in
run_meta
#[``foo, ``P1, ``P2].forM fun n => do
let e ← mkConstWithLevelParams n
let some thm ← mkCongrSimp? e (subsingletonInstImplicitRhs := false) | throwError "no thm"
let kinds ← getCongrSimpKinds e (← getFunInfo e)
logInfo m!"thm for {e}: {thm.type}\nkinds: {repr kinds}" So this does not work: /-- error: cannot select argument -/
#guard_msgs in
example [TypeClass n] [TypeClass (id n)] (h : P2 n) : P2 (id n) := by
conv => arg 1 And this worked before example [PropClass n] [PropClass (id n)] (h : P1 n) : P1 (id n) := by
conv => arg 1; rw [id]
exact h And my fix seems only to matter for example [Decidable p] [Decidable (id p)] (h : foo p) : foo (id p) := by
conv => arg 1; rw [id]
exact h So this looks plausible, although I certainly don’t understand the |
this fixes #4394, see there for an analysis.
One effect of this fix is that /--
error: tactic 'fail' failed
p : Prop
inst✝ : Decidable p
⊢ Decidable (id p)
---
error: unsolved goals
p : Prop
inst✝ : Decidable p
⊢ foo (id p)
-/
#guard_msgs in
example [Decidable p] : foo p := by
conv =>
arg 1
· rw [← id.eq_def p]
· tactic => fail Not sure if that’s intended for the |
this fixes #4394, see there for an analysis.
Consider
The problem seems to be this code:
This assumes that all goals in
mvarIds
, which is the result ofare equality goals, but due to
there this can also contain subsingleton goals.
Probably these should be solved, once the new
p
is known, using type class search?Versions
4.10.0-nightly-2024-06-07
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: