3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-11-02 04:27:52 +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

@ -25,7 +25,7 @@ Revision History:
bool macro_finder::is_macro(expr * n, app_ref & head, expr_ref & def) {
if (!is_forall(n))
return false;
TRACE("macro_finder", tout << "processing: " << mk_pp(n, m) << "\n";);
TRACE(macro_finder, tout << "processing: " << mk_pp(n, m) << "\n";);
expr * body = to_quantifier(n)->get_expr();
unsigned num_decls = to_quantifier(n)->get_num_decls();
return m_util.is_simple_macro(body, num_decls, head, def);
@ -89,7 +89,7 @@ bool macro_finder::is_arith_macro(expr * n, proof * pr, bool deps_valid, expr_de
}
// is ge or le
//
TRACE("macro_finder", tout << "is_arith_macro: is_ge or is_le " << f->get_name() << "\n";);
TRACE(macro_finder, tout << "is_arith_macro: is_ge or is_le " << f->get_name() << "\n";);
func_decl * k = m.mk_fresh_func_decl(f->get_name(), symbol::null, f->get_arity(), f->get_domain(), f->get_range());
app * k_app = m.mk_app(k, head->get_num_args(), head->get_args());
expr_ref_buffer new_rhs_args(m);
@ -161,7 +161,7 @@ bool macro_finder::is_arith_macro(expr * n, proof * pr, vector<justified_expr>&
}
// is ge or le
//
TRACE("macro_finder", tout << "is_arith_macro: is_ge or is_le\n";);
TRACE(macro_finder, tout << "is_arith_macro: is_ge or is_le\n";);
func_decl * k = m.mk_fresh_func_decl(f->get_name(), symbol::null, f->get_arity(), f->get_domain(), f->get_range());
app * k_app = m.mk_app(k, head->get_num_args(), head->get_args());
expr_ref_buffer new_rhs_args(m);
@ -270,7 +270,7 @@ macro_finder::macro_finder(ast_manager & m, macro_manager & mm):
}
bool macro_finder::expand_macros(expr_ref_vector const& exprs, proof_ref_vector const& prs, expr_dependency_ref_vector const& deps, expr_ref_vector & new_exprs, proof_ref_vector & new_prs, expr_dependency_ref_vector & new_deps) {
TRACE("macro_finder", tout << "starting expand_macros:\n";
TRACE(macro_finder, tout << "starting expand_macros:\n";
m_macro_manager.display(tout););
bool found_new_macro = false;
unsigned num = exprs.size();
@ -286,15 +286,15 @@ bool macro_finder::expand_macros(expr_ref_vector const& exprs, proof_ref_vector
m_macro_manager.expand_macros(n, pr, dep, new_n, new_pr, new_dep);
app_ref head(m), t(m);
if (is_macro(new_n, head, def) && m_macro_manager.insert(head->get_decl(), to_quantifier(new_n.get()), new_pr, new_dep)) {
TRACE("macro_finder", tout << "found new macro: " << head->get_decl()->get_name() << "\n" << new_n << "\n";);
TRACE(macro_finder, tout << "found new macro: " << head->get_decl()->get_name() << "\n" << new_n << "\n";);
found_new_macro = true;
}
else if (is_arith_macro(new_n, new_pr, deps_valid, new_dep, new_exprs, new_prs, new_deps)) {
TRACE("macro_finder", tout << "found new arith macro:\n" << new_n << "\n";);
TRACE(macro_finder, tout << "found new arith macro:\n" << new_n << "\n";);
found_new_macro = true;
}
else if (m_util.is_pseudo_predicate_macro(new_n, head, t, def)) {
TRACE("macro_finder", tout << "found new pseudo macro:\n" << head->get_decl()->get_name() << "\n" << t << "\n" << def << "\n";);
TRACE(macro_finder, tout << "found new pseudo macro:\n" << head->get_decl()->get_name() << "\n" << t << "\n" << def << "\n";);
pseudo_predicate_macro2macro(m, head, t, def, to_quantifier(new_n), new_pr, deps_valid, new_dep, new_exprs, new_prs, new_deps);
found_new_macro = true;
}
@ -313,7 +313,7 @@ bool macro_finder::expand_macros(expr_ref_vector const& exprs, proof_ref_vector
}
void macro_finder::operator()(expr_ref_vector const& exprs, proof_ref_vector const & prs, expr_dependency_ref_vector const & deps, expr_ref_vector & new_exprs, proof_ref_vector & new_prs, expr_dependency_ref_vector & new_deps) {
TRACE("macro_finder", tout << "processing macros...\n";);
TRACE(macro_finder, tout << "processing macros...\n";);
expr_ref_vector _new_exprs(m);
proof_ref_vector _new_prs(m);
expr_dependency_ref_vector _new_deps(m);
@ -342,7 +342,7 @@ void macro_finder::operator()(expr_ref_vector const& exprs, proof_ref_vector con
bool macro_finder::expand_macros(unsigned num, justified_expr const * fmls, vector<justified_expr>& new_fmls) {
TRACE("macro_finder", tout << "starting expand_macros:\n";
TRACE(macro_finder, tout << "starting expand_macros:\n";
m_macro_manager.display(tout););
bool found_new_macro = false;
for (unsigned i = 0; i < num; i++) {
@ -354,15 +354,15 @@ bool macro_finder::expand_macros(unsigned num, justified_expr const * fmls, vect
m_macro_manager.expand_macros(n, pr, nullptr, new_n, new_pr, new_dep);
app_ref head(m), t(m);
if (is_macro(new_n, head, def) && m_macro_manager.insert(head->get_decl(), to_quantifier(new_n.get()), new_pr)) {
TRACE("macro_finder", tout << "found new macro: " << head->get_decl()->get_name() << "\n" << new_n << "\n";);
TRACE(macro_finder, tout << "found new macro: " << head->get_decl()->get_name() << "\n" << new_n << "\n";);
found_new_macro = true;
}
else if (is_arith_macro(new_n, new_pr, new_fmls)) {
TRACE("macro_finder", tout << "found new arith macro:\n" << new_n << "\n";);
TRACE(macro_finder, tout << "found new arith macro:\n" << new_n << "\n";);
found_new_macro = true;
}
else if (m_util.is_pseudo_predicate_macro(new_n, head, t, def)) {
TRACE("macro_finder", tout << "found new pseudo macro:\n" << head << "\n" << t << "\n" << def << "\n";);
TRACE(macro_finder, tout << "found new pseudo macro:\n" << head << "\n" << t << "\n" << def << "\n";);
pseudo_predicate_macro2macro(m, head, t, def, to_quantifier(new_n), new_pr, new_fmls);
found_new_macro = true;
}
@ -384,7 +384,7 @@ void macro_finder::revert_unsafe_macros(vector<justified_expr>& new_fmls) {
void macro_finder::operator()(unsigned n, justified_expr const* fmls, vector<justified_expr>& new_fmls) {
m_macro_manager.unsafe_macros().reset();
TRACE("macro_finder", tout << "processing macros...\n";);
TRACE(macro_finder, tout << "processing macros...\n";);
vector<justified_expr> _new_fmls;
if (expand_macros(n, fmls, _new_fmls)) {
while (true) {

View file

@ -114,11 +114,11 @@ void macro_manager::copy_to(macro_manager& dst) {
}
bool macro_manager::insert(func_decl * f, quantifier * q, proof * pr, expr_dependency* dep) {
TRACE("macro_insert", tout << "trying to create macro: " << f->get_name() << "\n" << mk_pp(q, m) << "\n";);
TRACE(macro_insert, tout << "trying to create macro: " << f->get_name() << "\n" << mk_pp(q, m) << "\n";);
// if we already have a macro for f then return false;
if (m_decls.contains(f)) {
TRACE("macro_insert", tout << "we already have a macro for: " << f->get_name() << "\n";);
TRACE(macro_insert, tout << "we already have a macro for: " << f->get_name() << "\n";);
return false;
}
@ -145,7 +145,7 @@ bool macro_manager::insert(func_decl * f, quantifier * q, proof * pr, expr_depen
m_macro_deps.push_back(dep);
m_decl2macro_dep.insert(f, dep);
TRACE("macro_insert", tout << "A macro was successfully created for: " << f->get_name() << "\n";);
TRACE(macro_insert, tout << "A macro was successfully created for: " << f->get_name() << "\n";);
// Nothing's forbidden anymore; if something's bad, we detected it earlier.
// mark_forbidden(m->get_expr());
@ -223,7 +223,7 @@ func_decl * macro_manager::get_macro_interpretation(unsigned i, expr_ref & inter
expr_ref def(m);
bool r;
get_head_def(q, f, head, def, r);
TRACE("macro_bug",
TRACE(macro_bug,
tout << f->get_name() << "\n" << mk_pp(head, m) << "\n" << mk_pp(q, m) << "\n";);
m_util.mk_macro_interpretation(head, q->get_num_decls(), def, interp);
return f;
@ -290,7 +290,7 @@ struct macro_manager::macro_expander_cfg : public default_rewriter_cfg {
app * n = to_app(_n);
quantifier * q = nullptr;
func_decl * d = n->get_decl(), *d2 = nullptr;
TRACE("macro_manager", tout << "trying to expand:\n" << mk_pp(n, m) << "\nd:\n" << d->get_name() << "\n";);
TRACE(macro_manager, tout << "trying to expand:\n" << mk_pp(n, m) << "\nd:\n" << d->get_name() << "\n";);
if (mm.m_decl2macro.find(d, q)) {
app * head = nullptr;
expr_ref def(m);
@ -298,7 +298,7 @@ struct macro_manager::macro_expander_cfg : public default_rewriter_cfg {
mm.get_head_def(q, d, head, def, revert);
unsigned num = n->get_num_args();
SASSERT(head && def);
TRACE("macro_manager", tout << "expanding: " << mk_pp(n, m) << "\n" << mk_pp(head, m) << " " << mk_pp(def, m) << "\n";);
TRACE(macro_manager, tout << "expanding: " << mk_pp(n, m) << "\n" << mk_pp(head, m) << " " << mk_pp(def, m) << "\n";);
ptr_buffer<expr> subst_args;
subst_args.resize(num, 0);
for (unsigned i = 0; i < num; i++) {
@ -377,7 +377,7 @@ void macro_manager::expand_macros(expr * n, proof * pr, expr_dependency * dep, e
macro_expander_rw proc(m, *this);
proof_ref n_eq_r_pr(m);
SASSERT(!old_pr || m.get_fact(old_pr) == old_n);
TRACE("macro_manager_bug", tout << "expand_macros:\n" << mk_pp(n, m) << "\n";);
TRACE(macro_manager_bug, tout << "expand_macros:\n" << mk_pp(n, m) << "\n";);
proc(old_n, r, n_eq_r_pr);
new_pr = m.mk_modus_ponens(old_pr, n_eq_r_pr);
new_dep = m.mk_join(old_dep, proc.m_cfg.m_used_macro_dependencies);

View file

@ -312,7 +312,7 @@ bool macro_util::is_arith_macro(expr * n, unsigned num_decls, app_ref & head, ex
mk_sub(tmp, rhs, def);
else
mk_sub(rhs, tmp, def);
TRACE("macro_util", tout << def << "\n";);
TRACE(macro_util, tout << def << "\n";);
return true;
}
@ -351,7 +351,7 @@ bool macro_util::is_pseudo_head(expr * n, unsigned num_decls, app_ref & head, ap
bool macro_util::is_pseudo_predicate_macro(expr * n, app_ref & head, app_ref & t, expr_ref & def) {
if (!is_forall(n))
return false;
TRACE("macro_util", tout << "processing: " << mk_pp(n, m) << "\n";);
TRACE(macro_util, tout << "processing: " << mk_pp(n, m) << "\n";);
expr * body = to_quantifier(n)->get_expr();
unsigned num_decls = to_quantifier(n)->get_num_decls();
expr * lhs, *rhs;
@ -483,7 +483,7 @@ void macro_util::quasi_macro_head_to_macro_head(app * qhead, unsigned & num_decl
See normalize_expr
*/
void macro_util::mk_macro_interpretation(app * head, unsigned num_decls, expr * def, expr_ref & interp) const {
TRACE("macro_util", tout << mk_pp(head, m) << "\n" << mk_pp(def, m) << "\n";);
TRACE(macro_util, tout << mk_pp(head, m) << "\n" << mk_pp(def, m) << "\n";);
SASSERT(is_macro_head(head, head->get_num_args()) ||
is_quasi_macro_ok(head, head->get_num_args(), def));
SASSERT(!occurs(head->get_decl(), def));
@ -505,7 +505,7 @@ void macro_util::normalize_expr(app * head, unsigned num_decls, expr * t, expr_r
var_mapping.resize(num_decls);
bool changed = false;
unsigned num_args = head->get_num_args();
TRACE("macro_util",
TRACE(macro_util,
tout << "head: " << mk_pp(head, m) << "\n";
tout << "applying substitution to:\n" << mk_bounded_pp(t, m) << "\n";);
for (unsigned i = 0; i < num_args; i++) {
@ -524,7 +524,7 @@ void macro_util::normalize_expr(app * head, unsigned num_decls, expr * t, expr_r
if (changed) {
// REMARK: t may have nested quantifiers... So, I must use the std order for variable substitution.
var_subst subst(m, true);
TRACE("macro_util",
TRACE(macro_util,
tout << "head: " << mk_pp(head, m) << "\n";
tout << "applying substitution to:\n" << mk_ll_pp(t, m) << "\nsubstitution:\n";
for (unsigned i = 0; i < var_mapping.size(); i++) {
@ -633,12 +633,12 @@ void hint_to_macro_head(ast_manager & m, app * head, unsigned & num_decls, app_r
is_hint_head(head, vars) must also return true
*/
bool macro_util::is_poly_hint(expr * n, app * head, expr * exception) {
TRACE("macro_util", tout << "is_poly_hint n:\n" << mk_pp(n, m) << "\nhead:\n" << mk_pp(head, m) << "\nexception:\n";
TRACE(macro_util, tout << "is_poly_hint n:\n" << mk_pp(n, m) << "\nhead:\n" << mk_pp(head, m) << "\nexception:\n";
if (exception) tout << mk_pp(exception, m); else tout << "<null>";
tout << "\n";);
ptr_buffer<var> vars;
if (!is_hint_head(head, vars)) {
TRACE("macro_util", tout << "failed because head is not hint head\n";);
TRACE(macro_util, tout << "failed because head is not hint head\n";);
return false;
}
func_decl * f = head->get_decl();
@ -655,11 +655,11 @@ bool macro_util::is_poly_hint(expr * n, app * head, expr * exception) {
for (unsigned i = 0; i < num_args; i++) {
expr * arg = args[i];
if (arg != exception && (occurs(f, arg) || !vars_of_is_subset(arg, vars))) {
TRACE("macro_util", tout << "failed because of:\n" << mk_pp(arg, m) << "\n";);
TRACE(macro_util, tout << "failed because of:\n" << mk_pp(arg, m) << "\n";);
return false;
}
}
TRACE("macro_util", tout << "succeeded\n";);
TRACE(macro_util, tout << "succeeded\n";);
return true;
}
@ -714,7 +714,7 @@ void macro_util::insert_macro(app * head, unsigned num_decls, expr * def, expr *
void macro_util::insert_quasi_macro(app * head, unsigned num_decls, expr * def, expr * cond, bool ineq, bool satisfy_atom,
bool hint, macro_candidates & r) {
TRACE("macro_util", tout << expr_ref(head, m) << "\n";);
TRACE(macro_util, tout << expr_ref(head, m) << "\n";);
if (!is_macro_head(head, head->get_num_args())) {
app_ref new_head(m);
expr_ref extra_cond(m);
@ -728,7 +728,7 @@ void macro_util::insert_quasi_macro(app * head, unsigned num_decls, expr * def,
}
else {
hint_to_macro_head(m, head, num_decls, new_head);
TRACE("macro_util",
TRACE(macro_util,
tout << "hint macro head: " << mk_ismt2_pp(new_head, m) << std::endl;
tout << "hint macro def: " << mk_ismt2_pp(def, m) << std::endl; );
}
@ -863,7 +863,7 @@ void macro_util::collect_arith_macro_candidates(expr * lhs, expr * rhs, expr * a
}
void macro_util::collect_arith_macro_candidates(expr * atom, unsigned num_decls, macro_candidates & r) {
TRACE("macro_util", tout << "collect_arith_macro_candidates:\n" << mk_pp(atom, m) << "\n";);
TRACE(macro_util, tout << "collect_arith_macro_candidates:\n" << mk_pp(atom, m) << "\n";);
if (!m.is_eq(atom) && !is_le_ge(atom))
return;
expr * lhs = to_app(atom)->get_arg(0);
@ -912,7 +912,7 @@ void macro_util::collect_arith_macro_candidates(expr * atom, unsigned num_decls,
void macro_util::collect_macro_candidates_core(expr * atom, unsigned num_decls, macro_candidates & r) {
expr* lhs, *rhs;
TRACE("macro_util", tout << "Candidate check for: " << mk_ismt2_pp(atom, m) << std::endl;);
TRACE(macro_util, tout << "Candidate check for: " << mk_ismt2_pp(atom, m) << std::endl;);
auto insert_quasi = [&](expr* lhs, expr* rhs) {
if (is_quasi_macro_head(lhs, num_decls) &&

View file

@ -157,7 +157,7 @@ bool quasi_macros::is_quasi_macro(expr * e, app_ref & a, expr_ref & t) const {
// Our definition of a quasi-macro:
// Forall X. f[X] = T[X], where f[X] is a term starting with symbol f, f is uninterpreted,
// f[X] contains all universally quantified variables, and f does not occur in T[X].
TRACE("quasi_macros", tout << "Checking for quasi macro: " << mk_pp(e, m) << std::endl;);
TRACE(quasi_macros, tout << "Checking for quasi macro: " << mk_pp(e, m) << std::endl;);
if (is_forall(e)) {
quantifier * q = to_quantifier(e);
@ -273,7 +273,7 @@ bool quasi_macros::quasi_macro_to_macro(quantifier * q, app * a, expr * t, quant
}
bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
TRACE("quasi_macros", tout << "Finding quasi-macros in: " << std::endl;
TRACE(quasi_macros, tout << "Finding quasi-macros in: " << std::endl;
for (unsigned i = 0 ; i < n ; i++)
tout << i << ": " << mk_pp(exprs[i], m) << std::endl; );
bool res = false;
@ -284,7 +284,7 @@ bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
for (unsigned i = 0 ; i < n ; i++)
find_occurrences(exprs[i]);
TRACE("quasi_macros",
TRACE(quasi_macros,
tout << "Occurrences: " << std::endl;
for (auto & kd : m_occurrences)
tout << kd.m_key->get_name() << ": " << kd.m_value << std::endl; );
@ -296,7 +296,7 @@ bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
quantifier_ref macro(m);
if (is_quasi_macro(exprs[i], a, t) &&
quasi_macro_to_macro(to_quantifier(exprs[i]), a, t, macro)) {
TRACE("quasi_macros", tout << "Found quasi macro: " << mk_pp(exprs[i], m) << std::endl;
TRACE(quasi_macros, tout << "Found quasi macro: " << mk_pp(exprs[i], m) << std::endl;
tout << "Macro: " << mk_pp(macro, m) << std::endl; );
proof * pr = nullptr;
if (m.proofs_enabled())
@ -311,7 +311,7 @@ bool quasi_macros::find_macros(unsigned n, expr * const * exprs) {
}
bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
TRACE("quasi_macros", tout << "Finding quasi-macros in: " << std::endl;
TRACE(quasi_macros, tout << "Finding quasi-macros in: " << std::endl;
for (unsigned i = 0; i < n; i++)
tout << i << ": " << mk_pp(exprs[i].fml(), m) << std::endl; );
bool res = false;
@ -322,7 +322,7 @@ bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
for (unsigned i = 0 ; i < n ; i++)
find_occurrences(exprs[i].fml());
TRACE("quasi_macros", tout << "Occurrences: " << std::endl;
TRACE(quasi_macros, tout << "Occurrences: " << std::endl;
for (auto kv : m_occurrences)
tout << kv.m_key->get_name() << ": " << kv.m_value << std::endl; );
@ -333,7 +333,7 @@ bool quasi_macros::find_macros(unsigned n, justified_expr const * exprs) {
quantifier_ref macro(m);
if (is_quasi_macro(exprs[i].fml(), a, t) &&
quasi_macro_to_macro(to_quantifier(exprs[i].fml()), a, t, macro)) {
TRACE("quasi_macros", tout << "Found quasi macro: " << mk_pp(exprs[i].fml(), m) << std::endl;
TRACE(quasi_macros, tout << "Found quasi macro: " << mk_pp(exprs[i].fml(), m) << std::endl;
tout << "Macro: " << mk_pp(macro, m) << std::endl; );
proof * pr = nullptr;
if (m.proofs_enabled())
@ -387,7 +387,7 @@ void quasi_macros::apply_macros(unsigned n, justified_expr const* fmls, vector<j
}
bool quasi_macros::operator()(unsigned n, justified_expr const* fmls, vector<justified_expr>& new_fmls) {
TRACE("quasi_macros", m_macro_manager.display(tout););
TRACE(quasi_macros, m_macro_manager.display(tout););
if (find_macros(n, fmls)) {
apply_macros(n, fmls, new_fmls);
return true;