Built with
doc-gen4, running Lean4.
Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents.
Use
Ctrl+โCtrl+โto navigate,
Ctrl+๐ฑ๏ธto focus.
On Mac, use
Cmdinstead of
Ctrl.
/-
Copyright (c) 2022 Siddhartha Gadgil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Siddhartha Gadgil, Jannis Limperg
-/
import Lean
import Std.Tactic.RCases
import Mathlib.Tactic.Cache
open Lean (HashSet)
open Lean Meta Elab Tactic
namespace Mathlib.Tactic
/--
Get all metavariables which `mvarId` depends on. These are the metavariables
which occur in the target or local context or delayed assignment (if any) of
`mvarId`, plus the metvariables which occur in these metavariables, etc.
-/
partial def getUnassignedGoalMVarDependencies (mvarId : MVarId) :
MetaM (HashSet MVarId) :=
return (โ go mvarId |>.run {}): ?m.3822
(โ go(โ go mvarId |>.run {}): ?m.3822
mvarId(โ go mvarId |>.run {}): ?m.3822
|>.run(โ go mvarId |>.run {}): ?m.3822
{}(โ go mvarId |>.run {}): ?m.3822
).snd: {ฮฑ : Type ?u.3850} โ {ฮฒ : Type ?u.3849} โ ฮฑ ร ฮฒ โ ฮฒ
snd
where
/-- auxiliary function for `getUnassignedGoalMVarDependencies` -/
addMVars (e : Expr) : StateRefT (HashSet MVarId) MetaM Unit := do
let mvars โ getMVars e
let mut s โ get
set ({} : HashSet MVarId) -- Ensure that `s` is not shared.
for mvarId in mvars do
unless โ mvarId.isDelayedAssigned do
s := s.insert mvarId
set s
mvars.forM go
/-- auxiliary function for `getUnassignedGoalMVarDependencies` -/
go (mvarId : MVarId) : StateRefT (HashSet MVarId) MetaM Unit :=
withIncRecDepth do
let mdecl โ mvarId.getDecl
addMVars mdecl.type
for ldecl in mdecl.lctx do
addMVars ldecl.type
if let (some val) := ldecl.value? then
addMVars val
if let (some ass) โ getDelayedMVarAssignment? mvarId then
let pendingMVarId := ass.mvarIdPending
unless โ pendingMVarId.isAssigned <||> pendingMVarId.isDelayedAssigned do
modify (ยท.insert pendingMVarId)
go pendingMVarId
/-- Modifier `recover` for a tactic (sequence) to debug cases where goals are closed incorrectly.
The tactic `recover tacs` for a tactic (sequence) tacs applies the tactics and then adds goals
that are not closed starting from the original -/
elab "recover" tacs:tacticSeq : tactic => do
let originalGoals โ getGoals
evalTactic tacs
let mut unassigned : HashSet MVarId := {}
for mvarId in originalGoals do
unless โ mvarId.isAssigned <||> mvarId.isDelayedAssigned do
unassigned := unassigned.insert mvarId
let unassignedMVarDependencies: ?m.19002
unassignedMVarDependencies โ getUnassignedGoalMVarDependencies mvarId
unassigned := unassigned.insertMany unassignedMVarDependencies: ?m.19002
unassignedMVarDependencies.toList
setGoals <| ((โ getGoals) ++ unassigned.toList).eraseDups: {ฮฑ : Type ?u.19427} โ [inst : BEq ฮฑ] โ List ฮฑ โ List ฮฑ
eraseDups