3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-05 18:42:44 +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

@ -203,7 +203,7 @@ namespace opt {
return true;
}
#define PASSERT(_e_) { CTRACE("qe", !(_e_), display(tout, r); display(tout);); SASSERT(_e_); }
#define PASSERT(_e_) { CTRACE(qe, !(_e_), display(tout, r); display(tout);); SASSERT(_e_); }
bool model_based_opt::invariant(unsigned index, row const& r) {
vector<var> const& vars = r.m_vars;
@ -250,7 +250,7 @@ namespace opt {
inf_eps model_based_opt::maximize() {
SASSERT(invariant());
unsigned_vector bound_trail, bound_vars;
TRACE("opt", display(tout << "tableau\n"););
TRACE(opt, display(tout << "tableau\n"););
while (!objective().m_vars.empty()) {
var v = objective().m_vars.back();
unsigned x = v.m_id;
@ -259,7 +259,7 @@ namespace opt {
rational bound_coeff;
if (find_bound(x, bound_row_index, bound_coeff, coeff.is_pos())) {
SASSERT(!bound_coeff.is_zero());
TRACE("opt", display(tout << "update: " << v << " ", objective());
TRACE(opt, display(tout << "update: " << v << " ", objective());
for (unsigned above : m_above) {
display(tout << "resolve: ", m_rows[above]);
});
@ -280,7 +280,7 @@ namespace opt {
bound_vars.push_back(x);
}
else {
TRACE("opt", display(tout << "unbound: " << v << " ", objective()););
TRACE(opt, display(tout << "unbound: " << v << " ", objective()););
update_values(bound_vars, bound_trail);
return inf_eps::infinity();
}
@ -364,7 +364,7 @@ namespace opt {
new_x_val += eps;
}
}
TRACE("opt", display(tout << "v" << x
TRACE(opt, display(tout << "v" << x
<< " coeff_x: " << x_coeff
<< " old_x_val: " << old_x_val
<< " new_x_val: " << new_x_val
@ -558,7 +558,7 @@ namespace opt {
if (m_rows[row_dst].m_alive) {
rational a2 = get_coefficient(row_dst, x);
if (is_int(x)) {
TRACE("opt",
TRACE(opt,
tout << "v" << x << ": " << a1 << " " << a2 << ":\n";
display(tout, m_rows[row_dst]);
display(tout, m_rows[row_src]););
@ -569,7 +569,7 @@ namespace opt {
mul(row_dst, abs(a1));
mul_add(false, row_dst, -abs(a2), row_src);
}
TRACE("opt", display(tout << "result ", m_rows[row_dst]););
TRACE(opt, display(tout << "result ", m_rows[row_dst]););
normalize(row_dst);
}
else {
@ -621,7 +621,7 @@ namespace opt {
if (use_case1) {
TRACE("opt", tout << "slack: " << slack << " " << src_c << " " << dst_val << " " << dst_c << " " << src_val << "\n";);
TRACE(opt, tout << "slack: " << slack << " " << src_c << " " << dst_val << " " << dst_c << " " << src_val << "\n";);
// dst <- abs_src_c*dst + abs_dst_c*src + slack
mul(row_dst, abs_src_c);
add(row_dst, slack);
@ -696,7 +696,7 @@ namespace opt {
// exists z in [0 .. |b|-2] . |b| | (z + s) && a*n_sign(b)(s + z) + |b|t <= 0
//
TRACE("qe", tout << "finite disjunction " << distance << " " << src_c << " " << dst_c << "\n";);
TRACE(qe, tout << "finite disjunction " << distance << " " << src_c << " " << dst_c << "\n";);
vector<var> coeffs;
if (abs_dst_c <= abs_src_c) {
rational z = mod(dst_val, abs_dst_c);
@ -1174,7 +1174,7 @@ namespace opt {
result = def::from_row(m_rows[lub_index], x);
else
result = def::from_row(m_rows[glb_index], x);
TRACE("opt1", display(tout << "resolution result:", *result) << "\n");
TRACE(opt1, display(tout << "resolution result:", *result) << "\n");
}
// The number of matching lower and upper bounds is small.
@ -1271,7 +1271,7 @@ namespace opt {
def_ref result(nullptr);
unsigned_vector div_rows(_div_rows), mod_rows(_mod_rows);
SASSERT(!div_rows.empty() || !mod_rows.empty());
TRACE("opt", display(tout << "solve_div v" << x << "\n"));
TRACE(opt, display(tout << "solve_div v" << x << "\n"));
rational K(1);
for (unsigned ri : div_rows)
@ -1494,11 +1494,11 @@ namespace opt {
result = *(*y_def * K) + *z_def;
m_var2value[x] = eval(*result);
TRACE("opt", tout << y << " := " << *y_def << "\n";
TRACE(opt, tout << y << " := " << *y_def << "\n";
tout << z << " := " << *z_def << "\n";
tout << x << " := " << *result << "\n");
}
TRACE("opt", display(tout << "solve_div done v" << x << "\n"));
TRACE(opt, display(tout << "solve_div done v" << x << "\n"));
return result;
}
@ -1527,7 +1527,7 @@ namespace opt {
throw default_exception("modulo 0 is not defined");
}
if (D.is_neg()) D = abs(D);
TRACE("opt1", display(tout << "lcm: " << D << " x: v" << x << " tableau\n"););
TRACE(opt1, display(tout << "lcm: " << D << " x: v" << x << " tableau\n"););
rational val_x = m_var2value[x];
rational u = mod(val_x, D);
SASSERT(u.is_nonneg() && u < D);
@ -1536,7 +1536,7 @@ namespace opt {
SASSERT(invariant(idx, m_rows[idx]));
normalize(idx);
}
TRACE("opt1", display(tout << "tableau after replace x under mod\n"););
TRACE(opt1, display(tout << "tableau after replace x under mod\n"););
//
// update inequalities such that u is added to t and
// D is multiplied to coefficient of x.
@ -1559,13 +1559,13 @@ namespace opt {
visited.insert(row_id);
normalize(row_id);
}
TRACE("opt1", display(tout << "tableau after replace v" << x << " := " << D << " * v" << y << "\n"););
TRACE(opt1, display(tout << "tableau after replace v" << x << " := " << D << " * v" << y << "\n"););
def_ref result = project(y, compute_def);
if (compute_def) {
result = *(*result * D) + u;
m_var2value[x] = eval(*result);
}
TRACE("opt1", display(tout << "tableau after project v" << y << "\n"););
TRACE(opt1, display(tout << "tableau after project v" << y << "\n"););
return result;
}
@ -1631,7 +1631,7 @@ namespace opt {
// 3 | -t & 21 | (-ct + 3s) & a-t <= 3u
model_based_opt::def_ref model_based_opt::solve_for(unsigned row_id1, unsigned x, bool compute_def) {
TRACE("opt", tout << "v" << x << " := " << eval(x) << "\n" << m_rows[row_id1] << "\n";
TRACE(opt, tout << "v" << x << " := " << eval(x) << "\n" << m_rows[row_id1] << "\n";
display(tout));
rational a = get_coefficient(row_id1, x), b;
row& r1 = m_rows[row_id1];
@ -1690,10 +1690,10 @@ namespace opt {
if (compute_def) {
result = def::from_row(m_rows[row_id1], x);
m_var2value[x] = eval(*result);
TRACE("opt1", tout << "updated eval " << x << " := " << eval(x) << "\n";);
TRACE(opt1, tout << "updated eval " << x << " := " << eval(x) << "\n";);
}
retire_row(row_id1);
TRACE("opt", display(tout << "solved v" << x << "\n"));
TRACE(opt, display(tout << "solved v" << x << "\n"));
return result;
}
@ -1709,7 +1709,7 @@ namespace opt {
m_result.push_back(project(vars[i], compute_def));
if (compute_def)
eliminate(vars[i], *(m_result.back()));
TRACE("opt", display(tout << "After projecting: v" << vars[i] << "\n"););
TRACE(opt, display(tout << "After projecting: v" << vars[i] << "\n"););
}
return m_result;
}

View file

@ -129,7 +129,7 @@ namespace smt {
m_graph.add_edge(e.get_target(), e.get_source(), e.get_weight(), explanation());
}
}
TRACE("network_flow", {
TRACE(network_flow, {
tout << "Difference logic optimization:" << std::endl;
display_dual(tout);
tout << "Minimum cost flow:" << std::endl;
@ -143,7 +143,7 @@ namespace smt {
template<typename Ext>
void network_flow<Ext>::initialize() {
TRACE("network_flow", tout << "initialize...\n";);
TRACE(network_flow, tout << "initialize...\n";);
// Create an artificial root node to construct initial spanning tree
unsigned num_nodes = m_graph.get_num_nodes();
unsigned num_edges = m_graph.get_num_edges();
@ -180,7 +180,7 @@ namespace smt {
m_tree->initialize(tree);
TRACE("network_flow",
TRACE(network_flow,
tout << pp_vector("Potentials", m_potentials);
tout << pp_vector("Flows", m_flows);
tout << "Cost: " << get_cost() << "\n";
@ -206,7 +206,7 @@ namespace smt {
start = src;
}
SASSERT(m_tree->in_subtree_t2(start));
TRACE("network_flow", tout << "update_potentials of T_" << start << " with change = " << change << "...\n";);
TRACE(network_flow, tout << "update_potentials of T_" << start << " with change = " << change << "...\n";);
svector<node> descendants;
m_tree->get_descendants(start, descendants);
SASSERT(descendants.size() >= 1);
@ -214,7 +214,7 @@ namespace smt {
node u = descendants[i];
m_potentials[u] += change;
}
TRACE("network_flow", tout << pp_vector("Potentials", m_potentials););
TRACE(network_flow, tout << pp_vector("Potentials", m_potentials););
}
template<typename Ext>
@ -230,7 +230,7 @@ namespace smt {
edge_id e_id = path[i];
m_flows[e_id] += against[i] ? - *m_delta : *m_delta;
}
TRACE("network_flow", tout << pp_vector("Flows", m_flows););
TRACE(network_flow, tout << pp_vector("Flows", m_flows););
}
template<typename Ext>
@ -288,7 +288,7 @@ namespace smt {
bool bounded = choose_leaving_edge();
if (!bounded) return UNBOUNDED;
vector<edge>const& es = m_graph.get_all_edges();
TRACE("network_flow",
TRACE(network_flow,
{
edge const& e_in = es[m_enter_id];
edge const& e_out = es[m_leave_id];
@ -310,7 +310,7 @@ namespace smt {
m_states[m_leave_id] = LOWER;
update_spanning_tree();
update_potentials();
TRACE("network_flow",
TRACE(network_flow,
tout << "Spanning tree:\n";
display_spanning_tree(tout);
tout << "Cost: " << get_cost() << "\n";
@ -319,14 +319,14 @@ namespace smt {
SASSERT(check_well_formed());
}
}
TRACE("network_flow",
TRACE(network_flow,
tout << "Spanning tree:\n";
display_spanning_tree(tout);
tout << "Cost: " << get_cost() << "\n";
display_primal(tout);
);
if (is_infeasible()) return INFEASIBLE;
TRACE("network_flow", tout << "Found optimal solution.\n";);
TRACE(network_flow, tout << "Found optimal solution.\n";);
SASSERT(check_optimal());
return OPTIMAL;
}
@ -418,7 +418,7 @@ namespace smt {
for (unsigned i = 0; i < m_potentials.size(); ++i) {
total_balance += m_balances[i] * m_potentials[i];
}
TRACE("network_flow", tout << "Total balance: " << total_balance << ", total cost: " << total_cost << std::endl;);
TRACE(network_flow, tout << "Total balance: " << total_balance << ", total cost: " << total_cost << std::endl;);
return total_cost == total_balance;
}

View file

@ -51,7 +51,7 @@ namespace simplex {
m.mul(coeffs[m_base_vars[i]], mul, a);
m.set(b, m_vars[v].m_base_coeff);
m.lcm(a, b, c);
TRACE("simplex",
TRACE(simplex,
m.display(tout << " a: ", a);
m.display(tout << " b v" << v << " : ", b);
m.display(tout << " c: ", c);
@ -69,7 +69,7 @@ namespace simplex {
M.mul(r, b);
m.neg(a);
M.add(r, a, row(m_vars[v].m_base2row));
TRACE("simplex", M.display_row(tout, r););
TRACE(simplex, M.display_row(tout, r););
}
scoped_numeral base_coeff(m);
@ -87,7 +87,7 @@ namespace simplex {
}
}
SASSERT(!m.is_zero(base_coeff));
TRACE("simplex",
TRACE(simplex,
for (unsigned i = 0; i < num_vars; ++i) {
m.display(tout << "v" << vars[i] << " * ", coeffs[i]); tout << " ";
if (i + 1 < num_vars) tout << " + ";
@ -132,7 +132,7 @@ namespace simplex {
void simplex<Ext>::add_patch(var_t v) {
SASSERT(is_base(v));
if (outside_bounds(v)) {
TRACE("simplex", tout << "Add patch: v" << v << "\n";);
TRACE(simplex, tout << "Add patch: v" << v << "\n";);
m_to_patch.insert(v);
}
}
@ -151,7 +151,7 @@ namespace simplex {
template<typename Ext>
void simplex<Ext>::del_row(var_t var) {
TRACE("simplex", tout << var << "\n";);
TRACE(simplex, tout << var << "\n";);
row r;
if (is_base(var)) {
r = row(m_vars[var].m_base2row);
@ -182,7 +182,7 @@ namespace simplex {
SASSERT(!below_lower(old_base) && !above_upper(old_base));
}
del_row(r);
TRACE("simplex", display(tout););
TRACE(simplex, display(tout););
SASSERT(well_formed());
}
@ -203,7 +203,7 @@ namespace simplex {
var_info& vi = m_vars[var];
em.set(vi.m_lower, b);
vi.m_lower_valid = true;
TRACE("simplex", em.display(tout << "v" << var << " lower: ", b);
TRACE(simplex, em.display(tout << "v" << var << " lower: ", b);
em.display(tout << " value: ", vi.m_value););
SASSERT(!vi.m_upper_valid || em.le(b, vi.m_upper));
if (!vi.m_is_base && em.lt(vi.m_value, b)) {
@ -339,7 +339,7 @@ namespace simplex {
m_bland = false;
SASSERT(well_formed());
while ((v = select_var_to_fix()) != null_var) {
TRACE("simplex", display(tout << "v" << v << "\n"););
TRACE(simplex, display(tout << "v" << v << "\n"););
if (!m_limit.inc() || num_iterations > m_max_iterations) {
return l_undef;
}
@ -686,7 +686,7 @@ namespace simplex {
// optimal
return l_true;
}
TRACE("simplex", tout << "x_i: v" << x_i << " x_j: v" << x_j << "\n";);
TRACE(simplex, tout << "x_i: v" << x_i << " x_j: v" << x_j << "\n";);
var_info& vj = m_vars[x_j];
if (x_i == null_var) {
if (inc_x_j && vj.m_upper_valid) {
@ -714,10 +714,10 @@ namespace simplex {
//
pivot(x_i, x_j, a_ij);
TRACE("simplex", display(tout << "after pivot\n"););
TRACE(simplex, display(tout << "after pivot\n"););
move_to_bound(x_i, !inc_x_i);
SASSERT(well_formed_row(row(m_vars[x_j].m_base2row)));
TRACE("simplex", display(tout););
TRACE(simplex, display(tout););
SASSERT(is_feasible());
}
return l_true;
@ -733,7 +733,7 @@ namespace simplex {
else {
em.sub(vi.m_upper, vi.m_value, delta);
}
TRACE("simplex", tout << "move " << (to_lower?"to_lower":"to_upper")
TRACE(simplex, tout << "move " << (to_lower?"to_lower":"to_upper")
<< " v" << x << " delta: " << em.to_string(delta) << "\n";);
col_iterator it = M.col_begin(x), end = M.col_end(x);
for (; it != end && is_pos(delta); ++it) {
@ -766,7 +766,7 @@ namespace simplex {
em.mul(delta2, base_coeff, delta2);
em.div(delta2, coeff, delta2);
em.abs(delta2);
TRACE("simplex", tout << "Delta for v" << s << " " << delta2 << "\n";);
TRACE(simplex, tout << "Delta for v" << s << " " << delta2 << "\n";);
if (delta2 < delta) {
delta = delta2;
}
@ -805,7 +805,7 @@ namespace simplex {
if (x == v) continue;
bool inc_x = m.is_pos(it->m_coeff) == m.is_pos(m_vars[v].m_base_coeff);
if ((inc_x && at_upper(x)) || (!inc_x && at_lower(x))) {
TRACE("simplex", tout << "v" << x << " pos: " << inc_x
TRACE(simplex, tout << "v" << x << " pos: " << inc_x
<< " at upper: " << at_upper(x)
<< " at lower: " << at_lower(x) << "\n";);
continue; // variable cannot be used for improving bounds.
@ -826,7 +826,7 @@ namespace simplex {
((is_zero(new_gain) && is_zero(gain) && (x_i == null_var || y < x_i)));
if (better) {
TRACE("simplex",
TRACE(simplex,
em.display(tout << "gain:", gain);
em.display(tout << " new gain:", new_gain);
tout << " base x_i: " << y << ", new base x_j: " << x << ", inc x_j: " << inc_x << "\n";);
@ -871,7 +871,7 @@ namespace simplex {
numeral const& a_ii = vi.m_base_coeff;
bool sign_eq = (m.is_pos(a_ii) == m.is_pos(a_ij));
bool inc_s = sign_eq != inc_x_j;
TRACE("simplex", tout << "x_j: v" << x_j << ", base x_i: v" << s
TRACE(simplex, tout << "x_j: v" << x_j << ", base x_i: v" << s
<< ", inc_x_i: " << inc_s
<< ", inc_x_j: " << inc_x_j
<< ", upper valid:" << vi.m_upper_valid
@ -896,7 +896,7 @@ namespace simplex {
gain = curr_gain;
new_a_ij = a_ij;
inc_x_i = inc_s;
TRACE("simplex", tout << "x_j v" << x_j << " x_i v" << x_i << " gain: ";
TRACE(simplex, tout << "x_j v" << x_j << " x_i v" << x_i << " gain: ";
tout << curr_gain << "\n";);
}
}
@ -910,7 +910,7 @@ namespace simplex {
if (m_left_basis.contains(v)) {
num_repeated++;
if (num_repeated > m_blands_rule_threshold) {
TRACE("simplex", tout << "using blands rule, " << num_repeated << "\n";);
TRACE(simplex, tout << "using blands rule, " << num_repeated << "\n";);
// std::cerr << "BLANDS RULE...\n";
m_bland = true;
}
@ -1019,7 +1019,7 @@ namespace simplex {
}
if (!em.is_zero(sum)) {
IF_VERBOSE(0, M.display_row(verbose_stream(), r););
TRACE("pb", display(tout << "non-well formed row\n"); M.display_row(tout << "row: ", r););
TRACE(pb, display(tout << "non-well formed row\n"); M.display_row(tout << "row: ", r););
throw default_exception("non-well formed row");
}