2013-11-21 01:02:41 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <utility>
|
2013-11-25 18:39:40 +00:00
|
|
|
#include <algorithm>
|
2013-11-27 03:15:49 +00:00
|
|
|
#include "util/lua.h"
|
2013-11-25 18:39:40 +00:00
|
|
|
#include "util/rc.h"
|
2013-11-25 09:06:11 +00:00
|
|
|
#include "util/interrupt.h"
|
|
|
|
#include "util/optional.h"
|
2013-11-30 19:28:10 +00:00
|
|
|
#include "util/name_set.h"
|
2013-11-29 05:08:12 +00:00
|
|
|
#include "library/io_state.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
#include "library/tactic/goal.h"
|
|
|
|
#include "library/tactic/proof_builder.h"
|
2013-11-25 19:43:16 +00:00
|
|
|
#include "library/tactic/cex_builder.h"
|
2013-11-21 01:02:41 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-11-21 20:34:37 +00:00
|
|
|
typedef list<std::pair<name, goal>> goals;
|
2013-12-05 12:41:08 +00:00
|
|
|
/**
|
|
|
|
\brief Return the name of the i-th goal.
|
|
|
|
|
|
|
|
\remark Return none if i == 0 or i > size(g)
|
|
|
|
*/
|
|
|
|
optional<name> get_ith_goal_name(goals const & gs, unsigned i);
|
2013-11-25 19:43:16 +00:00
|
|
|
|
|
|
|
enum class precision {
|
|
|
|
Precise,
|
|
|
|
Under, // counter-examples can be trusted
|
|
|
|
Over, // proofs can be trusted
|
|
|
|
UnderOver // proof_state is garbage: it was produced using under and over approximation steps.
|
|
|
|
};
|
|
|
|
|
|
|
|
precision mk_union(precision p1, precision p2);
|
2013-11-25 21:04:09 +00:00
|
|
|
bool trust_proof(precision p);
|
2013-11-25 19:43:16 +00:00
|
|
|
bool trust_cex(precision p);
|
|
|
|
|
2013-11-21 01:02:41 +00:00
|
|
|
class proof_state {
|
2013-11-25 18:39:40 +00:00
|
|
|
struct cell {
|
|
|
|
MK_LEAN_RC();
|
2013-11-25 19:43:16 +00:00
|
|
|
precision m_precision;
|
2013-11-25 18:39:40 +00:00
|
|
|
goals m_goals;
|
2013-12-13 01:47:11 +00:00
|
|
|
ro_metavar_env m_menv;
|
2013-11-25 18:39:40 +00:00
|
|
|
proof_builder m_proof_builder;
|
2013-11-25 19:43:16 +00:00
|
|
|
cex_builder m_cex_builder;
|
2013-11-25 18:39:40 +00:00
|
|
|
void dealloc() { delete this; }
|
|
|
|
cell():m_rc(1) {}
|
2013-12-13 01:47:11 +00:00
|
|
|
cell(precision prec, goals const & gs, ro_metavar_env const & menv, proof_builder const & p, cex_builder const & c):
|
2013-11-25 19:43:16 +00:00
|
|
|
m_rc(1), m_precision(prec), m_goals(gs), m_menv(menv), m_proof_builder(p), m_cex_builder(c) {}
|
2013-12-13 01:47:11 +00:00
|
|
|
cell(goals const & gs, ro_metavar_env const & menv, proof_builder const & p, cex_builder const & c):
|
2013-11-25 19:43:16 +00:00
|
|
|
m_rc(1), m_precision(precision::Precise), m_goals(gs), m_menv(menv), m_proof_builder(p), m_cex_builder(c) {}
|
2013-11-25 18:39:40 +00:00
|
|
|
};
|
|
|
|
cell * m_ptr;
|
2013-11-21 01:02:41 +00:00
|
|
|
public:
|
2013-11-25 18:39:40 +00:00
|
|
|
proof_state():m_ptr(new cell()) {}
|
|
|
|
proof_state(proof_state const & s):m_ptr(s.m_ptr) { if (m_ptr) m_ptr->inc_ref(); }
|
|
|
|
proof_state(proof_state && s):m_ptr(s.m_ptr) { s.m_ptr = nullptr; }
|
2013-12-13 01:47:11 +00:00
|
|
|
proof_state(goals const & gs, ro_metavar_env const & menv, proof_builder const & p, cex_builder const & c):
|
2013-11-25 19:43:16 +00:00
|
|
|
m_ptr(new cell(gs, menv, p, c)) {}
|
2013-12-13 01:47:11 +00:00
|
|
|
proof_state(precision prec, goals const & gs, ro_metavar_env const & menv, proof_builder const & p, cex_builder const & c):
|
2013-11-30 19:28:10 +00:00
|
|
|
m_ptr(new cell(prec, gs, menv, p, c)) {}
|
2013-11-25 19:43:16 +00:00
|
|
|
proof_state(proof_state const & s, goals const & gs, proof_builder const & p):
|
2013-12-13 01:47:11 +00:00
|
|
|
m_ptr(new cell(s.get_precision(), gs, s.m_ptr->m_menv, p, s.get_cex_builder())) {}
|
2013-11-30 19:28:10 +00:00
|
|
|
proof_state(proof_state const & s, goals const & gs):
|
2013-12-13 01:47:11 +00:00
|
|
|
m_ptr(new cell(s.get_precision(), gs, s.m_ptr->m_menv, s.get_proof_builder(), s.get_cex_builder())) {}
|
2013-11-30 19:28:10 +00:00
|
|
|
proof_state(proof_state const & s, goals const & gs, proof_builder const & p, cex_builder const & c):
|
2013-12-13 01:47:11 +00:00
|
|
|
m_ptr(new cell(s.get_precision(), gs, s.m_ptr->m_menv, p, c)) {}
|
2013-11-25 18:39:40 +00:00
|
|
|
~proof_state() { if (m_ptr) m_ptr->dec_ref(); }
|
|
|
|
friend void swap(proof_state & a, proof_state & b) { std::swap(a.m_ptr, b.m_ptr); }
|
2013-12-13 23:00:30 +00:00
|
|
|
proof_state & operator=(proof_state const & s) { LEAN_COPY_REF(s); }
|
|
|
|
proof_state & operator=(proof_state && s) { LEAN_MOVE_REF(s); }
|
2013-11-25 19:43:16 +00:00
|
|
|
precision get_precision() const { lean_assert(m_ptr); return m_ptr->m_precision; }
|
2013-11-25 18:39:40 +00:00
|
|
|
goals const & get_goals() const { lean_assert(m_ptr); return m_ptr->m_goals; }
|
2013-12-13 01:47:11 +00:00
|
|
|
ro_metavar_env const & get_menv() const { lean_assert(m_ptr); return m_ptr->m_menv; }
|
2013-11-25 18:39:40 +00:00
|
|
|
proof_builder const & get_proof_builder() const { lean_assert(m_ptr); return m_ptr->m_proof_builder; }
|
2013-11-25 19:43:16 +00:00
|
|
|
cex_builder const & get_cex_builder() const { lean_assert(m_ptr); return m_ptr->m_cex_builder; }
|
2013-11-25 21:04:09 +00:00
|
|
|
/**
|
|
|
|
\brief Return true iff this state does not have any goals left, and
|
|
|
|
the precision is \c Precise or \c Over
|
|
|
|
*/
|
|
|
|
bool is_proof_final_state() const;
|
|
|
|
/**
|
|
|
|
\brief Return true iff this state has only one goal of the form <tt> |- false</tt>,
|
|
|
|
and the precision is \c Precise or \c Under
|
|
|
|
*/
|
|
|
|
bool is_cex_final_state() const;
|
2013-11-30 19:28:10 +00:00
|
|
|
/**
|
|
|
|
\brief Store in \c r the goal names
|
|
|
|
*/
|
|
|
|
void get_goal_names(name_set & r) const;
|
2013-12-05 12:41:08 +00:00
|
|
|
|
|
|
|
optional<name> get_ith_goal_name(unsigned i) const { return ::lean::get_ith_goal_name(get_goals(), i); }
|
|
|
|
|
2013-11-22 00:44:31 +00:00
|
|
|
format pp(formatter const & fmt, options const & opts) const;
|
2013-11-21 01:02:41 +00:00
|
|
|
};
|
2013-11-21 20:34:37 +00:00
|
|
|
|
2013-12-13 00:33:31 +00:00
|
|
|
proof_state to_proof_state(ro_environment const & env, context const & ctx, expr const & t);
|
2013-11-21 23:31:55 +00:00
|
|
|
|
2013-11-25 09:06:11 +00:00
|
|
|
inline optional<proof_state> some_proof_state(proof_state const & s, goals const & gs, proof_builder const & p) {
|
|
|
|
return some(proof_state(s, gs, p));
|
|
|
|
}
|
|
|
|
inline optional<proof_state> none_proof_state() { return optional<proof_state> (); }
|
|
|
|
|
2013-11-21 23:31:55 +00:00
|
|
|
template<typename F>
|
|
|
|
goals map_goals(proof_state const & s, F && f) {
|
|
|
|
return map_filter(s.get_goals(), [=](std::pair<name, goal> const & in, std::pair<name, goal> & out) -> bool {
|
2013-11-25 09:06:11 +00:00
|
|
|
check_interrupted();
|
2013-12-08 07:21:07 +00:00
|
|
|
optional<goal> new_goal = f(in.first, in.second);
|
2013-11-21 23:31:55 +00:00
|
|
|
if (new_goal) {
|
|
|
|
out.first = in.first;
|
2013-12-08 07:21:07 +00:00
|
|
|
out.second = *new_goal;
|
2013-11-21 23:31:55 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-11-27 03:15:49 +00:00
|
|
|
|
2013-12-10 21:09:35 +00:00
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, proof_state & s);
|
2013-11-29 05:08:12 +00:00
|
|
|
|
2013-11-27 03:15:49 +00:00
|
|
|
UDATA_DEFS_CORE(goals)
|
|
|
|
UDATA_DEFS(proof_state)
|
|
|
|
void open_proof_state(lua_State * L);
|
2013-11-21 01:02:41 +00:00
|
|
|
}
|