3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-23 08:47:37 +00:00

Standardize for-loop increments to prefix form (++i) (#8199)

* Initial plan

* Convert postfix to prefix increment in for loops

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

* Fix member variable increment conversion bug

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

* Update API generator to produce prefix increments

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-14 19:55:31 -08:00 committed by Nikolaj Bjorner
parent 851b8ea31c
commit 317dd92105
475 changed files with 3237 additions and 3237 deletions

View file

@ -91,7 +91,7 @@ namespace {
void display(std::ostream & out) const {
out << "lbl-hasher:\n";
bool first = true;
for (unsigned i = 0; i < m_lbl2hash.size(); i++) {
for (unsigned i = 0; i < m_lbl2hash.size(); ++i) {
if (m_lbl2hash[i] != -1) {
if (first)
first = false;
@ -258,14 +258,14 @@ namespace {
out << "(GET_CGR";
display_num_args(out, c.m_num_args);
out << " " << c.m_label->get_name() << " " << c.m_oreg;
for (unsigned i = 0; i < c.m_num_args; i++)
for (unsigned i = 0; i < c.m_num_args; ++i)
out << " " << c.m_iregs[i];
out << ")";
}
void display_is_cgr(std::ostream & out, const is_cgr & c) {
out << "(IS_CGR " << c.m_label->get_name() << " " << c.m_ireg;
for (unsigned i = 0; i < c.m_num_args; i++)
for (unsigned i = 0; i < c.m_num_args; ++i)
out << " " << c.m_iregs[i];
out << ")";
}
@ -274,14 +274,14 @@ namespace {
out << "(YIELD";
display_num_args(out, y.m_num_bindings);
out << " #" << y.m_qa->get_id();
for (unsigned i = 0; i < y.m_num_bindings; i++) {
for (unsigned i = 0; i < y.m_num_bindings; ++i) {
out << " " << y.m_bindings[i];
}
out << ")";
}
void display_joints(std::ostream & out, unsigned num_joints, enode * const * joints) {
for (unsigned i = 0; i < num_joints; i++) {
for (unsigned i = 0; i < num_joints; ++i) {
if (i > 0)
out << " ";
enode * bare = joints[i];
@ -399,7 +399,7 @@ namespace {
friend class code_tree_manager;
void display_seq(std::ostream & out, instruction * head, unsigned indent) const {
for (unsigned i = 0; i < indent; i++) {
for (unsigned i = 0; i < indent; ++i) {
out << " ";
}
instruction * curr = head;
@ -440,7 +440,7 @@ namespace {
}
else {
out << p->get_decl()->get_name() << ":" << m_lbl_hasher(p->get_decl()) << " ";
for (unsigned i = 0; i < p->get_num_args(); i++) {
for (unsigned i = 0; i < p->get_num_args(); ++i) {
expr * arg = p->get_arg(i);
if (is_app(arg))
display_label_hashes(out, to_app(arg));
@ -451,7 +451,7 @@ namespace {
void display_label_hashes(std::ostream & out, app * p) const {
ast_manager & m = m_context->get_manager();
if (m.is_pattern(p)) {
for (unsigned i = 0; i < p->get_num_args(); i++) {
for (unsigned i = 0; i < p->get_num_args(); ++i) {
expr * arg = p->get_arg(i);
if (is_app(arg)) {
display_label_hashes_core(out, to_app(arg));
@ -833,7 +833,7 @@ namespace {
app * p = to_app(mp->get_arg(first_idx));
SASSERT(t->get_root_lbl() == p->get_decl());
unsigned num_args = p->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
set_register(i+1, p->get_arg(i));
m_todo.push_back(i+1);
}
@ -841,7 +841,7 @@ namespace {
if (num_decls > m_vars.size()) {
m_vars.resize(num_decls, -1);
}
for (unsigned j = 0; j < num_decls; j++) {
for (unsigned j = 0; j < num_decls; ++j) {
m_vars[j] = -1;
}
}
@ -993,7 +993,7 @@ namespace {
if (IS_CGR_SUPPORT && all_args_are_bound_vars(first_app)) {
// use IS_CGR instead of BIND
sbuffer<unsigned> iregs;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = to_app(first_app)->get_arg(i);
SASSERT(is_var(arg));
SASSERT(m_vars[to_var(arg)->get_idx()] != -1);
@ -1005,7 +1005,7 @@ namespace {
// Generate a BIND operation for this application.
unsigned oreg = m_tree->m_num_regs;
m_tree->m_num_regs += num_args;
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
set_register(oreg + j, first_app->get_arg(j));
m_aux.push_back(oreg + j);
}
@ -1030,7 +1030,7 @@ namespace {
return 0;
}
unsigned num_args = n->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = n->get_arg(i);
if (is_var(arg)) {
unsigned var_id = to_var(arg)->get_idx();
@ -1066,7 +1066,7 @@ namespace {
sbuffer<unsigned> iregs;
unsigned num_args = n->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = n->get_arg(i);
if (is_var(arg)) {
SASSERT(m_vars[to_var(arg)->get_idx()] != -1);
@ -1090,13 +1090,13 @@ namespace {
void linearise_multi_pattern(unsigned first_idx) {
unsigned num_args = m_mp->get_num_args();
// multi_pattern support
for (unsigned i = 1; i < num_args; i++) {
for (unsigned i = 1; i < num_args; ++i) {
// select the pattern with the biggest number of bound variables
app * best = nullptr;
unsigned best_num_bvars = 0;
unsigned best_j = 0;
bool found_bounded_mp = false;
for (unsigned j = 0; j < m_mp->get_num_args(); j++) {
for (unsigned j = 0; j < m_mp->get_num_args(); ++j) {
if (m_mp_already_processed[j])
continue;
app * p = to_app(m_mp->get_arg(j));
@ -1132,7 +1132,7 @@ namespace {
m_tree->m_num_regs += num_args;
ptr_buffer<enode> joints;
bool has_depth1_joint = false; // VAR_TAG or GROUND_TERM_TAG
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
expr * curr = p->get_arg(j);
SASSERT(!is_quantifier(curr));
set_register(oreg + j, curr);
@ -1145,7 +1145,7 @@ namespace {
}
if (has_depth1_joint) {
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
expr * curr = p->get_arg(j);
if (is_var(curr)) {
@ -1170,7 +1170,7 @@ namespace {
}
else {
// Only try to use depth2 joints if there is no depth1 joint.
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
expr * curr = p->get_arg(j);
if (!is_app(curr)) {
joints.push_back(0);
@ -1178,7 +1178,7 @@ namespace {
}
unsigned num_args2 = to_app(curr)->get_num_args();
unsigned k = 0;
for (; k < num_args2; k++) {
for (; k < num_args2; ++k) {
expr * arg = to_app(curr)->get_arg(k);
if (!is_var(arg))
continue;
@ -1219,7 +1219,7 @@ namespace {
}
// check that all variables are captured by pattern.
for (unsigned i = 0; i < m_qa->get_num_decls(); i++)
for (unsigned i = 0; i < m_qa->get_num_decls(); ++i)
if (m_vars[i] == -1)
return;
@ -1405,7 +1405,7 @@ namespace {
bool is_compatible(cont * instr) const {
unsigned oreg = instr->m_oreg;
for (unsigned i = 0; i < instr->m_num_args; i++)
for (unsigned i = 0; i < instr->m_num_args; ++i)
if (m_registers[oreg + i] != 0)
return false;
return true;
@ -1439,7 +1439,7 @@ namespace {
unsigned oreg = static_cast<bind*>(curr)->m_oreg;
unsigned num_args = static_cast<bind*>(curr)->m_num_args;
SASSERT(n->get_num_args() == num_args);
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
set_register(oreg + i, n->get_arg(i));
m_to_reset.push_back(oreg + i);
}
@ -1500,7 +1500,7 @@ namespace {
app * app = to_app(m_registers[ireg]);
unsigned oreg = bnd->m_oreg;
unsigned num_args = bnd->m_num_args;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
set_register(oreg + i, app->get_arg(i));
m_todo.push_back(oreg + i);
}
@ -1948,13 +1948,13 @@ namespace {
return false;
default: {
m_args.reserve(num_args+1, 0);
for (unsigned i = 0; i < num_args; i++)
for (unsigned i = 0; i < num_args; ++i)
m_args[i] = m_registers[pc->m_iregs[i]]->get_root();
SASSERT(n != 0);
do {
if (n->get_decl() == f && n->get_num_args() == num_args) {
unsigned i = 0;
for (; i < num_args; i++) {
for (; i < num_args; ++i) {
if (n->get_arg(i)->get_root() != m_args[i])
break;
}
@ -2126,7 +2126,7 @@ namespace {
unsigned short num_args = c->m_num_args;
enode * r;
// quick filter... check if any of the joint points have zero parents...
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
void * bare = c->m_joints[i];
enode * n = nullptr;
switch (GET_TAG(bare)) {
@ -2151,7 +2151,7 @@ namespace {
}
// traverse each joint and select the best one.
enode_vector * best_v = nullptr;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
enode * bare = c->m_joints[i];
enode_vector * curr_v = nullptr;
switch (GET_TAG(bare)) {
@ -2253,7 +2253,7 @@ namespace {
display_reg(out, static_cast<const filter *>(instr)->m_reg);
break;
case YIELD1: case YIELD2: case YIELD3: case YIELD4: case YIELD5: case YIELD6: case YIELDN:
for (unsigned i = 0; i < static_cast<const yield *>(instr)->m_num_bindings; i++) {
for (unsigned i = 0; i < static_cast<const yield *>(instr)->m_num_bindings; ++i) {
display_reg(out, static_cast<const yield *>(instr)->m_bindings[i]);
}
break;
@ -2383,7 +2383,7 @@ namespace {
m_num_args = m_app->get_num_args();
if (m_num_args != static_cast<const initn *>(m_pc)->m_num_args)
goto backtrack;
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_registers[i+1] = m_app->get_arg(i);
m_pc = m_pc->m_next;
goto main_loop;
@ -2525,7 +2525,7 @@ namespace {
case BINDN:
BIND_COMMON();
m_num_args = static_cast<const bind *>(m_pc)->m_num_args;
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_registers[m_oreg+i] = m_app->get_arg(i);
m_pc = m_pc->m_next;
goto main_loop;
@ -2587,7 +2587,7 @@ namespace {
case YIELDN:
m_num_args = static_cast<const yield *>(m_pc)->m_num_bindings;
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_bindings[i] = m_registers[static_cast<const yield *>(m_pc)->m_bindings[m_num_args - i - 1]];
ON_MATCH(m_num_args);
goto backtrack;
@ -2662,7 +2662,7 @@ namespace {
case GET_CGRN:
m_num_args = static_cast<const get_cgr *>(m_pc)->m_num_args;
m_args.reserve(m_num_args, 0);
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_args[i] = m_registers[static_cast<const get_cgr *>(m_pc)->m_iregs[i]];
GET_CGR_COMMON();
@ -2680,7 +2680,7 @@ namespace {
goto backtrack;
m_pattern_instances.push_back(m_app);
TRACE(mam_int, tout << "continue candidate:\n" << mk_ll_pp(m_app->get_expr(), m););
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_registers[m_oreg+i] = m_app->get_arg(i);
m_pc = m_pc->m_next;
goto main_loop;
@ -2798,7 +2798,7 @@ namespace {
case BINDN:
BBIND_COMMON();
m_num_args = m_b->m_num_args;
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_registers[m_oreg+i] = m_app->get_arg(i);
m_pc = m_b->m_next;
goto main_loop;
@ -2825,7 +2825,7 @@ namespace {
TRACE(mam_int, tout << "continue next candidate:\n" << mk_ll_pp(m_app->get_expr(), m););
m_num_args = c->m_num_args;
m_oreg = c->m_oreg;
for (unsigned i = 0; i < m_num_args; i++)
for (unsigned i = 0; i < m_num_args; ++i)
m_registers[m_oreg+i] = m_app->get_arg(i);
m_pc = c->m_next;
goto main_loop;
@ -3061,7 +3061,7 @@ namespace {
void display(std::ostream & out, unsigned indent) {
path_tree * curr = this;
while (curr != nullptr) {
for (unsigned i = 0; i < indent; i++) out << " ";
for (unsigned i = 0; i < indent; ++i) out << " ";
out << curr->m_label->get_name() << ":" << curr->m_arg_idx;
if (curr->m_ground_arg)
out << ":#" << curr->m_ground_arg->get_owner_id() << ":" << curr->m_ground_arg_idx;
@ -3207,7 +3207,7 @@ namespace {
void update_children_plbls(enode * app, unsigned char elem) {
unsigned num_args = app->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
enode * c = app->get_arg(i);
approx_set & r_plbls = c->get_root()->get_plbls();
if (!r_plbls.may_contain(elem)) {
@ -3243,8 +3243,8 @@ namespace {
}
void reset_pp_pc() {
for (unsigned i = 0; i < APPROX_SET_CAPACITY; i++) {
for (unsigned j = 0; j < APPROX_SET_CAPACITY; j++) {
for (unsigned i = 0; i < APPROX_SET_CAPACITY; ++i) {
for (unsigned j = 0; j < APPROX_SET_CAPACITY; ++j) {
m_pp[i][j].first = 0;
m_pp[i][j].second = 0;
m_pc[i][j] = nullptr;
@ -3409,7 +3409,7 @@ namespace {
enode * get_ground_arg(app * pat, quantifier * qa, unsigned & pos) {
pos = 0;
unsigned num_args = pat->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = pat->get_arg(i);
if (is_ground(arg)) {
pos = i;
@ -3429,7 +3429,7 @@ namespace {
unsigned ground_arg_pos = 0;
enode * ground_arg = get_ground_arg(pat, qa, ground_arg_pos);
func_decl * plbl = pat->get_decl();
for (unsigned short i = 0; i < num_args; i++) {
for (unsigned short i = 0; i < num_args; ++i) {
expr * child = pat->get_arg(i);
path * new_path = new (m_tmp_region) path(plbl, i, ground_arg_pos, ground_arg, pat_idx, p);
@ -3471,7 +3471,7 @@ namespace {
unsigned num_vars = qa->get_num_decls();
if (num_vars >= m_var_paths.size())
m_var_paths.resize(num_vars+1);
for (unsigned i = 0; i < num_vars; i++)
for (unsigned i = 0; i < num_vars; ++i)
m_var_paths[i].reset();
m_tmp_region.reset();
// Given a multi-pattern (p_1, ..., p_n)
@ -3481,15 +3481,15 @@ namespace {
// ...
// (p_n, p_2, ..., p_1)
unsigned num_patterns = mp->get_num_args();
for (unsigned i = 0; i < num_patterns; i++) {
for (unsigned i = 0; i < num_patterns; ++i) {
app * pat = to_app(mp->get_arg(i));
update_filters(pat, nullptr, qa, mp, i);
}
}
void display_filter_info(std::ostream & out) {
for (unsigned i = 0; i < APPROX_SET_CAPACITY; i++) {
for (unsigned j = 0; j < APPROX_SET_CAPACITY; j++) {
for (unsigned i = 0; i < APPROX_SET_CAPACITY; ++i) {
for (unsigned j = 0; j < APPROX_SET_CAPACITY; ++j) {
if (m_pp[i][j].first) {
out << "pp[" << i << "][" << j << "]:\n";
m_pp[i][j].first->display(out, 1);
@ -3778,7 +3778,7 @@ namespace {
void collect_ground_exprs(quantifier * qa, app * mp) {
ptr_buffer<app> todo;
unsigned num_patterns = mp->get_num_args();
for (unsigned i = 0; i < num_patterns; i++) {
for (unsigned i = 0; i < num_patterns; ++i) {
app * pat = to_app(mp->get_arg(i));
TRACE(mam_pat, tout << mk_ismt2_pp(qa, m) << "\npat:\n" << mk_ismt2_pp(pat, m) << "\n";);
SASSERT(!pat->is_ground());
@ -3794,7 +3794,7 @@ namespace {
}
else {
unsigned num_args = n->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = n->get_arg(i);
if (is_app(arg))
todo.push_back(to_app(arg));
@ -3834,7 +3834,7 @@ namespace {
// However, the simplifier may turn a non-ground pattern into a ground one.
// So, we should check it again here.
unsigned num_patterns = mp->get_num_args();
for (unsigned i = 0; i < num_patterns; i++)
for (unsigned i = 0; i < num_patterns; ++i)
if (is_ground(mp->get_arg(i)))
return; // ignore multi-pattern containing ground pattern.
update_filters(qa, mp);
@ -3844,7 +3844,7 @@ namespace {
// e-matching. So, for a multi-pattern [ p_1, ..., p_n ],
// we have to make n insertions. In the i-th insertion,
// the pattern p_i is assumed to be the first one.
for (unsigned i = 0; i < num_patterns; i++)
for (unsigned i = 0; i < num_patterns; ++i)
m_trees.add_pattern(qa, mp, i);
}
@ -3933,7 +3933,7 @@ namespace {
if (!m_context.slow_contains_instance(qa, num_bindings, bindings)) {
TRACE(missing_instance,
tout << "qa:\n" << mk_ll_pp(qa, m) << "\npat:\n" << mk_ll_pp(pat, m);
for (unsigned i = 0; i < num_bindings; i++)
for (unsigned i = 0; i < num_bindings; ++i)
tout << "#" << bindings[i]->get_expr_id() << "\n" << mk_ll_pp(bindings[i]->get_expr(), m) << "\n";
);
UNREACHABLE();
@ -3941,7 +3941,7 @@ namespace {
return;
}
DEBUG_CODE(
for (unsigned i = 0; i < num_bindings; i++) {
for (unsigned i = 0; i < num_bindings; ++i) {
SASSERT(bindings[i]->get_generation() <= max_generation);
});