Lean4
/-- `synthesizeUsing type tac` synthesizes an element of type `type` using tactic `tac`.
The tactic `tac` is allowed to leave goals open, and these remain as metavariables in the
returned expression.
-/
-- In Lean3 this was called `solve_aux`,
-- and took a `TacticM α` and captured the produced value in `α`.
-- As this was barely used, we've simplified here.
def synthesizeUsing {u : Level} (type : Q(Sort u)) (tac : TacticM Unit) : MetaM (List MVarId × Q($type)) := do
let m ← mkFreshExprMVar type
let goals ← (Term.withoutErrToSorry <| run m.mvarId! tac).run'
return (goals, ← instantiateMVars m)