Skip to content

Commit 6209295

Browse files
committed
Implement Settings Aliases without nested calls (fixes clang 20 build)
The problem in the current implementation is that it does the following: struct DefineAliases { DefineAliases & setName(std::string_view value); DefineAliases & addAlias(std::string_view value); }; DefineAlises() .setName() .addAlias() And even though it looks very **natural and clean**, there is a problem with such approach. Right now ClickHouse has 1252 settings, so it will have 1252 nested setName() calls and bunch of addAlias() calls (for those settings which has aliases) And this bails out on clang 20 on arm64 (likely only there because the each frame is heavier due to larger number of registers): /ch/src/Core/Settings.cpp:6713:1: error: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely [-Werror,-Wstack-exhausted] 6713 | DECLARE_SETTINGS_TRAITS_ALLOW_CUSTOM_SETTINGS(SettingsTraits, LIST_OF_SETTINGS) | ^ /ch/src/Core/BaseSettings.h:885:5: note: expanded from macro 'DECLARE_SETTINGS_TRAITS_ALLOW_CUSTOM_SETTINGS' 885 | DECLARE_SETTINGS_TRAITS_COMMON(SETTINGS_TRAITS_NAME, LIST_OF_SETTINGS_MACRO, 1) | ^ /ch/src/Core/BaseSettings.h:946:52: note: expanded from macro 'DECLARE_SETTINGS_TRAITS_COMMON' 946 | DefineAliases() LIST_OF_SETTINGS_MACRO(ALIAS_TO, ALIAS_FROM); \ So instead of this we can simply create the std::unordered_map for aliases using initializer list, but, for this I have to change the declaration, since with the chain of DECLARE() ALIAS() it is not possible to do, so now there is DECLARE() and DECLARE_WITH_ALIAS(), the later should be called instead if the setting has alias. This will also to skip settings without aliases during aliases_to_settings initialization, which should be a good thing. P.S. Thanks to Rual new settings encapsulated so good that this changes did not require recompile everything!
1 parent 9a480c9 commit 6209295

28 files changed

+119
-141
lines changed

src/Coordination/CoordinationSettings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ void CoordinationSettingsImpl::loadFromConfig(const String & config_elem, const
102102
max_requests_append_size = max_requests_batch_size;
103103
}
104104

105-
#define INITIALIZE_SETTING_EXTERN(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS) \
105+
#define INITIALIZE_SETTING_EXTERN(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS, ...) \
106106
CoordinationSettings##TYPE NAME = &CoordinationSettingsImpl ::NAME;
107107

108108
namespace CoordinationSetting
109109
{
110-
LIST_OF_COORDINATION_SETTINGS(INITIALIZE_SETTING_EXTERN, SKIP_ALIAS)
110+
LIST_OF_COORDINATION_SETTINGS(INITIALIZE_SETTING_EXTERN, INITIALIZE_SETTING_EXTERN)
111111
}
112112

113113
#undef INITIALIZE_SETTING_EXTERN

