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

@ -34,7 +34,7 @@ namespace pb {
void solver::set_conflict(constraint& c, literal lit) {
m_stats.m_num_conflicts++;
TRACE("pb", display(tout, c, true); );
TRACE(pb, display(tout, c, true); );
if (!validate_conflict(c)) {
IF_VERBOSE(0, display(verbose_stream(), c, true));
UNREACHABLE();
@ -56,7 +56,7 @@ namespace pb {
default:
m_stats.m_num_propagations++;
m_num_propagations_since_pop++;
//TRACE("pb", tout << "#prop: " << m_stats.m_num_propagations << " - " << c.lit() << " => " << lit << "\n";);
//TRACE(pb, tout << "#prop: " << m_stats.m_num_propagations << " - " << c.lit() << " => " << lit << "\n";);
SASSERT(validate_unit_propagation(c, lit));
assign(lit, sat::justification::mk_ext_justification(s().scope_lvl(), c.cindex()));
break;
@ -69,7 +69,7 @@ namespace pb {
void solver::simplify(constraint& p) {
SASSERT(s().at_base_lvl());
if (p.lit() != sat::null_literal && value(p.lit()) == l_false) {
TRACE("pb", tout << "pb: flip sign " << p << "\n";);
TRACE(pb, tout << "pb: flip sign " << p << "\n";);
IF_VERBOSE(2, verbose_stream() << "sign is flipped " << p << "\n";);
return;
}
@ -280,7 +280,7 @@ namespace pb {
*/
lbool solver::add_assign(pbc& p, literal alit) {
BADLOG(display(verbose_stream() << "assign: " << alit << " watch: " << p.num_watch() << " size: " << p.size(), p, true));
TRACE("pb", display(tout << "assign: " << alit << "\n", p, true););
TRACE(pb, display(tout << "assign: " << alit << "\n", p, true););
SASSERT(!inconsistent());
unsigned sz = p.size();
unsigned bound = p.k();
@ -348,7 +348,7 @@ namespace pb {
SASSERT(validate_watch(p, sat::null_literal));
BADLOG(display(verbose_stream() << "conflict: " << alit << " watch: " << p.num_watch() << " size: " << p.size(), p, true));
SASSERT(bound <= slack);
TRACE("pb", tout << "conflict " << alit << "\n";);
TRACE(pb, tout << "conflict " << alit << "\n";);
set_conflict(p, alit);
return l_false;
}
@ -372,7 +372,7 @@ namespace pb {
//
if (slack < bound + m_a_max) {
BADLOG(verbose_stream() << "slack " << slack << " " << bound << " " << m_a_max << "\n";);
TRACE("pb", tout << p << "\n"; for(auto j : m_pb_undef) tout << j << " "; tout << "\n";);
TRACE(pb, tout << p << "\n"; for(auto j : m_pb_undef) tout << j << " "; tout << "\n";);
for (unsigned index1 : m_pb_undef) {
if (index1 == num_watch) {
index1 = index;
@ -389,7 +389,7 @@ namespace pb {
SASSERT(validate_watch(p, alit)); // except that alit is still watched.
TRACE("pb", display(tout << "assign: " << alit << "\n", p, true););
TRACE(pb, display(tout << "assign: " << alit << "\n", p, true););
BADLOG(verbose_stream() << "unwatch " << alit << " watch: " << p.num_watch() << " size: " << p.size() << " slack: " << p.slack() << " " << inconsistent() << "\n");
@ -497,7 +497,7 @@ namespace pb {
bool_var v = l.var();
SASSERT(v != sat::null_bool_var);
m_coeffs.reserve(v + 1, 0);
TRACE("ba_verbose", tout << l << " " << offset << "\n";);
TRACE(ba_verbose, tout << l << " " << offset << "\n";);
int64_t coeff0 = m_coeffs[v];
if (coeff0 == 0) {
@ -547,7 +547,7 @@ namespace pb {
literal l = literal(v, c1 < 0);
c1 = std::abs(c1);
unsigned c = static_cast<unsigned>(c1);
// TRACE("pb", tout << l << " " << c << "\n";);
// TRACE(pb, tout << l << " " << c << "\n";);
m_overflow |= c != c1;
return wliteral(c, l);
}
@ -638,7 +638,7 @@ namespace pb {
m_bound = 0;
literal consequent = s().m_not_l;
sat::justification js = s().m_conflict;
TRACE("pb", tout << consequent << " " << js << "\n";);
TRACE(pb, tout << consequent << " " << js << "\n";);
bool unique_max;
m_conflict_lvl = s().get_max_lvl(consequent, js, unique_max);
if (m_conflict_lvl == 0) {
@ -666,8 +666,8 @@ namespace pb {
goto process_next_resolvent;
}
DEBUG_CODE(TRACE("sat_verbose", display(tout, m_A);););
TRACE("pb", tout << "process consequent: " << consequent << " : "; s().display_justification(tout, js) << "\n";);
DEBUG_CODE(TRACE(sat_verbose, display(tout, m_A);););
TRACE(pb, tout << "process consequent: " << consequent << " : "; s().display_justification(tout, js) << "\n";);
SASSERT(offset > 0);
if (_debug_conflict) {
@ -729,7 +729,7 @@ namespace pb {
inc_bound(offset);
inc_coeff(consequent, offset);
get_antecedents(consequent, p, m_lemma);
TRACE("pb", display(tout, p, true); tout << m_lemma << "\n";);
TRACE(pb, display(tout, p, true); tout << m_lemma << "\n";);
if (_debug_conflict) {
verbose_stream() << consequent << " ";
verbose_stream() << "antecedents: " << m_lemma << "\n";
@ -754,7 +754,7 @@ namespace pb {
active2pb(m_C);
VERIFY(validate_resolvent());
m_A = m_C;
TRACE("pb", display(tout << "conflict: ", m_A);););
TRACE(pb, display(tout << "conflict: ", m_A);););
cut();
@ -781,7 +781,7 @@ namespace pb {
SASSERT(lvl(v) == m_conflict_lvl);
s().reset_mark(v);
--idx;
TRACE("sat_verbose", tout << "Unmark: v" << v << "\n";);
TRACE(sat_verbose, tout << "Unmark: v" << v << "\n";);
--m_num_marks;
js = s().m_justification[v];
offset = get_abs_coeff(v);
@ -875,7 +875,7 @@ namespace pb {
}
}
ineq.divide(c);
TRACE("pb", display(tout << "var: " << v << " " << c << ": ", ineq, true););
TRACE(pb, display(tout << "var: " << v << " " << c << ": ", ineq, true););
}
void solver::round_to_one(bool_var w) {
@ -893,7 +893,7 @@ namespace pb {
SASSERT(validate_lemma());
divide(c);
SASSERT(validate_lemma());
TRACE("pb", active2pb(m_B); display(tout, m_B, true););
TRACE(pb, active2pb(m_B); display(tout, m_B, true););
}
void solver::divide(unsigned c) {
@ -923,14 +923,14 @@ namespace pb {
}
void solver::resolve_with(ineq const& ineq) {
TRACE("pb", display(tout, ineq, true););
TRACE(pb, display(tout, ineq, true););
inc_bound(ineq.m_k);
TRACE("pb", tout << "bound: " << m_bound << "\n";);
TRACE(pb, tout << "bound: " << m_bound << "\n";);
for (unsigned i = ineq.size(); i-- > 0; ) {
literal l = ineq.lit(i);
inc_coeff(l, static_cast<unsigned>(ineq.coeff(i)));
TRACE("pb", tout << "bound: " << m_bound << " lit: " << l << " coeff: " << ineq.coeff(i) << "\n";);
TRACE(pb, tout << "bound: " << m_bound << " lit: " << l << " coeff: " << ineq.coeff(i) << "\n";);
}
}
@ -983,11 +983,11 @@ namespace pb {
consequent.neg();
process_antecedent(consequent, 1);
}
TRACE("pb", tout << consequent << " " << js << "\n";);
TRACE(pb, tout << consequent << " " << js << "\n";);
unsigned idx = s().m_trail.size() - 1;
do {
TRACE("pb", s().display_justification(tout << "process consequent: " << consequent << " : ", js) << "\n";
TRACE(pb, s().display_justification(tout << "process consequent: " << consequent << " : ", js) << "\n";
if (consequent != sat::null_literal) { active2pb(m_A); display(tout, m_A, true); }
);
@ -1049,7 +1049,7 @@ namespace pb {
}
else {
SASSERT(k > c);
TRACE("pb", tout << "visited: " << l << "\n";);
TRACE(pb, tout << "visited: " << l << "\n";);
k -= c;
}
}
@ -1098,7 +1098,7 @@ namespace pb {
}
}
if (idx == 0) {
TRACE("pb", tout << "there is no consequent\n";);
TRACE(pb, tout << "there is no consequent\n";);
goto bail_out;
}
--idx;
@ -1111,7 +1111,7 @@ namespace pb {
js = s().m_justification[v];
}
while (m_num_marks > 0 && !m_overflow);
TRACE("pb", active2pb(m_A); display(tout, m_A, true););
TRACE(pb, active2pb(m_A); display(tout, m_A, true););
// TBD: check if this is useful
if (!m_overflow && consequent != sat::null_literal) {
@ -1123,7 +1123,7 @@ namespace pb {
}
bail_out:
TRACE("pb", tout << "bail " << m_overflow << "\n";);
TRACE(pb, tout << "bail " << m_overflow << "\n";);
if (m_overflow) {
++m_stats.m_num_overflow;
m_overflow = false;
@ -1179,23 +1179,23 @@ namespace pb {
}
}
if (slack >= 0) {
TRACE("pb", tout << "slack is non-negative\n";);
TRACE(pb, tout << "slack is non-negative\n";);
IF_VERBOSE(20, verbose_stream() << "(sat.card slack: " << slack << " skipped: " << num_skipped << ")\n";);
return false;
}
if (m_overflow) {
TRACE("pb", tout << "overflow\n";);
TRACE(pb, tout << "overflow\n";);
return false;
}
if (m_lemma[0] == sat::null_literal) {
if (m_lemma.size() == 1) {
s().set_conflict(sat::justification(0));
}
TRACE("pb", tout << "no asserting literal\n";);
TRACE(pb, tout << "no asserting literal\n";);
return false;
}
TRACE("pb", tout << m_lemma << "\n";);
TRACE(pb, tout << m_lemma << "\n";);
if (get_config().m_drat && m_solver) {
s().m_drat.add(m_lemma, sat::status::th(true, get_id()));
@ -1204,7 +1204,7 @@ namespace pb {
s().m_lemma.reset();
s().m_lemma.append(m_lemma);
for (unsigned i = 1; i < m_lemma.size(); ++i) {
CTRACE("pb", s().is_marked(m_lemma[i].var()), tout << "marked: " << m_lemma[i] << "\n";);
CTRACE(pb, s().is_marked(m_lemma[i].var()), tout << "marked: " << m_lemma[i] << "\n";);
s().mark(m_lemma[i].var());
}
return true;
@ -1550,7 +1550,7 @@ namespace pb {
}
void solver::get_antecedents(literal l, pbc const& p, literal_vector& r) {
TRACE("pb", display(tout << l << " level: " << s().scope_lvl() << " ", p, true););
TRACE(pb, display(tout << l << " level: " << s().scope_lvl() << " ", p, true););
SASSERT(p.lit() == sat::null_literal || value(p.lit()) == l_true);
if (p.lit() != sat::null_literal) {
@ -1602,7 +1602,7 @@ namespace pb {
if (j < p.num_watch()) {
j = p.num_watch();
}
CTRACE("pb", coeff == 0, display(tout << l << " coeff: " << coeff << "\n", p, true););
CTRACE(pb, coeff == 0, display(tout << l << " coeff: " << coeff << "\n", p, true););
if (_debug_conflict) {
IF_VERBOSE(0, verbose_stream() << "coeff " << coeff << "\n";);
@ -1653,7 +1653,7 @@ namespace pb {
for (unsigned i = 0; !found && i < c.k(); ++i) {
found = c[i] == l;
}
CTRACE("pb",!found, s().display(tout << l << ":" << c << "\n"););
CTRACE(pb,!found, s().display(tout << l << ":" << c << "\n"););
SASSERT(found););
VERIFY(c.lit() == sat::null_literal || value(c.lit()) != l_false);
@ -1693,7 +1693,7 @@ namespace pb {
}
void solver::remove_constraint(constraint& c, char const* reason) {
TRACE("pb", display(tout << "remove ", c, true) << " " << reason << "\n";);
TRACE(pb, display(tout << "remove ", c, true) << " " << reason << "\n";);
IF_VERBOSE(21, display(verbose_stream() << "remove " << reason << " ", c, true););
c.nullify_tracking_literal(*this);
clear_watch(c);
@ -1868,7 +1868,7 @@ namespace pb {
}
void solver::gc_half(char const* st_name) {
TRACE("pb", tout << "gc\n";);
TRACE(pb, tout << "gc\n";);
unsigned sz = m_learned.size();
unsigned new_sz = sz/2;
unsigned removed = 0;
@ -1915,7 +1915,7 @@ namespace pb {
// literal is assigned to false.
unsigned sz = c.size();
unsigned bound = c.k();
TRACE("pb", tout << "assign: " << c.lit() << ": " << ~alit << "@" << lvl(~alit) << " " << c << "\n";);
TRACE(pb, tout << "assign: " << c.lit() << ": " << ~alit << "@" << lvl(~alit) << " " << c << "\n";);
SASSERT(0 < bound && bound <= sz);
if (bound == sz) {
@ -1953,7 +1953,7 @@ namespace pb {
// conflict
if (bound != index && value(c[bound]) == l_false) {
TRACE("pb", tout << "conflict " << c[bound] << " " << alit << "\n";);
TRACE(pb, tout << "conflict " << c[bound] << " " << alit << "\n";);
if (c.lit() != sat::null_literal && value(c.lit()) == l_undef) {
if (index + 1 < bound) c.swap(index, bound - 1);
assign(c, ~c.lit());
@ -1967,7 +1967,7 @@ namespace pb {
c.swap(index, bound);
}
// TRACE("pb", tout << "no swap " << index << " " << alit << "\n";);
// TRACE(pb, tout << "no swap " << index << " " << alit << "\n";);
// there are no literals to swap with,
// prepare for unit propagation by swapping the false literal into
// position bound. Then literals in positions 0..bound-1 have to be
@ -2002,7 +2002,7 @@ namespace pb {
}
void solver::pop(unsigned n) {
TRACE("sat_verbose", tout << "pop:" << n << "\n";);
TRACE(sat_verbose, tout << "pop:" << n << "\n";);
unsigned new_lim = m_constraint_to_reinit_lim.size() - n;
m_constraint_to_reinit_last_sz = m_constraint_to_reinit_lim[new_lim];
m_constraint_to_reinit_lim.shrink(new_lim);
@ -2333,7 +2333,7 @@ namespace pb {
}
if (!all_units) {
TRACE("pb", tout << "replacing by pb: " << c << "\n";);
TRACE(pb, tout << "replacing by pb: " << c << "\n";);
m_wlits.reset();
for (unsigned i = 0; i < sz; ++i) {
m_wlits.push_back(wliteral(coeffs[i], c[i]));
@ -2898,13 +2898,13 @@ namespace pb {
SASSERT(&c1 != &c2);
if (subsumes(c1, c2, slit)) {
if (slit.empty()) {
TRACE("pb", tout << "subsume cardinality\n" << c1 << "\n" << c2 << "\n";);
TRACE(pb, tout << "subsume cardinality\n" << c1 << "\n" << c2 << "\n";);
remove_constraint(c2, "subsumed");
++m_stats.m_num_pb_subsumes;
set_non_learned(c1);
}
else {
TRACE("pb", tout << "self subsume cardinality\n";);
TRACE(pb, tout << "self subsume cardinality\n";);
IF_VERBOSE(11,
verbose_stream() << "self-subsume cardinality\n";
verbose_stream() << c1 << "\n";
@ -2936,7 +2936,7 @@ namespace pb {
// self-subsumption is TBD
}
else {
TRACE("pb", tout << "remove\n" << c1 << "\n" << c2 << "\n";);
TRACE(pb, tout << "remove\n" << c1 << "\n" << c2 << "\n";);
removed_clauses.push_back(&c2);
++m_stats.m_num_clause_subsumes;
set_non_learned(c1);
@ -3268,7 +3268,7 @@ namespace pb {
val += wl.first;
}
}
CTRACE("pb", val >= 0, active2pb(m_A); display(tout, m_A, true););
CTRACE(pb, val >= 0, active2pb(m_A); display(tout, m_A, true););
return val < 0;
}
@ -3281,7 +3281,7 @@ namespace pb {
if (!is_false(wl.second))
k += wl.first;
}
CTRACE("pb", k > 0, display(tout, ineq, true););
CTRACE(pb, k > 0, display(tout, ineq, true););
return k <= 0;
}
@ -3340,7 +3340,7 @@ namespace pb {
return nullptr;
}
constraint* c = add_pb_ge(sat::null_literal, m_wlits, m_bound, true);
TRACE("pb", if (c) display(tout, *c, true););
TRACE(pb, if (c) display(tout, *c, true););
++m_stats.m_num_lemmas;
return c;
}
@ -3528,7 +3528,7 @@ namespace pb {
s0.assign_scoped(l2);
s0.assign_scoped(l3);
lbool is_sat = s0.check();
TRACE("pb", s0.display(tout << "trying sat encoding"););
TRACE(pb, s0.display(tout << "trying sat encoding"););
if (is_sat == l_false) return true;
IF_VERBOSE(0,
@ -3639,11 +3639,11 @@ namespace pb {
bool solver::validate_conflict(literal_vector const& lits, ineq& p) {
for (literal l : lits) {
if (value(l) != l_false) {
TRACE("pb", tout << "literal " << l << " is not false\n";);
TRACE(pb, tout << "literal " << l << " is not false\n";);
return false;
}
if (!p.contains(l)) {
TRACE("pb", tout << "lemma contains literal " << l << " not in inequality\n";);
TRACE(pb, tout << "lemma contains literal " << l << " not in inequality\n";);
return false;
}
}
@ -3654,7 +3654,7 @@ namespace pb {
value += coeff;
}
}
CTRACE("pb", value >= p.m_k, tout << "slack: " << value << " bound " << p.m_k << "\n";
CTRACE(pb, value >= p.m_k, tout << "slack: " << value << " bound " << p.m_k << "\n";
display(tout, p);
tout << lits << "\n";);
return value < p.m_k;