3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-27 05:26:01 +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

@ -161,7 +161,7 @@ void asserted_formulas::assert_expr(expr * e, proof * _in_pr) {
return;
if (m_smt_params.m_preprocess) {
TRACE("assert_expr_bug", tout << r << "\n";);
TRACE(assert_expr_bug, tout << r << "\n";);
set_eliminate_and(false); // do not eliminate and before nnf.
m_rewriter(e, r, pr);
if (m.proofs_enabled()) {
@ -170,13 +170,13 @@ void asserted_formulas::assert_expr(expr * e, proof * _in_pr) {
else
pr = m.mk_modus_ponens(in_pr, pr);
}
TRACE("assert_expr_bug", tout << "after...\n" << r << "\n" << pr << "\n";);
TRACE(assert_expr_bug, tout << "after...\n" << r << "\n" << pr << "\n";);
}
m_has_quantifiers |= ::has_quantifiers(e);
push_assertion(r, pr, m_formulas);
TRACE("asserted_formulas_bug", tout << "after assert_expr\n"; display(tout););
TRACE(asserted_formulas_bug, tout << "after assert_expr\n"; display(tout););
}
void asserted_formulas::assert_expr(expr * e) {
@ -195,7 +195,7 @@ void asserted_formulas::push_scope_core() {
reduce();
commit();
SASSERT(inconsistent() || m_qhead == m_formulas.size() || m.limit().is_canceled());
TRACE("asserted_formulas_scopes", tout << "before push: " << m_scopes.size() << "\n");
TRACE(asserted_formulas_scopes, tout << "before push: " << m_scopes.size() << "\n");
m_scoped_substitution.push();
m_scopes.push_back(scope());
scope & s = m_scopes.back();
@ -208,7 +208,7 @@ void asserted_formulas::push_scope_core() {
m_macro_manager.push_scope();
m_bv_size_reduce.push_scope();
commit();
TRACE("asserted_formulas_scopes", tout << "after push: " << m_scopes.size() << "\n");
TRACE(asserted_formulas_scopes, tout << "after push: " << m_scopes.size() << "\n");
}
void asserted_formulas::force_push() {
@ -224,7 +224,7 @@ void asserted_formulas::pop_scope(unsigned num_scopes) {
num_scopes -= m_lazy_scopes;
m_lazy_scopes = 0;
TRACE("asserted_formulas_scopes", tout << "before pop " << num_scopes << " of " << m_scopes.size() << "\n";);
TRACE(asserted_formulas_scopes, tout << "before pop " << num_scopes << " of " << m_scopes.size() << "\n";);
m_bv_sharing.pop_scope(num_scopes);
m_macro_manager.pop_scope(num_scopes);
m_bv_size_reduce.pop_scope(num_scopes);
@ -238,7 +238,7 @@ void asserted_formulas::pop_scope(unsigned num_scopes) {
m_qhead = s.m_formulas_lim;
m_scopes.shrink(new_lvl);
flush_cache();
TRACE("asserted_formulas_scopes", tout << "after pop " << num_scopes << "\n";);
TRACE(asserted_formulas_scopes, tout << "after pop " << num_scopes << "\n";);
}
void asserted_formulas::reset() {
@ -275,7 +275,7 @@ void asserted_formulas::reduce() {
if (m_macro_manager.has_macros())
invoke(m_find_macros);
TRACE("before_reduce", display(tout););
TRACE(before_reduce, display(tout););
CASSERT("well_sorted", check_well_sorted());
IF_VERBOSE(10, verbose_stream() << "(smt.simplify-begin :num-exprs " << get_total_size() << ")\n";);
@ -308,9 +308,9 @@ void asserted_formulas::reduce() {
// if (!invoke(m_propagate_values)) return;
IF_VERBOSE(10, verbose_stream() << "(smt.simplifier-done :num-exprs " << get_total_size() << ")\n";);
TRACE("after_reduce", display(tout););
TRACE("after_reduce_ll", ast_mark visited; display_ll(tout, visited););
TRACE("macros", m_macro_manager.display(tout););
TRACE(after_reduce, display(tout););
TRACE(after_reduce_ll, ast_mark visited; display_ll(tout, visited););
TRACE(macros, m_macro_manager.display(tout););
flush_cache();
CASSERT("well_sorted",check_well_sorted());
@ -331,11 +331,11 @@ bool asserted_formulas::invoke(simplify_fmls& s) {
s();
IF_VERBOSE(10, verbose_stream() << "(smt." << s.id() << " :num-exprs " << get_total_size() << ")\n";);
IF_VERBOSE(10000, verbose_stream() << "total size: " << get_total_size() << "\n";);
TRACE("reduce_step_ll", ast_mark visited; display_ll(tout, visited););
TRACE(reduce_step_ll, ast_mark visited; display_ll(tout, visited););
CASSERT("well_sorted",check_well_sorted());
TRACE("after_reduce", display(tout << s.id() << "\n"););
TRACE(after_reduce, display(tout << s.id() << "\n"););
if (inconsistent() || canceled()) {
TRACE("after_reduce_ll", ast_mark visited; display_ll(tout, visited););
TRACE(after_reduce_ll, ast_mark visited; display_ll(tout, visited););
return false;
}
else {
@ -430,7 +430,7 @@ void asserted_formulas::flatten_clauses() {
void asserted_formulas::apply_quasi_macros() {
TRACE("before_quasi_macros", display(tout););
TRACE(before_quasi_macros, display(tout););
vector<justified_expr> new_fmls;
quasi_macros proc(m, m_macro_manager);
while (m_qhead == 0 &&
@ -440,7 +440,7 @@ void asserted_formulas::apply_quasi_macros() {
swap_asserted_formulas(new_fmls);
new_fmls.reset();
}
TRACE("after_quasi_macros", display(tout););
TRACE(after_quasi_macros, display(tout););
reduce_and_solve();
}
@ -452,10 +452,10 @@ void asserted_formulas::nnf_cnf() {
unsigned i = m_qhead;
unsigned sz = m_formulas.size();
TRACE("nnf_bug", tout << "i: " << i << " sz: " << sz << "\n";);
TRACE(nnf_bug, tout << "i: " << i << " sz: " << sz << "\n";);
for (; i < sz; i++) {
expr * n = m_formulas[i].fml();
TRACE("nnf_bug", tout << "processing:\n" << mk_pp(n, m) << "\n";);
TRACE(nnf_bug, tout << "processing:\n" << mk_pp(n, m) << "\n";);
proof_ref pr(m_formulas[i].pr(), m);
expr_ref r1(m);
proof_ref pr1(m);
@ -510,7 +510,7 @@ void asserted_formulas::simplify_fmls::operator()() {
return;
}
af.swap_asserted_formulas(new_fmls);
TRACE("asserted_formulas", af.display(tout););
TRACE(asserted_formulas, af.display(tout););
post_op();
}
@ -546,7 +546,7 @@ void asserted_formulas::propagate_values() {
while (!inconsistent() && sz/20 < delta_prop) {
m_scoped_substitution.push();
unsigned prop = num_prop;
TRACE("propagate_values", display(tout << "before:\n"););
TRACE(propagate_values, display(tout << "before:\n"););
unsigned i = m_qhead;
for (; i < sz; i++) {
prop += propagate_values(i);
@ -554,7 +554,7 @@ void asserted_formulas::propagate_values() {
flush_cache();
m_scoped_substitution.pop(1);
m_scoped_substitution.push();
TRACE("propagate_values", tout << "middle:\n"; display(tout););
TRACE(propagate_values, tout << "middle:\n"; display(tout););
i = sz;
while (i > m_qhead) {
--i;
@ -562,14 +562,14 @@ void asserted_formulas::propagate_values() {
}
m_scoped_substitution.pop(1);
flush_cache();
TRACE("propagate_values", tout << "after:\n"; display(tout););
TRACE(propagate_values, tout << "after:\n"; display(tout););
delta_prop = prop - num_prop;
num_prop = prop;
if (sz <= m_formulas.size())
break;
sz = m_formulas.size();
}
TRACE("asserted_formulas", tout << num_prop << "\n";);
TRACE(asserted_formulas, tout << num_prop << "\n";);
if (num_prop > 0)
m_reduce_asserted_formulas();
}
@ -597,17 +597,17 @@ bool asserted_formulas::update_substitution(expr* n, proof* pr) {
proof_ref pr1(m);
if (is_ground(n) && m.is_eq(n, lhs, rhs)) {
if (is_gt(lhs, rhs)) {
TRACE("propagate_values", tout << "insert " << mk_pp(lhs, m) << " -> " << mk_pp(rhs, m) << "\n";);
TRACE(propagate_values, tout << "insert " << mk_pp(lhs, m) << " -> " << mk_pp(rhs, m) << "\n";);
m_scoped_substitution.insert(lhs, rhs, pr);
return true;
}
if (is_gt(rhs, lhs)) {
TRACE("propagate_values", tout << "insert " << mk_pp(rhs, m) << " -> " << mk_pp(lhs, m) << "\n";);
TRACE(propagate_values, tout << "insert " << mk_pp(rhs, m) << " -> " << mk_pp(lhs, m) << "\n";);
pr1 = m.proofs_enabled() ? m.mk_symmetry(pr) : nullptr;
m_scoped_substitution.insert(rhs, lhs, pr1);
return true;
}
TRACE("propagate_values", tout << "incompatible " << mk_pp(n, m) << "\n";);
TRACE(propagate_values, tout << "incompatible " << mk_pp(n, m) << "\n";);
}
if (m.is_not(n, n1)) {
pr1 = m.proofs_enabled() ? m.mk_iff_false(pr) : nullptr;
@ -679,7 +679,7 @@ proof * asserted_formulas::get_inconsistency_proof() const {
void asserted_formulas::refine_inj_axiom_fn::simplify(justified_expr const& j, expr_ref& n, proof_ref& p) {
expr* f = j.fml();
if (is_quantifier(f) && simplify_inj_axiom(m, to_quantifier(f), n)) {
TRACE("inj_axiom", tout << "simplifying...\n" << mk_pp(f, m) << "\n" << n << "\n";);
TRACE(inj_axiom, tout << "simplifying...\n" << mk_pp(f, m) << "\n" << n << "\n";);
}
else {
n = j.fml();

View file

@ -124,7 +124,7 @@ class asserted_formulas {
distribute_forall_fn(asserted_formulas& af): simplify_fmls(af, "distribute-forall"), m_functor(af.m) {}
void simplify(justified_expr const& j, expr_ref& n, proof_ref& p) override { m_functor(j.fml(), n); }
bool should_apply() const override { return af.m_smt_params.m_distribute_forall && af.has_quantifiers(); }
void post_op() override { af.reduce_and_solve(); TRACE("asserted_formulas", af.display(tout);); }
void post_op() override { af.reduce_and_solve(); TRACE(asserted_formulas, af.display(tout);); }
};
class pattern_inference_fn : public simplify_fmls {

View file

@ -328,7 +328,7 @@ struct check_logic::imp {
}
void fail_non_diff(expr * t) {
TRACE("check_logic", tout << mk_pp(t, m) << "\n";);
TRACE(check_logic, tout << mk_pp(t, m) << "\n";);
fail("logic only supports difference arithmetic");
}

View file

@ -126,7 +126,7 @@ public:
}
solver* translate(ast_manager& m, params_ref const& p) override {
TRACE("solver", tout << "translate\n";);
TRACE(solver, tout << "translate\n";);
solver* s1 = m_solver1->translate(m, p);
solver* s2 = m_solver2->translate(m, p);
combined_solver* r = alloc(combined_solver, s1, s2, p);
@ -177,11 +177,11 @@ public:
switch_inc_mode();
m_solver1->push();
m_solver2->push();
TRACE("pop", tout << "push\n";);
TRACE(pop, tout << "push\n";);
}
void pop(unsigned n) override {
TRACE("pop", tout << n << "\n";);
TRACE(pop, tout << n << "\n";);
switch_inc_mode();
m_solver1->pop(n);
m_solver2->pop(n);

View file

@ -59,7 +59,7 @@ struct mus::imp {
unsigned idx = m_lit2expr.size();
m_expr2lit.insert(lit, idx);
m_lit2expr.push_back(lit);
TRACE("mus", tout << idx << ": " << mk_pp(lit, m) << "\n" << m_lit2expr << "\n";);
TRACE(mus, tout << idx << ": " << mk_pp(lit, m) << "\n" << m_lit2expr << "\n";);
return idx;
}
@ -80,10 +80,10 @@ struct mus::imp {
lbool get_mus1(expr_ref_vector& mus) {
ptr_vector<expr> unknown(m_lit2expr.size(), m_lit2expr.data());
expr_ref_vector core_exprs(m);
TRACE("mus", m_solver.display(tout););
TRACE(mus, m_solver.display(tout););
while (!unknown.empty()) {
IF_VERBOSE(12, verbose_stream() << "(mus reducing core: " << unknown.size() << " new core: " << mus.size() << ")\n";);
TRACE("mus", display_vec(tout << "core: ", unknown); display_vec(tout << "mus: ", mus););
TRACE(mus, display_vec(tout << "core: ", unknown); display_vec(tout << "mus: ", mus););
expr* lit = unknown.back();
unknown.pop_back();
expr_ref not_lit(mk_not(m, lit), m);
@ -112,7 +112,7 @@ struct mus::imp {
unknown.push_back(c);
}
}
TRACE("mus", tout << "core exprs:" << core_exprs << "\n";
TRACE(mus, tout << "core exprs:" << core_exprs << "\n";
display_vec(tout << "core:", unknown);
display_vec(tout << "mus:", mus);
);
@ -164,7 +164,7 @@ struct mus::imp {
scoped_append assume_lit(*this, mus, lit); // current unknown literal
switch (m_solver.check_sat(mus)) {
case l_true: {
TRACE("mus", tout << "literal can be satisfied: " << mk_pp(lit, m) << "\n";);
TRACE(mus, tout << "literal can be satisfied: " << mk_pp(lit, m) << "\n";);
mss.push_back(lit);
m_solver.get_model(mdl);
model_evaluator eval(*mdl.get());
@ -183,7 +183,7 @@ struct mus::imp {
break;
}
case l_false:
TRACE("mus", tout << "literal is in a core: " << mk_pp(lit, m) << "\n";);
TRACE(mus, tout << "literal is in a core: " << mk_pp(lit, m) << "\n";);
nmcs.push_back(mk_not(m, lit));
nmcs_set.insert(nmcs.back());
get_core(core);

View file

@ -138,7 +138,7 @@ class simplifier_solver : public solver {
m_preprocess.reduce();
if (!m.inc())
return;
TRACE("solver", tout << "qhead " << qhead << "\n";
TRACE(solver, tout << "qhead " << qhead << "\n";
m_preprocess_state.display(tout));
m_preprocess_state.advance_qhead();
}
@ -225,7 +225,7 @@ public:
lbool check_sat_core(unsigned num_assumptions, expr* const* assumptions) override {
expr_ref_vector _assumptions(m, num_assumptions, assumptions);
flush(_assumptions);
TRACE("simplifier", tout << _assumptions);
TRACE(simplifier, tout << _assumptions);
return s->check_sat_core(num_assumptions, _assumptions.data());
}
@ -236,7 +236,7 @@ public:
model_ref m_cached_model;
void get_model_core(model_ref& m) override {
CTRACE("simplifier", m_mc.get(), m_mc->display(tout));
CTRACE(simplifier, m_mc.get(), m_mc->display(tout));
if (m_cached_model) {
m = m_cached_model;
return;

View file

@ -107,7 +107,7 @@ public:
extract_clauses_and_dependencies(in, clauses, assumptions, bool2dep, fmc);
ref<solver> local_solver = m_solver->translate(m, m_params);
local_solver->assert_expr(clauses);
TRACE("solver2tactic", tout << "clauses asserted\n";);
TRACE(solver2tactic, tout << "clauses asserted\n";);
lbool r;
try {
r = local_solver->check_sat(assumptions.size(), assumptions.data());
@ -116,7 +116,7 @@ public:
local_solver->collect_statistics(m_st);
throw;
}
TRACE("solver2tactic", tout << "check sat result " << r << "\n";);
TRACE(solver2tactic, tout << "check sat result " << r << "\n";);
proof* pr = local_solver->get_proof();
if (pr) in->set(proof2proof_converter(m, pr));
local_solver->collect_statistics(m_st);

View file

@ -35,7 +35,7 @@ void solver_na2as::assert_expr_core2(expr * t, expr * a) {
else {
SASSERT(is_uninterp_const(a));
SASSERT(m.is_bool(a));
TRACE("solver_na2as", tout << "asserting\n" << mk_ismt2_pp(t, m) << "\n" << mk_ismt2_pp(a, m) << "\n";);
TRACE(solver_na2as, tout << "asserting\n" << mk_ismt2_pp(t, m) << "\n" << mk_ismt2_pp(a, m) << "\n";);
m_assumptions.push_back(a);
expr_ref new_t(m);
new_t = m.mk_implies(a, t);
@ -61,7 +61,7 @@ struct append_assumptions {
lbool solver_na2as::check_sat_core(unsigned num_assumptions, expr * const * assumptions) {
append_assumptions app(m_assumptions, num_assumptions, assumptions);
TRACE("solver_na2as", display(tout););
TRACE(solver_na2as, display(tout););
return check_sat_core2(m_assumptions.size(), m_assumptions.data());
}

View file

@ -287,7 +287,7 @@ private:
lbool last_status, double last_time) {
std::string file_name = mk_file_name();
std::ofstream out(file_name);
STRACE("spacer.ind_gen", tout << "Dumping benchmark to " << file_name << "\n";);
STRACE(spacer_ind_gen, tout << "Dumping benchmark to " << file_name << "\n";);
if (!out) {
IF_VERBOSE(0, verbose_stream() << "could not open file " << file_name << " for output\n");
return;

View file

@ -201,12 +201,12 @@ void tactic2solver::push_core() {
m_last_assertions_valid = false;
m_scopes.push_back(m_assertions.size());
m_result = nullptr;
TRACE("pop", tout << m_scopes.size() << "\n";);
TRACE(pop, tout << m_scopes.size() << "\n";);
}
void tactic2solver::pop_core(unsigned n) {
m_last_assertions_valid = false;
TRACE("pop", tout << m_scopes.size() << " " << n << "\n";);
TRACE(pop, tout << m_scopes.size() << " " << n << "\n";);
n = std::min(m_scopes.size(), n);
unsigned new_lvl = m_scopes.size() - n;
unsigned old_sz = m_scopes[new_lvl];
@ -240,7 +240,7 @@ lbool tactic2solver::check_sat_core2(unsigned num_assumptions, expr * const * as
expr_dependency_ref core(m);
std::string reason_unknown = "unknown";
labels_vec labels;
TRACE("tactic", g->display(tout););
TRACE(tactic, g->display(tout););
try {
switch (::check_sat(*m_tactic, g, md, labels, pr, core, reason_unknown)) {
case l_true:
@ -260,8 +260,8 @@ lbool tactic2solver::check_sat_core2(unsigned num_assumptions, expr * const * as
}
break;
}
CTRACE("tactic", md.get(), tout << *md.get() << "\n";);
TRACE("tactic",
CTRACE(tactic, md.get(), tout << *md.get() << "\n";);
TRACE(tactic,
if (m_mc) m_mc->display(tout << "mc:\n");
if (g->mc()) g->mc()->display(tout << "\ng:\n");
if (md) tout << "\nmodel:\n" << *md.get() << "\n";
@ -270,12 +270,12 @@ lbool tactic2solver::check_sat_core2(unsigned num_assumptions, expr * const * as
}
catch (z3_error & ex) {
TRACE("tactic2solver", tout << "exception: " << ex.what() << "\n";);
TRACE(tactic2solver, tout << "exception: " << ex.what() << "\n";);
m_result->m_proof = pr;
throw ex;
}
catch (z3_exception & ex) {
TRACE("tactic2solver", tout << "exception: " << ex.what() << "\n";);
TRACE(tactic2solver, tout << "exception: " << ex.what() << "\n";);
m_result->set_status(l_undef);
m_result->m_unknown = ex.what();
m_result->m_proof = pr;