2014-09-13 17:21:10 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "library/unifier.h"
|
2014-09-19 20:30:08 +00:00
|
|
|
#include "library/reducible.h"
|
2014-09-13 17:21:10 +00:00
|
|
|
#include "library/metavar_closure.h"
|
|
|
|
#include "frontends/lean/util.h"
|
2014-10-04 16:15:42 +00:00
|
|
|
#include "frontends/lean/info_manager.h"
|
2014-09-13 17:21:10 +00:00
|
|
|
namespace lean {
|
2014-09-25 15:38:02 +00:00
|
|
|
/** \brief Create a "choice" constraint that postpone the
|
|
|
|
solving the constraints <tt>(cs union (m =?= e))</tt>.
|
|
|
|
*/
|
2014-09-13 17:21:10 +00:00
|
|
|
constraint mk_proof_qed_cnstr(environment const & env, expr const & m, expr const & e,
|
2014-10-04 16:15:42 +00:00
|
|
|
constraint_seq const & cs, unifier_config const & cfg,
|
|
|
|
info_manager * im, bool relax) {
|
2014-09-13 17:21:10 +00:00
|
|
|
justification j = mk_failed_to_synthesize_jst(env, m);
|
|
|
|
auto choice_fn = [=](expr const & meta, expr const & meta_type, substitution const & s,
|
|
|
|
name_generator const & _ngen) {
|
|
|
|
name_generator ngen(_ngen);
|
2014-09-19 20:30:08 +00:00
|
|
|
type_checker_ptr tc(mk_type_checker(env, ngen.mk_child(), relax));
|
2014-09-13 17:21:10 +00:00
|
|
|
pair<expr, constraint_seq> tcs = tc->infer(e);
|
|
|
|
expr e_type = tcs.first;
|
|
|
|
justification new_j = mk_type_mismatch_jst(e, e_type, meta_type);
|
|
|
|
pair<bool, constraint_seq> dcs = tc->is_def_eq(e_type, meta_type, new_j);
|
|
|
|
if (!dcs.first)
|
|
|
|
throw unifier_exception(new_j, s);
|
|
|
|
constraint_seq new_cs = cs + tcs.second + dcs.second;
|
|
|
|
buffer<constraint> cs_buffer;
|
|
|
|
new_cs.linearize(cs_buffer);
|
2014-09-26 03:07:51 +00:00
|
|
|
|
|
|
|
metavar_closure cls(meta);
|
|
|
|
cls.add(meta_type);
|
|
|
|
cls.mk_constraints(s, j, relax, cs_buffer);
|
2014-09-13 17:21:10 +00:00
|
|
|
cs_buffer.push_back(mk_eq_cnstr(meta, e, j, relax));
|
2014-09-26 03:07:51 +00:00
|
|
|
|
2014-09-13 17:21:10 +00:00
|
|
|
unifier_config new_cfg(cfg);
|
|
|
|
new_cfg.m_discard = false;
|
2014-10-07 23:47:41 +00:00
|
|
|
unify_result_seq seq = unify(env, cs_buffer.size(), cs_buffer.data(), ngen, substitution(), new_cfg);
|
2014-09-13 17:21:10 +00:00
|
|
|
auto p = seq.pull();
|
|
|
|
lean_assert(p);
|
|
|
|
substitution new_s = p->first.first;
|
|
|
|
constraints postponed = map(p->first.second,
|
|
|
|
[&](constraint const & c) {
|
|
|
|
// we erase internal justifications
|
|
|
|
return update_justification(c, j);
|
|
|
|
});
|
2014-10-04 16:15:42 +00:00
|
|
|
if (im)
|
|
|
|
im->instantiate(new_s);
|
2014-09-13 17:21:10 +00:00
|
|
|
constraints r = cls.mk_constraints(new_s, j, relax);
|
|
|
|
return append(r, postponed);
|
|
|
|
};
|
|
|
|
bool owner = false;
|
|
|
|
return mk_choice_cnstr(m, choice_fn, to_delay_factor(cnstr_group::Epilogue), owner, j, relax);
|
|
|
|
}
|
|
|
|
}
|