Skip to content

Commit d179176

Browse files
authored
[libc++][format] Adds ABI tags to inline constexpr variables. (#86293)
This uses the macro on record types and inline constexpr variables. The tagged declarations are very likely to change in future versions of libc++: - __fields are internal types used to control the formatter's parse functions which fields to expect. Newer formatters may add new fields. For example the filesystem::path formatter accepted in the recent Tokyo meeting added a new 'g' flag, which differs from the 'g' type. - The Unicode tables. The number of entries in these table likely differ between Unicode versions. The tables contain only a part of all Unicode properties. Typically they are stored in a 32-bit entry where some bits contain the properties and other bits the size of the range. Changes in the Unicode or C++ algorithms may require more properties to be available in C++. This may affect the number of bits available in the range. If needed, other declarations get the macro. This is mainly a first time to review this approach. This was originally https://reviews.llvm.org/D143494 where a new macro _LIBCPP_HIDE_FROM_ABI_TYPE was defined. Testing revealed the existing macro _LIBCPP_HIDE_FROM_ABI could be used. The "parts" of the macro that do not affect records are not harmful. Based on this information the existing macro was used and additional documentation was written.
1 parent 2745f72 commit d179176

8 files changed

+13
-8
lines changed

libcxx/include/__config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,12 @@ typedef __char32_t char32_t;
805805
// the implementation of a virtual function in an ABI-incompatible way in the first place,
806806
// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
807807
//
808+
// The macro can be applied to record and enum types. When the tagged type is nested in
809+
// a record this "parent" record needs to have the macro too. Another use case for applying
810+
// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
811+
// This can be useful for inline variables that are implementation details which are expected
812+
// to change in the future.
813+
//
808814
// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
809815
// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
810816
// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.

libcxx/include/__format/escaped_output_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace __escaped_output_table {
110110
/// - bits [0, 10] The size of the range, allowing 2048 elements.
111111
/// - bits [11, 31] The lower bound code point of the range. The upper bound of
112112
/// the range is lower bound + size.
113-
inline constexpr uint32_t __entries[893] = {
113+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[893] = {
114114
0x00000020,
115115
0x0003f821,
116116
0x00056800,

libcxx/include/__format/extended_grapheme_cluster_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ enum class __property : uint8_t {
125125
/// following benchmark.
126126
/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
127127
// clang-format off
128-
inline constexpr uint32_t __entries[1496] = {
128+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
129129
0x00000091,
130130
0x00005005,
131131
0x00005811,

libcxx/include/__format/parser_std_format_spec.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr uint32_t __substitute_arg_id(basic_format_arg<_C
129129
///
130130
/// They default to false so when a new field is added it needs to be opted in
131131
/// explicitly.
132-
// TODO FMT Use an ABI tag for this struct.
133-
struct __fields {
132+
struct _LIBCPP_HIDE_FROM_ABI __fields {
134133
uint16_t __sign_ : 1 {false};
135134
uint16_t __alternate_form_ : 1 {false};
136135
uint16_t __zero_padding_ : 1 {false};

libcxx/include/__format/width_estimation_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace __width_estimation_table {
119119
/// - bits [0, 13] The size of the range, allowing 16384 elements.
120120
/// - bits [14, 31] The lower bound code point of the range. The upper bound of
121121
/// the range is lower bound + size.
122-
inline constexpr uint32_t __entries[108] = {
122+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[108] = {
123123
0x0440005f /* 00001100 - 0000115f [ 96] */, //
124124
0x08c68001 /* 0000231a - 0000231b [ 2] */, //
125125
0x08ca4001 /* 00002329 - 0000232a [ 2] */, //

libcxx/utils/generate_escaped_output_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
124124
/// - bits [0, 10] The size of the range, allowing 2048 elements.
125125
/// - bits [11, 31] The lower bound code point of the range. The upper bound of
126126
/// the range is lower bound + size.
127-
inline constexpr uint32_t __entries[{size}] = {{
127+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[{size}] = {{
128128
{entries}}};
129129
130130
/// At the end of the valid Unicode code points space a lot of code points are

libcxx/utils/generate_extended_grapheme_cluster_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
113113
/// following benchmark.
114114
/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
115115
// clang-format off
116-
inline constexpr uint32_t __entries[{size}] = {{
116+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[{size}] = {{
117117
{entries}}};
118118
// clang-format on
119119

libcxx/utils/generate_width_estimation_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
143143
/// - bits [0, 13] The size of the range, allowing 16384 elements.
144144
/// - bits [14, 31] The lower bound code point of the range. The upper bound of
145145
/// the range is lower bound + size.
146-
inline constexpr uint32_t __entries[{size}] = {{
146+
_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[{size}] = {{
147147
{entries}}};
148148
149149
/// The upper bound entry of EastAsianWidth.txt.

0 commit comments

Comments
 (0)