3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-23 00:50:29 +00:00
z3/src/ast/simplifiers/then_simplifier.h
LeeYoungJoon 0a93ff515d
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).
2025-05-28 14:31:25 +01:00

133 lines
3.7 KiB
C++

/*++
Copyright (c) 2022 Microsoft Corporation
Module Name:
then_simplifier.h
Abstract:
create a simplifier from a sequence of simplifiers
Author:
Nikolaj Bjorner (nbjorner) 2022-11-24
--*/
#pragma once
#include "util/stopwatch.h"
#include "ast/simplifiers/dependent_expr_state.h"
class then_simplifier : public dependent_expr_simplifier {
scoped_ptr_vector<dependent_expr_simplifier> m_simplifiers;
struct collect_stats {
stopwatch m_watch;
double m_start_memory = 0;
dependent_expr_simplifier& s;
collect_stats(dependent_expr_simplifier& s) :
m_start_memory(static_cast<double>(memory::get_allocation_size()) / static_cast<double>(1024 * 1024)),
s(s) {
m_watch.start();
}
~collect_stats() {
m_watch.stop();
double end_memory = static_cast<double>(memory::get_allocation_size()) / static_cast<double>(1024 * 1024);
IF_VERBOSE(10,
statistics st;
verbose_stream() << "(" << s.name()
<< " :num-exprs " << s.get_fmls().num_exprs()
<< " :num-asts " << s.get_manager().get_num_asts()
<< " :time " << std::fixed << std::setprecision(2) << m_watch.get_seconds()
<< " :before-memory " << std::fixed << std::setprecision(2) << m_start_memory
<< " :after-memory " << std::fixed << std::setprecision(2) << end_memory
<< ")" << "\n";
s.collect_statistics(st);
if (st.size() > 0)
st.display_smt2(verbose_stream()));
}
};
protected:
bool m_bail_on_no_change = false;
public:
then_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls):
dependent_expr_simplifier(m, fmls) {
}
char const* name() const override { return "and-then"; }
void add_simplifier(dependent_expr_simplifier* s) {
m_simplifiers.push_back(s);
}
void reduce() override {
TRACE(simplifier, tout << m_fmls);
for (auto* s : m_simplifiers) {
if (m_fmls.inconsistent())
break;
if (!m.inc())
break;
s->reset_statistics();
collect_stats _cs(*s);
m_fmls.reset_updated();
try {
s->reduce();
m_fmls.flatten_suffix();
}
catch (rewriter_exception &) {
break;
}
TRACE(simplifier, tout << s->name() << "\n" << m_fmls);
if (m_bail_on_no_change && !m_fmls.updated())
break;
}
}
void collect_statistics(statistics& st) const override {
for (auto* s : m_simplifiers)
s->collect_statistics(st);
}
void reset_statistics() override {
for (auto* s : m_simplifiers)
s->reset_statistics();
}
void updt_params(params_ref const& p) override {
for (auto* s : m_simplifiers)
s->updt_params(p);
}
void collect_param_descrs(param_descrs& r) override {
for (auto* s : m_simplifiers)
s->collect_param_descrs(r);
}
void push() override {
for (auto* s : m_simplifiers)
s->push();
}
void pop(unsigned n) override {
for (auto* s : m_simplifiers)
s->pop(n);
}
};
class if_change_simplifier : public then_simplifier {
public:
if_change_simplifier(ast_manager& m, params_ref const& p, dependent_expr_state& fmls):
then_simplifier(m, p, fmls) {
m_bail_on_no_change = true;
}
char const* name() const override { return "if-change-then"; }
};