mirror of
				https://github.com/jart/cosmopolitan.git
				synced 2025-10-26 19:16:41 +00:00 
			
		
		
		
	Upgrade to 2022-era LLVM LIBCXX
This commit is contained in:
		
							parent
							
								
									2f4ca71f26
								
							
						
					
					
						commit
						8e68384e15
					
				
					 2078 changed files with 165657 additions and 65010 deletions
				
			
		
							
								
								
									
										201
									
								
								third_party/libcxx/__coroutine/coroutine_handle.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										201
									
								
								third_party/libcxx/__coroutine/coroutine_handle.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,201 @@ | |||
| //===----------------------------------------------------------------------===//
 | ||||
| //
 | ||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 | ||||
| // See https://llvm.org/LICENSE.txt for license information.
 | ||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 | ||||
| //
 | ||||
| //===----------------------------------------------------------------------===//
 | ||||
| 
 | ||||
| #ifndef _LIBCPP___COROUTINE_COROUTINE_HANDLE_H | ||||
| #define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H | ||||
| 
 | ||||
| #include <__assert> | ||||
| #include <__config> | ||||
| #include <__functional/hash.h> | ||||
| #include <__memory/addressof.h> | ||||
| #include <__type_traits/remove_cv.h> | ||||
| #include <compare> | ||||
| #include <cstddef> | ||||
| 
 | ||||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||
| #  pragma GCC system_header | ||||
| #endif | ||||
| 
 | ||||
| #if _LIBCPP_STD_VER >= 20 | ||||
| 
 | ||||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||||
| 
 | ||||
| // [coroutine.handle]
 | ||||
| template <class _Promise = void> | ||||
| struct _LIBCPP_TEMPLATE_VIS coroutine_handle; | ||||
| 
 | ||||
| template <> | ||||
| struct _LIBCPP_TEMPLATE_VIS coroutine_handle<void> { | ||||
| public: | ||||
|     // [coroutine.handle.con], construct/reset
 | ||||
|     constexpr coroutine_handle() noexcept = default; | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr coroutine_handle(nullptr_t) noexcept {} | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     coroutine_handle& operator=(nullptr_t) noexcept { | ||||
|         __handle_ = nullptr; | ||||
|         return *this; | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.export.import], export/import
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void* address() const noexcept { return __handle_; } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     static constexpr coroutine_handle from_address(void* __addr) noexcept { | ||||
|         coroutine_handle __tmp; | ||||
|         __tmp.__handle_ = __addr; | ||||
|         return __tmp; | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.observers], observers
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr explicit operator bool() const noexcept { | ||||
|         return __handle_ != nullptr; | ||||
|     } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     bool done() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines"); | ||||
|         return __builtin_coro_done(__handle_); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.resumption], resumption
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void operator()() const { resume(); } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void resume() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines"); | ||||
|         _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done"); | ||||
|         __builtin_coro_resume(__handle_); | ||||
|     } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void destroy() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines"); | ||||
|         __builtin_coro_destroy(__handle_); | ||||
|     } | ||||
| 
 | ||||
| private: | ||||
|     _LIBCPP_HIDE_FROM_ABI bool __is_suspended() const { | ||||
|         // FIXME actually implement a check for if the coro is suspended.
 | ||||
|         return __handle_ != nullptr; | ||||
|     } | ||||
| 
 | ||||
|     void* __handle_ = nullptr; | ||||
| }; | ||||
| 
 | ||||
| // [coroutine.handle.compare]
 | ||||
| inline _LIBCPP_HIDE_FROM_ABI | ||||
| constexpr bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { | ||||
|     return __x.address() == __y.address(); | ||||
| } | ||||
| inline _LIBCPP_HIDE_FROM_ABI | ||||
| constexpr strong_ordering operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { | ||||
|     return compare_three_way()(__x.address(), __y.address()); | ||||
| } | ||||
| 
 | ||||
| template <class _Promise> | ||||
| struct _LIBCPP_TEMPLATE_VIS coroutine_handle { | ||||
| public: | ||||
|     // [coroutine.handle.con], construct/reset
 | ||||
|     constexpr coroutine_handle() noexcept = default; | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr coroutine_handle(nullptr_t) noexcept {} | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     static coroutine_handle from_promise(_Promise& __promise) { | ||||
|         using _RawPromise = __remove_cv_t<_Promise>; | ||||
|         coroutine_handle __tmp; | ||||
|         __tmp.__handle_ = | ||||
|             __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true); | ||||
|         return __tmp; | ||||
|     } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     coroutine_handle& operator=(nullptr_t) noexcept { | ||||
|         __handle_ = nullptr; | ||||
|         return *this; | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.export.import], export/import
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void* address() const noexcept { return __handle_; } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     static constexpr coroutine_handle from_address(void* __addr) noexcept { | ||||
|         coroutine_handle __tmp; | ||||
|         __tmp.__handle_ = __addr; | ||||
|         return __tmp; | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.conv], conversion
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr operator coroutine_handle<>() const noexcept { | ||||
|         return coroutine_handle<>::from_address(address()); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.observers], observers
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr explicit operator bool() const noexcept { | ||||
|         return __handle_ != nullptr; | ||||
|     } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     bool done() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines"); | ||||
|         return __builtin_coro_done(__handle_); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.resumption], resumption
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void operator()() const { resume(); } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void resume() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines"); | ||||
|         _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done"); | ||||
|         __builtin_coro_resume(__handle_); | ||||
|     } | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     void destroy() const { | ||||
|         _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines"); | ||||
|         __builtin_coro_destroy(__handle_); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.promise], promise access
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     _Promise& promise() const { | ||||
|         return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, alignof(_Promise), false)); | ||||
|     } | ||||
| 
 | ||||
