From e7aa8da81672448622fd1f7f940bf42082208266 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Thu, 27 Feb 2025 17:05:14 -0700 Subject: [PATCH 1/2] :arrow_up: Update `stdx` and use `stdx::env` instead of `logging::env` --- CMakeLists.txt | 2 +- include/flow/log.hpp | 2 +- include/log/catalog/mipi_builder.hpp | 4 +- include/log/catalog/mipi_encoder.hpp | 10 ++-- include/log/env.hpp | 87 +--------------------------- include/log/flavor.hpp | 2 +- include/log/fmt/logger.hpp | 4 +- include/log/log.hpp | 6 +- include/log/module.hpp | 2 +- test/flow/custom_log_levels.cpp | 14 ++--- test/flow/log_levels.cpp | 2 +- test/log/catalog1_lib.cpp | 2 +- test/log/catalog2a_lib.cpp | 3 +- test/log/catalog2b_lib.cpp | 3 +- test/log/env.cpp | 11 ++-- test/log/fmt_logger.cpp | 2 +- test/log/mipi_encoder.cpp | 15 +++-- test/log/module_id.cpp | 10 ++-- 18 files changed, 48 insertions(+), 133 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d86d885..660d660a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ include(cmake/string_catalog.cmake) add_versioned_package("gh:boostorg/mp11#boost-1.83.0") fmt_recipe(11.1.3) add_versioned_package("gh:intel/cpp-baremetal-concurrency#7c5b26c") -add_versioned_package("gh:intel/cpp-std-extensions#37cc9c5") +add_versioned_package("gh:intel/cpp-std-extensions#ec95cd6") add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#73d95bc") set(GEN_STR_CATALOG diff --git a/include/flow/log.hpp b/include/flow/log.hpp index d34516ed..7a4f440e 100644 --- a/include/flow/log.hpp +++ b/include/flow/log.hpp @@ -9,7 +9,7 @@ namespace flow { using default_log_env = - logging::make_env_t; + stdx::make_env_t; template constexpr auto log_env = default_log_env{}; diff --git a/include/log/catalog/mipi_builder.hpp b/include/log/catalog/mipi_builder.hpp index 0352f051..476b417f 100644 --- a/include/log/catalog/mipi_builder.hpp +++ b/include/log/catalog/mipi_builder.hpp @@ -132,8 +132,6 @@ struct default_builder { return std::forward(t).query(*this); } - CONSTEVAL auto operator()(auto &&) const { - return stdx::ct(); - } + CONSTEVAL auto operator()(auto &&) const { return default_builder{}; } } get_builder; } // namespace logging::mipi diff --git a/include/log/catalog/mipi_encoder.hpp b/include/log/catalog/mipi_encoder.hpp index f06f2df0..c2f4a474 100644 --- a/include/log/catalog/mipi_encoder.hpp +++ b/include/log/catalog/mipi_encoder.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -13,6 +12,8 @@ #include #include +#include + #include #include #include @@ -49,11 +50,10 @@ template struct log_handler { template auto log_msg(Msg msg) -> void { msg.apply([&](S, Args... args) { - constexpr auto L = stdx::to_underlying(get_level(Env{}).value); + constexpr auto L = stdx::to_underlying(get_level(Env{})); using Message = decltype(detail::to_message()); - using Module = - decltype(detail::to_module()); - auto builder = get_builder(Env{}).value; + using Module = decltype(detail::to_module()); + auto builder = get_builder(Env{}); write(builder.template build(catalog(), module(), args...)); }); diff --git a/include/log/env.hpp b/include/log/env.hpp index f11b8183..6bb047f0 100644 --- a/include/log/env.hpp +++ b/include/log/env.hpp @@ -1,90 +1,9 @@ #pragma once #include -#include -#include +#include -#include - -namespace logging { -template struct prop { - [[nodiscard]] CONSTEVAL static auto query(decltype(Query)) noexcept { - return Value; - } -}; - -namespace detail { -template -concept valid_query_for = requires { Env::query(Q{}); }; - -template -concept valid_query_over = (... or valid_query_for); - -template struct has_query { - template - using fn = std::bool_constant>; -}; -} // namespace detail - -template struct env { - template Q> - CONSTEVAL static auto query(Q) noexcept { - using I = boost::mp11::mp_find_if_q, - detail::has_query>; - using E = boost::mp11::mp_at, I>; - return Q{}(E{}); - } -}; - -namespace detail { -template struct autowrap { - // NOLINTNEXTLINE(google-explicit-constructor) - CONSTEVAL autowrap(T t) : value(t) {} - T value; -}; - -// NOLINTNEXTLINE(modernize-avoid-c-arrays) -template using str_lit_t = char const (&)[N]; - -template struct autowrap> { - // NOLINTNEXTLINE(google-explicit-constructor) - CONSTEVAL autowrap(str_lit_t str) : value(str) {} - stdx::ct_string value; -}; - -template autowrap(T) -> autowrap; -template autowrap(str_lit_t) -> autowrap>; - -template struct wrap { - constexpr static auto value = V; -}; - -template struct for_each_pair; -template struct for_each_pair> { - template - using type = env< - prop...>, - 2 * Is>::value.value, - stdx::ct...>, - (2 * Is) + 1>::value.value>()>...>; -}; -} // namespace detail - -template > -constexpr auto make_env = [] { - using new_env_t = typename detail::for_each_pair< - std::make_index_sequence>::template type; - return boost::mp11::mp_append{}; -}; - -template -using extend_env_t = decltype(make_env.template operator()()); - -template -using make_env_t = extend_env_t, Args...>; -} // namespace logging - -using cib_log_env_t = logging::env<>; +using cib_log_env_t = stdx::env<>; // NOLINTBEGIN(cppcoreguidelines-macro-usage) @@ -96,7 +15,7 @@ using cib_log_env_t = logging::env<>; #define CIB_LOG_ENV_DECL(...) \ [[maybe_unused]] typedef decltype([] { \ - return logging::extend_env_t{}; \ + return stdx::extend_env_t{}; \ }()) cib_log_env_t #define CIB_LOG_ENV(...) \ diff --git a/include/log/flavor.hpp b/include/log/flavor.hpp index a8126248..f5da90e9 100644 --- a/include/log/flavor.hpp +++ b/include/log/flavor.hpp @@ -18,7 +18,7 @@ struct default_flavor_t; } CONSTEVAL auto operator()(auto &&) const { - return stdx::ct{}>(); + return stdx::type_identity{}; } } get_flavor; } // namespace logging diff --git a/include/log/fmt/logger.hpp b/include/log/fmt/logger.hpp index c5987c75..5432d904 100644 --- a/include/log/fmt/logger.hpp +++ b/include/log/fmt/logger.hpp @@ -50,8 +50,8 @@ template struct log_handler { stdx::for_each( [&](auto &out) { ::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime, - level_wrapper{}, - get_module(Env{}).value); + level_wrapper{}, + get_module(Env{})); msg.apply( [&](StringType, auto const &...args) { ::fmt::format_to(out, StringType::value, args...); diff --git a/include/log/log.hpp b/include/log/log.hpp index 4bebb621..bc4b8724 100644 --- a/include/log/log.hpp +++ b/include/log/log.hpp @@ -40,7 +40,7 @@ template inline auto config = null::config{}; template constexpr static auto get_config() -> auto & { - using flavor_t = typename decltype(get_flavor(Env{}).value)::type; + using flavor_t = typename decltype(get_flavor(Env{}))::type; if constexpr (std::same_as) { return config; } else { @@ -63,7 +63,7 @@ static auto log(TArgs &&...args) -> void { #define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \ logging::log< \ - logging::extend_env_t>( \ + stdx::extend_env_t>( \ __FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) #define CIB_TRACE(...) \ @@ -109,7 +109,7 @@ template static auto log_version() -> void { } // namespace logging #define CIB_LOG_V(FLAVOR) \ - logging::log_version{}>>() #define CIB_LOG_VERSION() CIB_LOG_V(logging::default_flavor_t) diff --git a/include/log/module.hpp b/include/log/module.hpp index b36ec730..26eef322 100644 --- a/include/log/module.hpp +++ b/include/log/module.hpp @@ -18,7 +18,7 @@ namespace logging { CONSTEVAL auto operator()(auto &&) const { using namespace stdx::literals; - return "default"_ctst; + return "default"_cts; } } get_module; } // namespace logging diff --git a/test/flow/custom_log_levels.cpp b/test/flow/custom_log_levels.cpp index 9d22e497..e535d9ba 100644 --- a/test/flow/custom_log_levels.cpp +++ b/test/flow/custom_log_levels.cpp @@ -41,7 +41,7 @@ struct log_config { template auto log(FilenameStringType, LineNumberType, MsgType const &) -> void { - log_calls.push_back(logging::get_level(Env{}).value); + log_calls.push_back(logging::get_level(Env{})); } }; log_handler logger; @@ -51,16 +51,16 @@ struct log_config { template <> inline auto logging::config<> = log_config{}; using user1_log_env = - logging::extend_env_t; + stdx::extend_env_t; using user2_log_env = - logging::extend_env_t; + stdx::extend_env_t; using info_log_env = - logging::extend_env_t; + stdx::extend_env_t; template <> constexpr auto flow::log_env<"default"> = info_log_env{}; diff --git a/test/flow/log_levels.cpp b/test/flow/log_levels.cpp index 82037067..35dc015d 100644 --- a/test/flow/log_levels.cpp +++ b/test/flow/log_levels.cpp @@ -38,7 +38,7 @@ struct log_config { template auto log(FilenameStringType, LineNumberType, MsgType const &) -> void { - log_calls.push_back(logging::get_level(Env{}).value); + log_calls.push_back(logging::get_level(Env{})); } }; log_handler logger; diff --git a/test/log/catalog1_lib.cpp b/test/log/catalog1_lib.cpp index 95dc1e9c..aa6fd15f 100644 --- a/test/log/catalog1_lib.cpp +++ b/test/log/catalog1_lib.cpp @@ -18,7 +18,7 @@ struct test_log_args_destination { } }; -using log_env1 = logging::make_env_t; +using log_env1 = stdx::make_env_t; } // namespace auto log_zero_args() -> void; diff --git a/test/log/catalog2a_lib.cpp b/test/log/catalog2a_lib.cpp index eb441442..979d4c74 100644 --- a/test/log/catalog2a_lib.cpp +++ b/test/log/catalog2a_lib.cpp @@ -19,8 +19,7 @@ struct test_log_args_destination { } }; -using log_env2a = - logging::make_env_t; +using log_env2a = stdx::make_env_t; } // namespace auto log_two_rt_args() -> void; diff --git a/test/log/catalog2b_lib.cpp b/test/log/catalog2b_lib.cpp index 573303dc..45e427f2 100644 --- a/test/log/catalog2b_lib.cpp +++ b/test/log/catalog2b_lib.cpp @@ -15,8 +15,7 @@ struct test_log_args_destination { auto log_by_args(std::uint32_t, auto...) -> void { ++log_calls; } }; -using log_env2b = - logging::make_env_t; +using log_env2b = stdx::make_env_t; } // namespace auto log_rt_enum_arg() -> void; diff --git a/test/log/env.cpp b/test/log/env.cpp index 539067c2..98d1b6d9 100644 --- a/test/log/env.cpp +++ b/test/log/env.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -43,7 +44,7 @@ TEST_CASE("supplement environment", "[log_env]") { using namespace stdx::literals; CIB_LOG_ENV(logging::get_module, "hello"); static_assert(custom(cib_log_env_t{}) == 1); - static_assert(logging::get_module(cib_log_env_t{}) == "hello"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "hello"_cts); } } @@ -52,19 +53,19 @@ TEST_CASE("multi-value environment", "[log_env]") { using namespace stdx::literals; static_assert(custom(cib_log_env_t{}) == 1); - static_assert(logging::get_module(cib_log_env_t{}) == "hello"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "hello"_cts); } namespace { -auto logged_modules = std::vector{}; +auto logged_modules = std::vector{}; struct log_handler { template auto log(FilenameStringType, LineNumberType, MsgType const &) -> void { using namespace stdx::literals; - logged_modules.push_back( - std::string_view{logging::get_module(Env{}).value}); + logged_modules.emplace_back( + std::string_view{logging::get_module(Env{})}); } }; diff --git a/test/log/fmt_logger.cpp b/test/log/fmt_logger.cpp index af3385c1..08451e11 100644 --- a/test/log/fmt_logger.cpp +++ b/test/log/fmt_logger.cpp @@ -163,7 +163,7 @@ inline auto logging::config = logging::fmt::config{std::back_inserter(secure_buffer)}; #define SECURE_TRACE(MSG, ...) \ - logging::log{}>>( \ __FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) diff --git a/test/log/mipi_encoder.cpp b/test/log/mipi_encoder.cpp index b96b781b..c8c61779 100644 --- a/test/log/mipi_encoder.cpp +++ b/test/log/mipi_encoder.cpp @@ -49,16 +49,15 @@ struct test_conc_policy { return (static_cast(test_string_id) << 4u) | 0x1u; } -[[maybe_unused]] constexpr auto expected_catalog32_header(logging::level level, - module_id m) - -> std::uint32_t { +[[maybe_unused]] constexpr auto +expected_catalog32_header(logging::level level, module_id m) -> std::uint32_t { return (0x1u << 24u) | (m << 16u) | (static_cast(level) << 4u) | 0x3u; } -[[maybe_unused]] constexpr auto expected_msg_header(logging::level level, - module_id m, std::size_t sz) - -> std::uint32_t { +[[maybe_unused]] constexpr auto +expected_msg_header(logging::level level, module_id m, + std::size_t sz) -> std::uint32_t { return sz > 0 ? expected_catalog32_header(level, m) : expected_short32_header(); } @@ -125,7 +124,7 @@ struct test_log_version_destination { } }; -using log_env = logging::make_env_t; +using log_env = stdx::make_env_t; } // namespace template <> inline auto conc::injected_policy<> = test_conc_policy{}; @@ -295,7 +294,7 @@ template struct test_catalog_args_destination { } // namespace TEST_CASE("log with overridden builder", "[mipi]") { - using catalog_env = logging::make_env_t< + using catalog_env = stdx::make_env_t< logging::get_level, logging::level::TRACE, logging::mipi::get_builder, logging::mipi::builder{}>; diff --git a/test/log/module_id.cpp b/test/log/module_id.cpp index 8b99411f..e75f6caf 100644 --- a/test/log/module_id.cpp +++ b/test/log/module_id.cpp @@ -9,7 +9,7 @@ TEST_CASE("default log module id", "[module_id]") { using namespace stdx::literals; - static_assert(logging::get_module(cib_log_env_t{}) == "default"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "default"_cts); } namespace ns { @@ -17,14 +17,14 @@ CIB_LOG_MODULE("ns"); TEST_CASE("log module id overridden at namespace scope", "[module_id]") { using namespace stdx::literals; - static_assert(logging::get_module(cib_log_env_t{}) == "ns"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "ns"_cts); } } // namespace ns struct S { template constexpr static auto test() { using namespace stdx::literals; - static_assert(logging::get_module(cib_log_env_t{}) == "S"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "S"_cts); } CIB_LOG_MODULE("S"); @@ -37,7 +37,7 @@ TEST_CASE("log module id overridden at class scope", "[module_id]") { template constexpr static auto func_test() { CIB_LOG_MODULE("fn"); using namespace stdx::literals; - static_assert(logging::get_module(cib_log_env_t{}) == "fn"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "fn"_cts); } TEST_CASE("log module id overridden at function scope", "[module_id]") { @@ -50,6 +50,6 @@ TEST_CASE("log module id overridden at statement scope", "[module_id]") { { CIB_LOG_MODULE("statement"); using namespace stdx::literals; - static_assert(logging::get_module(cib_log_env_t{}) == "statement"_ctst); + static_assert(logging::get_module(cib_log_env_t{}) == "statement"_cts); } } From 329167a88c5f53f6a40257f17ca73d94e1162237 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Tue, 4 Mar 2025 10:44:00 -0700 Subject: [PATCH 2/2] :alien: Fix clang-format changes from upstream --- include/interrupt/dynamic_controller.hpp | 4 ++-- test/interrupt/common.hpp | 2 +- test/log/catalog1_lib.cpp | 3 ++- test/log/catalog2a_lib.cpp | 3 ++- test/log/catalog2b_lib.cpp | 3 ++- test/log/mipi_encoder.cpp | 14 ++++++++------ test/msg/send.cpp | 5 +++-- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/interrupt/dynamic_controller.hpp b/include/interrupt/dynamic_controller.hpp index 0b006aba..cf9c93ee 100644 --- a/include/interrupt/dynamic_controller.hpp +++ b/include/interrupt/dynamic_controller.hpp @@ -1,12 +1,12 @@ #pragma once -#include - #include #include #include #include +#include + #include #include diff --git a/test/interrupt/common.hpp b/test/interrupt/common.hpp index afe51619..1959d19f 100644 --- a/test/interrupt/common.hpp +++ b/test/interrupt/common.hpp @@ -48,7 +48,7 @@ struct test_nexus { template struct enable_field_t { static inline bool value{}; - constexpr friend auto operator==(enable_field_t, enable_field_t) + friend constexpr auto operator==(enable_field_t, enable_field_t) -> bool = default; }; template struct status_field_t { diff --git a/test/log/catalog1_lib.cpp b/test/log/catalog1_lib.cpp index aa6fd15f..3d9f8131 100644 --- a/test/log/catalog1_lib.cpp +++ b/test/log/catalog1_lib.cpp @@ -1,8 +1,9 @@ #include "catalog_concurrency.hpp" -#include #include +#include + #include template <> inline auto conc::injected_policy<> = test_conc_policy{}; diff --git a/test/log/catalog2a_lib.cpp b/test/log/catalog2a_lib.cpp index 979d4c74..8a792f2f 100644 --- a/test/log/catalog2a_lib.cpp +++ b/test/log/catalog2a_lib.cpp @@ -1,9 +1,10 @@ #include "catalog_concurrency.hpp" #include "catalog_enums.hpp" -#include #include +#include + #include template <> inline auto conc::injected_policy<> = test_conc_policy{}; diff --git a/test/log/catalog2b_lib.cpp b/test/log/catalog2b_lib.cpp index 45e427f2..69c8432b 100644 --- a/test/log/catalog2b_lib.cpp +++ b/test/log/catalog2b_lib.cpp @@ -1,9 +1,10 @@ #include "catalog_concurrency.hpp" #include "catalog_enums.hpp" -#include #include +#include + #include template <> inline auto conc::injected_policy<> = test_conc_policy{}; diff --git a/test/log/mipi_encoder.cpp b/test/log/mipi_encoder.cpp index c8c61779..6dc4e157 100644 --- a/test/log/mipi_encoder.cpp +++ b/test/log/mipi_encoder.cpp @@ -1,9 +1,10 @@ -#include #include #include #include +#include + #include #include @@ -49,15 +50,16 @@ struct test_conc_policy { return (static_cast(test_string_id) << 4u) | 0x1u; } -[[maybe_unused]] constexpr auto -expected_catalog32_header(logging::level level, module_id m) -> std::uint32_t { +[[maybe_unused]] constexpr auto expected_catalog32_header(logging::level level, + module_id m) + -> std::uint32_t { return (0x1u << 24u) | (m << 16u) | (static_cast(level) << 4u) | 0x3u; } -[[maybe_unused]] constexpr auto -expected_msg_header(logging::level level, module_id m, - std::size_t sz) -> std::uint32_t { +[[maybe_unused]] constexpr auto expected_msg_header(logging::level level, + module_id m, std::size_t sz) + -> std::uint32_t { return sz > 0 ? expected_catalog32_header(level, m) : expected_short32_header(); } diff --git a/test/msg/send.cpp b/test/msg/send.cpp index 70454f23..674bac0f 100644 --- a/test/msg/send.cpp +++ b/test/msg/send.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include #include @@ -7,6 +5,9 @@ #include #include +#include +#include + #include #include