3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-03 22:06:11 +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 GitHub
parent 1bf463d77a
commit 2436943794
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
475 changed files with 3237 additions and 3237 deletions

View file

@ -53,12 +53,12 @@ struct bit_blaster_model_converter : public model_converter {
void collect_bits(obj_hashtable<func_decl> & bits) {
unsigned sz = m_bits.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr * bs = m_bits.get(i);
SASSERT(!TO_BOOL || is_app_of(bs, m().get_family_id("bv"), OP_MKBV));
SASSERT(TO_BOOL || is_app_of(bs, m().get_family_id("bv"), OP_CONCAT));
unsigned num_args = to_app(bs)->get_num_args();
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
expr * bit = to_app(bs)->get_arg(j);
SASSERT(!TO_BOOL || m().is_bool(bit));
SASSERT(TO_BOOL || is_sort_of(bit->get_sort(), m().get_family_id("bv"), BV_SORT));
@ -77,7 +77,7 @@ struct bit_blaster_model_converter : public model_converter {
void copy_non_bits(obj_hashtable<func_decl> & bits, model * old_model, model * new_model) {
unsigned num = old_model->get_num_constants();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
func_decl * f = old_model->get_constant(i);
if (bits.contains(f))
continue;
@ -97,7 +97,7 @@ struct bit_blaster_model_converter : public model_converter {
rational two(2);
SASSERT(m_vars.size() == m_bits.size());
unsigned sz = m_vars.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr* new_val = old_model->get_const_interp(m_vars.get(i));
if (new_val) {
new_model->register_decl(m_vars.get(i), new_val);
@ -125,7 +125,7 @@ struct bit_blaster_model_converter : public model_converter {
}
else {
SASSERT(is_app_of(bs, m().get_family_id("bv"), OP_CONCAT));
for (unsigned j = 0; j < bv_sz; j++) {
for (unsigned j = 0; j < bv_sz; ++j) {
val *= two;
expr * bit = to_app(bs)->get_arg(j);
SASSERT(util.is_bv(bit));
@ -196,7 +196,7 @@ struct bit_blaster_model_converter : public model_converter {
for (func_decl * f : m_newbits)
display_del(out, f);
unsigned sz = m_vars.size();
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
display_add(out, m(), m_vars.get(i), m_bits.get(i));
}
@ -216,7 +216,7 @@ struct bit_blaster_model_converter : public model_converter {
if (!util.is_numeral(value, r))
continue;
unsigned sz = m_vars.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if (m_vars.get(i) != to_app(var)->get_decl())
continue;
unsigned k = 0;

View file

@ -67,7 +67,7 @@ class bit_blaster_tactic : public tactic {
proof_ref new_pr(m());
unsigned size = g->size();
bool change = false;
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

@ -105,7 +105,7 @@ class bv1_blaster_tactic : public tactic {
}
sort * b = butil().mk_sort(1);
ptr_buffer<expr> bits;
for (unsigned i = 0; i < bv_size; i++) {
for (unsigned i = 0; i < bv_size; ++i) {
bits.push_back(m().mk_fresh_const(nullptr, b));
m_newbits.push_back(to_app(bits.back())->get_decl());
m_saved.push_back(m_newbits.back());
@ -155,7 +155,7 @@ class bv1_blaster_tactic : public tactic {
SASSERT(t_bits.size() == e_bits.size());
bit_buffer new_ites;
unsigned num = t_bits.size();
for (unsigned i = 0; i < num; i++)
for (unsigned i = 0; i < num; ++i)
new_ites.push_back(t_bits[i] == e_bits[i] ? t_bits[i] : m().mk_ite(c, t_bits[i], e_bits[i]));
result = butil().mk_concat(new_ites.size(), new_ites.data());
}
@ -168,7 +168,7 @@ class bv1_blaster_tactic : public tactic {
rational v = f->get_parameter(0).get_rational();
rational two(2);
unsigned sz = f->get_parameter(1).get_int();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if ((v % two).is_zero())
bits.push_back(m_bit0);
else
@ -189,7 +189,7 @@ class bv1_blaster_tactic : public tactic {
unsigned start = sz - 1 - high;
unsigned end = sz - 1 - low;
bit_buffer bits;
for (unsigned i = start; i <= end; i++) {
for (unsigned i = start; i <= end; ++i) {
bits.push_back(arg_bits[i]);
}
result = butil().mk_concat(bits.size(), bits.data());
@ -198,7 +198,7 @@ class bv1_blaster_tactic : public tactic {
void reduce_concat(unsigned num, expr * const * args, expr_ref & result) {
bit_buffer bits;
bit_buffer arg_bits;
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
expr * arg = args[i];
arg_bits.reset();
get_bits(arg, arg_bits);
@ -215,7 +215,7 @@ class bv1_blaster_tactic : public tactic {
SASSERT(bits1.size() == bits2.size());
bit_buffer new_bits;
unsigned num = bits1.size();
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
new_bits.push_back(m().mk_ite(m().mk_eq(bits1[i], bits2[i]), m_bit0, m_bit1));
}
result = butil().mk_concat(new_bits.size(), new_bits.data());
@ -229,21 +229,21 @@ class bv1_blaster_tactic : public tactic {
return;
}
reduce_bin_xor(args[0], args[1], result);
for (unsigned i = 2; i < num_args; i++) {
for (unsigned i = 2; i < num_args; ++i) {
reduce_bin_xor(result, args[i], result);
}
#else
ptr_buffer<bit_buffer> args_bits;
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
bit_buffer * buff_i = alloc(bit_buffer);
get_bits(args[i], *buff_i);
args_bits.push_back(buff_i);
}
bit_buffer new_bits;
unsigned sz = butil().get_bv_size(args[0]);
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
ptr_buffer<expr> eqs;
for (unsigned j = 0; j < num_args; j++) {
for (unsigned j = 0; j < num_args; ++j) {
bit_buffer * buff_j = args_bits[j];
eqs.push_back(m().mk_eq(buff_j->get(i), m_bit1));
}
@ -367,7 +367,7 @@ class bv1_blaster_tactic : public tactic {
unsigned sz = g.size();
visitor proc(m_rw.cfg().butil().get_family_id());
try {
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
expr * f = g.form(i);
for_each_expr_core<visitor, expr_fast_mark1, false, true>(proc, visited, f);
}
@ -394,7 +394,7 @@ class bv1_blaster_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) {
if (g->inconsistent())
break;
expr * curr = g->form(idx);

View file

@ -58,7 +58,7 @@ struct bv_bound_chk_rewriter_cfg : public default_rewriter_cfg {
const br_status st = reduce_app_core(f, num, args, result, result_pr);
CTRACE(bv_bound_chk_step, st != BR_FAILED,
tout << f->get_name() << "\n";
for (unsigned i = 0; i < num; i++) tout << mk_ismt2_pp(args[i], m()) << "\n";
for (unsigned i = 0; i < num; ++i) tout << mk_ismt2_pp(args[i], m()) << "\n";
tout << "---------->\n" << mk_ismt2_pp(result, m()) << "\n";);
return st;
}
@ -151,7 +151,7 @@ public:
ast_manager& m(g->m());
expr_ref new_curr(m);
const 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);
m_rw(curr, new_curr);

View file

@ -134,7 +134,7 @@ public:
};
#endif
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
bool negated = false;
f = g.form(i);
if (m.is_not(f)) {
@ -327,10 +327,10 @@ public:
if (!(m_unsigned_lowers.empty() && m_unsigned_uppers.empty())) {
TRACE(bv_size_reduction,
tout << "m_unsigned_lowers: " << std::endl;
for (obj_map<app, numeral>::iterator it = m_unsigned_lowers.begin(); it != m_unsigned_lowers.end(); it++)
for (obj_map<app, numeral>::iterator it = m_unsigned_lowers.begin(); it != m_unsigned_lowers.end(); ++it)
tout << mk_ismt2_pp(it->m_key, m) << " >= " << it->m_value.to_string() << std::endl;
tout << "m_unsigned_uppers: " << std::endl;
for (obj_map<app, numeral>::iterator it = m_unsigned_uppers.begin(); it != m_unsigned_uppers.end(); it++)
for (obj_map<app, numeral>::iterator it = m_unsigned_uppers.begin(); it != m_unsigned_uppers.end(); ++it)
tout << mk_ismt2_pp(it->m_key, m) << " <= " << it->m_value.to_string() << std::endl;
);
@ -398,7 +398,7 @@ public:
unsigned sz = g.size();
expr * f;
expr_ref new_f(m);
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if (g.inconsistent())
return;
f = g.form(i);

View file

@ -61,7 +61,7 @@ sort * bvarray2uf_rewriter_cfg::get_index_sort(expr * e) {
sort * bvarray2uf_rewriter_cfg::get_index_sort(sort * s) {
SASSERT(s->get_num_parameters() >= 2);
unsigned total_width = 0;
for (unsigned i = 0; i < s->get_num_parameters() - 1; i++) {
for (unsigned i = 0; i < s->get_num_parameters() - 1; ++i) {
parameter const & p = s->get_parameter(i);
SASSERT(p.is_ast() && is_sort(to_sort(p.get_ast())));
SASSERT(m_bv_util.is_bv_sort(to_sort(p.get_ast())));
@ -90,7 +90,7 @@ bool bvarray2uf_rewriter_cfg::is_bv_array(sort * s) {
return false;
SASSERT(s->get_num_parameters() >= 2);
for (unsigned i = 0; i < s->get_num_parameters(); i++) {
for (unsigned i = 0; i < s->get_num_parameters(); ++i) {
parameter const & p = s->get_parameter(i);
if (!p.is_ast() || !is_sort(to_sort(p.get_ast())) ||
!m_bv_util.is_bv_sort(to_sort(p.get_ast())))
@ -201,7 +201,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
bool has_bv_arrays = false;
func_decl_ref f_t(m_manager);
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
if (is_bv_array(args[i])) {
SASSERT(m_array_util.is_as_array(args[i]));
has_bv_arrays = true;
@ -279,7 +279,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
func_decl_ref map_f(to_func_decl(f->get_parameter(0).get_ast()), m_manager);
func_decl_ref_vector ss(m_manager);
for (unsigned i = 0; i < num; i++) {
for (unsigned i = 0; i < num; ++i) {
SASSERT(m_array_util.is_array(args[i]));
func_decl_ref fd(mk_uf_for_array(args[i]), m_manager);
ss.push_back(fd);
@ -291,7 +291,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
var_ref x(m_manager.mk_var(0, sorts[0]), m_manager);
expr_ref_vector new_args(m_manager);
for (unsigned i = 0; i < num; i++)
for (unsigned i = 0; i < num; ++i)
new_args.push_back(m_manager.mk_app(ss[i].get(), x.get()));
expr_ref body(m_manager);
@ -362,7 +362,7 @@ bool bvarray2uf_rewriter_cfg::pre_visit(expr * t)
quantifier * q = to_quantifier(t);
TRACE(bvarray2uf_rw_q, tout << "pre_visit quantifier [" << q->get_id() << "]: " << mk_ismt2_pp(q->get_expr(), m()) << std::endl;);
sort_ref_vector new_bindings(m_manager);
for (unsigned i = 0; i < q->get_num_decls(); i++)
for (unsigned i = 0; i < q->get_num_decls(); ++i)
new_bindings.push_back(q->get_decl_sort(i));
SASSERT(new_bindings.size() == q->get_num_decls());
m_bindings.append(new_bindings);

View file

@ -72,7 +72,7 @@ class bvarray2uf_tactic : public tactic {
expr_ref new_curr(m_manager);
proof_ref new_pr(m_manager);
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

@ -133,7 +133,7 @@ public:
rw.set_is_fd(&m_is_fd);
expr_ref new_curr(m);
proof_ref new_pr(m);
for (unsigned idx = 0; idx < size; idx++) {
for (unsigned idx = 0; idx < size; ++idx) {
rw(g->form(idx), new_curr, new_pr);
if (produce_proofs) {
proof * pr = g->pr(idx);

View file

@ -79,7 +79,7 @@ class elim_small_bv_tactic : public tactic {
// (VAR 0) is in the first position of substitution; (VAR num_decls-1) is in the last position.
for (unsigned i = 0; i < max_var_idx_p1; i++)
for (unsigned i = 0; i < max_var_idx_p1; ++i)
substitution.push_back(nullptr);
// (VAR num_decls) ... (VAR num_decls+sz-1); are in positions num_decls .. num_decls+sz-1
@ -89,7 +89,7 @@ class elim_small_bv_tactic : public tactic {
// (VAR 0) should be in the last position of substitution.
TRACE(elim_small_bv, tout << "substitution: " << std::endl;
for (unsigned k = 0; k < substitution.size(); k++) {
for (unsigned k = 0; k < substitution.size(); ++k) {
expr * se = substitution[k];
tout << k << " = ";
if (se == 0) tout << "0";
@ -151,7 +151,7 @@ class elim_small_bv_tactic : public tactic {
if (max_num > m_max_steps || max_num + num_steps > m_max_steps)
return false;
for (unsigned j = 0; j < max_num && !max_steps_exceeded(num_steps); j++) {
for (unsigned j = 0; j < max_num && !max_steps_exceeded(num_steps); ++j) {
expr_ref n(m_util.mk_numeral(j, bv_sz), m);
new_bodies.push_back(replace_var(uv, num_decls, max_var_idx_p1, i, s, body, n));
num_steps++;
@ -170,7 +170,7 @@ class elim_small_bv_tactic : public tactic {
}
TRACE(elim_small_bv, tout << "new bodies: " << std::endl;
for (unsigned k = 0; k < new_bodies.size(); k++)
for (unsigned k = 0; k < new_bodies.size(); ++k)
tout << mk_ismt2_pp(new_bodies[k].get(), m) << std::endl; );
body = is_forall(q) ? m.mk_and(new_bodies.size(), new_bodies.data()) :
@ -200,7 +200,7 @@ class elim_small_bv_tactic : public tactic {
quantifier * q = to_quantifier(t);
TRACE(elim_small_bv, tout << "pre_visit quantifier [" << q->get_id() << "]: " << mk_ismt2_pp(q->get_expr(), m) << std::endl;);
sort_ref_vector new_bindings(m);
for (unsigned i = 0; i < q->get_num_decls(); i++)
for (unsigned i = 0; i < q->get_num_decls(); ++i)
new_bindings.push_back(q->get_decl_sort(i));
SASSERT(new_bindings.size() == q->get_num_decls());
m_bindings.append(new_bindings);