3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-16 04:20:25 +00:00

Added limit to "visit" to allow detecting multiple visits (#6435)

* Memory leak in .NET user-propagator
The user-propagator object has to be manually disposed (IDisposable), otherwise it stays in memory forever, as it cannot be garbage collected automatically

* Throw an exception if variable passed to decide is already assigned instead of running in an assertion violation

* Added limit to "visit" to allow detecting multiple visits

* Putting visit in a separate class
(Reason: We will probably need two of them in the sat::solver)

* Bugfix
This commit is contained in:
Clemens Eisenhofer 2022-11-03 11:34:52 +01:00 committed by GitHub
parent e0bbe8dfc0
commit 6790f18132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 52 deletions

View file

@ -3441,10 +3441,10 @@ namespace sat {
for (unsigned i = m_clauses_to_reinit.size(); i-- > old_sz; ) {
clause_wrapper const& cw = m_clauses_to_reinit[i];
for (unsigned j = cw.size(); j-- > 0; )
mark_visited(cw[j].var());
m_visited.mark_visited(cw[j].var());
}
for (literal lit : m_lemma)
mark_visited(lit.var());
m_visited.mark_visited(lit.var());
auto is_active = [&](bool_var v) {
return value(v) != l_undef && lvl(v) <= new_lvl;
@ -3452,7 +3452,7 @@ namespace sat {
for (unsigned i = old_num_vars; i < sz; ++i) {
bool_var v = m_active_vars[i];
if (is_external(v) || is_visited(v) || is_active(v)) {
if (is_external(v) || m_visited.is_visited(v) || is_active(v)) {
m_vars_to_reinit.push_back(v);
m_active_vars[j++] = v;
m_var_scope[v] = new_lvl;
@ -4697,10 +4697,10 @@ namespace sat {
bool solver::all_distinct(literal_vector const& lits) {
init_visited();
for (literal l : lits) {
if (is_visited(l.var())) {
if (m_visited.is_visited(l.var())) {
return false;
}
mark_visited(l.var());
m_visited.mark_visited(l.var());
}
return true;
}
@ -4708,30 +4708,12 @@ namespace sat {
bool solver::all_distinct(clause const& c) {
init_visited();
for (literal l : c) {
if (is_visited(l.var())) {
if (m_visited.is_visited(l.var())) {
return false;
}
mark_visited(l.var());
m_visited.mark_visited(l.var());
}
return true;
}
void solver::init_ts(unsigned n, svector<unsigned>& v, unsigned& ts) {
if (v.empty())
ts = 0;
ts++;
if (ts == 0) {
ts = 1;
v.reset();
}
while (v.size() < n)
v.push_back(0);
}
void solver::init_visited() {
init_ts(2 * num_vars(), m_visited, m_visited_ts);
}
};