3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-23 00:37:36 +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

@ -102,7 +102,7 @@ bool demodulator_util::is_demodulator(expr * e, app_ref & large, expr_ref & smal
if (m.is_eq(qe, lhs, rhs)) {
int subset = is_subset(lhs, rhs);
int smaller = is_smaller(lhs, rhs);
TRACE("demodulator", tout << "testing is_demodulator:\n"
TRACE(demodulator, tout << "testing is_demodulator:\n"
<< mk_pp(lhs, m) << "\n"
<< mk_pp(rhs, m) << "\n"
<< "subset: " << subset << ", smaller: " << smaller << "\n";);
@ -190,7 +190,7 @@ demodulator_rewriter_util::demodulator_rewriter_util(ast_manager& m):
expr_ref demodulator_rewriter_util::rewrite(expr * n) {
TRACE("demodulator", tout << "rewrite: " << mk_pp(n, m) << std::endl; );
TRACE(demodulator, tout << "rewrite: " << mk_pp(n, m) << std::endl; );
app * a;
SASSERT(m_rewrite_todo.empty());
@ -199,7 +199,7 @@ expr_ref demodulator_rewriter_util::rewrite(expr * n) {
m_rewrite_todo.push_back(n);
while (!m_rewrite_todo.empty()) {
TRACE("demodulator_stack", tout << "STACK: " << std::endl;
TRACE(demodulator_stack, tout << "STACK: " << std::endl;
for (unsigned i = 0; i < m_rewrite_todo.size(); i++)
tout << std::dec << i << ": " << std::hex << (size_t)m_rewrite_todo[i] <<
" = " << mk_pp(m_rewrite_todo[i], m) << std::endl;
@ -251,7 +251,7 @@ expr_ref demodulator_rewriter_util::rewrite(expr * n) {
else {
expr_ref na(m);
na = m_th_rewriter.mk_app(f, m_new_args);
TRACE("demodulator_bug", tout << "e:\n" << mk_pp(e, m) << "\nnew_args: \n";
TRACE(demodulator_bug, tout << "e:\n" << mk_pp(e, m) << "\nnew_args: \n";
tout << m_new_args << "\n";
tout << "=====>\n";
tout << "na:\n " << na << "\n";);
@ -289,7 +289,7 @@ expr_ref demodulator_rewriter_util::rewrite(expr * n) {
SASSERT(ebp.second);
expr * r = ebp.first;
TRACE("demodulator", tout << "rewrite result: " << mk_pp(r, m) << std::endl; );
TRACE(demodulator, tout << "rewrite result: " << mk_pp(r, m) << std::endl; );
return expr_ref(r, m);
}
@ -309,7 +309,7 @@ bool demodulator_rewriter_util::rewrite_visit_children(app * a) {
for (expr* t : m_rewrite_todo) {
if (t == v) {
recursive = true;
TRACE("demodulator", tout << "Detected demodulator cycle: " <<
TRACE(demodulator, tout << "Detected demodulator cycle: " <<
mk_pp(a, m) << " --> " << mk_pp(v, m) << std::endl;);
rewrite_cache(e, v, true);
break;
@ -362,7 +362,7 @@ demodulator_rewriter::~demodulator_rewriter() {
void demodulator_rewriter::insert_fwd_idx(app * large, expr * small, quantifier * demodulator) {
SASSERT(demodulator);
SASSERT(large && small);
TRACE("demodulator_fwd", tout << "INSERT: " << mk_pp(demodulator, m) << std::endl; );
TRACE(demodulator_fwd, tout << "INSERT: " << mk_pp(demodulator, m) << std::endl; );
func_decl * fd = to_app(large)->get_decl();
@ -382,7 +382,7 @@ void demodulator_rewriter::insert_fwd_idx(app * large, expr * small, quantifier
}
void demodulator_rewriter::remove_fwd_idx(func_decl * f, quantifier * demodulator) {
TRACE("demodulator_fwd", tout << "REMOVE: " << std::hex << (size_t)demodulator << std::endl; );
TRACE(demodulator_fwd, tout << "REMOVE: " << std::hex << (size_t)demodulator << std::endl; );
quantifier_set* qs;
if (m_fwd_idx.find(f, qs)) {
@ -425,7 +425,7 @@ bool demodulator_rewriter::rewrite1(func_decl * f, expr_ref_vector const & args,
quantifier_set* set;
if (!m_fwd_idx.find(f, set))
return false;
TRACE("demodulator_bug", tout << "trying to rewrite: " << f->get_name() << " args:\n";
TRACE(demodulator_bug, tout << "trying to rewrite: " << f->get_name() << " args:\n";
tout << m_new_args << "\n";);
for (quantifier* d : *set) {
@ -435,12 +435,12 @@ bool demodulator_rewriter::rewrite1(func_decl * f, expr_ref_vector const & args,
if (lhs->get_num_args() != args.size())
continue;
TRACE("demodulator_bug", tout << "Matching with demodulator: " << mk_pp(d, m) << std::endl; );
TRACE(demodulator_bug, tout << "Matching with demodulator: " << mk_pp(d, m) << std::endl; );
SASSERT(lhs->get_decl() == f);
if (m_match_subst(lhs, rhs, args.data(), np)) {
TRACE("demodulator_bug", tout << "succeeded...\n" << mk_pp(rhs, m) << "\n===>\n" << mk_pp(np, m) << "\n";);
TRACE(demodulator_bug, tout << "succeeded...\n" << mk_pp(rhs, m) << "\n===>\n" << mk_pp(np, m) << "\n";);
m_new_exprs.push_back(np);
return true;
}
@ -464,7 +464,7 @@ bool demodulator_rewriter::rewrite_visit_children(app * a) {
for (expr* t : m_rewrite_todo) {
if (t == v) {
recursive = true;
TRACE("demodulator", tout << "Detected demodulator cycle: " <<
TRACE(demodulator, tout << "Detected demodulator cycle: " <<
mk_pp(a, m) << " --> " << mk_pp(v, m) << std::endl;);
rewrite_cache(e, v, true);
break;
@ -486,7 +486,7 @@ expr * demodulator_rewriter::rewrite(expr * n) {
if (m_fwd_idx.empty())
return n;
TRACE("demodulator", tout << "rewrite: " << mk_pp(n, m) << std::endl; );
TRACE(demodulator, tout << "rewrite: " << mk_pp(n, m) << std::endl; );
app * a;
SASSERT(m_rewrite_todo.empty());
@ -494,7 +494,7 @@ expr * demodulator_rewriter::rewrite(expr * n) {
m_rewrite_todo.push_back(n);
while (!m_rewrite_todo.empty()) {
TRACE("demodulator_stack", tout << "STACK: " << std::endl;
TRACE(demodulator_stack, tout << "STACK: " << std::endl;
for (unsigned i = 0; i < m_rewrite_todo.size(); i++)
tout << std::dec << i << ": " << std::hex << (size_t)m_rewrite_todo[i] <<
" = " << mk_pp(m_rewrite_todo[i], m) << std::endl;
@ -549,7 +549,7 @@ expr * demodulator_rewriter::rewrite(expr * n) {
na = m.mk_app(f, m_new_args);
else
m_bsimp.mk_app(f, m_new_args.size(), m_new_args.data(), na);
TRACE("demodulator_bug", tout << "e:\n" << mk_pp(e, m) << "\nnew_args: \n";
TRACE(demodulator_bug, tout << "e:\n" << mk_pp(e, m) << "\nnew_args: \n";
tout << m_new_args << "\n";
tout << "=====>\n";
tout << "na:\n " << na << "\n";);
@ -587,7 +587,7 @@ expr * demodulator_rewriter::rewrite(expr * n) {
SASSERT(ebp.second);
expr * r = ebp.first;
TRACE("demodulator", tout << "rewrite result: " << mk_pp(r, m) << std::endl; );
TRACE(demodulator, tout << "rewrite result: " << mk_pp(r, m) << std::endl; );
return r;
}
@ -703,7 +703,7 @@ void demodulator_rewriter::reschedule_demodulators(func_decl * f, expr * lhs) {
if (!m_match_subst.can_rewrite(d, lhs))
continue;
TRACE("demodulator", tout << "Rescheduling: " << std::endl << mk_pp(d, m) << std::endl);
TRACE(demodulator, tout << "Rescheduling: " << std::endl << mk_pp(d, m) << std::endl);
remove_fwd_idx(df, d);
remove_bwd_idx(d);
@ -714,7 +714,7 @@ void demodulator_rewriter::reschedule_demodulators(func_decl * f, expr * lhs) {
void demodulator_rewriter::operator()(expr_ref_vector const& exprs,
expr_ref_vector & new_exprs) {
TRACE("demodulator", tout << "before demodulator:\n" << exprs);
TRACE(demodulator, tout << "before demodulator:\n" << exprs);
// Initially, m_todo contains all formulas. That is, it contains the argument exprs. m_fwd_idx, m_processed, m_back_idx are empty.
for (expr* e : exprs)
@ -745,7 +745,7 @@ void demodulator_rewriter::operator()(expr_ref_vector const& exprs,
}
else {
// np is a demodulator that allows us to replace 'large' with 'small'.
TRACE("demodulator", tout << "Found demodulator:\n" << large << "\n ---> " << small << "\n");
TRACE(demodulator, tout << "Found demodulator:\n" << large << "\n ---> " << small << "\n");
// let f be the top symbol of n'
func_decl * f = large->get_decl();
@ -764,18 +764,18 @@ void demodulator_rewriter::operator()(expr_ref_vector const& exprs,
// the result is the contents of m_processed + all demodulators in m_fwd_idx.
for (expr* e : m_processed) {
new_exprs.push_back(e);
TRACE("demodulator", tout << mk_pp(e, m) << std::endl; );
TRACE(demodulator, tout << mk_pp(e, m) << std::endl; );
}
for (auto const& [k, set] : m_fwd_idx) {
if (set) {
for (expr* e : *set)
new_exprs.push_back(e);
TRACE("demodulator", for (expr* e : *set) tout << mk_pp(e, m) << std::endl; );
TRACE(demodulator, for (expr* e : *set) tout << mk_pp(e, m) << std::endl; );
}
}
TRACE("demodulator", tout << "after demodulator:\n" << new_exprs << "\n";);
TRACE(demodulator, tout << "after demodulator:\n" << new_exprs << "\n";);
}

View file

@ -39,7 +39,7 @@ void substitution::reset() {
void substitution::reset_cache() {
TRACE("subst_bug", tout << "substitution::reset_cache\n";
TRACE(subst_bug, tout << "substitution::reset_cache\n";
for (unsigned i = 0; i < m_new_exprs.size(); i++) { tout << mk_pp(m_new_exprs.get(i), m_manager) << "\nref_count: " << m_new_exprs.get(i)->get_ref_count() << "\n"; });
m_apply_cache.reset();
@ -74,7 +74,7 @@ inline void substitution::apply_visit(expr_offset const & n, bool & visited) {
void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, expr_offset const & n,
expr_offset const & s, expr_offset const & t, expr_ref & result) {
TRACE("subst_bug", tout << "BEGIN substitution::apply\n";);
TRACE(subst_bug, tout << "BEGIN substitution::apply\n";);
// It is incorrect to cache results between different calls if we are applying a substitution
@ -95,13 +95,13 @@ void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, e
m_todo.push_back(n);
while (!m_todo.empty()) {
expr_offset n = m_todo.back();
TRACE("subst_bug", tout << "n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset() << "\n";);
TRACE(subst_bug, tout << "n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset() << "\n";);
if (m_apply_cache.contains(n)) {
m_todo.pop_back();
continue;
}
expr_offset n_prime = n == s ? t : n;
TRACE("subst_bug", tout << "n_prime: " << mk_pp(n_prime.get_expr(), m_manager) << " : " << n_prime.get_offset() << "\n";);
TRACE(subst_bug, tout << "n_prime: " << mk_pp(n_prime.get_expr(), m_manager) << " : " << n_prime.get_offset() << "\n";);
visited = true;
e = n_prime.get_expr();
off = n_prime.get_offset();
@ -109,13 +109,13 @@ void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, e
case AST_VAR:
if (find(to_var(e)->get_idx(), off, n1)) {
apply_visit(n1, visited);
TRACE("subst_bug", tout << "visited: " << visited << ", n1: " << mk_pp(n1.get_expr(), m_manager) << " : " << n1.get_offset() << "\n";);
TRACE(subst_bug, tout << "visited: " << visited << ", n1: " << mk_pp(n1.get_expr(), m_manager) << " : " << n1.get_offset() << "\n";);
if (visited) {
m_todo.pop_back();
expr * new_expr = nullptr;
m_apply_cache.find(n1, new_expr);
m_apply_cache.insert(n, new_expr);
TRACE("subst_bug", tout << "1. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
TRACE(subst_bug, tout << "1. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
<< " --> " << mk_pp(new_expr, m_manager) << "\n";);
}
}
@ -129,7 +129,7 @@ void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, e
m_new_exprs.push_back(new_expr);
}
m_apply_cache.insert(n, new_expr);
TRACE("subst_bug", tout << "2. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
TRACE(subst_bug, tout << "2. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
<< " --> " << mk_pp(new_expr, m_manager) << "\n";);
}
break;
@ -155,14 +155,14 @@ void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, e
}
if (!has_new_args) {
m_apply_cache.insert(n, e);
TRACE("subst_bug", tout << "3. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
TRACE(subst_bug, tout << "3. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
<< " --> " << mk_pp(e, m_manager) << "\n";);
}
else {
expr * new_expr = m_manager.mk_app(to_app(e)->get_decl(), new_args.size(), new_args.data());
m_new_exprs.push_back(new_expr);
m_apply_cache.insert(n, new_expr);
TRACE("subst_bug", tout << "3. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
TRACE(subst_bug, tout << "3. insert n: " << mk_pp(n.get_expr(), m_manager) << " : " << n.get_offset()
<< " --> " << mk_pp(new_expr, m_manager) << "\n";);
}
}
@ -221,7 +221,7 @@ void substitution::apply(unsigned num_actual_offsets, unsigned const * deltas, e
if (s != expr_offset(nullptr,0))
reset_cache();
TRACE("subst_bug", tout << "END substitution::apply\nresult:\n" << mk_pp(e, m_manager) << "\nref_count: " << e->get_ref_count() << "\n";);
TRACE(subst_bug, tout << "END substitution::apply\nresult:\n" << mk_pp(e, m_manager) << "\nref_count: " << e->get_ref_count() << "\n";);
}
inline substitution::color substitution::get_color(expr_offset const & p) const {

View file

@ -132,7 +132,7 @@ public:
// -----------------------------------
void insert(unsigned v_idx, unsigned offset, expr_offset const & t) {
TRACE("subst_insert", tout << "inserting: #" << v_idx << ":" << offset << " --> " << mk_pp(t.get_expr(), m_manager)
TRACE(subst_insert, tout << "inserting: #" << v_idx << ":" << offset << " --> " << mk_pp(t.get_expr(), m_manager)
<< ":" << t.get_offset() << "\n";);
m_vars.push_back(var_offset(v_idx, offset));
m_refs.push_back(t.get_expr());

View file

@ -106,7 +106,7 @@ void substitution_tree::linearize(svector<subst> & result) {
If save_set_registers == true, then r_i's are stored in m_to_reset.
*/
void substitution_tree::process_args(app * in, app * out) {
CTRACE("subst_tree_bug", in->get_num_args() != out->get_num_args(), tout << mk_ismt2_pp(in, m_manager) << "\n"
CTRACE(subst_tree_bug, in->get_num_args() != out->get_num_args(), tout << mk_ismt2_pp(in, m_manager) << "\n"
<< mk_ismt2_pp(out, m_manager) << "\n";);
unsigned num = out->get_num_args();
for (unsigned i = 0; i < num; i++) {
@ -622,7 +622,7 @@ void substitution_tree::display(std::ostream & out, node * n, unsigned delta) co
bool substitution_tree::backtrack() {
while (!m_bstack.empty()) {
TRACE("st", tout << "backtracking...\n";);
TRACE(st, tout << "backtracking...\n";);
m_subst->pop_scope();
node * n = m_bstack.back();
@ -636,9 +636,9 @@ bool substitution_tree::backtrack() {
}
inline expr_offset substitution_tree::find(expr_offset p) {
TRACE("substitution_tree_bug", tout << "find...\n";);
TRACE(substitution_tree_bug, tout << "find...\n";);
while (is_var(p.get_expr())) {
TRACE("substitution_tree_bug", tout << mk_pp(p.get_expr(), m_manager) << " " << p.get_offset() << "\n";);
TRACE(substitution_tree_bug, tout << mk_pp(p.get_expr(), m_manager) << " " << p.get_offset() << "\n";);
if (!m_subst->find(to_var(p.get_expr()), p.get_offset(), p))
return p;
}
@ -647,7 +647,7 @@ inline expr_offset substitution_tree::find(expr_offset p) {
template<substitution_tree::st_visit_mode Mode>
bool substitution_tree::bind_var(var * v, unsigned offset, expr_offset const & p) {
TRACE("st", tout << "bind_var: " << mk_pp(v, m_manager) << " " << offset << "\n" <<
TRACE(st, tout << "bind_var: " << mk_pp(v, m_manager) << " " << offset << "\n" <<
mk_pp(p.get_expr(), m_manager) << " " << p.get_offset() << "\n";);
if (Mode == STV_INST && offset == m_st_offset) {
SASSERT(!is_var(p.get_expr()) || p.get_offset() != m_reg_offset);
@ -666,7 +666,7 @@ bool substitution_tree::bind_var(var * v, unsigned offset, expr_offset const & p
return false;
}
m_subst->insert(v, offset, p);
TRACE("st_bug", tout << "substitution updated\n"; m_subst->display(tout););
TRACE(st_bug, tout << "substitution updated\n"; m_subst->display(tout););
return true;
}
@ -687,7 +687,7 @@ bool substitution_tree::unify_match(expr_offset p1, expr_offset p2) {
SASSERT(!is_quantifier(n2));
bool v1 = is_var(n1);
bool v2 = is_var(n2);
TRACE("st",
TRACE(st,
tout << "n1: " << mk_pp(n1, m_manager) << " " << p1.get_offset() << "\n";
tout << "n2: " << mk_pp(n2, m_manager) << " " << p2.get_offset() << "\n";);
if (v1 && v2) {
@ -758,7 +758,7 @@ bool substitution_tree::visit(svector<subst> const & sv) {
svector<subst>::const_iterator end = sv.end();
for (; it != end; ++it) {
subst const & s = *it;
TRACE("st", tout << "processing subst:\n"; display(tout, s); tout << "\n";);
TRACE(st, tout << "processing subst:\n"; display(tout, s); tout << "\n";);
var * rin = s.first;
expr * out = s.second;
expr_offset p1(rin, m_reg_offset);
@ -778,9 +778,9 @@ bool substitution_tree::visit(expr * e, st_visitor & st, node * r) {
while (true) {
node * n = m_bstack.back();
TRACE("st", tout << "push scope...\n";);
TRACE(st, tout << "push scope...\n";);
m_subst->push_scope();
TRACE("st", tout << "processing node:\n"; display(tout, n->m_subst); tout << "\n";);
TRACE(st, tout << "processing node:\n"; display(tout, n->m_subst); tout << "\n";);
if (visit<Mode>(n->m_subst)) {
if (n->m_leaf) {
// if searching for unifiers and the substitution is cyclic, then backtrack.
@ -789,7 +789,7 @@ bool substitution_tree::visit(expr * e, st_visitor & st, node * r) {
break;
}
else {
TRACE("st_bug", tout << "found match:\n"; m_subst->display(tout); tout << "m_subst: " << m_subst << "\n";);
TRACE(st_bug, tout << "found match:\n"; m_subst->display(tout); tout << "m_subst: " << m_subst << "\n";);
if (!st(n->m_expr)) {
clear_stack();
return false;

View file

@ -145,13 +145,13 @@ bool unifier::operator()(unsigned num_exprs, expr ** es, substitution & s, bool
reset(num_offsets);
m_subst = &s;
#if 1
TRACE("unifier", for (unsigned i = 0; i < num_exprs; ++i) tout << mk_pp(es[i], m_manager) << "\n";);
TRACE(unifier, for (unsigned i = 0; i < num_exprs; ++i) tout << mk_pp(es[i], m_manager) << "\n";);
for (unsigned i = s.get_num_bindings(); i > 0; ) {
--i;
std::pair<unsigned,unsigned> bound;
expr_offset root, child;
s.get_binding(i, bound, root);
TRACE("unifier", tout << bound.first << " |-> " << mk_pp(root.get_expr(), m_manager) << "\n";);
TRACE(unifier, tout << bound.first << " |-> " << mk_pp(root.get_expr(), m_manager) << "\n";);
if (is_var(root.get_expr())) {
var* v = m_manager.mk_var(bound.first,to_var(root.get_expr())->get_sort());
child = expr_offset(v, bound.second);