From 17642bcf91e221a0ed207ae7b38fa5b2d26196db Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Thu, 27 Aug 2026 11:27:44 +0200 Subject: [PATCH] [native] Delete the std::format logging machinery from the CoreCLR host With every CoreCLR-lane call site converted to the printf-style `log_*f` functions, the `std::format`-based macros and templates in `clr/include/shared/log_types.hh` have no users left. They generated no code (the templates were never instantiated), but they kept `` and the whole `std::format` API reachable from CLR translation units. `clr/include/shared/log_types.hh` is now byte-for-byte identical to the NativeAOT stub. The only piece worth keeping was the `std::string_view` overload of `log_write`, which is used by `common/runtime-base/timing-internal.cc` and was previously duplicated in both the CoreCLR and MonoVM copies of `log_types.hh`. It moves to `common/include/shared/log_functions.hh`, so all three lanes share a single definition, and the duplicate is dropped from `mono/shared/log_types.hh`. There is no code size change - this removes dead declarations, not dead code. `std::format` is now entirely absent from the `clr/`, `common/` and `nativeaot/` trees; only MonoVM still uses it. Verified by building the CoreCLR, MonoVM and NativeAOT lanes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e --- src/native/clr/include/shared/log_types.hh | 114 ------------------ .../common/include/shared/log_functions.hh | 9 ++ src/native/mono/shared/log_types.hh | 8 -- 3 files changed, 9 insertions(+), 122 deletions(-) diff --git a/src/native/clr/include/shared/log_types.hh b/src/native/clr/include/shared/log_types.hh index 54e164c87f8..e4b75d6ea0e 100644 --- a/src/native/clr/include/shared/log_types.hh +++ b/src/native/clr/include/shared/log_types.hh @@ -1,119 +1,5 @@ #pragma once -#include -#include -#include -#include - #include -// We redeclare macros here -#if defined(log_debug) -#undef log_debug -#endif - -#if defined(log_info) -#undef log_info -#endif - -#define DO_LOG_FMT(_level, _category_, _fmt_, ...) \ - do { \ - if ((log_categories & ((_category_))) != 0) { \ - ::log_ ## _level ## _nocheck_fmt ((_category_), _fmt_ __VA_OPT__(,) __VA_ARGS__); \ - } \ - } while (0) - -// -// For std::format spec, see https://en.cppreference.com/w/cpp/utility/format/spec -// - -// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style -#define log_debug(_category_, _fmt_, ...) DO_LOG_FMT (debug, (_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) - -// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style -#define log_info(_category_, _fmt_, ...) DO_LOG_FMT (info, (_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) - -// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style -#define log_warn(_category_, _fmt_, ...) log_warn_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) - -// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style -#define log_error(_category_, _fmt_, ...) log_error_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) - -// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style -#define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) - -namespace xamarin::android { - [[gnu::always_inline]] - static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept - { - log_write (category, level, message.data ()); - } - - template [[gnu::always_inline]] - static inline constexpr void log_write_fmt (LogCategories category, LogLevel level, std::format_string fmt, Args&& ...args) - { - log_write (category, level, std::format (fmt, std::forward(args)...).c_str ()); - } -} - -template [[gnu::always_inline]] -static inline constexpr void log_debug_nocheck_fmt (LogCategories category, std::format_string fmt, Args&& ...args) -{ - log_write (category, xamarin::android::LogLevel::Debug, std::format (fmt, std::forward(args)...).c_str ()); -} - -[[gnu::always_inline]] -static inline constexpr void log_debug_nocheck (LogCategories category, std::string_view const& message) noexcept -{ - log_write (category, xamarin::android::LogLevel::Debug, message.data ()); -} - -template [[gnu::always_inline]] -static inline constexpr void log_info_nocheck_fmt (LogCategories category, std::format_string fmt, Args&& ...args) -{ - log_write (category, xamarin::android::LogLevel::Info, std::format (fmt, std::forward(args)...).c_str ()); -} - -[[gnu::always_inline]] -static inline constexpr void log_info_nocheck (LogCategories category, std::string_view const& message) noexcept -{ - log_write (category, xamarin::android::LogLevel::Info, message.data ()); -} - -template [[gnu::always_inline]] -static inline constexpr void log_warn_fmt (LogCategories category, std::format_string fmt, Args&& ...args) noexcept -{ - log_write (category, xamarin::android::LogLevel::Warn, std::format (fmt, std::forward(args)...).c_str ()); -} - -[[gnu::always_inline]] -static inline constexpr void log_warn_fmt (LogCategories category, std::string_view const& message) noexcept -{ - log_write (category, xamarin::android::LogLevel::Warn, message.data ()); -} - -template [[gnu::always_inline]] -static inline constexpr void log_error_fmt (LogCategories category, std::format_string fmt, Args&& ...args) noexcept -{ - log_write (category, xamarin::android::LogLevel::Error, std::format (fmt, std::forward(args)...).c_str ()); -} - -[[gnu::always_inline]] -static inline constexpr void log_error_fmt (LogCategories category, std::string_view const& message) noexcept -{ - log_write (category, xamarin::android::LogLevel::Error, message.data ()); -} - -template [[gnu::always_inline]] -static inline constexpr void log_fatal_fmt (LogCategories category, std::format_string fmt, Args&& ...args) noexcept -{ - log_write (category, xamarin::android::LogLevel::Fatal, std::format (fmt, std::forward(args)...).c_str ()); -} - -[[gnu::always_inline]] -static inline constexpr void log_fatal_fmt (LogCategories category, std::string_view const& message) noexcept -{ - log_write (category, xamarin::android::LogLevel::Fatal, message.data ()); -} - extern unsigned int log_categories; diff --git a/src/native/common/include/shared/log_functions.hh b/src/native/common/include/shared/log_functions.hh index 098b739a684..264502261f5 100644 --- a/src/native/common/include/shared/log_functions.hh +++ b/src/native/common/include/shared/log_functions.hh @@ -1,6 +1,7 @@ #pragma once #include +#include #include "java-interop-logger.h" #include @@ -15,4 +16,12 @@ namespace xamarin::android { void log_infof (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); void log_warnf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); + + // `message` must be a NUL-terminated string, `std::string_view` is used here merely to avoid + // having to call `.data ()` at every call site that uses a string literal. + [[gnu::always_inline]] + static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept + { + log_write (category, level, message.data ()); + } } diff --git a/src/native/mono/shared/log_types.hh b/src/native/mono/shared/log_types.hh index bbb0fb6e936..5da08dec30f 100644 --- a/src/native/mono/shared/log_types.hh +++ b/src/native/mono/shared/log_types.hh @@ -42,14 +42,6 @@ // NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style #define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) -namespace xamarin::android { - [[gnu::always_inline]] - static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept - { - log_write (category, level, message.data ()); - } -} - template [[gnu::always_inline]] static inline constexpr void log_debug_nocheck_fmt (LogCategories category, std::format_string fmt, Args&& ...args) {