Skip to content

Commit bf75564

Browse files
authored
fix: impossible to not cleanup the goal (#14205)
This PR stops the `impossible` tactic combinator to run `cleanup` on the goal before negation, as that would defeat the point. It also moves the `revertAll` function to `Revert.lean`, removes the change of MVarId kind (`.revert` takes care of that internally, difference should only matter if the goal has empty local context) and renames the residual lean file to `MarkAccessible.lean`. Fixes: #14201
1 parent de5b7f2 commit bf75564

8 files changed

Lines changed: 36 additions & 25 deletions

File tree

src/Lean/Elab/Tactic/Grind/Have.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module
77
prelude
88
public import Lean.Elab.Tactic.Grind.Basic
99
import Lean.Meta.Tactic.Grind.Intro
10-
import Lean.Meta.Tactic.Grind.RevertAll
10+
import Lean.Meta.Tactic.Grind.MarkAccessible
1111
import Lean.Elab.SyntheticMVars
1212
import Lean.Meta.Tactic.Grind.Solve
1313
namespace Lean.Elab.Tactic.Grind

src/Lean/Elab/Tactic/Impossible.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ private def mkImpossibleNegType (mainGoal : MVarId) (goalType : Expr)
3232
(cfg : Parser.Tactic.ImpossibleConfig) :
3333
MetaM (Expr × Array Name) := mainGoal.withContext do
3434
let dummy ← mkFreshExprSyntheticOpaqueMVar goalType
35-
let cleaned ← dummy.mvarId!.cleanup
36-
let (_, reverted) ← cleaned.revert
37-
(clearAuxDeclsInsteadOfRevert := true)
38-
(← cleaned.getDecl).lctx.getFVarIds
35+
let reverted ← dummy.mvarId!.revertAll
3936
let revertedType ← reverted.getType
4037
let r ← Closure.mkValueTypeClosure revertedType (mkConst ``True)
4138
(zetaDelta := false)

src/Lean/Meta/Tactic/Grind.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Leonardo de Moura
66
module
77
prelude
88
public import Lean.Meta.Tactic.Grind.Attr
9-
public import Lean.Meta.Tactic.Grind.RevertAll
9+
public import Lean.Meta.Tactic.Grind.MarkAccessible
1010
public import Lean.Meta.Tactic.Grind.Types
1111
public import Lean.Meta.Tactic.Grind.Util
1212
public import Lean.Meta.Tactic.Grind.Cases

src/Lean/Meta/Tactic/Grind/Intro.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Lean.Meta.Tactic.Grind.Util
1212
import Lean.Meta.Tactic.Grind.CasesMatch
1313
import Lean.Meta.Tactic.Grind.Injection
1414
import Lean.Meta.Tactic.Grind.Core
15-
import Lean.Meta.Tactic.Grind.RevertAll
15+
import Lean.Meta.Tactic.Grind.MarkAccessible
1616
import Init.Grind.Util
1717
public section
1818
namespace Lean.Meta.Grind

src/Lean/Meta/Tactic/Grind/Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Lean.PrettyPrinter
1212
import Lean.Meta.Tactic.ExposeNames
1313
import Lean.Meta.Tactic.Simp.Diagnostics
1414
import Lean.Meta.Tactic.Simp.Rewrite
15-
import Lean.Meta.Tactic.Grind.RevertAll
15+
import Lean.Meta.Tactic.Grind.MarkAccessible
1616
import Lean.Meta.Tactic.Grind.Proj
1717
import Lean.Meta.Tactic.Grind.ForallProp
1818
import Lean.Meta.Tactic.Grind.CtorIdx

src/Lean/Meta/Tactic/Grind/RevertAll.lean renamed to src/Lean/Meta/Tactic/Grind/MarkAccessible.lean

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,4 @@ def _root_.Lean.MVarId.markAccessible (mvarId : MVarId) : MetaM MVarId := mvarId
5151
mvarId.assign mvarNew
5252
return mvarNew.mvarId!
5353

54-
/--
55-
Reverts all free variables in the goal `mvarId`.
56-
**Remark**: Auxiliary local declarations are cleared.
57-
The `grind` tactic also clears them, but this tactic can be used independently by users.
58-
-/
59-
def _root_.Lean.MVarId.revertAll (mvarId : MVarId) : MetaM MVarId := mvarId.withContext do
60-
mvarId.checkNotAssigned `revertAll
61-
let mut toRevert := #[]
62-
for fvarId in (← getLCtx).getFVarIds do
63-
unless (← fvarId.getDecl).isAuxDecl do
64-
toRevert := toRevert.push fvarId
65-
mvarId.setKind .natural
66-
let (_, mvarId) ← mvarId.revert toRevert
67-
(preserveOrder := true)
68-
(clearAuxDeclsInsteadOfRevert := true)
69-
return mvarId
70-
7154
end Lean.Meta.Grind

src/Lean/Meta/Tactic/Revert.lean

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,19 @@ def _root_.Lean.MVarId.revertFrom (mvarId : MVarId) (fvarId : FVarId) : MetaM (A
6666
let fvarIds := (← getLCtx).foldl (init := #[]) (start := localDecl.index) fun fvarIds decl => fvarIds.push decl.fvarId
6767
mvarId.revert fvarIds (preserveOrder := true) (clearAuxDeclsInsteadOfRevert := true)
6868

69+
/--
70+
Reverts all free variables in the goal `mvarId`.
71+
**Remark**: Auxiliary local declarations are cleared.
72+
-/
73+
def _root_.Lean.MVarId.revertAll (mvarId : MVarId) : MetaM MVarId := mvarId.withContext do
74+
mvarId.checkNotAssigned `revertAll
75+
let mut toRevert := #[]
76+
for fvarId in (← getLCtx).getFVarIds do
77+
unless (← fvarId.getDecl).isAuxDecl do
78+
toRevert := toRevert.push fvarId
79+
let (_, mvarId) ← mvarId.revert toRevert
80+
(preserveOrder := true)
81+
(clearAuxDeclsInsteadOfRevert := true)
82+
return mvarId
83+
6984
end Lean.Meta

tests/elab/impossibleTactic.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Lean
2+
3+
set_option linter.unusedVariables false
4+
25
/-! # Tests for the `impossible` tactic combinator -/
36

47
-- Closed goal: the negation has no binders, so the user proves it directly.
@@ -250,3 +253,16 @@ example : 0 = 1 ∧ True := by
250253
constructor
251254
impossible by decide
252255
trivial
256+
257+
-- Test that we don’t run `cleanup` in `impossible`.
258+
259+
/--
260+
error: unsolved goals
261+
⊢ False
262+
---
263+
trace: ⊢ ¬∀ {α : Type u_1} (xs : List α), xs.length > 0 → xs = [] → False
264+
-/
265+
#guard_msgs in
266+
example (xs : List α) (h : xs.length > 0) : xs ≠ [] := by
267+
intro h_empty
268+
impossible by trace_state; simp

0 commit comments

Comments
 (0)