lean4-htt/src/kernel/trace.h
Sebastian Ullrich f47dfe9e7f
perf: Options.hasTrace (#12001)
Drastically speeds up `isTracingEnabledFor` in the common case, which
has evolved from "no options set" to "`Elab.async` and probably some
linter options set but no `trace`".

## Breaking changes

`Lean.Options` is now an opaque type. The basic but not all of the
`KVMap` API has been redefined on top of it.
2026-01-16 09:03:40 +00:00

49 lines
1.2 KiB
C++

/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <memory>
#include <string>
#include "library/elab_environment.h"
#include "util/options.h"
#include "util/message_definitions.h"
namespace lean {
void register_trace_class(name const & n, name const & decl_name = {});
bool is_trace_class_enabled(name const & n);
class scope_trace_env {
options const * m_old_opts;
void init(elab_environment * env, options * opts);
public:
scope_trace_env(elab_environment const & env, options const & opts);
~scope_trace_env();
};
struct tclass { name m_cls; tclass(name const & c):m_cls(c) {} };
struct tout {
sstream m_out;
~tout();
};
template <typename T>
tout & operator<<(tout const & out, T const & t) {
tout & out_mut = const_cast<tout &>(out);
out_mut.m_out << t;
return out_mut;
}
std::ostream & operator<<(std::ostream & ios, tclass const &);
#define lean_trace(CName, CODE) { \
if (lean::is_trace_class_enabled(CName)) { \
tout() << tclass(CName); CODE \
}}
void initialize_trace();
void finalize_trace();
}