3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-26 21:16:02 +00:00

Centralize and document TRACE tags using X-macros (#7657)

* Introduce X-macro-based trace tag definition
- Created trace_tags.def to centralize TRACE tag definitions
- Each tag includes a symbolic name and description
- Set up enum class TraceTag for type-safe usage in TRACE macros

* Add script to generate Markdown documentation from trace_tags.def
- Python script parses trace_tags.def and outputs trace_tags.md

* Refactor TRACE_NEW to prepend TraceTag and pass enum to is_trace_enabled

* trace: improve trace tag handling system with hierarchical tagging

- Introduce hierarchical tag-class structure: enabling a tag class activates all child tags
- Unify TRACE, STRACE, SCTRACE, and CTRACE under enum TraceTag
- Implement initial version of trace_tag.def using X(tag, tag_class, description)
  (class names and descriptions to be refined in a future update)

* trace: replace all string-based TRACE tags with enum TraceTag
- Migrated all TRACE, STRACE, SCTRACE, and CTRACE macros to use enum TraceTag values instead of raw string literals

* trace : add cstring header

* trace : Add Markdown documentation generation from trace_tags.def via mk_api_doc.py

* trace : rename macro parameter 'class' to 'tag_class' and remove Unicode comment in trace_tags.h.

* trace : Add TODO comment for future implementation of tag_class activation

* trace : Disable code related to tag_class until implementation is ready (#7663).
This commit is contained in:
LeeYoungJoon 2025-05-28 22:31:25 +09:00 committed by GitHub
parent d766292dab
commit 0a93ff515d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
583 changed files with 8698 additions and 7299 deletions

View file

@ -66,7 +66,7 @@ struct bit_blaster_model_converter : public model_converter {
bits.insert(to_app(bit)->get_decl());
}
}
TRACE("model_converter",
TRACE(model_converter,
tout << "bits that should not be included in the model:\n";
for (func_decl* f : bits) {
tout << f->get_name() << " ";
@ -81,14 +81,14 @@ struct bit_blaster_model_converter : public model_converter {
func_decl * f = old_model->get_constant(i);
if (bits.contains(f))
continue;
TRACE("model_converter", tout << "non-bit: " << f->get_name() << "\n";);
TRACE(model_converter, tout << "non-bit: " << f->get_name() << "\n";);
expr * fi = old_model->get_const_interp(f);
new_model->register_decl(f, fi);
}
TRACE("model_converter", tout << "after copy non bits:\n"; model_pp(tout, *new_model););
TRACE(model_converter, tout << "after copy non bits:\n"; model_pp(tout, *new_model););
new_model->copy_func_interps(*old_model);
new_model->copy_usort_interps(*old_model);
TRACE("model_converter", tout << "after copying functions and sorts:\n"; model_pp(tout, *new_model););
TRACE(model_converter, tout << "after copying functions and sorts:\n"; model_pp(tout, *new_model););
}
void mk_bvs(model * old_model, model * new_model) {

View file

@ -59,7 +59,7 @@ class bit_blaster_tactic : public tactic {
tactic_report report("bit-blast", *g);
TRACE("before_bit_blaster", g->display(tout););
TRACE(before_bit_blaster, g->display(tout););
m_num_steps = 0;
m_rewriter->start_rewrite();
@ -79,7 +79,7 @@ class bit_blaster_tactic : public tactic {
}
if (curr != new_curr) {
change = true;
TRACE("bit_blaster", tout << mk_pp(curr, m()) << " -> " << new_curr << "\n";);
TRACE(bit_blaster, tout << mk_pp(curr, m()) << " -> " << new_curr << "\n";);
g->update(idx, new_curr, new_pr, g->dep(idx));
}
}
@ -92,7 +92,7 @@ class bit_blaster_tactic : public tactic {
}
g->inc_depth();
result.push_back(g.get());
TRACE("after_bit_blaster", g->display(tout); if (g->mc()) g->mc()->display(tout); tout << "\n";);
TRACE(after_bit_blaster, g->display(tout); if (g->mc()) g->mc()->display(tout); tout << "\n";);
m_rewriter->cleanup();
}

View file

@ -56,7 +56,7 @@ struct bv_bound_chk_rewriter_cfg : public default_rewriter_cfg {
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) {
const br_status st = reduce_app_core(f, num, args, result, result_pr);
CTRACE("bv_bound_chk_step", st != BR_FAILED,
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";
tout << "---------->\n" << mk_ismt2_pp(result, m()) << "\n";);

View file

@ -145,7 +145,7 @@ public:
if (m_util.is_bv_sle(f, lhs, rhs)) {
bv_sz = m_util.get_bv_size(lhs);
if (is_uninterp_const(lhs) && m_util.is_numeral(rhs, val, bv_sz)) {
TRACE("bv_size_reduction", tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
TRACE(bv_size_reduction, tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
// v <= k
val = m_util.norm(val, bv_sz, true);
if (negated) {
@ -160,7 +160,7 @@ public:
else update_signed_upper(to_app(lhs), val);
}
else if (is_uninterp_const(rhs) && m_util.is_numeral(lhs, val, bv_sz)) {
TRACE("bv_size_reduction", tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
TRACE(bv_size_reduction, tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
// k <= v
val = m_util.norm(val, bv_sz, true);
if (negated) {
@ -178,7 +178,7 @@ public:
#if 0
else if (m_util.is_bv_ule(f, lhs, rhs)) {
if (is_uninterp_const(lhs) && m_util.is_numeral(rhs, val, bv_sz)) {
TRACE("bv_size_reduction", tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
TRACE(bv_size_reduction, tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
// v <= k
if (negated)
update_unsigned_lower(to_app(lhs), val+numeral(1));
@ -186,7 +186,7 @@ public:
update_unsigned_upper(to_app(lhs), val);
}
else if (is_uninterp_const(rhs) && m_util.is_numeral(lhs, val, bv_sz)) {
TRACE("bv_size_reduction", tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
TRACE(bv_size_reduction, tout << (negated?"not ":"") << mk_ismt2_pp(f, m) << std::endl; );
// k <= v
if (negated)
update_unsigned_upper(to_app(rhs), val-numeral(1));
@ -212,7 +212,7 @@ public:
void run(goal & g, model_converter_ref & mc) {
if (g.inconsistent())
return;
TRACE("before_bv_size_reduction", g.display(tout););
TRACE(before_bv_size_reduction, g.display(tout););
m_produce_models = g.models_enabled();
mc = nullptr;
m_mc = nullptr;
@ -243,7 +243,7 @@ public:
if (!(m_signed_lowers.empty() || m_signed_uppers.empty())) {
TRACE("bv_size_reduction",
TRACE(bv_size_reduction,
tout << "m_signed_lowers: " << std::endl;
for (auto const& [k, v] : m_signed_lowers)
tout << mk_ismt2_pp(k, m) << " >= " << v.to_string() << std::endl;
@ -258,7 +258,7 @@ public:
obj_map<app, numeral>::obj_map_entry * entry = m_signed_uppers.find_core(k);
if (entry != nullptr) {
numeral u = m_util.norm(entry->get_data().m_value, bv_sz, true);
TRACE("bv_size_reduction", tout << l << " <= " << k->get_decl()->get_name() << " <= " << u << "\n";);
TRACE(bv_size_reduction, tout << l << " <= " << k->get_decl()->get_name() << " <= " << u << "\n";);
expr * new_def = nullptr;
app * new_const = nullptr;
if (l > u) {
@ -278,7 +278,7 @@ public:
{
// l <= v <= u <= 0
unsigned i_nb = l_nb;
TRACE("bv_size_reduction", tout << " l <= " << k->get_decl()->get_name() << " <= u <= 0 " << " --> " << i_nb << " bits\n";);
TRACE(bv_size_reduction, tout << " l <= " << k->get_decl()->get_name() << " <= u <= 0 " << " --> " << i_nb << " bits\n";);
if (i_nb < v_nb) {
new_const = m.mk_fresh_const(nullptr, m_util.mk_sort(i_nb));
new_def = m_util.mk_concat(m_util.mk_numeral(numeral(-1), v_nb - i_nb), new_const);
@ -288,7 +288,7 @@ public:
// l <= v <= 0 <= u
unsigned u_nb = u.get_num_bits();
unsigned i_nb = ((l_nb > u_nb) ? l_nb : u_nb) + 1;
TRACE("bv_size_reduction", tout << " l <= " << k->get_decl()->get_name() << " <= 0 <= u " << " --> " << i_nb << " bits\n";);
TRACE(bv_size_reduction, tout << " l <= " << k->get_decl()->get_name() << " <= 0 <= u " << " --> " << i_nb << " bits\n";);
if (i_nb < v_nb) {
new_const = m.mk_fresh_const(nullptr, m_util.mk_sort(i_nb));
new_def = m_util.mk_sign_extend(v_nb - i_nb, new_const);
@ -299,7 +299,7 @@ public:
// 0 <= l <= v <= u
unsigned u_nb = u.get_num_bits();
unsigned v_nb = m_util.get_bv_size(k);
TRACE("bv_size_reduction", tout << l << " <= " << k->get_decl()->get_name() << " <= " << u << " --> " << u_nb << " bits\n";);
TRACE(bv_size_reduction, tout << l << " <= " << k->get_decl()->get_name() << " <= " << u << " --> " << u_nb << " bits\n";);
if (u_nb < v_nb) {
new_const = m.mk_fresh_const(nullptr, m_util.mk_sort(u_nb));
new_def = m_util.mk_concat(m_util.mk_numeral(numeral(0), v_nb - u_nb), new_const);
@ -325,7 +325,7 @@ public:
#if 0
if (!(m_unsigned_lowers.empty() && m_unsigned_uppers.empty())) {
TRACE("bv_size_reduction",
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++)
tout << mk_ismt2_pp(it->m_key, m) << " >= " << it->m_value.to_string() << std::endl;
@ -352,7 +352,7 @@ public:
if (lse != 0 && lse->get_data().m_value > l) l = lse->get_data().m_value;
if (use != 0 && use->get_data().m_value < u) u = use->get_data().m_value;
TRACE("bv_size_reduction", tout << l << " <= " << v->get_decl()->get_name() << " <= " << u << "\n";);
TRACE(bv_size_reduction, tout << l << " <= " << v->get_decl()->get_name() << " <= " << u << "\n";);
expr * new_def = 0;
app * new_const = 0;
if (l > u) {
@ -384,7 +384,7 @@ public:
m_fmc->hide(new_const);
}
num_reduced++;
TRACE("bv_size_reduction", tout << "New definition = " << mk_ismt2_pp(new_def, m) << "\n";);
TRACE(bv_size_reduction, tout << "New definition = " << mk_ismt2_pp(new_def, m) << "\n";);
}
}
}
@ -413,7 +413,7 @@ public:
m_fmc = nullptr;
}
report_tactic_progress(":bv-reduced", num_reduced);
TRACE("after_bv_size_reduction", g.display(tout); if (m_mc) m_mc->display(tout););
TRACE(after_bv_size_reduction, g.display(tout); if (m_mc) m_mc->display(tout););
}
};
@ -422,7 +422,7 @@ void bv_size_reduction_tactic::operator()(goal_ref const & g,
goal_ref_buffer & result) {
fail_if_proof_generation("bv-size-reduction", g);
fail_if_unsat_core_generation("bv-size-reduction", g);
TRACE("goal", g->display(tout););
TRACE(goal, g->display(tout););
result.reset();
model_converter_ref mc;
run(*(g.get()), mc);

View file

@ -111,7 +111,7 @@ func_decl_ref bvarray2uf_rewriter_cfg::mk_uf_for_array(expr * e) {
sort * domain = get_index_sort(e);
sort * range = get_value_sort(e);
bv_f = m_manager.mk_fresh_func_decl("f_t", "", 1, &domain, range);
TRACE("bvarray2uf_rw", tout << "for " << mk_ismt2_pp(e, m_manager) << " new func_decl is " << mk_ismt2_pp(bv_f, m_manager) << std::endl; );
TRACE(bvarray2uf_rw, tout << "for " << mk_ismt2_pp(e, m_manager) << " new func_decl is " << mk_ismt2_pp(bv_f, m_manager) << std::endl; );
if (m_fmc) {
m_fmc->hide(bv_f);
if (is_uninterp_const(e))
@ -122,7 +122,7 @@ func_decl_ref bvarray2uf_rewriter_cfg::mk_uf_for_array(expr * e) {
m_manager.inc_ref(bv_f);
}
else {
TRACE("bvarray2uf_rw", tout << "for " << mk_ismt2_pp(e, m_manager) << " found " << mk_ismt2_pp(bv_f, m_manager) << std::endl; );
TRACE(bvarray2uf_rw, tout << "for " << mk_ismt2_pp(e, m_manager) << " found " << mk_ismt2_pp(bv_f, m_manager) << std::endl; );
}
return func_decl_ref(bv_f, m_manager);
@ -164,7 +164,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
func_decl_ref f_t(mk_uf_for_array(args[1]), m_manager);
func_decl_ref f_f(mk_uf_for_array(args[2]), m_manager);
TRACE("bvarray2uf_rw", tout << "(ite " << c << ", " << f_t->get_name()
TRACE(bvarray2uf_rw, tout << "(ite " << c << ", " << f_t->get_name()
<< ", " << f_f->get_name() << ")" << std::endl;);
sort * sorts[1] = { get_index_sort(args[1]->get_sort()) };
@ -189,7 +189,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
result = m_array_util.mk_as_array(bv_f);
TRACE("bvarray2uf_rw", tout << "result: " << mk_ismt2_pp(result, m_manager) << ")" << std::endl;);
TRACE(bvarray2uf_rw, tout << "result: " << mk_ismt2_pp(result, m_manager) << ")" << std::endl;);
res = BR_DONE;
}
@ -197,7 +197,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
throw default_exception("not handled by bvarray2uf");
}
else if (f->get_family_id() == null_family_id) {
TRACE("bvarray2uf_rw", tout << "UF APP: " << f->get_name() << std::endl; );
TRACE(bvarray2uf_rw, tout << "UF APP: " << f->get_name() << std::endl; );
bool has_bv_arrays = false;
func_decl_ref f_t(m_manager);
@ -225,13 +225,13 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
res = BR_FAILED;
}
else if (m_array_util.get_family_id() == f->get_family_id()) {
TRACE("bvarray2uf_rw", tout << "APP: " << f->get_name() << std::endl; );
TRACE(bvarray2uf_rw, tout << "APP: " << f->get_name() << std::endl; );
if (m_array_util.is_select(f)) {
SASSERT(num == 2);
expr * t = args[0];
expr * i = args[1];
TRACE("bvarray2uf_rw", tout <<
TRACE(bvarray2uf_rw, tout <<
"select; array: " << mk_ismt2_pp(t, m()) <<
" index: " << mk_ismt2_pp(i, m()) << std::endl;);
@ -309,7 +309,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
expr * s = args[0];
expr * i = args[1];
expr * v = args[2];
TRACE("bvarray2uf_rw", tout <<
TRACE(bvarray2uf_rw, tout <<
"store; array: " << mk_ismt2_pp(s, m()) <<
" index: " << mk_ismt2_pp(i, m()) <<
" value: " << mk_ismt2_pp(v, m()) << std::endl;);
@ -340,7 +340,7 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
expr_ref ground_atom(m_manager);
ground_atom = m_manager.mk_eq(m_manager.mk_app(f_t, i), v);
extra_assertions.push_back(ground_atom);
TRACE("bvarray2uf_rw", tout << "ground atom: " << mk_ismt2_pp(ground_atom, m()) << std::endl; );
TRACE(bvarray2uf_rw, tout << "ground atom: " << mk_ismt2_pp(ground_atom, m()) << std::endl; );
}
}
else {
@ -350,17 +350,17 @@ br_status bvarray2uf_rewriter_cfg::reduce_app(func_decl * f, unsigned num, expr
}
}
CTRACE("bvarray2uf_rw", res == BR_DONE, tout << "result: " << mk_ismt2_pp(result, m()) << std::endl; );
CTRACE(bvarray2uf_rw, res == BR_DONE, tout << "result: " << mk_ismt2_pp(result, m()) << std::endl; );
return res;
}
bool bvarray2uf_rewriter_cfg::pre_visit(expr * t)
{
TRACE("bvarray2uf_rw_q", tout << "pre_visit: " << mk_ismt2_pp(t, m()) << std::endl;);
TRACE(bvarray2uf_rw_q, tout << "pre_visit: " << mk_ismt2_pp(t, m()) << std::endl;);
if (is_quantifier(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;);
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++)
new_bindings.push_back(q->get_decl_sort(i));

View file

@ -69,7 +69,7 @@ class elim_small_bv_tactic : public tactic {
expr_ref replace_var(used_vars & uv,
unsigned num_decls, unsigned max_var_idx_p1,
unsigned idx, sort * s, expr * e, expr * replacement) {
TRACE("elim_small_bv", tout << "replace idx " << idx << " with " << mk_ismt2_pp(replacement, m) <<
TRACE(elim_small_bv, tout << "replace idx " << idx << " with " << mk_ismt2_pp(replacement, m) <<
" in " << mk_ismt2_pp(e, m) << std::endl;);
expr_ref res(m);
ptr_vector<expr> substitution;
@ -88,7 +88,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;
TRACE(elim_small_bv, tout << "substitution: " << std::endl;
for (unsigned k = 0; k < substitution.size(); k++) {
expr * se = substitution[k];
tout << k << " = ";
@ -103,13 +103,13 @@ class elim_small_bv_tactic : public tactic {
proof_ref pr(m);
m_simp(res, res, pr);
TRACE("elim_small_bv", tout << "replace done: " << mk_ismt2_pp(res, m) << std::endl;);
TRACE(elim_small_bv, tout << "replace done: " << mk_ismt2_pp(res, m) << std::endl;);
return res;
}
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) {
TRACE("elim_small_bv_app", expr_ref tmp(m.mk_app(f, num, args), m); tout << "reduce " << tmp << std::endl; );
TRACE(elim_small_bv_app, expr_ref tmp(m.mk_app(f, num, args), m); tout << "reduce " << tmp << std::endl; );
return BR_FAILED;
}
@ -123,7 +123,7 @@ class elim_small_bv_tactic : public tactic {
if (is_lambda(q)) {
return false;
}
TRACE("elim_small_bv", tout << "reduce_quantifier " << mk_ismt2_pp(q, m) << std::endl; );
TRACE(elim_small_bv, tout << "reduce_quantifier " << mk_ismt2_pp(q, m) << std::endl; );
unsigned long long num_steps = 0;
unsigned curr_sz = m_bindings.size();
SASSERT(q->get_num_decls() <= curr_sz);
@ -141,7 +141,7 @@ class elim_small_bv_tactic : public tactic {
expr_ref_vector new_bodies(m);
if (is_small_bv(s) && !max_steps_exceeded(num_steps)) {
unsigned bv_sz = m_util.get_bv_size(s);
TRACE("elim_small_bv", tout << "eliminating " << q->get_decl_name(i) <<
TRACE(elim_small_bv, tout << "eliminating " << q->get_decl_name(i) <<
"; sort = " << mk_ismt2_pp(s, m) <<
"; body = " << mk_ismt2_pp(body, m) << std::endl;);
@ -169,7 +169,7 @@ class elim_small_bv_tactic : public tactic {
return false;
}
TRACE("elim_small_bv", tout << "new bodies: " << std::endl;
TRACE(elim_small_bv, tout << "new bodies: " << std::endl;
for (unsigned k = 0; k < new_bodies.size(); k++)
tout << mk_ismt2_pp(new_bodies[k].get(), m) << std::endl; );
@ -187,7 +187,7 @@ class elim_small_bv_tactic : public tactic {
unused_vars_eliminator el(m, m_params);
result = el(new_q);
TRACE("elim_small_bv", tout << "elimination result: " << mk_ismt2_pp(result, m) << std::endl; );
TRACE(elim_small_bv, tout << "elimination result: " << mk_ismt2_pp(result, m) << std::endl; );
result_pr = nullptr; // proofs NIY
m_bindings.shrink(old_sz);
@ -195,10 +195,10 @@ class elim_small_bv_tactic : public tactic {
}
bool pre_visit(expr * t) {
TRACE("elim_small_bv_pre", tout << "pre_visit: " << mk_ismt2_pp(t, m) << std::endl;);
TRACE(elim_small_bv_pre, tout << "pre_visit: " << mk_ismt2_pp(t, m) << std::endl;);
if (is_quantifier(t)) {
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;);
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++)
new_bindings.push_back(q->get_decl_sort(i));