mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
fix traffic jam
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
27ec5c688f
commit
7bfb730fee
7 changed files with 217 additions and 94 deletions
|
@ -837,6 +837,7 @@ namespace datalog {
|
|||
}
|
||||
|
||||
lbool context::query(expr* query) {
|
||||
expr_ref _query(query, m);
|
||||
m_mc = mk_skip_model_converter();
|
||||
m_last_status = OK;
|
||||
m_last_answer = nullptr;
|
||||
|
|
|
@ -24,6 +24,7 @@ Revision History:
|
|||
#include "muz/rel/dl_table_relation.h"
|
||||
#include "muz/rel/dl_finite_product_relation.h"
|
||||
#include "ast/rewriter/bool_rewriter.h"
|
||||
#include "ast/rewriter/th_rewriter.h"
|
||||
|
||||
namespace datalog {
|
||||
|
||||
|
@ -1409,6 +1410,11 @@ namespace datalog {
|
|||
//create the condition with table values substituted in and relation values properly renamed
|
||||
expr_ref inner_cond(m_manager);
|
||||
inner_cond = m_subst(m_cond, m_renaming_for_inner_rel.size(), m_renaming_for_inner_rel.c_ptr());
|
||||
th_rewriter rw(m_manager);
|
||||
rw(inner_cond);
|
||||
if (m_manager.is_false(inner_cond)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
relation_base * new_rel = old_rel.clone();
|
||||
|
||||
|
|
|
@ -44,10 +44,7 @@ namespace datalog {
|
|||
}
|
||||
|
||||
void execution_context::reset() {
|
||||
reg_vector::iterator it=m_registers.begin();
|
||||
reg_vector::iterator end=m_registers.end();
|
||||
for(; it != end; ++it) {
|
||||
relation_base * rel = *it;
|
||||
for (relation_base * rel : m_registers) {
|
||||
if (rel) {
|
||||
rel->deallocate();
|
||||
}
|
||||
|
@ -148,10 +145,8 @@ namespace datalog {
|
|||
// -----------------------------------
|
||||
|
||||
instruction::~instruction() {
|
||||
fn_cache::iterator it = m_fn_cache.begin();
|
||||
fn_cache::iterator end = m_fn_cache.end();
|
||||
for(; it != end; ++it) {
|
||||
dealloc(it->m_value);
|
||||
for (auto& p : m_fn_cache) {
|
||||
dealloc(p.m_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,13 +215,13 @@ namespace datalog {
|
|||
void make_annotations(execution_context & ctx) override {
|
||||
ctx.set_register_annotation(m_reg, m_pred->get_name().bare_str());
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
const char * rel_name = m_pred->get_name().bare_str();
|
||||
if (m_store) {
|
||||
out << "store " << m_reg << " into " << rel_name;
|
||||
return out << "store " << m_reg << " into " << rel_name;
|
||||
}
|
||||
else {
|
||||
out << "load " << rel_name << " into " << m_reg;
|
||||
return out << "load " << rel_name << " into " << m_reg;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -251,8 +246,8 @@ namespace datalog {
|
|||
void make_annotations(execution_context & ctx) override {
|
||||
ctx.set_register_annotation(m_reg, "alloc");
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "dealloc " << m_reg;
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "dealloc " << m_reg;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -286,8 +281,8 @@ namespace datalog {
|
|||
ctx.set_register_annotation(m_src, str);
|
||||
}
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << (m_clone ? "clone " : "move ") << m_src << " into " << m_tgt;
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << (m_clone ? "clone " : "move ") << m_src << " into " << m_tgt;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -305,10 +300,7 @@ namespace datalog {
|
|||
instruction_block * m_body;
|
||||
|
||||
bool control_is_empty(execution_context & ctx) {
|
||||
idx_vector::const_iterator it=m_controls.begin();
|
||||
idx_vector::const_iterator end=m_controls.end();
|
||||
for(; it != end; ++it) {
|
||||
reg_idx r = *it;
|
||||
for (reg_idx r : m_controls) {
|
||||
if (ctx.reg(r) && !ctx.reg(r)->fast_empty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -343,9 +335,10 @@ namespace datalog {
|
|||
void make_annotations(execution_context & ctx) override {
|
||||
m_body->make_annotations(ctx);
|
||||
}
|
||||
void display_head_impl(execution_context const & ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const & ctx, std::ostream & out) const override {
|
||||
out << "while";
|
||||
print_container(m_controls, out);
|
||||
return out;
|
||||
}
|
||||
void display_body_impl(execution_context const & ctx, std::ostream & out, const std::string & indentation) const override {
|
||||
m_body->display_indented(ctx, out, indentation+" ");
|
||||
|
@ -413,12 +406,12 @@ namespace datalog {
|
|||
ctx.get_register_annotation(m_rel1, a1);
|
||||
ctx.set_register_annotation(m_res, "join " + a1 + " " + a2);
|
||||
}
|
||||
void display_head_impl(execution_context const & ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const & ctx, std::ostream & out) const override {
|
||||
out << "join " << m_rel1;
|
||||
print_container(m_cols1, out);
|
||||
out << " and " << m_rel2;
|
||||
print_container(m_cols2, out);
|
||||
out << " into " << m_res;
|
||||
return out << " into " << m_res;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -464,9 +457,9 @@ namespace datalog {
|
|||
a << "filter_equal " << m_col << " val: " << ctx.get_rel_context().get_rmanager().to_nice_string(m_value);
|
||||
ctx.set_register_annotation(m_reg, a.str());
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "filter_equal " << m_reg << " col: " << m_col << " val: "
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_value);
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "filter_equal " << m_reg << " col: " << m_col << " val: "
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_value);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -508,9 +501,10 @@ namespace datalog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "filter_identical " << m_reg << " ";
|
||||
print_container(m_cols, out);
|
||||
return out;
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
ctx.set_register_annotation(m_reg, "filter_identical");
|
||||
|
@ -556,9 +550,10 @@ namespace datalog {
|
|||
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "filter_interpreted " << m_reg << " using "
|
||||
<< mk_pp(m_cond, m_cond.get_manager());
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return
|
||||
out << "filter_interpreted " << m_reg << " using "
|
||||
<< mk_pp(m_cond, m_cond.get_manager());
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::stringstream a;
|
||||
|
@ -609,15 +604,16 @@ namespace datalog {
|
|||
if (ctx.reg(m_res)->fast_empty()) {
|
||||
ctx.make_empty(m_res);
|
||||
}
|
||||
//TRACE("dl_verbose", reg.display(tout << "post-filter-interpreted-and-project:\n"););
|
||||
// TRACE("dl_verbose", reg.display(tout << "post-filter-interpreted-and-project:\n"););
|
||||
return true;
|
||||
}
|
||||
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "filter_interpreted_and_project " << m_src << " into " << m_res;
|
||||
out << " using " << mk_pp(m_cond, m_cond.get_manager());
|
||||
out << " deleting columns ";
|
||||
print_container(m_cols, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
|
@ -730,11 +726,12 @@ namespace datalog {
|
|||
}
|
||||
ctx.set_register_annotation(m_delta, str);
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << (m_widen ? "widen " : "union ") << m_src << " into " << m_tgt;
|
||||
if (m_delta!=execution_context::void_register) {
|
||||
out << " with delta " << m_delta;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -786,10 +783,11 @@ namespace datalog {
|
|||
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << (m_projection ? "project " : "rename ") << m_src << " into " << m_tgt;
|
||||
out << (m_projection ? " deleting columns " : " with cycle ");
|
||||
print_container(m_cols, out);
|
||||
return out;
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::stringstream s;
|
||||
|
@ -851,7 +849,7 @@ namespace datalog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
relation_base const* r1 = ctx.reg(m_rel1);
|
||||
relation_base const* r2 = ctx.reg(m_rel2);
|
||||
out << "join_project " << m_rel1;
|
||||
|
@ -868,6 +866,7 @@ namespace datalog {
|
|||
print_container(m_cols2, out);
|
||||
out << " into " << m_res << " removing columns ";
|
||||
print_container(m_removed_cols, out);
|
||||
return out;
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::string s1 = "rel1", s2 = "rel2";
|
||||
|
@ -922,9 +921,9 @@ namespace datalog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "select_equal_and_project " << m_src <<" into " << m_result << " col: " << m_col
|
||||
<< " val: " << ctx.get_rel_context().get_rmanager().to_nice_string(m_value);
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "select_equal_and_project " << m_src <<" into " << m_result << " col: " << m_col
|
||||
<< " val: " << ctx.get_rel_context().get_rmanager().to_nice_string(m_value);
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::stringstream s;
|
||||
|
@ -979,12 +978,12 @@ namespace datalog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "filter_by_negation on " << m_tgt;
|
||||
print_container(m_cols1, out);
|
||||
out << " with " << m_neg_rel;
|
||||
print_container(m_cols2, out);
|
||||
out << " as the negated table";
|
||||
return out << " as the negated table";
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::string s = "negated relation";
|
||||
|
@ -1018,10 +1017,10 @@ namespace datalog {
|
|||
ctx.set_reg(m_tgt, rel);
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "mk_unary_singleton into " << m_tgt << " sort:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig[0]) << " val:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig[0], m_fact[0]);
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "mk_unary_singleton into " << m_tgt << " sort:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig[0]) << " val:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig[0], m_fact[0]);
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::string s;
|
||||
|
@ -1049,10 +1048,10 @@ namespace datalog {
|
|||
ctx.set_reg(m_tgt, ctx.get_rel_context().get_rmanager().mk_full_relation(m_sig, m_pred));
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "mk_total into " << m_tgt << " sort:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig)
|
||||
<< " " << m_pred->get_name();
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "mk_total into " << m_tgt << " sort:"
|
||||
<< ctx.get_rel_context().get_rmanager().to_nice_string(m_sig)
|
||||
<< " " << m_pred->get_name();
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::string s;
|
||||
|
@ -1076,8 +1075,8 @@ namespace datalog {
|
|||
ctx.get_rel_context().get_rmanager().mark_saturated(m_pred);
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "mark_saturated " << m_pred->get_name().bare_str();
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
return out << "mark_saturated " << m_pred->get_name().bare_str();
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
}
|
||||
|
@ -1100,9 +1099,10 @@ namespace datalog {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
std::ostream& display_head_impl(execution_context const& ctx, std::ostream & out) const override {
|
||||
out << "instr_assert_signature of " << m_tgt << " signature:";
|
||||
print_container(m_sig, out);
|
||||
return out;
|
||||
}
|
||||
void make_annotations(execution_context & ctx) override {
|
||||
std::string s;
|
||||
|
@ -1128,10 +1128,8 @@ namespace datalog {
|
|||
}
|
||||
|
||||
void instruction_block::reset() {
|
||||
instr_seq_type::iterator it = m_data.begin();
|
||||
instr_seq_type::iterator end = m_data.end();
|
||||
for(; it!=end; ++it) {
|
||||
dealloc(*it);
|
||||
for (auto* t : m_data) {
|
||||
dealloc(t);
|
||||
}
|
||||
m_data.reset();
|
||||
m_observer = nullptr;
|
||||
|
@ -1139,54 +1137,40 @@ namespace datalog {
|
|||
|
||||
bool instruction_block::perform(execution_context & ctx) const {
|
||||
cost_recorder crec;
|
||||
instr_seq_type::const_iterator it = m_data.begin();
|
||||
instr_seq_type::const_iterator end = m_data.end();
|
||||
bool success = true;
|
||||
for(; it!=end && success; ++it) {
|
||||
|
||||
instruction * instr=(*it);
|
||||
for (instruction * instr : m_data) {
|
||||
crec.start(instr); //finish is performed by the next start() or by the destructor of crec
|
||||
|
||||
TRACE("dl",
|
||||
tout <<"% ";
|
||||
instr->display_head_impl(ctx, tout);
|
||||
tout <<"\n";);
|
||||
success = !ctx.should_terminate() && instr->perform(ctx);
|
||||
TRACE("dl", instr->display_head_impl(ctx, tout << "% ") << "\n";);
|
||||
|
||||
if (ctx.should_terminate() || !instr->perform(ctx)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
void instruction_block::process_all_costs() {
|
||||
instr_seq_type::iterator it = m_data.begin();
|
||||
instr_seq_type::iterator end = m_data.end();
|
||||
for(; it!=end; ++it) {
|
||||
(*it)->process_all_costs();
|
||||
for (auto* t : m_data) {
|
||||
t->process_all_costs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void instruction_block::collect_statistics(statistics& st) const {
|
||||
instr_seq_type::const_iterator it = m_data.begin();
|
||||
instr_seq_type::const_iterator end = m_data.end();
|
||||
for(; it!=end; ++it) {
|
||||
(*it)->collect_statistics(st);
|
||||
for (auto* t : m_data) {
|
||||
t->collect_statistics(st);
|
||||
}
|
||||
}
|
||||
|
||||
void instruction_block::make_annotations(execution_context & ctx) {
|
||||
instr_seq_type::iterator it = m_data.begin();
|
||||
instr_seq_type::iterator end = m_data.end();
|
||||
for(; it!=end; ++it) {
|
||||
(*it)->make_annotations(ctx);
|
||||
for (auto* t : m_data) {
|
||||
t->make_annotations(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void instruction_block::display_indented(execution_context const& _ctx, std::ostream & out, const std::string & indentation) const {
|
||||
rel_context const& ctx = _ctx.get_rel_context();
|
||||
instr_seq_type::const_iterator it = m_data.begin();
|
||||
instr_seq_type::const_iterator end = m_data.end();
|
||||
for(; it!=end; ++it) {
|
||||
instruction * i = (*it);
|
||||
for (auto* i : m_data) {
|
||||
if (i->passes_output_thresholds(ctx.get_context()) || i->being_recorded()) {
|
||||
i->display_indented(_ctx, out, indentation);
|
||||
}
|
||||
|
|
|
@ -225,8 +225,8 @@ namespace datalog {
|
|||
|
||||
The newline character at the end should not be printed.
|
||||
*/
|
||||
virtual void display_head_impl(execution_context const & ctx, std::ostream & out) const {
|
||||
out << "<instruction>";
|
||||
virtual std::ostream& display_head_impl(execution_context const & ctx, std::ostream & out) const {
|
||||
return out << "<instruction>";
|
||||
}
|
||||
/**
|
||||
\brief If relevant, output the body of the current instruction.
|
||||
|
|
|
@ -478,11 +478,13 @@ namespace datalog {
|
|||
|
||||
relation_mutator_fn * explanation_relation_plugin::mk_filter_interpreted_fn(const relation_base & r,
|
||||
app * cond) {
|
||||
if (&r.get_plugin()!=this) {
|
||||
if (&r.get_plugin() != this) {
|
||||
TRACE("dl", tout << "not same plugin\n";);
|
||||
return nullptr;
|
||||
}
|
||||
ast_manager & m = get_ast_manager();
|
||||
if (!m.is_eq(cond)) {
|
||||
TRACE("dl", tout << "not equality " << mk_pp(cond, m) << "\n";);
|
||||
return nullptr;
|
||||
}
|
||||
expr * arg1 = cond->get_arg(0);
|
||||
|
@ -493,11 +495,13 @@ namespace datalog {
|
|||
}
|
||||
|
||||
if (!is_var(arg1) || !is_app(arg2)) {
|
||||
TRACE("dl", tout << "not variable assignemnt\n";);
|
||||
return nullptr;
|
||||
}
|
||||
var * col_var = to_var(arg1);
|
||||
app * new_rule = to_app(arg2);
|
||||
if (!get_context().get_decl_util().is_rule_sort(col_var->get_sort())) {
|
||||
TRACE("dl", tout << "not rule sort\n";);
|
||||
return nullptr;
|
||||
}
|
||||
unsigned col_idx = col_var->get_idx();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue