refactor(library/blast/strategies): rename 'debug_action_strategy' to 'action_strategy'

Now, we can also provide a "name" for tracing purposes when
instantiating action_strategy.
This commit is contained in:
Leonardo de Moura 2015-12-29 20:45:24 -08:00
parent 41a01bb606
commit 251b53c669
5 changed files with 72 additions and 54 deletions

View file

@ -1,2 +1,2 @@
add_library(blast_strategies OBJECT simple_strategy.cpp iterative_deepening.cpp
preprocess_strategy.cpp debug_action_strategy.cpp portfolio.cpp)
preprocess_strategy.cpp action_strategy.cpp portfolio.cpp)

View file

@ -10,12 +10,14 @@ Author: Leonardo de Moura
namespace lean {
namespace blast {
class debug_action_strategy_core_fn : public strategy_fn {
class action_strategy_core_fn : public strategy_fn {
char const * m_name;
virtual action_result pre(hypothesis_idx) { return action_result::failed(); }
virtual action_result post(hypothesis_idx) { return action_result::failed(); }
virtual action_result next() { return action_result::failed(); }
virtual char const * get_name() const override { return "debug-action"; }
virtual char const * get_name() const override { return m_name; }
virtual action_result hypothesis_pre_activation(hypothesis_idx hidx) override {
Try(assumption_contradiction_actions(hidx));
@ -37,33 +39,38 @@ class debug_action_strategy_core_fn : public strategy_fn {
Try(next());
return action_result::failed();
}
public:
action_strategy_core_fn(char const * n):m_name(n) {}
};
class debug_pre_action_strategy_fn : public debug_action_strategy_core_fn {
class pre_action_strategy_fn : public action_strategy_core_fn {
std::function<action_result(hypothesis_idx)> m_action;
virtual action_result pre(hypothesis_idx hidx) { return m_action(hidx); }
public:
debug_pre_action_strategy_fn(std::function<action_result(hypothesis_idx)> const & a):
pre_action_strategy_fn(char const * n, std::function<action_result(hypothesis_idx)> const & a):
action_strategy_core_fn(n),
m_action(a) {}
};
class debug_post_action_strategy_fn : public debug_action_strategy_core_fn {
class post_action_strategy_fn : public action_strategy_core_fn {
std::function<action_result(hypothesis_idx)> m_action;
virtual action_result post(hypothesis_idx hidx) { return m_action(hidx); }
public:
debug_post_action_strategy_fn(std::function<action_result(hypothesis_idx)> const & a):
post_action_strategy_fn(char const * n, std::function<action_result(hypothesis_idx)> const & a):
action_strategy_core_fn(n),
m_action(a) {}
};
class debug_action_strategy_fn : public debug_action_strategy_core_fn {
class action_strategy_fn : public action_strategy_core_fn {
std::function<action_result()> m_action;
virtual action_result next() { return m_action(); }
public:
debug_action_strategy_fn(std::function<action_result()> const & a):
action_strategy_fn(char const * n, std::function<action_result()> const & a):
action_strategy_core_fn(n),
m_action(a) {}
};
class xdebug_action_strategy_fn : public debug_action_strategy_core_fn {
class xaction_strategy_fn : public action_strategy_core_fn {
std::function<action_result(hypothesis_idx)> m_pre;
std::function<action_result(hypothesis_idx)> m_post;
std::function<action_result()> m_next;
@ -72,27 +79,30 @@ class xdebug_action_strategy_fn : public debug_action_strategy_core_fn {
virtual action_result post(hypothesis_idx hidx) { return m_post(hidx); }
virtual action_result next() { return m_next(); }
public:
xdebug_action_strategy_fn(std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next):
xaction_strategy_fn(char const * n,
std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next):
action_strategy_core_fn(n),
m_pre(pre), m_post(post), m_next(next) {}
};
strategy mk_debug_action_strategy(std::function<action_result()> const & a) {
return [=]() { return debug_action_strategy_fn(a)(); }; // NOLINT
strategy mk_action_strategy(char const * n, std::function<action_result()> const & a) {
return [=]() { return action_strategy_fn(n, a)(); }; // NOLINT
}
strategy mk_debug_pre_action_strategy(std::function<action_result(hypothesis_idx)> const & a) {
return [=]() { return debug_pre_action_strategy_fn(a)(); }; // NOLINT
strategy mk_pre_action_strategy(char const * n, std::function<action_result(hypothesis_idx)> const & a) {
return [=]() { return pre_action_strategy_fn(n, a)(); }; // NOLINT
}
strategy mk_debug_post_action_strategy(std::function<action_result(hypothesis_idx)> const & a) {
return [=]() { return debug_post_action_strategy_fn(a)(); }; // NOLINT
strategy mk_post_action_strategy(char const * n, std::function<action_result(hypothesis_idx)> const & a) {
return [=]() { return post_action_strategy_fn(n, a)(); }; // NOLINT
}
strategy mk_debug_action_strategy(std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next) {
return [=]() { return xdebug_action_strategy_fn(pre, post, next)(); }; // NOLINT
strategy mk_action_strategy(char const * n,
std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next) {
return [=]() { return xaction_strategy_fn(n, pre, post, next)(); }; // NOLINT
}
}}

View file

@ -0,0 +1,23 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "library/blast/strategy.h"
namespace lean {
namespace blast {
/* \brief Create minimalistic strategies for testing and executing actions.
These strategies apply basic actions (e.g., intros and assumption) and the given action. */
strategy mk_action_strategy(char const * name,
std::function<action_result()> const & a);
strategy mk_pre_action_strategy(char const * name,
std::function<action_result(hypothesis_idx)> const & a);
strategy mk_action_strategy(char const * name,
std::function<action_result(hypothesis_idx)> const & a);
strategy mk_action_strategy(char const * name,
std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next);
}}

View file

@ -1,19 +0,0 @@
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "library/blast/strategy.h"
namespace lean {
namespace blast {
/* \brief Create minimalistic strategies for testing the given action.
These strategies apply basic actions (e.g., intros and assumption) and the given action. */
strategy mk_debug_action_strategy(std::function<action_result()> const & a);
strategy mk_debug_pre_action_strategy(std::function<action_result(hypothesis_idx)> const & a);
strategy mk_debug_post_action_strategy(std::function<action_result(hypothesis_idx)> const & a);
strategy mk_debug_action_strategy(std::function<action_result(hypothesis_idx)> const & pre,
std::function<action_result(hypothesis_idx)> const & post,
std::function<action_result()> const & next);
}}

View file

@ -15,7 +15,7 @@ Author: Leonardo de Moura
#include "library/blast/grinder/grinder_strategy.h"
#include "library/blast/strategies/simple_strategy.h"
#include "library/blast/strategies/preprocess_strategy.h"
#include "library/blast/strategies/debug_action_strategy.h"
#include "library/blast/strategies/action_strategy.h"
namespace lean {
namespace blast {
@ -39,25 +39,28 @@ static optional<expr> apply_simple() {
static optional<expr> apply_cc() {
flet<bool> set(get_config().m_cc, true);
return mk_debug_pre_action_strategy(assert_cc_action)();
return mk_pre_action_strategy("cc", assert_cc_action)();
}
static optional<expr> apply_ematch() {
flet<bool> set(get_config().m_ematch, true);
return mk_debug_action_strategy(assert_cc_action,
unit_propagate,
ematch_action)();
return mk_action_strategy("ematch",
assert_cc_action,
unit_propagate,
ematch_action)();
}
static optional<expr> apply_ematch_simp() {
flet<bool> set(get_config().m_ematch, true);
return mk_debug_action_strategy(assert_cc_action,
unit_propagate,
ematch_simp_action)();
return mk_action_strategy("ematch_simp",
assert_cc_action,
unit_propagate,
ematch_simp_action)();
}
static optional<expr> apply_constructor() {
return mk_debug_action_strategy([]() { return constructor_action(); })();
return mk_action_strategy("constructor",
[]() { return constructor_action(); })();
}
static optional<expr> apply_backward() {
@ -65,9 +68,10 @@ static optional<expr> apply_backward() {
}
static optional<expr> apply_unit() {
return mk_debug_action_strategy(unit_preprocess,
unit_propagate,
[]() { return action_result::failed(); })();
return mk_action_strategy("unit",
unit_preprocess,
unit_propagate,
[]() { return action_result::failed(); })();
}
static optional<expr> apply_grind() {