@@ -185,33 +185,44 @@ def runString (p : ProofSnapshot) (t : String) : IO ProofSnapshot :=
185185/-- Pretty print the current goals in the `ProofSnapshot`. -/
186186def ppGoals (p : ProofSnapshot) : IO (List Format) :=
187187 Prod.fst <$> p.runMetaM do p.tacticState.goals.mapM (Meta.ppGoal ·)
188+
188189/--
189190Construct a `ProofSnapshot` from a `ContextInfo` and optional `LocalContext`, and a list of goals.
190-
191191For convenience, we also allow a list of `Expr`s, and these are appended to the goals
192192as fresh metavariables with the given types.
193193-/
194194def create (ctx : ContextInfo) (lctx? : Option LocalContext) (env? : Option Environment)
195195 (goals : List MVarId) (rootGoals? : Option (List MVarId)) (types : List Expr := [])
196196 : IO ProofSnapshot := do
197- ctx.runMetaM (lctx?.getD {}) do
198- let goals := goals ++ (← types.mapM fun t => Expr.mvarId! <$> Meta.mkFreshExprMVar (some t))
199- let s ← getThe Core.State
200- let s := match env? with
201- | none => s
202- | some env => { s with env }
203- pure <|
204- { coreState := s
205- coreContext := ← readThe Core.Context
206- metaState := ← getThe Meta.State
207- metaContext := ← readThe Meta.Context
208- termState := {}
209- termContext := {}
210- tacticState := { goals }
211- tacticContext := { elaborator := .anonymous }
212- rootGoals := match rootGoals? with
213- | none => goals
214- | some gs => gs }
197+ -- Get the local context from the goals if not provided.
198+ let lctx ← match lctx? with
199+ | none => match goals with
200+ | g :: _ => ctx.runMetaM {} do pure (← g.getDecl).lctx
201+ | [] => match rootGoals? with
202+ | some (g :: _) => ctx.runMetaM {} do pure (← g.getDecl).lctx
203+ | _ => pure {}
204+ | some lctx => pure lctx
205+
206+ ctx.runMetaM lctx do
207+ -- update local instances, which is necessary when `types` is non-empty
208+ Meta.withLocalInstances (lctx.decls.toList.filterMap id) do
209+ let goals := goals ++ (← types.mapM fun t => Expr.mvarId! <$> Meta.mkFreshExprMVar (some t))
210+ let s ← getThe Core.State
211+ let s := match env? with
212+ | none => s
213+ | some env => { s with env }
214+ pure <|
215+ { coreState := s
216+ coreContext := ← readThe Core.Context
217+ metaState := ← getThe Meta.State
218+ metaContext := ← readThe Meta.Context
219+ termState := {}
220+ termContext := {}
221+ tacticState := { goals }
222+ tacticContext := { elaborator := .anonymous }
223+ rootGoals := match rootGoals? with
224+ | none => goals
225+ | some gs => gs }
215226
216227open Lean.Core in
217228/-- A copy of `Core.State` with the `Environment`, caches, and logging omitted. -/
0 commit comments