@@ -44,14 +44,15 @@ struct mbp_array_tg::impl {
4444 obj_pair_hashtable<expr, expr> m_seenp;
4545
4646 // apply rules that split on model
47- bool m_use_mdl;
47+ bool m_use_mdl = false ;
4848
4949 // m_has_store.is_marked(t) if t has a subterm store(v) where v is a
5050 // variable to be eliminated
5151 ast_mark m_has_stores;
5252 // variables required for applying rules
5353 vector<expr_ref_vector> indices;
54- expr_ref_vector terms, rdTerms;
54+ expr_ref_vector terms;
55+ app_ref_vector rdTerms;
5556
5657 bool has_var (expr *t) { return contains_vars (t, m_vars_set, m); }
5758
@@ -157,7 +158,7 @@ struct mbp_array_tg::impl {
157158 impl (ast_manager &man, mbp::term_graph &tg, model &mdl,
158159 obj_hashtable<app> &vars_set, expr_sparse_mark &seen)
159160 : m(man), m_array_util(m), m_tg(tg), m_mdl(mdl), m_vars_set(vars_set),
160- m_new_vars (m), m_seen(seen), m_use_mdl( false ), terms(m), rdTerms(m) {}
161+ m_new_vars (m), m_seen(seen), terms(m), rdTerms(m) {}
161162
162163 // create a peq where write terms are preferred on the left hand side
163164 peq mk_wr_peq (expr *e1 , expr *e2 ) {
@@ -186,9 +187,9 @@ struct mbp_array_tg::impl {
186187 // !(select(y, j) = elem)
187188 void elimwreq (peq p, bool is_neg) {
188189 expr* a = nullptr , *j = nullptr , *elem = nullptr ;
189- VERIFY (is_arr_write (p.lhs (), a, j, elem));
190+ VERIFY (is_arr_write (p.lhs (), a, j, elem)); // TDOO: make this work with multi-arity arrays
190191 TRACE (" mbp_tg" ,
191- tout << " applying elimwreq on " << expr_ref (p.mk_peq (), m) << " is neg: " << is_neg; );
192+ tout << " applying elimwreq on " << expr_ref (p.mk_peq (), m) << " is neg: " << is_neg << " \n " );
192193 vector<expr_ref_vector> indices;
193194 bool in = false ;
194195 p.get_diff_indices (indices);
@@ -201,7 +202,8 @@ struct mbp_array_tg::impl {
201202 // save for later
202203 eq_index = i;
203204 break ;
204- } else
205+ }
206+ else
205207 deq.push_back (i);
206208 }
207209 }
@@ -216,7 +218,8 @@ struct mbp_array_tg::impl {
216218 m_tg.add_eq (p_new.mk_peq (), p.mk_peq ());
217219 return ;
218220 }
219- for (expr *d : deq) { m_tg.add_deq (j, d); }
221+ for (expr *d : deq)
222+ m_tg.add_deq (j, d);
220223 expr_ref_vector setOne (m);
221224 setOne.push_back (j);
222225 indices.push_back (setOne);
@@ -226,9 +229,11 @@ struct mbp_array_tg::impl {
226229 m_tg.add_lit (p_new.mk_peq ());
227230 m_tg.add_eq (rd, elem);
228231 m_tg.add_eq (p.mk_peq (), p_new.mk_peq ());
229- } else {
232+ }
233+ else {
230234 expr_ref rd_eq (m.mk_eq (rd, elem), m);
231- if (m_mdl.is_false (rd_eq)) { m_tg.add_deq (rd, elem); }
235+ if (m_mdl.is_false (rd_eq))
236+ m_tg.add_deq (rd, elem);
232237 else {
233238 expr_ref npeq (mk_not (p_new.mk_peq ()), m);
234239 m_tg.add_lit (npeq);
@@ -293,23 +298,22 @@ struct mbp_array_tg::impl {
293298 // iterate through all terms in m_tg and apply all array MBP rules once
294299 // returns true if any rules were applied
295300 bool apply () {
296- TRACE (" mbp_tg" , tout << " Iterating over terms of tg" ; );
301+ TRACE (" mbp_tg" , tout << " Iterating over terms of tg\n " );
297302 indices.reset ();
298303 rdTerms.reset ();
299304 m_new_vars.reset ();
300305 expr_ref e (m), rdEq (m), rdDeq (m);
301- expr *nt, *term ;
306+ expr *nt = nullptr ;
302307 bool progress = false , is_neg = false ;
303308
304309 // Not resetting terms because get_terms calls resize on terms
305310 m_tg.get_terms (terms, false );
306- for (unsigned i = 0 ; i < terms.size (); i++) {
307- term = terms.get (i);
311+ for (expr* term : terms) {
308312 if (m_seen.is_marked (term))
309313 continue ;
310314 if (m_tg.is_cgr (term))
311315 continue ;
312- TRACE (" mbp_tg" , tout << " processing " << expr_ref (term, m); );
316+ TRACE (" mbp_tg" , tout << " processing " << expr_ref (term, m) << " \n " );
313317 expr* a, *b;
314318 if (is_implicit_peq (term, a, b) || is_neg_peq (term, a, b)) {
315319 // rewrite array eq as peq
@@ -337,7 +341,6 @@ struct mbp_array_tg::impl {
337341 if (!m_array_util.is_store (p.lhs ()) && has_var (p.lhs ()) && !is_neg) {
338342 // TODO: don't apply this rule if vars in p.lhs() also
339343 // appear in p.rhs()
340-
341344 mark_seen (p.lhs ());
342345 mark_seen (nt);
343346 mark_seen (term);
@@ -357,6 +360,7 @@ struct mbp_array_tg::impl {
357360 continue ;
358361 }
359362 }
363+ TRACE (" mbp_tg" , tout << " not applying any rules on " << expr_ref (nt, m) << " " << is_rd_wr (nt) << " " << m_use_mdl << " \n " ;);
360364 if (m_use_mdl && is_rd_wr (nt)) {
361365 mark_seen (term);
362366 progress = true ;
@@ -368,23 +372,22 @@ struct mbp_array_tg::impl {
368372 // iterate over term graph again to collect read terms
369373 // irrespective of whether they have been marked or not
370374 rdTerms.reset ();
371- for (unsigned i = 0 ; i < terms.size (); i++) {
372- term = terms.get (i);
375+ for (auto term : terms) {
373376 if (m_array_util.is_select (term) &&
374377 has_var (to_app (term)->get_arg (0 ))) {
375- rdTerms.push_back (term);
378+ rdTerms.push_back (to_app ( term) );
376379 if (is_seen (term)) continue ;
377380 add_rdVar (term);
378381 mark_seen (term);
379382 }
380383 }
381384 if (!m_use_mdl)
382- return progress;
385+ return progress;
383386 for (unsigned i = 0 ; i < rdTerms.size (); i++) {
384- app* e1 = to_app ( rdTerms.get (i) );
387+ app* e1 = rdTerms.get (i);
385388 expr* a1 = e1 ->get_arg (0 );
386389 for (unsigned j = i + 1 ; j < rdTerms.size (); j++) {
387- app* e2 = to_app ( rdTerms.get (j) );
390+ app* e2 = rdTerms.get (j);
388391 expr* a2 = e2 ->get_arg (0 );
389392 if (!is_seen (e1 , e2 ) && a1 == e2 ) {
390393 mark_seen (e1 , e2 );
0 commit comments