[libcxx-commits] [libcxx] [RFC][libc++] Testing feature test macro script. (PR #90889)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 2 11:53:09 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

<details>
<summary>Changes</summary>

This is a proof-of-concept how we can test the script. Instead of storing the data in the script it's stored in a JSON file so a different file can be used for testing.

This is related to the RFC https://github.com/llvm/llvm-project/pull/89499

---
Full diff: https://github.com/llvm/llvm-project/pull/90889.diff


3 Files Affected:

- (added) libcxx/test/libcxx/feature_test_macro_csv.sh.py (+35) 
- (added) libcxx/utils/data/feature_test_macros/test_data.json (+136) 
- (modified) libcxx/utils/generate_feature_test_macro_components.py (+33) 


``````````diff
diff --git a/libcxx/test/libcxx/feature_test_macro_csv.sh.py b/libcxx/test/libcxx/feature_test_macro_csv.sh.py
new file mode 100644
index 00000000000000..2d80bfad63c859
--- /dev/null
+++ b/libcxx/test/libcxx/feature_test_macro_csv.sh.py
@@ -0,0 +1,35 @@
+# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/utils/data/feature_test_macros/test_data.json
+
+import sys
+import json
+
+sys.path.append(sys.argv[1])
+from generate_feature_test_macro_components import get_table
+
+
+data = json.load(open(f"{sys.argv[2]}"))
+table = get_table(data)
+
+expected = {
+    "__cpp_lib_any": {
+        "c++17": "201606L",
+        "c++20": "201606L",
+        "c++23": "201606L",
+        "c++26": "201606L",
+    },
+    "__cpp_lib_barrier": {"c++20": "201907L", "c++23": "201907L", "c++26": "201907L"},
+    "__cpp_lib_format": {
+        "c++20": "",
+        "c++23": "",
+        "c++26": "",
+    },
+    "__cpp_lib_variant": {
+        "c++17": "202102L",
+        "c++20": "202102L",
+        "c++23": "202102L",
+        "c++26": "202102L",
+    },
+}
+
+
+assert table == expected, f"expected\n{expected}\n\nresult\n{table}"
diff --git a/libcxx/utils/data/feature_test_macros/test_data.json b/libcxx/utils/data/feature_test_macros/test_data.json
new file mode 100644
index 00000000000000..5a98fba6403c09
--- /dev/null
+++ b/libcxx/utils/data/feature_test_macros/test_data.json
@@ -0,0 +1,136 @@
+[
+  {
+    "name": "__cpp_lib_any",
+    "values": {
+      "c++17": {
+        "201606": [
+          {
+            "implemented": true
+          }
+        ]
+      }
+    },
+    "headers": [
+      "any"
+    ]
+  },
+  {
+    "name": "__cpp_lib_barrier",
+    "values": {
+      "c++20": {
+        "201907": [
+          {
+            "implemented": true
+          }
+        ]
+      }
+    },
+    "headers": [
+      "barrier"
+    ],
+    "test_suite_guard":
+        "!defined(_LIBCPP_HAS_NO_THREADS) && (!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_SYNC)",
+    "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC"
+  },
+  {
+    "name": "__cpp_lib_format",
+    "values": {
+      "c++20": {
+        "201907": [
+          {
+            "number": "P0645R10",
+            "title": "Text Formatting",
+            "implemented": true
+          },
+          {
+            "number": "P1361R2",
+            "title": "Integration of chrono with text formatting",
+            "implemented": false
+          }
+        ],
+        "202106": [
+          {
+            "number": "P2216R3",
+            "title": "std::format improvements",
+            "implemented": true
+          }
+        ],
+        "202110": [
+          {
+            "number": "P2372R3",
+            "title": "Fixing locale handling in chrono formatters",
+            "implemented": false
+          },
+          {
+            "number": "P2418R2",
+            "title": "FAdd support for std::generator-like types to std::format",
+            "implemented": true
+          }
+        ]
+      },
+      "c++23": {
+        "202207": [
+          {
+            "number": "P2419R2",
+            "title": "Clarify handling of encodings in localized formatting of chrono types",
+            "implemented": false
+          }
+        ]
+      },
+      "c++26": {
+        "202306": [
+          {
+            "number": "P2637R3",
+            "title": "Member Visit",
+            "implemented": true
+          }
+        ],
+        "202311": [
+          {
+            "number": "P2918R2",
+            "title": "Runtime format strings II",
+            "implemented": true
+          }
+        ]
+      }
+    },
+    "headers": [
+      "format"
+    ]
+  },
+  {
+    "name": "__cpp_lib_variant",
+    "values": {
+      "c++17": {
+        "202102": [
+          {
+            "number": "",
+            "title": "``std::visit`` for classes derived from ``std::variant``",
+            "implemented": true
+          }
+        ]
+      },
+      "c++20": {
+        "202106": [
+          {
+            "number": "",
+            "title": "Fully constexpr ``std::variant``",
+            "implemented": false
+          }
+        ]
+      },
+      "c++26": {
+        "202306": [
+          {
+            "number": "",
+            "title": "Member visit",
+            "implemented": true
+          }
+        ]
+      }
+    },
+    "headers": [
+      "variant"
+    ]
+  }
+]
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index f2b8d55c0e11b0..04a8a8786b1a35 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -3,6 +3,7 @@
 import os
 from builtins import range
 from functools import reduce
+import json
 
 
 def get_libcxx_paths():
@@ -1857,6 +1858,38 @@ def produce_docs():
         f.write(doc_str)
 
 
+def get_table(data):
+    result = dict()
+    for feature in data:
+        last = None
+        entry = dict()
+        implemented = True
+        for std in get_std_dialects():
+            if std not in feature["values"].keys():
+                if last == None:
+                    continue
+                else:
+                    entry[std] = last
+            else:
+                if last == None:
+                    last = ""
+                if implemented:
+                    for value in feature["values"][std]:
+                        for paper in list(feature["values"][std][value]):
+                            if not paper["implemented"]:
+                                implemented = False
+                                break
+                        if implemented:
+                            last = f"{value}L"
+                        else:
+                            break
+
+                entry[std] = last
+        result[feature["name"]] = entry
+
+    return result
+
+
 def main():
     produce_version_header()
     produce_tests()

``````````

</details>


https://github.com/llvm/llvm-project/pull/90889


More information about the libcxx-commits mailing list