<commit_before>/*
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "kernel/type_checker.h"
#include "kernel/for_each_fn.h"
#include "kernel/error_msgs.h"
#include "library/util.h"
#include "library/constants.h"
#include "library/reducible.h"
#include "library/tactic/tactic.h"
#include "library/tactic/elaborate.h"
#include "library/tactic/expr_to_tactic.h"

namespace lean {
// Return true iff \c e is of the form (?m l_1 ... l_n), where ?m is a metavariable and l_i's local constants
bool is_meta_placeholder(expr const & e) {
    if (!is_meta(e))
        return false;
    buffer<expr> args;
    get_app_args(e, args);
    return std::all_of(args.begin(), args.end(), is_local);
}

tactic exact_tactic(elaborate_fn const & elab, expr const & e, bool enforce_type_during_elaboration, bool allow_metavars) {
    return tactic01([=](environment const & env, io_state const & ios, proof_state const & s) {
            proof_state new_s = s;
            goals const & gs  = new_s.get_goals();
            if (!gs) {
                throw_no_goal_if_enabled(s);
                return none_proof_state();
            }
            expr t                 = head(gs).get_type();
            bool report_unassigned = enforce_type_during_elaboration;
            optional<expr> new_e;
            try {
                new_e = elaborate_with_respect_to(env, ios, elab, new_s, e, some_expr(t),
                                                  report_unassigned, enforce_type_during_elaboration);
            } catch (exception &) {
                if (s.report_failure())
                    throw;
                else
                    return none_proof_state();
            }
            if (new_e) {
                goals const & gs   = new_s.get_goals();
                if (gs) {
                    goal const & g     = head(gs);
                    if (!allow_metavars && has_expr_metavar_relaxed(*new_e)) {
                        throw_tactic_exception_if_enabled(s, [=](formatter const & fmt) {
                                format r = format("invalid 'exact' tactic, term still contains metavariables "
                                                  "after elaboration");
                                r       += pp_indent_expr(fmt, *new_e);
                                return r;
                            });
                        return none_proof_state();
                    }
                    substitution subst = new_s.get_subst();
                    assign(subst, g, *new_e);<commit_msg>fix(library/tactic/exact_tactic): do not report unassigned metavariables in the 'refine' tactic<commit_after>/*
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "kernel/type_checker.h"
#include "kernel/for_each_fn.h"
#include "kernel/error_msgs.h"
#include "library/util.h"
#include "library/constants.h"
#include "library/reducible.h"
#include "library/tactic/tactic.h"
#include "library/tactic/elaborate.h"
#include "library/tactic/expr_to_tactic.h"

namespace lean {
// Return true iff \c e is of the form (?m l_1 ... l_n), where ?m is a metavariable and l_i's local constants
bool is_meta_placeholder(expr const & e) {
    if (!is_meta(e))
        return false;
    buffer<expr> args;
    get_app_args(e, args);
    return std::all_of(args.begin(), args.end(), is_local);
}

tactic exact_tactic(elaborate_fn const & elab, expr const & e, bool enforce_type_during_elaboration, bool allow_metavars) {
    return tactic01([=](environment const & env, io_state const & ios, proof_state const & s) {
            proof_state new_s = s;
            goals const & gs  = new_s.get_goals();
            if (!gs) {
                throw_no_goal_if_enabled(s);
                return none_proof_state();
            }
            expr t                 = head(gs).get_type();
            bool report_unassigned = !allow_metavars && enforce_type_during_elaboration;
            optional<expr> new_e;
            try {
                new_e = elaborate_with_respect_to(env, ios, elab, new_s, e, some_expr(t),
                                                  report_unassigned, enforce_type_during_elaboration);
            } catch (exception &) {
                if (s.report_failure())
                    throw;
                else
                    return none_proof_state();
            }
            if (new_e) {
                goals const & gs   = new_s.get_goals();
                if (gs) {
                    goal const & g     = head(gs);
                    if (!allow_metavars && has_expr_metavar_relaxed(*new_e)) {
                        throw_tactic_exception_if_enabled(s, [=](formatter const & fmt) {
                                format r = format("invalid 'exact' tactic, term still contains metavariables "
                                                  "after elaboration");
                                r       += pp_indent_expr(fmt, *new_e);
                                return r;
                            });
                        return none_proof_state();
                    }
                    substitution subst = new_s.get_subst();
                    assign(subst, g, *new_e);
{'fraction_non_alphanumeric': 0.09886215258347324, 'fraction_numerical': 0.003357582540570789, 'mean_word_length': 1.7190669371196754, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956214', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1529, 'n_words': 371}