3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-03-04 04:30:23 +00:00

Convert internal class enums to enum class for type safety (#8158)

* Initial plan

* Convert plain enums to enum class in EUF module

- Convert eq_status in euf::ac_plugin to enum class
- Convert undo_kind in euf::ac_plugin to enum class
- Convert undo_t in euf::arith_plugin to enum class
- Convert to_merge_t in euf::egraph to enum class
- Update all usage sites to use scoped enum syntax

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Convert more plain enums to enum class

- Convert state enum in substitution class
- Convert instruction enum in generic_model_converter class
- Convert eq_type enum in bit2int class
- Update all usage sites to use scoped enum syntax

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-11 17:44:59 -08:00 committed by GitHub
parent 31122b0c10
commit ee037dcafe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 54 additions and 54 deletions

View file

@ -154,64 +154,64 @@ namespace euf {
for (auto arg : ns) {
arg->shared.push_back(idx);
m_node_trail.push_back(arg);
push_undo(is_add_shared_index);
push_undo(undo_kind::is_add_shared_index);
}
m_shared_nodes.setx(n->get_id(), true, false);
sort(monomial(m));
m_shared_todo.insert(idx);
m_shared.push_back({ n, m, justification::axiom(get_id()) });
push_undo(is_register_shared);
push_undo(undo_kind::is_register_shared);
}
void ac_plugin::push_scope_eh() {
push_undo(is_push_scope);
push_undo(undo_kind::is_push_scope);
}
void ac_plugin::undo() {
auto k = m_undo.back();
m_undo.pop_back();
switch (k) {
case is_queue_eq: {
case undo_kind::is_queue_eq: {
m_queued.pop_back();
break;
}
case is_add_node: {
case undo_kind::is_add_node: {
auto* n = m_node_trail.back();
m_node_trail.pop_back();
m_nodes[n->n->get_id()] = nullptr;
n->~node();
break;
}
case is_push_scope: {
case undo_kind::is_push_scope: {
m_active.reset();
m_passive.reset();
m_units.reset();
m_queue_head = 0;
break;
}
case is_add_monomial: {
case undo_kind::is_add_monomial: {
m_monomials.pop_back();
break;
}
case is_add_shared_index: {
case undo_kind::is_add_shared_index: {
auto n = m_node_trail.back();
m_node_trail.pop_back();
n->shared.pop_back();
break;
}
case is_add_eq_index: {
case undo_kind::is_add_eq_index: {
auto n = m_node_trail.back();
m_node_trail.pop_back();
n->eqs.pop_back();
break;
}
case is_register_shared: {
case undo_kind::is_register_shared: {
auto s = m_shared.back();
m_shared_nodes[s.n->get_id()] = false;
m_shared.pop_back();
break;
}
case is_update_shared: {
case undo_kind::is_update_shared: {
auto [id, s] = m_update_shared_trail.back();
m_shared[id] = s;
m_update_shared_trail.pop_back();
@ -345,7 +345,7 @@ namespace euf {
if (l == r)
return;
m_queued.push_back({ l, r });
push_undo(is_queue_eq);
push_undo(undo_kind::is_queue_eq);
}
bool ac_plugin::init_equation(eq eq, bool is_active) {
@ -376,7 +376,7 @@ namespace euf {
if (!n->n->is_marked2()) {
n->eqs.push_back(eq_id);
n->n->mark2();
push_undo(is_add_eq_index);
push_undo(undo_kind::is_add_eq_index);
m_node_trail.push_back(n);
for (auto s : n->shared)
m_shared_todo.insert(s);
@ -387,7 +387,7 @@ namespace euf {
if (!n->n->is_marked2()) {
n->eqs.push_back(eq_id);
n->n->mark2();
push_undo(is_add_eq_index);
push_undo(undo_kind::is_add_eq_index);
m_node_trail.push_back(n);
for (auto s : n->shared)
m_shared_todo.insert(s);
@ -541,7 +541,7 @@ namespace euf {
unsigned ac_plugin::to_monomial(enode* e, ptr_vector<node> const& ms) {
unsigned id = m_monomials.size();
m_monomials.push_back({ ms, bloom(), e });
push_undo(is_add_monomial);
push_undo(undo_kind::is_add_monomial);
return id;
}
@ -581,7 +581,7 @@ namespace euf {
if (m_nodes.size() > id && m_nodes[id])
return m_nodes[id];
auto* r = node::mk(get_region(), n);
push_undo(is_add_node);
push_undo(undo_kind::is_add_node);
m_nodes.setx(id, r, nullptr);
m_node_trail.push_back(r);
if (is_op(n)) {
@ -1137,7 +1137,7 @@ namespace euf {
n->eqs.push_back(eq);
m_node_trail.push_back(n);
n->n->mark2();
push_undo(is_add_eq_index);
push_undo(undo_kind::is_add_eq_index);
}
}
for (auto n : old_r)
@ -1435,13 +1435,13 @@ namespace euf {
n->shared.push_back(idx);
m_shared_todo.insert(idx);
m_node_trail.push_back(n);
push_undo(is_add_shared_index);
push_undo(undo_kind::is_add_shared_index);
}
}
for (auto n : monomial(old_m))
n->n->unmark2();
m_update_shared_trail.push_back({ idx, s });
push_undo(is_update_shared);
push_undo(undo_kind::is_update_shared);
m_shared[idx].m = new_m;
m_shared[idx].j = j;
TRACE(plugin_verbose, tout << "shared simplified to " << m_pp_ll(*this, monomial(new_m)) << "\n");

View file

@ -56,7 +56,7 @@ namespace euf {
uint64_t m_filter = 0;
};
enum eq_status {
enum class eq_status {
is_processed_eq, is_passive_eq, is_to_simplify_eq, is_reducing_eq, is_dead_eq
};
@ -65,7 +65,7 @@ namespace euf {
eq(unsigned l, unsigned r, justification j):
l(l), r(r), j(j) {}
unsigned l, r; // refer to monomials
eq_status status = is_to_simplify_eq;
eq_status status = eq_status::is_to_simplify_eq;
justification j; // justification for equality
};
@ -146,7 +146,7 @@ namespace euf {
// backtrackable state
enum undo_kind {
enum class undo_kind {
is_queue_eq,
is_add_monomial,
is_add_node,

View file

@ -25,7 +25,7 @@ namespace euf {
class egraph;
class arith_plugin : public plugin {
enum undo_t { undo_add, undo_mul };
enum class undo_t { undo_add, undo_mul };
arith_util a;
svector<undo_t> m_undo;
ac_plugin m_add, m_mul;

View file

@ -661,14 +661,14 @@ namespace euf {
for (; i < m_to_merge.size() && m.limit().inc() && !inconsistent(); ++i) {
auto const& w = m_to_merge[i];
switch (w.t) {
case to_merge_plain:
case to_merge_comm:
case to_merge_t::to_merge_plain:
case to_merge_t::to_merge_comm:
merge(w.a, w.b, justification::congruence(w.commutativity(), m_congruence_timestamp++));
break;
case to_justified:
case to_merge_t::to_justified:
merge(w.a, w.b, w.j);
break;
case to_add_literal:
case to_merge_t::to_add_literal:
add_literal(w.a, w.b);
break;
}

View file

@ -88,15 +88,15 @@ namespace euf {
typedef ptr_vector<trail> trail_stack;
enum to_merge_t { to_merge_plain, to_merge_comm, to_justified, to_add_literal };
enum class to_merge_t { to_merge_plain, to_merge_comm, to_justified, to_add_literal };
struct to_merge {
enode* a, * b;
to_merge_t t;
justification j;
bool commutativity() const { return t == to_merge_comm; }
to_merge(enode* a, enode* b, bool c) : a(a), b(b), t(c ? to_merge_comm : to_merge_plain) {}
to_merge(enode* a, enode* b, justification j): a(a), b(b), t(to_justified), j(j) {}
to_merge(enode* p, enode* ante): a(p), b(ante), t(to_add_literal) {}
bool commutativity() const { return t == to_merge_t::to_merge_comm; }
to_merge(enode* a, enode* b, bool c) : a(a), b(b), t(c ? to_merge_t::to_merge_comm : to_merge_t::to_merge_plain) {}
to_merge(enode* a, enode* b, justification j): a(a), b(b), t(to_merge_t::to_justified), j(j) {}
to_merge(enode* p, enode* ante): a(p), b(ante), t(to_merge_t::to_add_literal) {}
};
struct stats {