| private: | ||||
|     _LIBCPP_HIDE_FROM_ABI bool __is_suspended() const { | ||||
|         // FIXME actually implement a check for if the coro is suspended.
 | ||||
|         return __handle_ != nullptr; | ||||
|     } | ||||
|     void* __handle_ = nullptr; | ||||
| }; | ||||
| 
 | ||||
| // [coroutine.handle.hash]
 | ||||
| template <class _Tp> | ||||
| struct hash<coroutine_handle<_Tp>> { | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     size_t operator()(const coroutine_handle<_Tp>& __v) const noexcept { return hash<void*>()(__v.address()); } | ||||
| }; | ||||
| 
 | ||||
| _LIBCPP_END_NAMESPACE_STD | ||||
| 
 | ||||
| #endif // __LIBCPP_STD_VER >= 20
 | ||||
| 
 | ||||
| #endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
 | ||||
							
								
								
									
										53
									
								
								third_party/libcxx/__coroutine/coroutine_traits.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								third_party/libcxx/__coroutine/coroutine_traits.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,53 @@ | |||
| //===----------------------------------------------------------------------===//
 | ||||
| //
 | ||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 | ||||
| // See https://llvm.org/LICENSE.txt for license information.
 | ||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 | ||||
| //
 | ||||
| //===----------------------------------------------------------------------===//
 | ||||
| 
 | ||||
| #ifndef _LIBCPP___COROUTINE_COROUTINE_TRAITS_H | ||||
| #define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H | ||||
| 
 | ||||
| #include <__config> | ||||
| #include <__type_traits/void_t.h> | ||||
| 
 | ||||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||
| #  pragma GCC system_header | ||||
| #endif | ||||
| 
 | ||||
| #if _LIBCPP_STD_VER >= 20 | ||||
| 
 | ||||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||||
| 
 | ||||
| // [coroutine.traits]
 | ||||
| // [coroutine.traits.primary]
 | ||||
| //   The header <coroutine> defined the primary template coroutine_traits such that
 | ||||
| // if ArgTypes is a parameter pack of types and if the qualified-id R::promise_type
 | ||||
| // is valid and denotes a type ([temp.deduct]), then coroutine_traits<R, ArgTypes...>
 | ||||
| // has the following publicly accessible memebr:
 | ||||
| //
 | ||||
| //    using promise_type = typename R::promise_type;
 | ||||
| //
 | ||||
| // Otherwise, coroutine_traits<R, ArgTypes...> has no members.
 | ||||
| template <class _Tp, class = void> | ||||
| struct __coroutine_traits_sfinae {}; | ||||
| 
 | ||||
| template <class _Tp> | ||||
| struct __coroutine_traits_sfinae< | ||||
|     _Tp, __void_t<typename _Tp::promise_type> > | ||||
| { | ||||
|   using promise_type = typename _Tp::promise_type; | ||||
| }; | ||||
| 
 | ||||
| template <class _Ret, class... _Args> | ||||
| struct coroutine_traits | ||||
|     : public __coroutine_traits_sfinae<_Ret> | ||||
| { | ||||
| }; | ||||
| 
 | ||||
| _LIBCPP_END_NAMESPACE_STD | ||||
| 
 | ||||
| #endif // __LIBCPP_STD_VER >= 20
 | ||||
| 
 | ||||
| #endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
 | ||||
							
								
								
									
										112
									
								
								third_party/libcxx/__coroutine/noop_coroutine_handle.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								third_party/libcxx/__coroutine/noop_coroutine_handle.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,112 @@ | |||
| //===----------------------------------------------------------------------===//
 | ||||
| //
 | ||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 | ||||
| // See https://llvm.org/LICENSE.txt for license information.
 | ||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 | ||||
| //
 | ||||
| //===----------------------------------------------------------------------===//
 | ||||
| 
 | ||||
| #ifndef _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H | ||||
| #define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H | ||||
| 
 | ||||
| #include <__config> | ||||
| #include <__coroutine/coroutine_handle.h> | ||||
| 
 | ||||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||
| #  pragma GCC system_header | ||||
| #endif | ||||
| 
 | ||||
| #if _LIBCPP_STD_VER >= 20 | ||||
| 
 | ||||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||||
| 
 | ||||
| #if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC) | ||||
| 
 | ||||
