3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-02 15:17:54 +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

@ -638,7 +638,7 @@ namespace datalog {
SASSERT(is_fact(head));
relation_fact fact(get_manager());
unsigned n = head->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
fact.push_back(to_app(head->get_arg(i)));
}
add_fact(head->get_decl(), fact);

View file

@ -108,7 +108,7 @@ namespace datalog {
var_idx_set& rule_manager::collect_tail_vars(rule * r) {
reset_collect_vars();
unsigned n = r->get_tail_size();
for (unsigned i=0;i<n;i++) {
for (unsigned i=0;i<n;++i) {
accumulate_vars(r->get_tail(i));
}
return finalize_collect_vars();
@ -118,7 +118,7 @@ namespace datalog {
reset_collect_vars();
unsigned n = r->get_tail_size();
accumulate_vars(r->get_head());
for (unsigned i=0;i<n;i++) {
for (unsigned i=0;i<n;++i) {
if (r->get_tail(i) != t) {
accumulate_vars(r->get_tail(i));
}
@ -130,7 +130,7 @@ namespace datalog {
reset_collect_vars();
unsigned n = r->get_tail_size();
accumulate_vars(r->get_head());
for (unsigned i=0;i<n;i++) {
for (unsigned i=0;i<n;++i) {
accumulate_vars(r->get_tail(i));
}
return finalize_collect_vars();
@ -305,7 +305,7 @@ namespace datalog {
body.push_back(to_app(q));
flatten_body(body);
func_decl* body_pred = nullptr;
for (unsigned i = 0; i < body.size(); i++) {
for (unsigned i = 0; i < body.size(); ++i) {
if (is_uninterp(body[i].get())) {
body_pred = body[i]->get_decl();
break;
@ -330,7 +330,7 @@ namespace datalog {
}
expr_ref_vector qhead_args(m);
for (unsigned i = 0; i < vars.size(); i++) {
for (unsigned i = 0; i < vars.size(); ++i) {
qhead_args.push_back(m.mk_var(vars.size()-i-1, vars[i]));
}
app_ref qhead(m.mk_app(qpred, qhead_args.data()), m);
@ -475,7 +475,7 @@ namespace datalog {
bool has_neg = false;
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
bool is_neg = (is_negated != nullptr && is_negated[i]);
app * curr = tail[i];
@ -544,7 +544,7 @@ namespace datalog {
r->m_uninterp_cnt = source->m_uninterp_cnt;
r->m_proof = nullptr;
m.inc_ref(r->m_head);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
r->m_tail[i] = source->m_tail[i];
m.inc_ref(r->get_tail(i));
}
@ -554,7 +554,7 @@ namespace datalog {
void rule_manager::to_formula(rule const& r, expr_ref& fml) {
ast_manager & m = fml.get_manager();
expr_ref_vector body(m);
for (unsigned i = 0; i < r.get_tail_size(); i++) {
for (unsigned i = 0; i < r.get_tail_size(); ++i) {
body.push_back(r.get_tail(i));
if (r.is_neg_tail(i)) {
body[body.size()-1] = m.mk_not(body.back());
@ -663,7 +663,7 @@ namespace datalog {
vctr.count_vars(head);
for (unsigned i = 0; i < ut_len; i++) {
for (unsigned i = 0; i < ut_len; ++i) {
app * t = r->get_tail(i);
vctr.count_vars(t);
tail.push_back(t);
@ -673,12 +673,12 @@ namespace datalog {
var_idx_set unbound_vars;
expr_ref_vector tails_with_unbound(m);
for (unsigned i = ut_len; i < t_len; i++) {
for (unsigned i = ut_len; i < t_len; ++i) {
app * t = r->get_tail(i);
m_free_vars(t);
bool has_unbound = false;
unsigned iv_size = m_free_vars.size();
for (unsigned i=0; i<iv_size; i++) {
for (unsigned i=0; i<iv_size; ++i) {
if (!m_free_vars[i]) { continue; }
if (vctr.get(i)==0) {
has_unbound = true;
@ -730,7 +730,7 @@ namespace datalog {
SASSERT(q_idx == q_var_cnt);
svector<symbol> qnames;
for (unsigned i = 0; i < q_var_cnt; i++) {
for (unsigned i = 0; i < q_var_cnt; ++i) {
qnames.push_back(symbol(i));
}
//quantifiers take this reversed
@ -838,7 +838,7 @@ namespace datalog {
throw default_exception(out.str());
}
unsigned num_args = to_app(head)->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = to_app(head)->get_arg(i);
if (!is_var(arg) && !m.is_value(arg)) {
std::ostringstream out;
@ -850,7 +850,7 @@ namespace datalog {
bool rule_manager::is_fact(app * head) const {
unsigned num_args = head->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
if (!m.is_value(head->get_arg(i)))
return false;
}
@ -860,7 +860,7 @@ namespace datalog {
void rule::deallocate(ast_manager & m) {
m.dec_ref(m_head);
unsigned n = get_tail_size();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
m.dec_ref(get_tail(i));
}
if (m_proof) {
@ -882,7 +882,7 @@ namespace datalog {
bool rule::is_in_tail(const func_decl * p, bool only_positive) const {
unsigned len = only_positive ? get_positive_tail_size() : get_uninterpreted_tail_size();
for (unsigned i = 0; i < len; i++) {
for (unsigned i = 0; i < len; ++i) {
if (get_tail(i)->get_decl()==p) {
return true;
}
@ -1003,7 +1003,7 @@ namespace datalog {
m.dec_ref(m_head);
m_head = new_head_a;
for (unsigned i = 0; i < m_tail_size; i++) {
for (unsigned i = 0; i < m_tail_size; ++i) {
app * old_tail = get_tail(i);
app_ref new_tail_a = rm.ensure_app(vs(old_tail, subst_vals.size(), subst_vals.data()));
bool sign = is_neg_tail(i);
@ -1025,7 +1025,7 @@ namespace datalog {
return;
}
out << " :- ";
for (unsigned i = 0; i < m_tail_size; i++) {
for (unsigned i = 0; i < m_tail_size; ++i) {
if (i > 0)
out << ",";
if (!compact)

View file

@ -89,7 +89,7 @@ namespace datalog {
void rule_dependencies::populate(unsigned n, rule * const * rules) {
SASSERT(m_data.empty());
for (unsigned i=0; i<n; i++) {
for (unsigned i=0; i<n; ++i) {
populate(rules[i]);
}
}
@ -393,11 +393,11 @@ namespace datalog {
bool rule_set::stratified_negation() {
ptr_vector<rule>::const_iterator it = m_rules.data();
ptr_vector<rule>::const_iterator end = m_rules.data() + m_rules.size();
for (; it != end; it++) {
for (; it != end; ++it) {
rule * r = *it;
func_decl * head_decl = r->get_decl();
unsigned n = r->get_uninterpreted_tail_size();
for (unsigned i = r->get_positive_tail_size(); i < n; i++) {
for (unsigned i = r->get_positive_tail_size(); i < n; ++i) {
SASSERT(r->is_neg_tail(i));
func_decl * tail_decl = r->get_decl(i);
unsigned neg_strat = get_predicate_strat(tail_decl);
@ -423,7 +423,7 @@ namespace datalog {
void rule_set::add_rules(const rule_set & src) {
SASSERT(!is_closed());
unsigned n = src.get_num_rules();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
add_rule(src.get_rule(i));
}
inherit_predicates(src);
@ -639,7 +639,7 @@ namespace datalog {
// We put components whose indegree is zero to m_strats and assign its
// m_components entry to zero.
unsigned comp_cnt = m_components.size();
for (unsigned i = 0; i < comp_cnt; i++) {
for (unsigned i = 0; i < comp_cnt; ++i) {
if (in_degrees[i] == 0) {
m_strats.push_back(m_components[i]);
m_components[i] = 0;
@ -681,7 +681,7 @@ namespace datalog {
SASSERT(m_pred_strat_nums.empty());
unsigned strat_cnt = m_strats.size();
for (unsigned strat_index=0; strat_index < strat_cnt; strat_index++) {
for (unsigned strat_index=0; strat_index < strat_cnt; ++strat_index) {
item_set * comp = m_strats[strat_index];
for (T * el : *comp) {
m_pred_strat_nums.insert(el, strat_index);

View file

@ -71,7 +71,7 @@ namespace datalog {
SASSERT(is_uninterp(pred));
unsigned res = 0;
unsigned n = pred->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
expr * arg = pred->get_arg(i);
if (is_var(arg)) {
res++;
@ -84,7 +84,7 @@ namespace datalog {
sort_ref_buffer & new_rule_domain, expr_ref_buffer & new_rule_args, app_ref & new_pred) {
expr_ref_buffer new_args(m);
unsigned n = pred->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
expr * arg = pred->get_arg(i);
if (m.is_value(arg)) {
new_args.push_back(arg);
@ -135,7 +135,7 @@ namespace datalog {
out << pred_decl->get_name() << '(';
for (unsigned i = 0; i < arity; i++) {
for (unsigned i = 0; i < arity; ++i) {
expr * arg = f->get_arg(i);
if (i != 0) {
out << ',';
@ -163,7 +163,7 @@ namespace datalog {
out << "\t(";
for(unsigned i = 0; i < arity; i++) {
for(unsigned i = 0; i < arity; ++i) {
if (i != 0) {
out << ',';
}
@ -198,7 +198,7 @@ namespace datalog {
bool variable_intersection::args_match(const app * f1, const app * f2)
{
unsigned n=size();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
unsigned f1_index, f2_index;
get(i, f1_index, f2_index);
if (!values_match(f1->get_arg(f1_index),f2->get_arg(f2_index))) {
@ -215,7 +215,7 @@ namespace datalog {
}
unsigned n = m_const_indexes.size();
for(unsigned i=0; i<n; i++) {
for(unsigned i=0; i<n; ++i) {
unsigned f_index = m_const_indexes[i];
if(!values_match(f->get_arg(f_index), m_consts[i].get())) {
return false;
@ -231,11 +231,11 @@ namespace datalog {
//TODO: optimize quadratic complexity
//TODO: optimize number of checks when variable occurs multiple times
unsigned arity = a->get_num_args();
for(unsigned i1=0; i1<arity; i1++) {
for(unsigned i1=0; i1<arity; ++i1) {
expr * e1=a->get_arg(i1);
if(is_var(e1)) {
var* v1=to_var(e1);
for(unsigned i2=i1+1; i2<arity; i2++) {
for(unsigned i2=i1+1; i2<arity; ++i2) {
expr * e2=a->get_arg(i2);
if(!is_var(e2)) {
continue;
@ -264,7 +264,7 @@ namespace datalog {
reset();
count_vars(r->get_head(), 1);
unsigned n = r->get_tail_size();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
count_vars(r->get_tail(i), coef);
}
}
@ -274,7 +274,7 @@ namespace datalog {
m_scopes.push_back(0);
unsigned n = r.get_tail_size();
bool has_var = false;
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
m_todo.push_back(r.get_tail(i));
m_scopes.push_back(0);
}
@ -432,7 +432,7 @@ namespace datalog {
unsigned src_ofs = src_sz - 1;
unsigned max_var_idx = 0;
for(unsigned i=0; i<src_sz; i++) {
for(unsigned i=0; i<src_sz; ++i) {
if (!src[i]) {
continue;
}
@ -445,7 +445,7 @@ namespace datalog {
unsigned tgt_sz = max_var_idx+1;
unsigned tgt_ofs = tgt_sz - 1;
tgt.resize(tgt_sz, nullptr);
for(unsigned i = 0; i < src_sz; i++) {
for(unsigned i = 0; i < src_sz; ++i) {
var* v = src[src_ofs-i];
if (!v) {
continue;
@ -490,7 +490,7 @@ namespace datalog {
SASSERT(permutation.empty() || ctr.get_positive_count()==permutation.size());
);
unsigned sz = permutation.size();
for(unsigned i=0; i<sz; i++) {
for(unsigned i=0; i<sz; ++i) {
if(i==permutation[i]) {
continue;
}
@ -514,7 +514,7 @@ namespace datalog {
SASSERT(res.empty());
identity = true;
unsigned sz = permutation.size();
for(unsigned new_i=0; new_i<sz; new_i++) {
for(unsigned new_i=0; new_i<sz; ++new_i) {
unsigned idx = permutation[new_i];
bool is_selected = translation[idx]!=UINT_MAX;
if(is_selected) {
@ -546,7 +546,7 @@ namespace datalog {
void add_sequence(unsigned start, unsigned count, unsigned_vector & v) {
unsigned after_last = start+count;
for(unsigned i=start; i<after_last; i++) {
for(unsigned i=start; i<after_last; ++i) {
v.push_back(i);
}
}

View file

@ -85,7 +85,7 @@ namespace datalog {
void copy_nonvariables(app * src, T& tgt)
{
unsigned n = src->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
expr * arg = src->get_arg(i);
if (!is_var(arg)) {
tgt[i] = arg;
@ -193,7 +193,7 @@ namespace datalog {
template<typename T>
void fill_into_second(const app * f1, T & tgt) const {
unsigned n = size();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
unsigned f1_index, tgt_index;
get(i, f1_index, tgt_index);
tgt[tgt_index] = f1->get_arg(f1_index);
@ -216,13 +216,13 @@ namespace datalog {
//TODO: optimize number of checks when variable occurs multiple times
unsigned a1num = expr_cont_get_size(a1);
unsigned a2num = expr_cont_get_size(a2);
for (unsigned i1 = 0; i1<a1num; i1++) {
for (unsigned i1 = 0; i1<a1num; ++i1) {
expr * e1 = expr_cont_get(a1,i1);
if (!is_var(e1)) {
continue;
}
var* v1 = to_var(e1);
for (unsigned i2 = 0; i2<a2num; i2++) {
for (unsigned i2 = 0; i2<a2num; ++i2) {
expr * e2 = expr_cont_get(a2,i2);
if (!is_var(e2)) {
continue;
@ -250,7 +250,7 @@ namespace datalog {
unsigned n = container.size();
unsigned ofs = 1;
unsigned r_i = 1;
for (unsigned i=removed_cols[0]+1; i<n; i++) {
for (unsigned i=removed_cols[0]+1; i<n; ++i) {
if (r_i!=removed_col_cnt && removed_cols[r_i]==i) {
r_i++;
ofs++;
@ -279,7 +279,7 @@ namespace datalog {
unsigned n = container.size();
unsigned ofs = 1;
unsigned r_i = 1;
for (unsigned i=removed_cols[0]+1; i<n; i++) {
for (unsigned i=removed_cols[0]+1; i<n; ++i) {
if (r_i!=removed_col_cnt && removed_cols[r_i]==i) {
r_i++;
ofs++;
@ -324,7 +324,7 @@ namespace datalog {
if (cycle_len < 2)
return;
auto aux = container[permutation_cycle[0]];
for (unsigned i = 1; i < cycle_len; i++)
for (unsigned i = 1; i < cycle_len; ++i)
container[permutation_cycle[i-1]] = container[permutation_cycle[i]];
container[permutation_cycle[cycle_len-1]] = aux;
}
@ -333,7 +333,7 @@ namespace datalog {
if (cycle_len < 2)
return;
T * aux = container.get(permutation_cycle[0]);
for (unsigned i=1; i < cycle_len; i++) {
for (unsigned i=1; i < cycle_len; ++i) {
container.set(permutation_cycle[i-1], container.get(permutation_cycle[i]));
}
container.set(permutation_cycle[cycle_len-1], aux);
@ -477,7 +477,7 @@ namespace datalog {
template<class T>
bool remove_from_vector(T & v, const typename T::data_t & el) {
unsigned sz = v.size();
for (unsigned i=0; i<sz; i++) {
for (unsigned i=0; i<sz; ++i) {
if (v[i]==el) {
std::swap(v[i], v.back());
v.pop_back();
@ -523,12 +523,12 @@ namespace datalog {
return;
}
unsigned_vector numbers;
for (unsigned i=0; i<len; i++) {
for (unsigned i=0; i<len; ++i) {
numbers.push_back(i);
}
aux__index_comparator<T> cmp(keys);
std::sort(numbers.begin(), numbers.end(), cmp);
for (unsigned i=0; i<len; i++) {
for (unsigned i=0; i<len; ++i) {
unsigned prev_i = i;
for (;;) {
unsigned src_i = numbers[prev_i];
@ -562,7 +562,7 @@ namespace datalog {
template<class Container>
void add_sequence_without_set(unsigned start, unsigned count, const Container & complement, unsigned_vector & v) {
unsigned after_last = start+count;
for (unsigned i=start; i<after_last; i++) {
for (unsigned i=start; i<after_last; ++i) {
if (!complement.contains(i)) {
v.push_back(i);
}