-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Reformulate availability in terms of LLVM releases #87563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Reformulate availability in terms of LLVM releases #87563
Conversation
@llvm/pr-subscribers-libcxx Author: Louis Dionne (ldionne) ChangesTo make it easier to maintain the availability macros for both upstream developers and vendors, this patch reformulates availability macros as a function of the upstream LLVM release that a feature was introduced in. This way, upstream developers can easily use the appropriate LLVM version, and vendors can simply fill in the platform version(s) in which a LLVM version landed. Patch is 30.60 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/87563.diff 1 Files Affected:
diff --git a/libcxx/include/__availability b/libcxx/include/__availability
index bb3ed0a8da521b..9614ffa32917f5 100644
--- a/libcxx/include/__availability
+++ b/libcxx/include/__availability
@@ -28,30 +28,32 @@
// that previously released library. Normally, this would be a load-time error
// when one tries to launch the program against the older library.
//
-// For example, the filesystem library was introduced in the dylib in macOS 10.15.
-// If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their
-// program, the compiler would normally not complain (because the required
-// declarations are in the headers), but the dynamic loader would fail to find
-// the symbols when actually trying to launch the program on macOS 10.13. To
-// turn this into a compile-time issue instead, declarations are annotated with
-// when they were introduced, and the compiler can produce a diagnostic if the
-// program references something that isn't available on the deployment target.
+// For example, the filesystem library was introduced in the dylib in LLVM 9.
+// On Apple platforms, this corresponds to macOS 10.15. If a user compiles on
+// a macOS 10.15 host but targets macOS 10.13 with their program, the compiler
+// would normally not complain (because the required declarations are in the
+// headers), but the dynamic loader would fail to find the symbols when actually
+// trying to launch the program on macOS 10.13. To turn this into a compile-time
+// issue instead, declarations are annotated with when they were introduced, and
+// the compiler can produce a diagnostic if the program references something that
+// isn't available on the deployment target.
//
// This mechanism is general in nature, and any vendor can add their markup to
// the library (see below). Whenever a new feature is added that requires support
// in the shared library, two macros are added below to allow marking the feature
// as unavailable:
-// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_NO_<feature>` which must be defined
-// exactly when compiling for a target that doesn't support the feature.
-// 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must always be defined
-// and must expand to the proper availability attribute for the platform.
+// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_<feature>` which must be defined
+// to `_LIBCPP_INTRODUCED_IN_<version>` for the appropriate LLVM version.
+// 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must be defined to
+// `_LIBCPP_INTRODUCED_IN_<version>_MARKUP` for the appropriate LLVM version.
//
// When vendors decide to ship the feature as part of their shared library, they
-// can update these macros appropriately for their platform, and the library will
-// use those to provide an optimal user experience.
+// can update the `_LIBCPP_INTRODUCED_IN_<version>` macro (and the markup counterpart)
+// based on the platform version they shipped that version of LLVM in. The library
+// will then use this markup to provide an optimal user experience on these platforms.
//
// Furthermore, many features in the standard library have corresponding
-// feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_NO_<feature>` macros
+// feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_<feature>` macros
// are checked by the corresponding feature-test macros generated by
// generate_feature_test_macro_components.py to ensure that the library
// doesn't announce a feature as being implemented if it is unavailable on
@@ -81,8 +83,6 @@
# endif
#endif
-#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
-
// These macros control the availability of std::bad_optional_access and
// other exception types. These were put in the shared library to prevent
// code bloat from every user program defining the vtable for these exception
@@ -91,28 +91,28 @@
// Note that when exceptions are disabled, the methods that normally throw
// these exceptions can be used even on older deployment targets, but those
// methods will abort instead of throwing.
-# define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS 1
-# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
+#define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
+#define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
-# define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS 1
-# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
+#define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
+#define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
-# define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST 1
-# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST
+#define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4
+#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP
// These macros control the availability of all parts of <filesystem> that
// depend on something in the dylib.
-# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
+#define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9
+#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
+#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH
+#define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP
// This controls the availability of the C++20 synchronization library,
// which requires shared library support for various operations
// (see libcxx/src/atomic.cpp). This includes <barier>, <latch>,
// <semaphore>, and notification functions on std::atomic.
-# define _LIBCPP_AVAILABILITY_HAS_SYNC 1
-# define _LIBCPP_AVAILABILITY_SYNC
+#define _LIBCPP_AVAILABILITY_HAS_SYNC _LIBCPP_INTRODUCED_IN_LLVM_10
+#define _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP
// Enable additional explicit instantiations of iostreams components. This
// reduces the number of weak definitions generated in programs that use
@@ -121,175 +121,287 @@
// TODO: Enable additional explicit instantiations on GCC once it supports exclude_from_explicit_instantiation,
// or once libc++ doesn't use the attribute anymore.
// TODO: Enable them on Windows once https://llvm.org/PR41018 has been fixed.
-# if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32)
-# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 1
-# else
-# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
-# endif
+#if !defined(_LIBCPP_COMPILER_GCC) && !defined(_WIN32)
+# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 _LIBCPP_INTRODUCED_IN_LLVM_12
+#else
+# define _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 0
+#endif
// This controls the availability of floating-point std::to_chars functions.
// These overloads were added later than the integer overloads.
-# define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT 1
-# define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT
+#define _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14
+#define _LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP
// This controls whether the library claims to provide a default verbose
// termination function, and consequently whether the headers will try
// to use it when the mechanism isn't overriden at compile-time.
-# define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT 1
-# define _LIBCPP_AVAILABILITY_VERBOSE_ABORT
+#define _LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15
+#define _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_INTRODUCED_IN_LLVM_15_MARKUP
// This controls the availability of the C++17 std::pmr library,
// which is implemented in large part in the built library.
-# define _LIBCPP_AVAILABILITY_HAS_PMR 1
-# define _LIBCPP_AVAILABILITY_PMR
+//
+// TODO: Enable std::pmr markup once https://github.com/llvm/llvm-project/issues/40340 has been fixed
+// Until then, it is possible for folks to try to use `std::pmr` when back-deploying to targets that don't support
+// it and it'll be a load-time error, but we don't have a good alternative because the library won't compile if we
+// use availability annotations until that bug has been fixed.
+#define _LIBCPP_AVAILABILITY_HAS_PMR _LIBCPP_INTRODUCED_IN_LLVM_16
+#define _LIBCPP_AVAILABILITY_PMR
// These macros controls the availability of __cxa_init_primary_exception
// in the built library, which std::make_exception_ptr might use
// (see libcxx/include/__exception/exception_ptr.h).
-# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 1
-# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION
+#define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18
+#define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP
// This controls the availability of C++23 <print>, which
// has a dependency on the built library (it needs access to
// the underlying buffer types of std::cout, std::cerr, and std::clog.
-# define _LIBCPP_AVAILABILITY_HAS_PRINT 1
-# define _LIBCPP_AVAILABILITY_PRINT
+#define _LIBCPP_AVAILABILITY_HAS_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18
+#define _LIBCPP_AVAILABILITY_PRINT _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP
// This controls the availability of the C++20 time zone database.
// The parser code is built in the library.
-# define _LIBCPP_AVAILABILITY_HAS_TZDB 1
-# define _LIBCPP_AVAILABILITY_TZDB
+#define _LIBCPP_AVAILABILITY_HAS_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19
+#define _LIBCPP_AVAILABILITY_TZDB _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP
-#elif defined(__APPLE__)
+// When availability annotations are disabled, we take for granted that features introduced
+// in all versions of the library are available.
+#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
-# define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS \
- (!defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 50000)
+# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP /* nothing */
-# define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
-# define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS
+# define _LIBCPP_INTRODUCED_IN_LLVM_5 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_5_MARKUP /* nothing */
-# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((availability(watchos, strict, introduced = 5.0)))
-# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
-# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
+# define _LIBCPP_INTRODUCED_IN_LLVM_6 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_6_MARKUP /* nothing */
-// TODO: Update once this is released
-# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0
-# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION __attribute__((unavailable))
+# define _LIBCPP_INTRODUCED_IN_LLVM_7 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_7_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_8 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_8_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_9 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP /* nothing */
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH /* nothing */
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP /* nothing */
-// <filesystem>
+# define _LIBCPP_INTRODUCED_IN_LLVM_10 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_11 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_11_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_12_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_13 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_13_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_14 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_14_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_15 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_15_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_16_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_17 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_17_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_18_MARKUP /* nothing */
+
+# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_19_MARKUP /* nothing */
+
+#elif defined(__APPLE__)
+
+// LLVM 4
+# if defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000
+# define _LIBCPP_INTRODUCED_IN_LLVM_4 0
+# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP __attribute__((availability(watchos, strict, introduced = 5.0)))
+# else
+# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_4_MARKUP /* nothing */
+# endif
+
+// LLVM 5-9
+# define _LIBCPP_INTRODUCED_IN_LLVM_5 _LIBCPP_INTRODUCED_IN_LLVM_9
+# define _LIBCPP_INTRODUCED_IN_LLVM_5_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
+# define _LIBCPP_INTRODUCED_IN_LLVM_6 _LIBCPP_INTRODUCED_IN_LLVM_9
+# define _LIBCPP_INTRODUCED_IN_LLVM_6_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
+# define _LIBCPP_INTRODUCED_IN_LLVM_7 _LIBCPP_INTRODUCED_IN_LLVM_9
+# define _LIBCPP_INTRODUCED_IN_LLVM_7_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
+# define _LIBCPP_INTRODUCED_IN_LLVM_8 _LIBCPP_INTRODUCED_IN_LLVM_9
+# define _LIBCPP_INTRODUCED_IN_LLVM_8_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP
// clang-format off
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) || \
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000)
// clang-format on
-# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 0
+# define _LIBCPP_INTRODUCED_IN_LLVM_9 0
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP \
+ __attribute__((availability(macos, strict, introduced = 10.15))) \
+ __attribute__((availability(ios, strict, introduced = 13.0))) \
+ __attribute__((availability(tvos, strict, introduced = 13.0))) \
+ __attribute__((availability(watchos, strict, introduced = 6.0)))
+// clang-format off
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH \
+ _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
+ _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop") \
+ _Pragma("clang attribute pop")
+// clang-format on
# else
-# define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_9 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP /* nothing */
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_PUSH /* nothing */
+# define _LIBCPP_INTRODUCED_IN_LLVM_9_MARKUP_POP /* nothing */
# endif
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY \
- __attribute__((availability(macos, strict, introduced = 10.15))) \
- __attribute__((availability(ios, strict, introduced = 13.0))) \
- __attribute__((availability(tvos, strict, introduced = 13.0))) \
- __attribute__((availability(watchos, strict, introduced = 6.0)))
+
+// LLVM 10
// clang-format off
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH \
- _Pragma("clang attribute push(__attribute__((availability(macos,strict,introduced=10.15))), apply_to=any(function,record))") \
- _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
- _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
- _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
-# define _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP \
- _Pragma("clang attribute pop") \
- _Pragma("clang attribute pop") \
- _Pragma("clang attribute pop") \
- _Pragma("clang attribute pop")
+# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
+ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 140000) || \
+ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 140000) || \
+ (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 70000)
// clang-format on
+# define _LIBCPP_INTRODUCED_IN_LLVM_10 0
+# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP \
+ __attribute__((availability(macos, strict, introduced = 11.0))) \
+ __attribute__((availability(ios, strict, introduced = 14.0))) \
+ __attribute__((availability(tvos, strict, introduced = 14.0))) \
+ __attribute__((availability(watchos, strict, introduced = 7.0)))
+# else
+# define _LIBCPP_INTRODUCED_IN_LLVM_10 1
+# define _LIBCPP_INTRODUCED_IN_LLVM_10_MARKUP /* nothing */
+# endif
-// std::to_chars(floating-point)
+// LLVM 11-12
+# define _LIBCPP_INTRODUCED_IN_LLVM_11 _LIBCPP_INTRODUCED_IN_LLVM_12
+# define _LIBCPP_INTRODUCED_IN_LLVM_11_MARKUP _LIBCPP_INTRODUCED_IN_LLVM_12_MARKUP
// clang-format off
-# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \
- (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \
- (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \
- (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300)
+# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \
+ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \
+ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) |...
[truncated]
|
@mordante @philnik777 I am eager to know what you think about this. IMO this is a major simplification, and I think it will (at the very least) make it easier to keep things in sync between upstream and downstream. This is in the same spirit as Mark's #78204 which did something similar but for the Lit features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks like a great simplification! I have some comments.
// 1. A macro named `_LIBCPP_AVAILABILITY_HAS_<feature>` which must be defined | ||
// to `_LIBCPP_INTRODUCED_IN_<version>` for the appropriate LLVM version. | ||
// 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must be defined to | ||
// `_LIBCPP_INTRODUCED_IN_<version>_MARKUP` for the appropriate LLVM version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused what the _MARKUP
suffix tries to convey. Can you explain that? Hopefully that clarifies the suffix or we can find a better suffix.
Actually after reading the rest of the patch, I think _ATTRIBUTE
would be a better suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used MARKUP
because I generally use the term "availability markup". But I am fine with ATTRIBUTE
as well, I think _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE
also makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now where MARKUP
comes from. Until reading "availability markup" I didn't connect the dots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it slipped through. #91269
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I like the idea very much.
libcxx/include/__availability
Outdated
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((availability(watchos, strict, introduced = 5.0))) | ||
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS | ||
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS | ||
# define _LIBCPP_INTRODUCED_IN_LLVM_6 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have macros which will never be used? I found that rather confusing while looking through the patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to be exhaustive, but I guess I agree this is not useful. I'll remove them.
libcxx/include/__availability
Outdated
# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0 | ||
# define _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION __attribute__((unavailable)) | ||
# define _LIBCPP_INTRODUCED_IN_LLVM_7 1 | ||
# define _LIBCPP_INTRODUCED_IN_LLVM_7_MARKUP /* nothing */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's actually better, but I think it might be more obvious what happens if we first define the _LIBCPP_INTRODUCED_IN_WHATEVER
macro and then the aliases for the individual features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I reordered them. I think I agree it's more readable that way.
To make it easier to maintain the availability macros for both upstream developers and vendors, this patch reformulates availability macros as a function of the upstream LLVM release that a feature was introduced in. This way, upstream developers can easily use the appropriate LLVM version, and vendors can simply fill in the platform version(s) in which a LLVM version landed.
b8aa134
to
b40d879
Compare
@mordante @philnik777 Gentle ping on this. The CI is green, the failure is a flake. |
…oo_ATTRIBUTE This was discussed in llvm#87563 and overlooked when I landed the patch.
To make it easier to maintain the availability macros for both upstream developers and vendors, this patch reformulates availability macros as a function of the upstream LLVM release that a feature was introduced in. This way, upstream developers can easily use the appropriate LLVM version, and vendors can simply fill in the platform version(s) in which a LLVM version landed.