src/Core/BaseSettings.h

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ struct BaseSettingsHelpers
7575
* #include <Core/BaseSettings.h>
7676
* #include <Core/BaseSettingsFwdMacrosImpl.h>
7777
*
78-
* #define APPLY_FOR_MYSETTINGS(DECLARE, ALIAS) \
78+
* #define APPLY_FOR_MYSETTINGS(DECLARE, DECLARE_WITH_ALIAS) \
7979
* DECLARE(UInt64, a, 100, "Description of a", 0) \
8080
* DECLARE(Float, f, 3.11, "Description of f", IMPORTANT) // IMPORTANT - means the setting can't be ignored by older versions) \
8181
* DECLARE(String, s, "default", "Description of s", 0)
82+
* DECLARE_WITH_ALIAS(String, experimental, "default", "Description of s", 0, stable)
8283
*
8384
* DECLARE_SETTINGS_TRAITS(MySettingsTraits, APPLY_FOR_MYSETTINGS)
8485
* IMPLEMENT_SETTINGS_TRAITS(MySettingsTraits, APPLY_FOR_MYSETTINGS)
@@ -91,7 +92,7 @@ struct BaseSettingsHelpers
9192
*
9293
* namespace MySetting
9394
* {
94-
* APPLY_FOR_MYSETTINGS(INITIALIZE_SETTING_EXTERN, SKIP_ALIAS)
95+
* APPLY_FOR_MYSETTINGS(INITIALIZE_SETTING_EXTERN, SETTING_SKIP_TRAIT)
9596
* }
9697
* #undef INITIALIZE_SETTING_EXTERN
9798
*
@@ -890,7 +891,7 @@ using AliasMap = std::unordered_map<std::string_view, std::string_view>;
890891
{ \
891892
struct Data \
892893
{ \
893-
LIST_OF_SETTINGS_MACRO(DECLARE_SETTINGS_TRAITS_, SKIP_ALIAS) \
894+
LIST_OF_SETTINGS_MACRO(DECLARE_SETTINGS_TRAITS_, DECLARE_SETTINGS_TRAITS_) \
894895
}; \
895896
\
896897
class Accessor \
@@ -942,9 +943,9 @@ using AliasMap = std::unordered_map<std::string_view, std::string_view>;
942943
}; \
943944
static constexpr bool allow_custom_settings = ALLOW_CUSTOM_SETTINGS; \
944945
\
945-
static inline const AliasMap aliases_to_settings = \
946-
DefineAliases() LIST_OF_SETTINGS_MACRO(ALIAS_TO, ALIAS_FROM); \
947-
\
946+
static inline const AliasMap aliases_to_settings = { \
947+
LIST_OF_SETTINGS_MACRO(SETTING_SKIP_TRAIT, DECLARE_SETTINGS_WITH_ALIAS_TRAITS_) \
948+
}; \
948949
using SettingsToAliasesMap = std::unordered_map<std::string_view, std::vector<std::string_view>>; \
949950
static inline const SettingsToAliasesMap & settingsToAliases() \
950951
{ \
@@ -968,36 +969,14 @@ using AliasMap = std::unordered_map<std::string_view, std::string_view>;
968969

969970

970971
/// NOLINTNEXTLINE
971-
#define SKIP_ALIAS(ALIAS_NAME)
972-
/// NOLINTNEXTLINE
973-
#define ALIAS_TO(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS) .setName(#NAME)
974-
/// NOLINTNEXTLINE
975-
#define ALIAS_FROM(ALIAS) .addAlias(#ALIAS)
976-
977-
struct DefineAliases
978-
{
979-
std::string_view name;
980-
AliasMap map;
981-
982-
DefineAliases & setName(std::string_view value)
983-
{
984-
name = value;
985-
return *this;
986-
}
987-
988-
DefineAliases & addAlias(std::string_view value)
989-
{
990-
map.emplace(value, name);
991-
return *this;
992-
}
993-
994-
/// NOLINTNEXTLINE(google-explicit-constructor)
995-
operator AliasMap() { return std::move(map); }
996-
};
972+
#define SETTING_SKIP_TRAIT(...)
997973

998974
/// NOLINTNEXTLINE
999-
#define DECLARE_SETTINGS_TRAITS_(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS) \
975+
#define DECLARE_SETTINGS_TRAITS_(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS, ...) \
1000976
SettingField##TYPE NAME {DEFAULT};
977+
/// NOLINTNEXTLINE
978+
#define DECLARE_SETTINGS_WITH_ALIAS_TRAITS_(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS, ALIAS) \
979+
{ #ALIAS, #NAME },
1001980

1002981
/// NOLINTNEXTLINE
1003982
#define IMPLEMENT_SETTINGS_TRAITS(SETTINGS_TRAITS_NAME, LIST_OF_SETTINGS_MACRO) \
@@ -1008,7 +987,7 @@ struct DefineAliases
1008987
Accessor res; \
1009988
constexpr int IMPORTANT = 0x01; \
1010989
UNUSED(IMPORTANT); \
1011-
LIST_OF_SETTINGS_MACRO(IMPLEMENT_SETTINGS_TRAITS_, SKIP_ALIAS) \
990+
LIST_OF_SETTINGS_MACRO(IMPLEMENT_SETTINGS_TRAITS_, IMPLEMENT_SETTINGS_TRAITS_) \
1012991
for (size_t i = 0; i < res.field_infos.size(); i++) \
1013992
{ \
1014993
const auto & info = res.field_infos[i]; \
@@ -1032,7 +1011,7 @@ struct DefineAliases
10321011
template class BaseSettings<SETTINGS_TRAITS_NAME>;
10331012

10341013
/// NOLINTNEXTLINE
1035-
#define IMPLEMENT_SETTINGS_TRAITS_(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS) \
1014+
#define IMPLEMENT_SETTINGS_TRAITS_(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS, ...) \
10361015
res.field_infos.emplace_back( \
10371016
FieldInfo{#NAME, #TYPE, DESCRIPTION, \
10381017
static_cast<UInt64>(FLAGS), \

src/Core/ServerSettings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,11 @@ void ServerSettingsImpl::loadSettingsFromConfig(const Poco::Util::AbstractConfig
11121112
}
11131113

11141114

1115-
#define INITIALIZE_SETTING_EXTERN(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS) ServerSettings##TYPE NAME = &ServerSettingsImpl ::NAME;
1115+
#define INITIALIZE_SETTING_EXTERN(TYPE, NAME, DEFAULT, DESCRIPTION, FLAGS, ...) ServerSettings##TYPE NAME = &ServerSettingsImpl ::NAME;
11161116

11171117
namespace ServerSetting
11181118
{
1119-
LIST_OF_SERVER_SETTINGS(INITIALIZE_SETTING_EXTERN, SKIP_ALIAS)
1119+
LIST_OF_SERVER_SETTINGS(INITIALIZE_SETTING_EXTERN, INITIALIZE_SETTING_EXTERN)
11201120
}
11211121

11221122
#undef INITIALIZE_SETTING_EXTERN

0 commit comments

Comments
 (0)