3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +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

39
src/util/visit_helper.h Normal file
View file

@ -0,0 +1,39 @@
#pragma once
#include "sat_literal.h"
class visit_helper {
unsigned_vector m_visited;
unsigned m_visited_begin = 0;
unsigned m_visited_end = 0;
void init_ts(unsigned n, unsigned lim = 1) {
SASSERT(lim > 0);
if (m_visited_end >= m_visited_end + lim) { // overflow
m_visited_begin = 0;
m_visited_end = lim;
m_visited.reset();
}
else {
m_visited_begin = m_visited_end;
m_visited_end = m_visited_end + lim;
}
while (m_visited.size() < n)
m_visited.push_back(0);
}
public:
void init_visited(unsigned num_vars, unsigned lim = 1) {
init_ts(2 * num_vars, lim);
}
void mark_visited(sat::literal l) { m_visited[l.index()] = m_visited_begin + 1; }
void mark_visited(sat::bool_var v) { mark_visited(sat::literal(v, false)); }
void inc_visited(sat::literal l) {
m_visited[l.index()] = std::min(m_visited_end, std::max(m_visited_begin, m_visited[l.index()]) + 1);
}
void inc_visited(sat::bool_var v) { inc_visited(sat::literal(v, false)); }
bool is_visited(sat::bool_var v) const { return is_visited(sat::literal(v, false)); }
bool is_visited(sat::literal l) const { return m_visited[l.index()] > m_visited_begin; }
unsigned num_visited(unsigned i) { return std::max(m_visited_begin, m_visited[i]) - m_visited_begin; }
};