lean4-htt/library/init/meta/async_tactic.lean
Leonardo de Moura 54f7bf9391 fix(frontends/lean, library/tactic): remove redundant error messages, and fix position of error messages
Summary:

We minimize the number of "'sorry' used warning messages".  We also
re-target the error to the main declaration. Example: foo._main ==> foo
We do not report for auxiliary declarations such as "_example" and
"foo.equations._eqn_1"

Get rid of the redundant error message "error : failed" for tactics.
We added "silent failures" in the tactic framework.

We do not store line/col information for tactics nested in notation
declarations.  Before this commit, we would have tactics such
as (tactic.save_info line col) nested inside of notation declarations.
2017-02-07 20:25:28 -08:00

57 lines
1.8 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
prelude
import init.meta.tactic
import init.meta.interactive
namespace tactic
private meta def report {α} (s : tactic_state) : option (unit → format) → α
| (some fmt) := undefined_core $ to_string $ fmt () ++ format.line ++ to_fmt s
| none := undefined_core "silent failure"
private meta def run_or_fail {α} (s : tactic_state) (tac : tactic α) : α :=
match tac s with
| (tactic_result.success a s) := a
| (tactic_result.exception fmt _ s') := report s' fmt
end
meta def run_async {α : Type} (tac : tactic α) : tactic (task α) := do
s ← read, return $ task.delay $ λ _,
match tac s with
| (tactic_result.success a s) := a
| (tactic_result.exception fmt _ s') := report s' fmt
end
meta def prove_goal_async (tac : tactic unit) : tactic unit := do
ctx ← local_context, revert_lst ctx,
tgt ← target, tgt ← instantiate_mvars tgt,
env ← get_env, tgt ← return $ env^.unfold_untrusted_macros tgt,
when tgt^.has_meta_var (fail "goal contains metavariables"),
params ← return tgt^.collect_univ_params,
lemma_name ← new_aux_decl_name,
proof ← run_async (do
goal_meta ← mk_meta_var tgt,
set_goals [goal_meta],
monad.for' ctx (λc, intro c^.local_pp_name),
tac,
proof ← instantiate_mvars goal_meta,
proof ← return $ env^.unfold_untrusted_macros proof,
when proof^.has_meta_var $ fail "async proof failed: contains metavariables",
return proof),
add_decl $ declaration.thm lemma_name params tgt proof,
exact (expr.const lemma_name (params^.for level.param))
namespace interactive
open interactive.types
/-- Proves the first goal asynchronously as a separate lemma. -/
meta def async (tac : irtactic) : tactic unit :=
prove_goal_async tac
end interactive
end tactic