3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-23 16:57:51 +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

@ -276,7 +276,7 @@ bool macro_finder::expand_macros(expr_ref_vector const& exprs, proof_ref_vector
unsigned num = exprs.size();
bool deps_valid = deps.size() == exprs.size();
SASSERT(deps_valid || deps.empty());
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * n = exprs[i];
proof * pr = m.proofs_enabled() ? prs[i] : nullptr;
expr_dependency * dep = deps.get(i, nullptr);
@ -345,7 +345,7 @@ bool macro_finder::expand_macros(unsigned num, justified_expr const * fmls, vect
TRACE(macro_finder, tout << "starting expand_macros:\n";
m_macro_manager.display(tout););
bool found_new_macro = false;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * n = fmls[i].fml();
proof * pr = m.proofs_enabled() ? fmls[i].pr() : nullptr;
expr_ref new_n(m), def(m);

View file

@ -58,7 +58,7 @@ void macro_manager::pop_scope(unsigned num_scopes) {
void macro_manager::restore_decls(unsigned old_sz) {
unsigned sz = m_decls.size();
for (unsigned i = old_sz; i < sz; i++) {
for (unsigned i = old_sz; i < sz; ++i) {
m_decl2macro.erase(m_decls.get(i));
m_deps.erase(m_decls.get(i));
if (m.proofs_enabled())
@ -74,7 +74,7 @@ void macro_manager::restore_decls(unsigned old_sz) {
void macro_manager::restore_forbidden(unsigned old_sz) {
unsigned sz = m_forbidden.size();
for (unsigned i = old_sz; i < sz; i++)
for (unsigned i = old_sz; i < sz; ++i)
m_forbidden_set.erase(m_forbidden.get(i));
m_forbidden.shrink(old_sz);
}
@ -176,7 +176,7 @@ namespace macro_manager_ns {
void macro_manager::mark_forbidden(unsigned n, justified_expr const * exprs) {
expr_mark visited;
macro_manager_ns::proc p(m_forbidden_set, m_forbidden);
for (unsigned i = 0; i < n; i++)
for (unsigned i = 0; i < n; ++i)
for_each_expr(p, visited, exprs[i].fml());
}
@ -203,7 +203,7 @@ void macro_manager::get_head_def(quantifier * q, func_decl * d, app * & head, ex
void macro_manager::display(std::ostream & out) {
unsigned sz = m_decls.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
func_decl * f = m_decls.get(i);
quantifier * q = nullptr;
m_decl2macro.find(f, q);
@ -267,11 +267,11 @@ struct macro_manager::macro_expander_cfg : public default_rewriter_cfg {
// So, I'm just erasing them.
bool erase_patterns = false;
for (unsigned i = 0; !erase_patterns && i < old_q->get_num_patterns(); i++) {
for (unsigned i = 0; !erase_patterns && i < old_q->get_num_patterns(); ++i) {
if (old_q->get_pattern(i) != new_patterns[i])
erase_patterns = true;
}
for (unsigned i = 0; !erase_patterns && i < old_q->get_num_no_patterns(); i++) {
for (unsigned i = 0; !erase_patterns && i < old_q->get_num_no_patterns(); ++i) {
if (old_q->get_no_pattern(i) != new_no_patterns[i])
erase_patterns = true;
}
@ -301,7 +301,7 @@ struct macro_manager::macro_expander_cfg : public default_rewriter_cfg {
TRACE(macro_manager, tout << "expanding: " << mk_pp(n, m) << "\n" << mk_pp(head, m) << " " << mk_pp(def, m) << "\n";);
ptr_buffer<expr> subst_args;
subst_args.resize(num, 0);
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
var * v = to_var(head->get_arg(i));
if (v->get_idx() >= num)
return false;

View file

@ -143,7 +143,7 @@ bool macro_util::is_macro_head(expr * n, unsigned num_decls) const {
to_app(n)->get_num_args() == num_decls) {
sbuffer<int> var2pos;
var2pos.resize(num_decls, -1);
for (unsigned i = 0; i < num_decls; i++) {
for (unsigned i = 0; i < num_decls; ++i) {
expr * c = to_app(n)->get_arg(i);
if (!is_var(c))
return false;
@ -252,7 +252,7 @@ bool macro_util::poly_contains_head(expr * n, func_decl * f, expr * exception) c
num_args = 1;
args = &n;
}
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = args[i];
if (arg != exception && occurs(f, arg))
return true;
@ -283,7 +283,7 @@ bool macro_util::is_arith_macro(expr * n, unsigned num_decls, app_ref & head, ex
lhs_num_args = 1;
lhs_args = &lhs;
}
for (unsigned i = 0; i < lhs_num_args; i++) {
for (unsigned i = 0; i < lhs_num_args; ++i) {
expr * arg = lhs_args[i];
expr * neg_arg;
if (h == nullptr &&
@ -392,7 +392,7 @@ bool macro_util::is_quasi_macro_head(expr * n, unsigned num_decls) const {
sbuffer<bool> found_vars;
found_vars.resize(num_decls, false);
unsigned num_found_vars = 0;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = to_app(n)->get_arg(i);
if (is_var(arg)) {
unsigned idx = to_var(arg)->get_idx();
@ -429,7 +429,7 @@ bool macro_util::is_quasi_macro_ok(expr * n, unsigned num_decls, expr * def) con
}
if (def)
fv.accumulate(def);
for (unsigned i = 0; i < fv.size(); i++) {
for (unsigned i = 0; i < fv.size(); ++i) {
if (i >= num_decls || !fv.contains(i))
continue; // Quasi-macros may have new variables.
if (found_vars[i] == false) {
@ -453,7 +453,7 @@ void macro_util::quasi_macro_head_to_macro_head(app * qhead, unsigned & num_decl
ptr_buffer<expr> new_args;
ptr_buffer<expr> new_conds;
unsigned next_var_idx = num_decls;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = qhead->get_arg(i);
if (is_var(arg)) {
unsigned idx = to_var(arg)->get_idx();
@ -508,7 +508,7 @@ void macro_util::normalize_expr(app * head, unsigned num_decls, expr * t, expr_r
TRACE(macro_util,
tout << "head: " << mk_pp(head, m) << "\n";
tout << "applying substitution to:\n" << mk_bounded_pp(t, m) << "\n";);
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
var * v = to_var(head->get_arg(i));
unsigned vi = v->get_idx();
SASSERT(vi < num_decls);
@ -527,7 +527,7 @@ void macro_util::normalize_expr(app * head, unsigned num_decls, expr * t, expr_r
TRACE(macro_util,
tout << "head: " << mk_pp(head, m) << "\n";
tout << "applying substitution to:\n" << mk_ll_pp(t, m) << "\nsubstitution:\n";
for (unsigned i = 0; i < var_mapping.size(); i++) {
for (unsigned i = 0; i < var_mapping.size(); ++i) {
if (var_mapping[i] != 0)
tout << "#" << i << " -> " << mk_ll_pp(var_mapping[i], m);
});
@ -652,7 +652,7 @@ bool macro_util::is_poly_hint(expr * n, app * head, expr * exception) {
num_args = 1;
args = &n;
}
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = args[i];
if (arg != exception && (occurs(f, arg) || !vars_of_is_subset(arg, vars))) {
TRACE(macro_util, tout << "failed because of:\n" << mk_pp(arg, m) << "\n";);
@ -744,7 +744,7 @@ bool macro_util::rest_contains_decl(func_decl * f, expr * except_lit) {
return false;
SASSERT(is_clause(m, m_curr_clause));
unsigned num_lits = get_clause_num_literals(m, m_curr_clause);
for (unsigned i = 0; i < num_lits; i++) {
for (unsigned i = 0; i < num_lits; ++i) {
expr * l = get_clause_literal(m, m_curr_clause, i);
if (l != except_lit && occurs(f, l))
return true;
@ -758,7 +758,7 @@ void macro_util::get_rest_clause_as_cond(expr * except_lit, expr_ref & extra_con
SASSERT(is_clause(m, m_curr_clause));
expr_ref_buffer neg_other_lits(m);
unsigned num_lits = get_clause_num_literals(m, m_curr_clause);
for (unsigned i = 0; i < num_lits; i++) {
for (unsigned i = 0; i < num_lits; ++i) {
expr * l = get_clause_literal(m, m_curr_clause, i);
if (l != except_lit) {
expr_ref neg_l(m);
@ -783,7 +783,7 @@ void macro_util::collect_poly_args(expr * n, expr * exception, ptr_buffer<expr>
num_args = 1;
_args = &n;
}
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = _args[i];
if (arg != exception)
args.push_back(arg);
@ -811,7 +811,7 @@ void macro_util::collect_arith_macro_candidates(expr * lhs, expr * rhs, expr * a
lhs_num_args = 1;
lhs_args = &lhs;
}
for (unsigned i = 0; i < lhs_num_args; i++) {
for (unsigned i = 0; i < lhs_num_args; ++i) {
expr * arg = lhs_args[i];
expr * neg_arg;
if (!is_app(arg))
@ -967,7 +967,7 @@ void macro_util::collect_macro_candidates(quantifier * q, macro_candidates & r)
if (is_clause(m, n)) {
m_curr_clause = n;
unsigned num_lits = get_clause_num_literals(m, n);
for (unsigned i = 0; i < num_lits; i++)
for (unsigned i = 0; i < num_lits; ++i)
collect_macro_candidates_core(get_clause_literal(m, n, i), num_decls, r);
m_curr_clause = nullptr;
}

View file

@ -36,7 +36,7 @@ void quantifier_macro_info::collect_macro_candidates(quantifier* q) {
qa = m.update_quantifier(q, quantifier_kind::forall_k, m.mk_not(q->get_expr()));
mutil.collect_macro_candidates(qa, candidates);
unsigned num_candidates = candidates.size();
for (unsigned i = 0; i < num_candidates; i++) {
for (unsigned i = 0; i < num_candidates; ++i) {
cond_macro* mc = alloc(cond_macro, m, candidates.get_f(i), candidates.get_def(i), candidates.get_cond(i),
candidates.ineq(i), candidates.satisfy_atom(i), candidates.hint(i), q->get_weight());
insert_macro(mc);

View file

@ -89,7 +89,7 @@ public:
void operator()(quantifier * n) {}
void operator()(app * n) {}
bool all_used() {
for (unsigned i = 0; i < m_bitset.size() ; i++)
for (unsigned i = 0; i < m_bitset.size() ; ++i)
if (!m_bitset.get(i))
return false;
return true;
@ -111,7 +111,7 @@ bool quasi_macros::fully_depends_on(app * a, quantifier * q) const {
if (is_var(arg))
bitset.set(to_var(arg)->get_idx(), true);
for (unsigned i = 0; i < bitset.size() ; i++)
for (unsigned i = 0; i < bitset.size() ; ++i)
if (!bitset.get(i))
return false;
@ -249,7 +249,7 @@ bool quasi_macros::quasi_macro_to_macro(quantifier * q, app * a, expr * t, quant
}
// We want to keep all the old variables [already reversed]
for (unsigned i = 0 ; i < q->get_num_decls() ; i++) {
for (unsigned i = 0 ; i < q->get_num_decls() ; ++i) {
new_var_names_rev.push_back(q->get_decl_name(i));
new_qsorts_rev.push_back(q->get_decl_sort(i));
}
@ -274,14 +274,14 @@ bool quasi_macros::quasi_macro_to_macro(quantifier * q, app * a, expr * t, quant
bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
TRACE(quasi_macros, tout << "Finding quasi-macros in: " << std::endl;
for (unsigned i = 0 ; i < n ; i++)
for (unsigned i = 0 ; i < n ; ++i)
tout << i << ": " << mk_pp(exprs[i], m) << std::endl; );
bool res = false;
m_occurrences.reset();
// Find out how many non-ground appearances for each uninterpreted function there are
for (unsigned i = 0 ; i < n ; i++)
for (unsigned i = 0 ; i < n ; ++i)
find_occurrences(exprs[i]);
TRACE(quasi_macros,
@ -290,7 +290,7 @@ bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
tout << kd.m_key->get_name() << ": " << kd.m_value << std::endl; );
// Find all macros
for (unsigned i = 0 ; i < n ; i++) {
for (unsigned i = 0 ; i < n ; ++i) {
app_ref a(m);
expr_ref t(m);
quantifier_ref macro(m);
@ -312,14 +312,14 @@ bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
TRACE(quasi_macros, tout << "Finding quasi-macros in: " << std::endl;
for (unsigned i = 0; i < n; i++)
for (unsigned i = 0; i < n; ++i)
tout << i << ": " << mk_pp(exprs[i].fml(), m) << std::endl; );
bool res = false;
m_occurrences.reset();
// Find out how many non-ground appearances for each uninterpreted function there are
for (unsigned i = 0 ; i < n ; i++)
for (unsigned i = 0 ; i < n ; ++i)
find_occurrences(exprs[i].fml());
TRACE(quasi_macros, tout << "Occurrences: " << std::endl;
@ -327,7 +327,7 @@ bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
tout << kv.m_key->get_name() << ": " << kv.m_value << std::endl; );
// Find all macros
for (unsigned i = 0 ; i < n ; i++) {
for (unsigned i = 0 ; i < n ; ++i) {
app_ref a(m);
expr_ref t(m);
quantifier_ref macro(m);
@ -348,7 +348,7 @@ bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
void quasi_macros::apply_macros(expr_ref_vector & exprs, proof_ref_vector & prs, expr_dependency_ref_vector& deps) {
unsigned n = exprs.size();
for (unsigned i = 0 ; i < n ; i++ ) {
for (unsigned i = 0 ; i < n ; ++i ) {
expr_ref r(m), rr(m);
proof_ref pr(m), prr(m);
expr_dependency_ref dep(m);
@ -374,7 +374,7 @@ bool quasi_macros::operator()(expr_ref_vector & exprs, proof_ref_vector & prs, e
}
void quasi_macros::apply_macros(unsigned n, justified_expr const* fmls, vector<justified_expr>& new_fmls) {
for (unsigned i = 0 ; i < n ; i++) {
for (unsigned i = 0 ; i < n ; ++i) {
expr_ref r(m), rr(m);
proof_ref pr(m), prr(m);
proof * p = m.proofs_enabled() ? fmls[i].pr() : nullptr;
@ -394,7 +394,7 @@ bool quasi_macros::operator()(unsigned n, justified_expr const* fmls, vector<jus
}
else {
// just copy them over
for (unsigned i = 0 ; i < n ; i++ ) {
for (unsigned i = 0 ; i < n ; ++i ) {
new_fmls.push_back(fmls[i]);
}
return false;