mirror of
https://github.com/Z3Prover/z3
synced 2026-01-21 09:34:43 +00:00
Subterms Theory (#8115)
* somewhaat failed attempt at declaring subterm predicate I can't really figure out how to link the smt parser to the rest of the machinenery, so I will stop here and try from the other side. I'll start implmenting the logic and see if it brings me back to the parser. * initial logic implmentation Very primitive, but I don't like have that much work uncommitted. * parser implementation * more theory * Working base * subterm reflexivity * a few optimization Skip adding obvious equalities or disequality * removed some optimisations * better handling of backtracking * stupid segfault Add m_subterm to the trail * Update src/smt/theory_datatype.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/ast/rewriter/datatype_rewriter.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/smt/theory_datatype.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/smt/theory_datatype.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/smt/theory_datatype.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * review * forgot to update `iterate_subterm`'s signature * fix iterator segfault * Remove duplicate include statement Removed duplicate include of 'theory_datatype.h'. * Replace 'optional' with 'std::option' in datatype_decl_plugin.h * Add is_subterm_predicate matcher to datatype_decl_plugin * Change std::option to std::optional for m_subterm * Update pdecl.h * Change has_subterm to use has_value method * Update pdecl.cpp --------- Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
7377d28c30
commit
deaced1711
9 changed files with 563 additions and 32 deletions
|
|
@ -2546,6 +2546,9 @@ void cmd_context::dt_eh::operator()(sort * dt, pdecl* pd) {
|
|||
m_owner.insert(a);
|
||||
}
|
||||
}
|
||||
if (func_decl * sub = m_dt_util.get_datatype_subterm(dt)) {
|
||||
m_owner.insert(sub);
|
||||
}
|
||||
if (!m_owner.m_scopes.empty() && !m_owner.m_global_decls) {
|
||||
m_owner.pm().inc_ref(pd);
|
||||
m_owner.m_psort_inst_stack.push_back(pd);
|
||||
|
|
|
|||
|
|
@ -541,6 +541,12 @@ void pconstructor_decl::display(std::ostream & out, pdatatype_decl const * const
|
|||
out << ")";
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~ psubterm_decl ~~~~~~~~~~~~ //
|
||||
std::ostream& psubterm_decl::display(std::ostream & out) const {
|
||||
return out << ":subterm " << m_name;
|
||||
}
|
||||
|
||||
|
||||
pdatatype_decl::pdatatype_decl(unsigned id, unsigned num_params, pdecl_manager & m,
|
||||
symbol const & n, unsigned num_constructors, pconstructor_decl * const * constructors):
|
||||
psort_decl(id, num_params, m, n),
|
||||
|
|
@ -589,7 +595,11 @@ datatype_decl * pdatatype_decl::instantiate_decl(pdecl_manager & m, unsigned n,
|
|||
for (auto c : m_constructors)
|
||||
cs.push_back(c->instantiate_decl(m, n, s));
|
||||
datatype_util util(m.m());
|
||||
return mk_datatype_decl(util, m_name, m_num_params, s, cs.size(), cs.data());
|
||||
symbol subterm_name = symbol::null;
|
||||
if (m_subterm.has_value()) {
|
||||
subterm_name = m_subterm->get_name();
|
||||
}
|
||||
return mk_datatype_decl(util, m_name, m_num_params, s, cs.size(), cs.data(), subterm_name);
|
||||
}
|
||||
|
||||
struct datatype_decl_buffer {
|
||||
|
|
@ -647,6 +657,9 @@ std::ostream& pdatatype_decl::display(std::ostream & out) const {
|
|||
}
|
||||
first = false;
|
||||
}
|
||||
if (m_subterm.has_value()) {
|
||||
m_subterm->display(out);
|
||||
}
|
||||
return out << ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -229,11 +229,23 @@ public:
|
|||
void display(std::ostream & out, pdatatype_decl const * const * dts) const;
|
||||
};
|
||||
|
||||
class psubterm_decl: public pdecl {
|
||||
friend class pdecl_manager;
|
||||
friend class pdatatype_decl;
|
||||
symbol m_name;
|
||||
ptype m_type;
|
||||
symbol const & get_name() const { return m_name; }
|
||||
public:
|
||||
psubterm_decl(symbol const& n) : pdecl(0, 0), m_name(n) {}
|
||||
std::ostream& display(std::ostream & out) const override;
|
||||
};
|
||||
|
||||
class pdatatype_decl : public psort_decl {
|
||||
friend class pdecl_manager;
|
||||
friend class pdatatypes_decl;
|
||||
ptr_vector<pconstructor_decl> m_constructors;
|
||||
pdatatypes_decl * m_parent;
|
||||
std::optional<psubterm_decl> m_subterm;
|
||||
pdatatype_decl(unsigned id, unsigned num_params, pdecl_manager & m, symbol const & n,
|
||||
unsigned num_constructors, pconstructor_decl * const * constructors);
|
||||
void finalize(pdecl_manager & m) override;
|
||||
|
|
@ -246,6 +258,7 @@ public:
|
|||
bool has_missing_refs(symbol & missing) const;
|
||||
bool has_duplicate_accessors(symbol & repeated) const;
|
||||
bool commit(pdecl_manager& m);
|
||||
void set_subterm(symbol const& n) { m_subterm = psubterm_decl(n); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue