Skip to content

Commit df579ce

Browse files
mordanteldionne
andauthored
[libc++] Adds is_implemented function for new ftm generator. (#134538)
At the moment the ftm macro for __cpp_lib_to_chars will have the following values: standard_ftms: { "c++17": "201611L", "c++20": "201611L", "c++23": "201611L", "c++26": "201611L", } implemented_ftms: { "c++17": None, } This is an issue with the test whether the FTM is implemented it does: self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std] This will fail in C++20 since implemented_ftms[ftm] does not have the key c++20. This adds a new helper function and removes the None entries when a FTM is not implemented. --------- Co-authored-by: Louis Dionne <[email protected]>
1 parent 1e54bca commit df579ce

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ def test_implementation(self):
3838
"c++23": "201907L",
3939
"c++26": "299900L",
4040
},
41-
"__cpp_lib_format": {
42-
"c++20": None,
43-
"c++23": None,
44-
"c++26": None,
45-
},
41+
"__cpp_lib_format": {},
4642
"__cpp_lib_parallel_algorithm": {
4743
"c++17": "201603L",
4844
"c++20": "201603L",
@@ -55,11 +51,7 @@ def test_implementation(self):
5551
"c++23": "202102L",
5652
"c++26": "202102L",
5753
},
58-
"__cpp_lib_missing_FTM_in_older_standard": {
59-
"c++17": None,
60-
"c++20": None,
61-
"c++26": None,
62-
},
54+
"__cpp_lib_missing_FTM_in_older_standard": {},
6355
}
6456

6557
self.assertEqual(self.ftm.implemented_ftms, expected)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
import unittest
13+
14+
UTILS = sys.argv[1]
15+
TEST_DATA = sys.argv[2]
16+
del sys.argv[1:3]
17+
18+
sys.path.append(UTILS)
19+
from generate_feature_test_macro_components import FeatureTestMacros, Metadata
20+
21+
22+
class Test(unittest.TestCase):
23+
def setUp(self):
24+
self.ftm = FeatureTestMacros(TEST_DATA)
25+
self.maxDiff = None # This causes the diff to be printed when the test fails
26+
27+
def test_implementation(self):
28+
# FTM not available in C++14.
29+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_any", "c++14"), False)
30+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_any", "c++17"), True)
31+
32+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_format", "c++20"), False)
33+
34+
# FTM C++20 202106L, libc++ has 202102L
35+
self.assertEqual(self.ftm.is_implemented("__cpp_lib_variant", "c++20"), False)
36+
37+
38+
if __name__ == "__main__":
39+
unittest.main()

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,8 @@ def get_ftms(
20112011
else:
20122012
break
20132013

2014-
entry[std] = last
2014+
if last:
2015+
entry[std] = last
20152016
result[feature["name"]] = entry
20162017

20172018
return result
@@ -2207,6 +2208,18 @@ def implemented_ftms(self) -> Dict[Ftm, Dict[Std, Optional[Value]]]:
22072208

22082209
return get_ftms(self.__data, self.std_dialects, True)
22092210

2211+
def is_implemented(self, ftm: Ftm, std: Std) -> bool:
2212+
"""Has the FTM `ftm` been implemented in the dialect `std`?"""
2213+
2214+
# When a paper for C++20 has not been implemented in libc++, then there will be no
2215+
# FTM entry in implemented_ftms for C++23 and later. Similarly, a paper like <format>
2216+
# has no entry in standard_ftms for e.g. C++11.
2217+
if not std in self.implemented_ftms[ftm].keys() or not std in self.standard_ftms[ftm].keys():
2218+
return False
2219+
2220+
return self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std]
2221+
2222+
22102223
@functools.cached_property
22112224
def ftm_metadata(self) -> Dict[Ftm, Metadata]:
22122225
"""Returns the metadata of the FTMs defined in the Standard.
@@ -2240,7 +2253,7 @@ def version_header_implementation(self) -> Dict[Std, Dict[Ftm, VersionHeader]]:
22402253
continue
22412254
last_value = value
22422255

2243-
implemented = self.implemented_ftms[ftm][std] == self.standard_ftms[ftm][std]
2256+
implemented = self.is_implemented(ftm, std)
22442257
entry = VersionHeader(
22452258
value,
22462259
implemented,

0 commit comments

Comments
 (0)