| // [coroutine.noop]
 | ||||
| // [coroutine.promise.noop]
 | ||||
| struct noop_coroutine_promise {}; | ||||
| 
 | ||||
| // [coroutine.handle.noop]
 | ||||
| template <> | ||||
| struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> { | ||||
| public: | ||||
|     // [coroutine.handle.noop.conv], conversion
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr operator coroutine_handle<>() const noexcept { | ||||
|         return coroutine_handle<>::from_address(address()); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.noop.observers], observers
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr explicit operator bool() const noexcept { return true; } | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr bool done() const noexcept { return false; } | ||||
| 
 | ||||
|     // [coroutine.handle.noop.resumption], resumption
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void operator()() const noexcept {} | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void resume() const noexcept {} | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void destroy() const noexcept {} | ||||
| 
 | ||||
|     // [coroutine.handle.noop.promise], promise access
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     noop_coroutine_promise& promise() const noexcept { | ||||
|         return *static_cast<noop_coroutine_promise*>( | ||||
|             __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false)); | ||||
|     } | ||||
| 
 | ||||
|     // [coroutine.handle.noop.address], address
 | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void* address() const noexcept { return __handle_; } | ||||
| 
 | ||||
| private: | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept; | ||||
| 
 | ||||
| #if __has_builtin(__builtin_coro_noop) | ||||
|     _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { | ||||
|         this->__handle_ = __builtin_coro_noop(); | ||||
|     } | ||||
| 
 | ||||
|     void* __handle_ = nullptr; | ||||
| 
 | ||||
| #elif defined(_LIBCPP_COMPILER_GCC) | ||||
|     // GCC doesn't implement __builtin_coro_noop().
 | ||||
|     // Construct the coroutine frame manually instead.
 | ||||
|     struct __noop_coroutine_frame_ty_ { | ||||
|         static void __dummy_resume_destroy_func() { } | ||||
| 
 | ||||
|         void (*__resume_)() = __dummy_resume_destroy_func; | ||||
|         void (*__destroy_)() = __dummy_resume_destroy_func; | ||||
|         struct noop_coroutine_promise __promise_; | ||||
|     }; | ||||
| 
 | ||||
|     static __noop_coroutine_frame_ty_ __noop_coroutine_frame_; | ||||
| 
 | ||||
|     void* __handle_ = &__noop_coroutine_frame_; | ||||
| 
 | ||||
|     _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default; | ||||
| 
 | ||||
| #endif // __has_builtin(__builtin_coro_noop)
 | ||||
| }; | ||||
| 
 | ||||
| using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>; | ||||
| 
 | ||||
| #if defined(_LIBCPP_COMPILER_GCC) | ||||
| inline noop_coroutine_handle::__noop_coroutine_frame_ty_ | ||||
|     noop_coroutine_handle::__noop_coroutine_frame_{}; | ||||
| #endif | ||||
| 
 | ||||
| // [coroutine.noop.coroutine]
 | ||||
| inline _LIBCPP_HIDE_FROM_ABI | ||||
| noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); } | ||||
| 
 | ||||
| #endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
 | ||||
| 
 | ||||
| _LIBCPP_END_NAMESPACE_STD | ||||
| 
 | ||||
| #endif // __LIBCPP_STD_VER >= 20
 | ||||
| 
 | ||||
| #endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
 | ||||
							
								
								
									
										46
									
								
								third_party/libcxx/__coroutine/trivial_awaitables.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								third_party/libcxx/__coroutine/trivial_awaitables.h
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| //===----------------------------------------------------------------------===//
 | ||||
| //
 | ||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 | ||||
| // See https://llvm.org/LICENSE.txt for license information.
 | ||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 | ||||
| //
 | ||||
| //===----------------------------------------------------------------------===//
 | ||||
| 
 | ||||
| #ifndef __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H | ||||
| #define __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H | ||||
| 
 | ||||
| #include <__config> | ||||
| #include <__coroutine/coroutine_handle.h> | ||||
| 
 | ||||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||
| #  pragma GCC system_header | ||||
| #endif | ||||
| 
 | ||||
| #if _LIBCPP_STD_VER >= 20 | ||||
| 
 | ||||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||||
| 
 | ||||
| // [coroutine.trivial.awaitables]
 | ||||
| struct suspend_never { | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr bool await_ready() const noexcept { return true; } | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void await_suspend(coroutine_handle<>) const noexcept {} | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void await_resume() const noexcept {} | ||||
| }; | ||||
| 
 | ||||
| struct suspend_always { | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr bool await_ready() const noexcept { return false; } | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void await_suspend(coroutine_handle<>) const noexcept {} | ||||
|     _LIBCPP_HIDE_FROM_ABI | ||||
|     constexpr void await_resume() const noexcept {} | ||||
| }; | ||||
| 
 | ||||
| _LIBCPP_END_NAMESPACE_STD | ||||
| 
 | ||||
| #endif // __LIBCPP_STD_VER >= 20
 | ||||
| 
 | ||||
| #endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue