3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-01 21:08:55 +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

@ -591,7 +591,7 @@ struct cofactor_elim_term_ite::imp {
bool has_new_args = false;
bool has_term_ite = false;
unsigned num = to_app(t)->get_num_args();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * arg = to_app(t)->get_arg(i);
expr * new_arg = nullptr;
TRACE(cofactor_bug, tout << "collecting child: " << arg->get_id() << "\n";);

View file

@ -80,7 +80,7 @@ void collect_occs::process(expr * t) {
void collect_occs::operator()(goal const & g, obj_hashtable<expr> & r) {
unsigned sz = g.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr * t = g.form(i);
process(t);
}

View file

@ -70,7 +70,7 @@ public:
collect_proc cp(m, m_stats);
expr_mark visited;
const unsigned sz = g->size();
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
for_each_expr(cp, visited, g->form(i));
std::cout << "(\n";
@ -157,7 +157,7 @@ protected:
}
void operator()(func_decl * f) {
for (unsigned i = 0; i < f->get_arity(); i++)
for (unsigned i = 0; i < f->get_arity(); ++i)
this->operator()(f->get_domain()[i]);
this->operator()(f->get_range());

View file

@ -179,7 +179,7 @@ struct ctx_simplify_tactic::imp {
restore_cache(0);
dealloc(m_simp);
DEBUG_CODE({
for (unsigned i = 0; i < m_cache.size(); i++) {
for (unsigned i = 0; i < m_cache.size(); ++i) {
CTRACE(ctx_simplify_tactic_bug, m_cache[i].m_from,
tout << "i: " << i << "\n" << mk_ismt2_pp(m_cache[i].m_from, m) << "\n";
tout << "m_result: " << m_cache[i].m_result << "\n";
@ -210,7 +210,7 @@ struct ctx_simplify_tactic::imp {
}
bool check_cache() {
for (unsigned i = 0; i < m_cache.size(); i++) {
for (unsigned i = 0; i < m_cache.size(); ++i) {
cache_cell & cell = m_cache[i];
if (cell.m_from != nullptr) {
SASSERT(cell.m_result != 0);
@ -294,7 +294,7 @@ struct ctx_simplify_tactic::imp {
m_simp->pop(num_scopes);
// restore cache
for (unsigned i = 0; i < num_scopes; i++) {
for (unsigned i = 0; i < num_scopes; ++i) {
restore_cache(lvl);
lvl--;
}
@ -354,7 +354,7 @@ struct ctx_simplify_tactic::imp {
unsigned old_lvl = scope_level();
bool modified = false;
unsigned num_args = t->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = t->get_arg(i);
expr_ref new_arg(m);
simplify(arg, new_arg);
@ -479,7 +479,7 @@ struct ctx_simplify_tactic::imp {
expr_ref_buffer new_args(m);
bool modified = false;
unsigned num_args = t->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = t->get_arg(i);
expr_ref new_arg(m);
simplify(arg, new_arg);

View file

@ -108,7 +108,7 @@ class elim_term_ite_tactic : public tactic {
expr_ref new_curr(m);
proof_ref new_pr(m);
unsigned size = g->size();
for (unsigned idx = 0; idx < size; idx++) {
for (unsigned idx = 0; idx < size; ++idx) {
expr * curr = g->form(idx);
m_rw(curr, new_curr, new_pr);
if (produce_proofs) {

View file

@ -82,7 +82,7 @@ class elim_uncnstr_tactic : public tactic {
}
bool uncnstr(unsigned num, expr * const * args) const {
for (unsigned i = 0; i < num; i++)
for (unsigned i = 0; i < num; ++i)
if (!uncnstr(args[i]))
return false;
return true;
@ -130,7 +130,7 @@ class elim_uncnstr_tactic : public tactic {
void add_defs(unsigned num, expr * const * args, expr * u, expr * identity) {
if (m_mc) {
add_def(args[0], u);
for (unsigned i = 1; i < num; i++)
for (unsigned i = 1; i < num; ++i)
add_def(args[i], identity);
}
}
@ -155,7 +155,7 @@ class elim_uncnstr_tactic : public tactic {
if (m().is_uninterp(get_array_range(s)))
return false;
unsigned arity = get_array_arity(s);
for (unsigned i = 0; i < arity; i++)
for (unsigned i = 0; i < arity; ++i)
if (m().is_uninterp(get_array_domain(s, i)))
return false;
// building
@ -164,7 +164,7 @@ class elim_uncnstr_tactic : public tactic {
// and d is a term different from (select t i1 ... in)
ptr_buffer<expr> new_args;
new_args.push_back(t);
for (unsigned i = 0; i < arity; i++)
for (unsigned i = 0; i < arity; ++i)
new_args.push_back(m().get_some_value(get_array_domain(s, i)));
expr_ref sel(m());
sel = m().mk_app(fid, OP_SELECT, new_args.size(), new_args.data());
@ -182,7 +182,7 @@ class elim_uncnstr_tactic : public tactic {
for (func_decl * constructor : constructors) {
unsigned num = constructor->get_arity();
unsigned target = UINT_MAX;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
sort * s_arg = constructor->get_domain(i);
if (s == s_arg) {
target = i;
@ -195,7 +195,7 @@ class elim_uncnstr_tactic : public tactic {
continue;
// use the constructor the distinct term constructor(...,t,...)
ptr_buffer<expr> new_args;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
if (i == target) {
new_args.push_back(t);
}
@ -403,7 +403,7 @@ class elim_uncnstr_tactic : public tactic {
return nullptr;
unsigned i;
expr * v = nullptr;
for (i = 0; i < num; i++) {
for (i = 0; i < num; ++i) {
expr * arg = args[i];
if (uncnstr(arg)) {
v = arg;
@ -418,7 +418,7 @@ class elim_uncnstr_tactic : public tactic {
if (!m_mc)
return u;
ptr_buffer<expr> new_args;
for (unsigned j = 0; j < num; j++) {
for (unsigned j = 0; j < num; ++j) {
if (j == i)
continue;
new_args.push_back(args[j]);
@ -775,7 +775,7 @@ class elim_uncnstr_tactic : public tactic {
return r;
}
func_decl * c = m_dt_util.get_accessor_constructor(f);
for (unsigned i = 0; i < c->get_arity(); i++)
for (unsigned i = 0; i < c->get_arity(); ++i)
if (!m().is_fully_interp(c->get_domain(i)))
return nullptr;
app * u;
@ -783,7 +783,7 @@ class elim_uncnstr_tactic : public tactic {
return u;
ptr_vector<func_decl> const & accs = *m_dt_util.get_constructor_accessors(c);
ptr_buffer<expr> new_args;
for (unsigned i = 0; i < accs.size(); i++) {
for (unsigned i = 0; i < accs.size(); ++i) {
if (accs[i] == f)
new_args.push_back(u);
else
@ -841,7 +841,7 @@ class elim_uncnstr_tactic : public tactic {
if (fid == null_family_id)
return BR_FAILED;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
if (!is_ground(args[i]))
return BR_FAILED; // non-ground terms are not handled.
}
@ -932,7 +932,7 @@ class elim_uncnstr_tactic : public tactic {
unsigned size = g->size();
unsigned idx = 0;
while (true) {
for (; idx < size; idx++) {
for (; idx < size; ++idx) {
expr * f = g->form(idx);
m_rw->operator()(f, new_f, new_pr);
if (f == new_f)

View file

@ -70,7 +70,7 @@ public:
proof_ref new_pr(m);
unsigned sz = g->size();
for (unsigned i = 0; !g->inconsistent() && i < sz; i++) {
for (unsigned i = 0; !g->inconsistent() && i < sz; ++i) {
expr * curr = g->form(i);
local_nnf(curr, defs, def_prs, new_curr, new_pr);
if (produce_proofs) {
@ -81,7 +81,7 @@ public:
}
sz = defs.size();
for (unsigned i = 0; !g->inconsistent() && i < sz; i++) {
for (unsigned i = 0; !g->inconsistent() && i < sz; ++i) {
if (produce_proofs)
g->assert_expr(defs.get(i), def_prs.get(i), nullptr);
else
@ -93,7 +93,7 @@ public:
if (num_extra_names > 0 && !g->inconsistent()) {
generic_model_converter * fmc = alloc(generic_model_converter, m, "nnf");
g->add(fmc);
for (unsigned i = 0; i < num_extra_names; i++)
for (unsigned i = 0; i < num_extra_names; ++i)
fmc->hide(dnames.get_name_decl(i));
}
}

View file

@ -51,7 +51,7 @@ class occf_tactic : public tactic {
SASSERT(m.is_or(cls));
bool found = false;
unsigned num = cls->get_num_args();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
if (is_constraint(cls->get_arg(i))) {
if (found)
return true;
@ -138,7 +138,7 @@ class occf_tactic : public tactic {
cnstr2bvar c2b;
unsigned sz = g->size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
checkpoint();
expr * f = g->form(i);
expr_dependency * d = g->dep(i);
@ -154,7 +154,7 @@ class occf_tactic : public tactic {
expr * keep = nullptr;
new_lits.reset();
unsigned num = cls->get_num_args();
for (unsigned j = 0; j < num; j++) {
for (unsigned j = 0; j < num; ++j) {
expr * l = cls->get_arg(j);
if (is_constraint(l)) {
expr * new_l = get_aux_lit(c2b, l, g);

View file

@ -159,7 +159,7 @@ class propagate_values_tactic : public tactic {
while (true) {
TRACE(propagate_values, tout << "while(true) loop\n"; m_goal->display_with_dependencies(tout););
if (forward) {
for (; m_idx < size; m_idx++) {
for (; m_idx < size; ++m_idx) {
process_current();
if (m_goal->inconsistent())
goto end;

View file

@ -146,7 +146,7 @@ class reduce_args_tactic : public tactic {
find_non_candidates_proc proc(m, m_bv, m_ar, non_candidates);
expr_fast_mark1 visited;
unsigned sz = g.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
checkpoint();
quick_for_each_expr(proc, visited, g.form(i));
}
@ -210,7 +210,7 @@ class reduce_args_tactic : public tactic {
decl2args.reset();
populate_decl2args_proc proc(m, m_bv, non_candidates, decl2args);
unsigned sz = g.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
checkpoint();
quick_for_each_expr(proc, visited, g.form(i));
}
@ -219,7 +219,7 @@ class reduce_args_tactic : public tactic {
ptr_buffer<func_decl> bad_decls;
for (auto const& [k, v] : decl2args) {
bool is_zero = true;
for (unsigned i = 0; i < v.size() && is_zero; i++) {
for (unsigned i = 0; i < v.size() && is_zero; ++i) {
if (v.get(i))
is_zero = false;
}
@ -247,7 +247,7 @@ class reduce_args_tactic : public tactic {
// compute the hash-code using only the arguments where m_bv is true.
unsigned a = 0x9e3779b9;
unsigned num_args = n->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
if (!m_bv.get(i))
continue; // ignore argument
a = hash_u_u(a, n->get_arg(i)->get_id());
@ -264,7 +264,7 @@ class reduce_args_tactic : public tactic {
// compare only the arguments where m_bv is true
SASSERT(n1->get_num_args() == n2->get_num_args());
unsigned num_args = n1->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
if (!m_bv.get(i))
continue; // ignore argument
if (n1->get_arg(i) != n2->get_arg(i))
@ -348,7 +348,7 @@ class reduce_args_tactic : public tactic {
}
ptr_buffer<expr> new_args;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
if (!bv.get(i))
new_args.push_back(args[i]);
}
@ -381,7 +381,7 @@ class reduce_args_tactic : public tactic {
bit_vector & bv = decl2args.find(f);
new_vars.reset();
new_args.reset();
for (unsigned i = 0; i < f->get_arity(); i++) {
for (unsigned i = 0; i < f->get_arity(); ++i) {
new_vars.push_back(m.mk_var(i, f->get_domain(i)));
if (!bv.get(i))
new_args.push_back(new_vars.back());
@ -394,7 +394,7 @@ class reduce_args_tactic : public tactic {
}
else {
new_eqs.reset();
for (unsigned i = 0; i < f->get_arity(); i++) {
for (unsigned i = 0; i < f->get_arity(); ++i) {
if (bv.get(i))
new_eqs.push_back(m.mk_eq(new_vars.get(i), t->get_arg(i)));
}

View file

@ -51,7 +51,7 @@ struct simplify_tactic::imp {
expr_ref new_curr(m());
proof_ref new_pr(m());
unsigned size = g.size();
for (unsigned idx = 0; idx < size; idx++) {
for (unsigned idx = 0; idx < size; ++idx) {
if (g.inconsistent())
break;
expr * curr = g.form(idx);

View file

@ -128,7 +128,7 @@ void special_relations_tactic::operator()(goal_ref const & g, goal_ref_buffer &
initialize();
obj_map<func_decl, sp_axioms> goal_features;
unsigned size = g->size();
for (unsigned idx = 0; idx < size; idx++) {
for (unsigned idx = 0; idx < size; ++idx) {
collect_feature(*g, idx, goal_features);
}
special_relations_util u(m);
@ -159,7 +159,7 @@ void special_relations_tactic::operator()(goal_ref const & g, goal_ref_buffer &
}
}
if (!replace.empty()) {
for (unsigned idx = 0; idx < size; idx++) {
for (unsigned idx = 0; idx < size; ++idx) {
if (to_delete.contains(idx)) {
g->update(idx, m.mk_true());
}

View file

@ -28,7 +28,7 @@ class split_clause_tactic : public tactic {
unsigned result_idx = UINT_MAX;
unsigned len = 0;
unsigned sz = in->size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr * f = in->form(i);
if (m.is_or(f)) {
unsigned curr_len = to_app(f)->get_num_args();
@ -61,7 +61,7 @@ class split_clause_tactic : public tactic {
SASSERT(num_source == m_clause->get_num_args());
proof_ref_buffer prs(m);
prs.push_back(m_clause_pr);
for (unsigned i = 0; i < num_source; i++) {
for (unsigned i = 0; i < num_source; ++i) {
proof * pr_i = source[i];
expr * not_li = m.mk_not(m_clause->get_arg(i));
prs.push_back(m.mk_lemma(pr_i, not_li));

View file

@ -664,14 +664,14 @@ class tseitin_cnf_tactic : public tactic {
bool visited = true;
unsigned num = t->get_num_args();
unsigned blowup = 1;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * a = t->get_arg(i);
expr * a0;
if (m_distributivity && m.is_not(a, a0) && m.is_or(a0) && !is_shared(a0)) {
unsigned num2 = to_app(a0)->get_num_args();
if (num2 < m_distributivity_blowup && blowup * num2 < m_distributivity_blowup && blowup < blowup * num2) {
blowup *= num2;
for (unsigned j = 0; j < num2; j++)
for (unsigned j = 0; j < num2; ++j)
visit(to_app(a0)->get_arg(j), visited);
continue;
}
@ -693,7 +693,7 @@ class tseitin_cnf_tactic : public tactic {
bool distributivity = false;
if (m_distributivity) {
// check if need to apply distributivity
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * a = t->get_arg(i);
expr * a0;
if (m.is_not(a, a0) && m.is_or(a0) && !is_shared(a0) && to_app(a0)->get_num_args() < m_distributivity_blowup) {
@ -706,7 +706,7 @@ class tseitin_cnf_tactic : public tactic {
if (!distributivity) {
// easy case
expr_ref_buffer lits(m); expr_ref l(m);
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
get_lit(t->get_arg(i), false, l);
lits.push_back(l);
}
@ -714,7 +714,7 @@ class tseitin_cnf_tactic : public tactic {
mk_clause(lits.size(), lits.data());
}
else {
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
inv(lits[i], l);
mk_clause(l, k);
}
@ -728,7 +728,7 @@ class tseitin_cnf_tactic : public tactic {
sbuffer<unsigned> it;
sbuffer<unsigned> offsets;
unsigned blowup = 1;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
it.push_back(0);
offsets.push_back(buffer.size());
expr * a = t->get_arg(i);
@ -739,7 +739,7 @@ class tseitin_cnf_tactic : public tactic {
szs.push_back(num2);
blowup *= num2;
expr_ref_buffer lits(m);
for (unsigned j = 0; j < num2; j++) {
for (unsigned j = 0; j < num2; ++j) {
get_lit(to_app(a0)->get_arg(j), true, nl);
buffer.push_back(nl);
if (!root) {
@ -766,12 +766,12 @@ class tseitin_cnf_tactic : public tactic {
sbuffer<expr**> arg_lits;
ptr_buffer<expr> lits;
expr ** buffer_ptr = buffer.data();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
arg_lits.push_back(buffer_ptr + offsets[i]);
}
do {
lits.reset();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
lits.push_back(arg_lits[i][it[i]]);
}
if (!root)
@ -863,7 +863,7 @@ class tseitin_cnf_tactic : public tactic {
g->reset();
unsigned sz = m_clauses.size();
expr_fast_mark1 added;
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr * cls = m_clauses.get(i);
if (added.is_marked(cls))
continue;