mirror of
https://github.com/Z3Prover/z3
synced 2026-02-20 07:24:40 +00:00
* 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).
99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
/*++
|
|
Copyright (c) 2006 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
cached_var_subst.cpp
|
|
|
|
Abstract:
|
|
|
|
<abstract>
|
|
|
|
Author:
|
|
|
|
Leonardo de Moura (leonardo) 2009-01-23.
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
#include "ast/rewriter/cached_var_subst.h"
|
|
#include "ast/rewriter/rewriter_def.h"
|
|
|
|
bool cached_var_subst::key_eq_proc::operator()(cached_var_subst::key * k1, cached_var_subst::key * k2) const {
|
|
if (k1->m_qa != k2->m_qa)
|
|
return false;
|
|
if (k1->m_num_bindings != k2->m_num_bindings)
|
|
return false;
|
|
for (unsigned i = 0; i < k1->m_num_bindings; i++)
|
|
if (k1->m_bindings[i] != k2->m_bindings[i])
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
cached_var_subst::cached_var_subst(ast_manager & _m):
|
|
m(_m),
|
|
m_proc(m),
|
|
m_refs(m) {
|
|
}
|
|
|
|
void cached_var_subst::reset() {
|
|
m_refs.reset();
|
|
m_instances.reset();
|
|
m_region.reset();
|
|
m_new_keys.reset();
|
|
m_key = nullptr;
|
|
}
|
|
|
|
expr** cached_var_subst::operator()(quantifier* qa, unsigned num_bindings) {
|
|
m_new_keys.reserve(num_bindings+1, 0);
|
|
m_key = m_new_keys[num_bindings];
|
|
if (m_key == nullptr)
|
|
m_key = static_cast<key*>(m_region.allocate(sizeof(key) + sizeof(expr*)*num_bindings));
|
|
m_key->m_qa = qa;
|
|
m_key->m_num_bindings = num_bindings;
|
|
return m_key->m_bindings;
|
|
}
|
|
|
|
|
|
expr_ref cached_var_subst::operator()() {
|
|
expr_ref result(m);
|
|
|
|
auto* entry = m_instances.insert_if_not_there3(m_key, nullptr);
|
|
unsigned num_bindings = m_key->m_num_bindings;
|
|
if (entry->get_data().m_key != m_key) {
|
|
SASSERT(entry->get_data().m_value != 0);
|
|
// entry was already there
|
|
m_new_keys[num_bindings] = m_key; // recycle key
|
|
result = entry->get_data().m_value;
|
|
SCTRACE(bindings, is_trace_enabled(TraceTag::coming_from_quant), tout << "(cache)\n";
|
|
for (unsigned i = 0; i < num_bindings; i++)
|
|
if (m_key->m_bindings[i])
|
|
tout << i << ": " << mk_ismt2_pp(m_key->m_bindings[i], result.m()) << ";\n";
|
|
tout.flush(););
|
|
return result;
|
|
}
|
|
|
|
SASSERT(entry->get_data().m_value == 0);
|
|
try {
|
|
result = m_proc(m_key->m_qa->get_expr(), m_key->m_num_bindings, m_key->m_bindings);
|
|
}
|
|
catch (...) {
|
|
// CMW: The var_subst reducer was interrupted and m_instances is
|
|
// in an inconsistent state; we need to remove (m_key, 0).
|
|
m_instances.remove(m_key);
|
|
throw;
|
|
}
|
|
|
|
// cache result
|
|
entry->get_data().m_value = result;
|
|
|
|
// remove key from cache
|
|
m_new_keys[num_bindings] = nullptr;
|
|
|
|
// increment reference counters
|
|
m_refs.push_back(m_key->m_qa);
|
|
for (unsigned i = 0; i < m_key->m_num_bindings; i++)
|
|
m_refs.push_back(m_key->m_bindings[i]);
|
|
m_refs.push_back(result);
|
|
return result;
|
|
}
|