3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-05-24 19:06:21 +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

@ -57,12 +57,12 @@ namespace datalog {
expr_ref_vector new_tail(m);
unsigned nb_predicates = r.get_uninterpreted_tail_size();
unsigned tail_size = r.get_tail_size();
for (unsigned i = 0; i < nb_predicates; i++) {
for (unsigned i = 0; i < nb_predicates; ++i) {
new_tail.push_back(r.get_tail(i));
}
expr_equiv_class array_eq_classes(m);
for(unsigned i = nb_predicates; i < tail_size; i++) {
for(unsigned i = nb_predicates; i < tail_size; ++i) {
expr* cond = r.get_tail(i);
expr* e1, *e2;
if (m.is_eq(cond, e1, e2) && m_a.is_array(e1->get_sort())) {
@ -82,7 +82,7 @@ namespace datalog {
}
}
for (expr * v : c_eq) {
for (unsigned i = 0; i < new_tail.size(); i++)
for (unsigned i = 0; i < new_tail.size(); ++i)
new_tail[i] = replace(new_tail[i].get(), representative, v);
}
for (expr * v : c_eq) {

View file

@ -53,7 +53,7 @@ namespace datalog {
dst = result.get();
unsigned nbrules = source.get_num_rules();
src_manager = &source.get_rule_manager();
for(unsigned i = 0; i < nbrules; i++) {
for(unsigned i = 0; i < nbrules; ++i) {
rule & r = *source.get_rule(i);
instantiate_rule(r, *result);
}
@ -77,20 +77,20 @@ namespace datalog {
expr_ref new_head = create_head(to_app(r.get_head()));
unsigned nb_predicates = r.get_uninterpreted_tail_size();
unsigned tail_size = r.get_tail_size();
for(unsigned i=0;i<nb_predicates;i++) {
for(unsigned i=0;i<nb_predicates;++i) {
preds.push_back(r.get_tail(i));
}
for(unsigned i=nb_predicates;i<tail_size;i++) {
for(unsigned i=nb_predicates;i<tail_size;++i) {
phi.push_back(r.get_tail(i));
}
//Retrieve selects
for(unsigned i=0;i<phi.size();i++)
for(unsigned i=0;i<phi.size();++i)
retrieve_selects(phi[i].get());
//Rewrite the predicates
expr_ref_vector new_tail(m);
for(unsigned i=0;i<preds.size();i++) {
for(unsigned i=0;i<preds.size();++i) {
new_tail.append(instantiate_pred(to_app(preds[i].get())));
}
new_tail.append(phi);
@ -105,13 +105,13 @@ namespace datalog {
expr_ref mk_array_instantiation::create_head(app* old_head) {
expr_ref_vector new_args(m);
for(unsigned i=0;i<old_head->get_num_args();i++) {
for(unsigned i=0;i<old_head->get_num_args();++i) {
expr*arg = old_head->get_arg(i);
if(m_a.is_array(arg->get_sort())) {
for(unsigned k=0; k< m_ctx.get_params().xform_instantiate_arrays_nb_quantifier();k++) {
for(unsigned k=0; k< m_ctx.get_params().xform_instantiate_arrays_nb_quantifier();++k) {
expr_ref_vector dummy_args(m);
dummy_args.push_back(arg);
for(unsigned i=0;i<get_array_arity(arg->get_sort());i++) {
for(unsigned i=0;i<get_array_arity(arg->get_sort());++i) {
dummy_args.push_back(m.mk_var(cnt, get_array_domain(arg->get_sort(), i)));
cnt++;
}
@ -139,7 +139,7 @@ namespace datalog {
app*f=to_app(e);
//Call the function recursively on all arguments
unsigned nbargs = f->get_num_args();
for(unsigned i=0;i<nbargs;i++) {
for(unsigned i=0;i<nbargs;++i) {
retrieve_selects(f->get_arg(i));
}
//If it is a select, then add it to selects
@ -161,10 +161,10 @@ namespace datalog {
expr_ref_vector mk_array_instantiation::getId(app*old_pred, const expr_ref_vector& n_args)
{
expr_ref_vector res(m);
for(unsigned i=0;i<n_args.size(); i++) {
for(unsigned i=0;i<n_args.size(); ++i) {
if(m_a.is_select(n_args[i])) {
app*select = to_app(n_args[i]);
for(unsigned j=1;j<select->get_num_args();j++) {
for(unsigned j=1;j<select->get_num_args();++j) {
res.push_back(select->get_arg(j));
}
}
@ -177,13 +177,13 @@ namespace datalog {
expr_ref_vector new_args(m);
new_args.append(n_args);
new_args.append(getId(old_pred, n_args));
for(unsigned i=0;i<new_args.size();i++) {
for(unsigned i=0;i<new_args.size();++i) {
if(m_a.is_select(new_args[i].get())) {
new_args[i] = mk_select_var(new_args[i].get());
}
}
sort_ref_vector new_sorts(m);
for(unsigned i=0;i<new_args.size();i++)
for(unsigned i=0;i<new_args.size();++i)
new_sorts.push_back(new_args.get(i)->get_sort());
expr_ref res(m);
func_decl_ref fun_decl(m);
@ -213,7 +213,7 @@ namespace datalog {
expr_ref res(m);
expr_ref_vector args(m);
args.push_back(array);
for(unsigned i=1; i<s->get_num_args();i++) {
for(unsigned i=1; i<s->get_num_args();++i) {
args.push_back(s->get_arg(i));
}
res = m_a.mk_select(args.size(), args.data());
@ -227,14 +227,14 @@ namespace datalog {
it != eq_classes.end(array); ++it) {
selects.insert_if_not_there(*it, ptr_vector<expr>());
ptr_vector<expr>& select_ops = selects[*it];
for(unsigned i=0;i<select_ops.size();i++) {
for(unsigned i=0;i<select_ops.size();++i) {
all_selects.push_back(rewrite_select(array, select_ops[i]));
}
}
if(all_selects.empty()) {
expr_ref_vector dummy_args(m);
dummy_args.push_back(array);
for(unsigned i=0;i<get_array_arity(array->get_sort());i++) {
for(unsigned i=0;i<get_array_arity(array->get_sort());++i) {
dummy_args.push_back(m.mk_var(cnt, get_array_domain(array->get_sort(), i)));
cnt++;
}
@ -249,7 +249,7 @@ namespace datalog {
unsigned nb_old_args=old_pred->get_num_args();
//Stores, for each old position, the list of a new possible arguments
vector<expr_ref_vector> arg_correspondance;
for(unsigned i=0;i<nb_old_args;i++) {
for(unsigned i=0;i<nb_old_args;++i) {
expr_ref arg(old_pred->get_arg(i), m);
if(m_a.is_array(arg->get_sort())) {
vector<expr_ref_vector> arg_possibilities(m_ctx.get_params().xform_instantiate_arrays_nb_quantifier(), retrieve_all_selects(arg));
@ -273,7 +273,7 @@ namespace datalog {
svector<unsigned> chosen(arg_correspondance.size(), 0u);
while(true) {
expr_ref_vector new_args(m);
for(unsigned i=0;i<chosen.size();i++) {
for(unsigned i=0;i<chosen.size();++i) {
new_args.push_back(arg_correspondance[i][chosen[i]].get());
}
res.push_back(create_pred(old_pred, new_args));

View file

@ -58,7 +58,7 @@ namespace datalog {
}
var_idx_set used_vars;
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))
return true;
@ -108,7 +108,7 @@ namespace datalog {
bool_vector new_is_negated;
unsigned sz = r->get_tail_size();
bool rule_modified = false;
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
app * tail = r->get_tail(i);
if (is_candidate(tail) && !r->is_neg_tail(i)) {
TRACE(mk_filter_rules, tout << "is_candidate: " << mk_pp(tail, m) << "\n";);
@ -117,7 +117,7 @@ namespace datalog {
ptr_buffer<expr> new_args;
var_idx_set used_vars;
unsigned num_args = tail->get_num_args();
for (unsigned i = 0; i < num_args; i++) {
for (unsigned i = 0; i < num_args; ++i) {
expr * arg = tail->get_arg(i);
if (is_var(arg)) {
unsigned vidx = to_var(arg)->get_idx();
@ -155,7 +155,7 @@ namespace datalog {
m_result = alloc(rule_set, m_context);
m_modified = false;
unsigned num_rules = source.get_num_rules();
for (unsigned i = 0; i < num_rules; i++) {
for (unsigned i = 0; i < num_rules; ++i) {
process(source.get_rule(i));
}
if(!m_modified) {

View file

@ -75,7 +75,7 @@ namespace datalog {
m_neg.reset();
unsigned tail_len = m_rule->get_tail_size();
for (unsigned i=0; i<tail_len; i++) {
for (unsigned i=0; i<tail_len; ++i) {
app_ref new_tail_el(m);
apply(m_rule->get_tail(i), new_tail_el);
m_tail.push_back(new_tail_el);
@ -142,7 +142,7 @@ namespace datalog {
unsigned neg_comparison = 0;
for (unsigned i=0; i<arg_cnt; i++) {
for (unsigned i=0; i<arg_cnt; ++i) {
expr * arg_a = a->get_arg(i);
expr * arg_b = b->get_arg(i);
@ -408,7 +408,7 @@ namespace datalog {
m_todo.reset();
m_leqs.reset();
for (unsigned i = u_len; i < len; i++) {
for (unsigned i = u_len; i < len; ++i) {
m_todo.push_back(r->get_tail(i));
SASSERT(!r->is_neg_tail(i));
}
@ -510,7 +510,7 @@ namespace datalog {
m_tail.reset();
m_tail_neg.reset();
for (unsigned i=0; i<u_len; i++) {
for (unsigned i=0; i<u_len; ++i) {
m_tail.push_back(r->get_tail(i));
m_tail_neg.push_back(r->is_neg_tail(i));
}
@ -525,7 +525,7 @@ namespace datalog {
}
else {
m_itail_members.reset();
for (unsigned i=u_len; i<len; i++) {
for (unsigned i=u_len; i<len; ++i) {
m_itail_members.push_back(r->get_tail(i));
SASSERT(!r->is_neg_tail(i));
}

View file

@ -45,7 +45,7 @@ namespace datalog {
void mk_magic_sets::adornment::populate(app * lit, const var_idx_set & bound_vars) {
SASSERT(empty());
unsigned arity = lit->get_num_args();
for (unsigned i = 0; i < arity; i++) {
for (unsigned i = 0; i < arity; ++i) {
const expr * arg = lit->get_arg(i);
bool bound = !is_var(arg) || bound_vars.contains(to_var(arg)->get_idx());
push_back(bound ? AD_BOUND : AD_FREE);
@ -65,7 +65,7 @@ namespace datalog {
unsigned get_bound_arg_count(app * lit, const var_idx_set & bound_vars) {
unsigned res = 0;
unsigned n = lit->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
const expr * arg = lit->get_arg(i);
if (!is_var(arg) || bound_vars.contains(to_var(arg)->get_idx())) {
SASSERT(is_var(arg) || is_app(arg));
@ -80,7 +80,7 @@ namespace datalog {
func_decl * pred = lit->get_decl();
float res = 1;
unsigned n = lit->get_num_args();
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
const expr * arg = lit->get_arg(i);
if (is_var(arg) && !bound_vars.contains(to_var(arg)->get_idx())) {
res *= m_context.get_sort_size_estimate(pred->get_domain(i));
@ -100,7 +100,7 @@ namespace datalog {
float best_cost;
int candidate_index = -1;
unsigned n = cont.size();
for (unsigned i=0; i<n; i++) {
for (unsigned i=0; i<n; ++i) {
app * lit = r->get_tail(cont[i]);
unsigned bound_cnt = get_bound_arg_count(lit, bound_vars);
if (bound_cnt==0) {
@ -153,7 +153,7 @@ namespace datalog {
unsigned l_arity = l->get_num_args();
ptr_vector<expr> bound_args;
for (unsigned i=0; i<l_arity; i++) {
for (unsigned i=0; i<l_arity; ++i) {
if (adn[i]==AD_BOUND) {
bound_args.push_back(l->get_arg(i));
}
@ -164,7 +164,7 @@ namespace datalog {
unsigned mag_arity = bound_args.size();
ptr_vector<sort> mag_domain;
for (unsigned i=0; i<l_arity; i++) {
for (unsigned i=0; i<l_arity; ++i) {
if (adn[i]==AD_BOUND) {
mag_domain.push_back(l_pred->get_domain(i));
}
@ -189,7 +189,7 @@ namespace datalog {
negations.push_back(false);
negations.append(tail_cnt, negated);
for (unsigned i=0; i<tail_cnt; i++) {
for (unsigned i=0; i<tail_cnt; ++i) {
if (m_extentional.contains(tail[i]->get_decl())) {
continue;
}
@ -206,7 +206,7 @@ namespace datalog {
SASSERT(head_len==head_adornment.size());
var_idx_set bound_vars;
for (unsigned i=0; i<head_len; i++) {
for (unsigned i=0; i<head_len; ++i) {
expr * arg = head->get_arg(i);
if (head_adornment[i]==AD_BOUND && is_var(arg)) {
bound_vars.insert(to_var(arg)->get_idx());
@ -216,7 +216,7 @@ namespace datalog {
unsigned processed_tail_len = r->get_uninterpreted_tail_size();
unsigned_vector exten_tails;
unsigned_vector inten_tails;
for (unsigned i=0; i<processed_tail_len; i++) {
for (unsigned i=0; i<processed_tail_len; ++i) {
app * t = r->get_tail(i);
if (m_extentional.contains(t->get_decl())) {
exten_tails.push_back(i);
@ -268,7 +268,7 @@ namespace datalog {
create_magic_rules(new_head, new_tail.size(), new_tail.data(), negations.data(), result);
unsigned tail_len = r->get_tail_size();
for (unsigned i=processed_tail_len; i<tail_len; i++) {
for (unsigned i=processed_tail_len; i<tail_len; ++i) {
new_tail.push_back(r->get_tail(i));
negations.push_back(r->is_neg_tail(i));
}
@ -287,7 +287,7 @@ namespace datalog {
SASSERT(arity == d.m_pred->get_arity());
ptr_vector<expr> args;
for (unsigned i=0; i<arity; i++) {
for (unsigned i=0; i<arity; ++i) {
args.push_back(m.mk_var(i, adn_pred->get_domain(i)));
}
@ -314,7 +314,7 @@ namespace datalog {
unsigned init_rule_cnt = source.get_num_rules();
{
func_decl_set intentional;
for (unsigned i=0; i<init_rule_cnt; i++) {
for (unsigned i=0; i<init_rule_cnt; ++i) {
func_decl* pred = source.get_rule(i)->get_decl();
intentional.insert(pred);
}

View file

@ -98,7 +98,7 @@ namespace datalog {
rule const& r, bool is_tgt, unsigned skipped_index,
app_ref_vector& res, bool_vector& res_neg) {
unsigned rule_len = r.get_tail_size();
for (unsigned i = 0; i < rule_len; i++) {
for (unsigned i = 0; i < rule_len; ++i) {
if (i != skipped_index) { //i can never be UINT_MAX, so we'll never skip if we're not supposed to
app_ref new_tail_el(m);
apply(r.get_tail(i), is_tgt, new_tail_el);
@ -224,7 +224,7 @@ namespace datalog {
}
unsigned ut_len = r->get_uninterpreted_tail_size();
for (unsigned i=0; i<ut_len; i++) {
for (unsigned i=0; i<ut_len; ++i) {
func_decl * pred = r->get_decl(i);
m_tail_pred_ctr.inc(pred);
@ -350,7 +350,7 @@ namespace datalog {
unsigned rule_cnt = orig.get_num_rules();
for (unsigned ri=0; ri<rule_cnt; ri++) {
for (unsigned ri=0; ri<rule_cnt; ++ri) {
rule * r = orig.get_rule(ri);
func_decl * head_pred = r->get_decl();

View file

@ -49,7 +49,7 @@ namespace datalog {
return false;
}
for (unsigned i = 0; i < pt_len; i++) {
for (unsigned i = 0; i < pt_len; ++i) {
func_decl * tail_pred = r->get_tail(i)->get_decl();
if (!m_total_relations.contains(tail_pred)) {
// this rule has a non-total predicate in the tail
@ -58,7 +58,7 @@ namespace datalog {
}
unsigned t_len = r->get_positive_tail_size();
for(unsigned i = pt_len; i < t_len; i++) {
for(unsigned i = pt_len; i < t_len; ++i) {
SASSERT(!r->is_neg_tail(i)); //we assume interpreted tail not to be negated
if (!m.is_true(r->get_tail(i))) {
//this rule has an interpreted tail which is not constant true
@ -69,7 +69,7 @@ namespace datalog {
var_idx_set head_vars;
app * head = r->get_head();
unsigned arity = head->get_num_args();
for(unsigned i=0; i<arity; i++) {
for(unsigned i=0; i<arity; ++i) {
expr * arg = head->get_arg(i);
if(!is_var(arg)) { return false; }
unsigned idx = to_var(arg)->get_idx();
@ -127,7 +127,7 @@ namespace datalog {
app_ref_vector tail(m);
bool_vector tail_neg;
for(unsigned i=0; i<u_len; i++) {
for(unsigned i=0; i<u_len; ++i) {
app * tail_atom = r->get_tail(i);
bool neg = r->is_neg_tail(i);
if(m_total_relations.contains(tail_atom->get_decl())
@ -158,7 +158,7 @@ namespace datalog {
}
//we just copy the interpreted part of the tail
for(unsigned i=u_len; i<len; i++) {
for(unsigned i=u_len; i<len; ++i) {
tail.push_back(r->get_tail(i));
tail_neg.push_back(r->is_neg_tail(i));
}
@ -273,7 +273,7 @@ namespace datalog {
if (arity > 30) { continue; }
//for now we only check booleans domains
for(unsigned i=0; i<arity; i++) {
for(unsigned i=0; i<arity; ++i) {
if(!m.is_bool(pred->get_domain(i))) {
goto next_pred;
}
@ -316,7 +316,7 @@ namespace datalog {
app * head = r->get_head();
unsigned arity = pred->get_arity();
for(unsigned i=0; i<arity; i++) {
for(unsigned i=0; i<arity; ++i) {
expr * arg = head->get_arg(i);
if(!is_app(arg)) {
goto next_rule;

View file

@ -62,7 +62,7 @@ namespace datalog {
symbol const& parent_name = pred->get_name();
unsigned arity = parent_arity-1;
ptr_vector<sort> domain;
for (unsigned i = 0; i < parent_arity; i++) {
for (unsigned i = 0; i < parent_arity; ++i) {
if (i != arg_index) {
domain.push_back(parent_domain[i]);
}
@ -97,7 +97,7 @@ namespace datalog {
rm.get_counter().reset();
rm.get_counter().count_vars(head, 1);
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
expr * arg = head->get_arg(i);
unsigned var_idx;
if (is_var(arg, var_idx) &&
@ -128,7 +128,7 @@ namespace datalog {
rm.get_counter().count_vars(head);
unsigned arg_index;
for (arg_index = 0; arg_index < head_arity; arg_index++) {
for (arg_index = 0; arg_index < head_arity; ++arg_index) {
expr * arg = head->get_arg(arg_index);
unsigned var_idx;
if (is_var(arg, var_idx) &&
@ -148,7 +148,7 @@ namespace datalog {
SASSERT(m_in_progress.contains(ci));
func_decl * cpred = m_map.find(ci);
ptr_vector<expr> cargs;
for (unsigned i=0; i < head_arity; i++) {
for (unsigned i=0; i < head_arity; ++i) {
if (i != arg_index) {
cargs.push_back(head->get_arg(i));
}
@ -197,7 +197,7 @@ namespace datalog {
func_decl * dtail_pred = m_map.find(ci);
ptr_vector<expr> dtail_args;
unsigned orig_dtail_arity = orig_dtail->get_num_args();
for (unsigned i = 0; i < orig_dtail_arity; i++) {
for (unsigned i = 0; i < orig_dtail_arity; ++i) {
if (i != arg_index) {
dtail_args.push_back(orig_dtail->get_arg(i));
}
@ -208,7 +208,7 @@ namespace datalog {
bool_vector tails_negated;
app_ref_vector tails(m);
unsigned tail_len = r->get_tail_size();
for (unsigned i = 0; i < tail_len; i++) {
for (unsigned i = 0; i < tail_len; ++i) {
tails_negated.push_back(r->is_neg_tail(i));
if (i == tail_index && !r->is_neg_tail(i)) {
tails.push_back(dtail);
@ -355,13 +355,13 @@ namespace datalog {
unsigned init_rule_cnt = source.get_num_rules();
for (unsigned i = 0; i < init_rule_cnt; i++) {
for (unsigned i = 0; i < init_rule_cnt; ++i) {
rule * r = source.get_rule(i);
m_rules.push_back(r);
m_head_occurrence_ctr.inc(r->get_decl());
}
for (unsigned i = 0; i < init_rule_cnt; i++) {
for (unsigned i = 0; i < init_rule_cnt; ++i) {
detect_tasks(source, i);
}