feat(library/blast): add get_config()

This commit is contained in:
Leonardo de Moura 2015-11-20 10:39:26 -08:00
parent c76b04719c
commit 028a2ab785
8 changed files with 42 additions and 15 deletions

View file

@ -29,6 +29,7 @@ Author: Leonardo de Moura
#include "library/blast/choice_point.h" #include "library/blast/choice_point.h"
#include "library/blast/congruence_closure.h" #include "library/blast/congruence_closure.h"
#include "library/blast/trace.h" #include "library/blast/trace.h"
#include "library/blast/options.h"
namespace lean { namespace lean {
namespace blast { namespace blast {
@ -792,7 +793,8 @@ struct scope_debug::imp {
blastenv m_benv; blastenv m_benv;
scope_blastenv m_scope2; scope_blastenv m_scope2;
scope_congruence_closure m_scope3; scope_congruence_closure m_scope3;
scope_trace m_scope4; scope_config m_scope4;
scope_trace m_scope5;
imp(environment const & env, io_state const & ios): imp(environment const & env, io_state const & ios):
m_scope1(true), m_scope1(true),
m_benv(env, ios, list<name>(), list<name>()), m_benv(env, ios, list<name>(), list<name>()),
@ -890,7 +892,8 @@ optional<expr> blast_goal(environment const & env, io_state const & ios, list<na
blast::blastenv b(env, ios, ls, ds); blast::blastenv b(env, ios, ls, ds);
blast::scope_blastenv scope2(b); blast::scope_blastenv scope2(b);
blast::scope_congruence_closure scope3; blast::scope_congruence_closure scope3;
blast::scope_trace scope4(ios.get_options()); blast::scope_config scope4(ios.get_options());
blast::scope_trace scope5;
return b(g); return b(g);
} }
void initialize_blast() { void initialize_blast() {

View file

@ -48,6 +48,23 @@ config::config(options const & o) {
m_trace = get_blast_trace(o); m_trace = get_blast_trace(o);
} }
LEAN_THREAD_PTR(config, g_config);
scope_config::scope_config(options const & o):
m_old(g_config),
m_config(o) {
g_config = &m_config;
}
scope_config::~scope_config() {
g_config = m_old;
}
config const & get_config() {
lean_assert(g_config);
return *g_config;
}
void initialize_options() { void initialize_options() {
g_blast_max_depth = new name{"blast", "max_depth"}; g_blast_max_depth = new name{"blast", "max_depth"};
g_blast_init_depth = new name{"blast", "init_depth"}; g_blast_init_depth = new name{"blast", "init_depth"};

View file

@ -17,7 +17,17 @@ struct config {
bool m_trace; bool m_trace;
config(options const & o); config(options const & o);
}; };
bool get_blast_trace(options const & o);
struct scope_config {
config * m_old;
config m_config;
public:
scope_config(options const & o);
~scope_config();
};
config const & get_config();
void initialize_options(); void initialize_options();
void finalize_options(); void finalize_options();
}} }}

View file

@ -27,7 +27,7 @@ namespace blast {
We use it mainly for testing new actions and the whole blast infra-structure. */ We use it mainly for testing new actions and the whole blast infra-structure. */
class simple_strategy : public strategy { class simple_strategy : public strategy {
action_result activate_hypothesis(bool preprocess) { action_result activate_hypothesis(bool preprocess) {
scope_trace scope(!preprocess && cfg().m_trace); scope_trace scope(!preprocess && get_config().m_trace);
auto hidx = curr_state().activate_hypothesis(); auto hidx = curr_state().activate_hypothesis();
if (!hidx) return action_result::failed(); if (!hidx) return action_result::failed();

View file

@ -12,9 +12,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
namespace blast { namespace blast {
strategy::strategy(): strategy::strategy() {}
m_config(ios().get_options()) {
}
action_result strategy::next_branch(expr pr) { action_result strategy::next_branch(expr pr) {
while (curr_state().has_proof_steps()) { while (curr_state().has_proof_steps()) {
@ -97,12 +95,12 @@ optional<expr> strategy::search() {
if (get_num_choice_points() > m_init_num_choices) if (get_num_choice_points() > m_init_num_choices)
throw exception("invalid blast preprocessing action, preprocessing actions should not create choice points"); throw exception("invalid blast preprocessing action, preprocessing actions should not create choice points");
state s = curr_state(); state s = curr_state();
unsigned d = m_config.m_init_depth; unsigned d = get_config().m_init_depth;
while (true) { while (true) {
if (auto r = search_upto(d)) if (auto r = search_upto(d))
return r; return r;
d += m_config.m_inc_depth; d += get_config().m_inc_depth;
if (d > m_config.m_max_depth) { if (d > get_config().m_max_depth) {
trace_curr_state(); trace_curr_state();
return none_expr(); return none_expr();
} }

View file

@ -19,7 +19,6 @@ namespace blast {
2- Next action to be performed (next_action method) 2- Next action to be performed (next_action method)
*/ */
class strategy { class strategy {
config m_config;
unsigned m_init_num_choices; unsigned m_init_num_choices;
optional<expr> invoke_preprocess(); optional<expr> invoke_preprocess();
protected: protected:
@ -32,7 +31,6 @@ protected:
public: public:
strategy(); strategy();
optional<expr> operator()() { return search(); } optional<expr> operator()() { return search(); }
config cfg() const { return m_config; }
}; };
#define TryStrategy(Code) {\ #define TryStrategy(Code) {\

View file

@ -48,8 +48,8 @@ scope_trace::scope_trace(bool enable):
g_trace = enable; g_trace = enable;
} }
scope_trace::scope_trace(options const & o): scope_trace::scope_trace():
scope_trace(get_blast_trace(o)) { scope_trace(get_config().m_trace) {
} }
scope_trace::~scope_trace() { scope_trace::~scope_trace() {

View file

@ -14,10 +14,11 @@ void trace(char const * msg);
void trace_action(char const * a); void trace_action(char const * a);
void trace_curr_state_if(action_result r); void trace_curr_state_if(action_result r);
bool is_trace_enabled(); bool is_trace_enabled();
class scope_trace { class scope_trace {
bool m_old; bool m_old;
public: public:
scope_trace(options const & o); scope_trace();
scope_trace(bool enable); scope_trace(bool enable);
~scope_trace(); ~scope_trace();
}; };