feat(libc): implement libc++ promise<void>, future<void> and future_error #27540
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27540"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by kiansaeidnia on 2026-11-26T16:53:44Z.
What
The RetroArch Azahar core (PPSA99169, import inventory on #5927) imports 18 libc++
std::__1names forpromise<void>andfuture<void>that libc did not define. This PR adds them:promise<void>: constructor, destructor,get_future,set_value,set_exception;future<void>: the constructor from a shared state, and the destructor;__assoc_sub_state:wait,__sub_wait,set_value,set_exception,__on_zero_shared, its vtable and RTTI;future_error: theerror_codeconstructor, the destructor and RTTI;future_category().This builds on #27519 (libc++
system_error), which adds the libc++error_codelayout and the category vtable thatfuture_categoryreuses, so this branch contains that commit too. #27519 has merged with that same commit, so the diff here is this change only and no rebase is needed.The layout and behaviour follow LLVM libc++ 17
future.cppand<future>, checked against the Azahar relocations. Azahar's inlinestd::asyncstates derive from the imported__assoc_sub_statevtable, so the layout and slot order are guest ABI:__assoc_sub_stateis 48 bytes:exception_ptrmutexcondition_variableThe vtable is D1, D0,
__on_zero_shared,__execute. The RTTI derives from an internal__shared_countrecord, which is not exported here.set_valueandset_exceptionthrowpromise_already_satisfiedon a second call, then wake the waiters.__sub_waitruns a deferred state through its__executeslot after unlocking. Otherwise it waits until the state is ready.future(state)throwsfuture_already_retrievedon a second attach.Destroying an unsatisfied promise while a future is alive stores a
broken_promisefuture_error.__on_zero_sharedcalls the deleting destructor once.future_erroris a libc++logic_errorplus anerror_codeat 16.future_categoryanswersfuture, with the libc++ 17 message strings.The debt fragment says the layout comes from libc++ 17 and the Azahar relocations, not from a console module. It also records two differences:
~promisebuilds thebroken_promiseexception_ptrwith__cxa_init_primary_exceptioninstead of throwing and catching it, so no handler sees it.std::invalid_argument(libc++ leaves that undefined).pr_overlapcould not comparelibc/CMakeLists.txtorApi.hppwith 21 PRs that conflict withmain: #7447, #7715, #8150, #8965, #11831, #12682, #12688, #12700, #12717, #12849, #12965, #16791, #17557, #18135, #19181, #23395, #24322, #24910, #24917, #25289 and #26224. I searched their diffs, and none addsLibcxxFuture.cppor any of these names, so the only shared lines are other entries in the source list. #14834 and #19864 touch the Dinkumwarefuture_error, which is a different symbol.Tested
Windows 11, MinGW-w64 GCC 16.2, Release. The new
guest_libcxx_futurepasses, also on repeated runs.guest_libcxx_system_error,guest_libcxx_conditionandguest_libcxx_exception_pointerpass too.The new test checks:
wait()on the main thread woken byset_valueon another thread;set_valueorset_exception(code 2), a secondget_future(code 1), and calls on no state (code 3), each withfuture_category();set_exception, with the storedexception_ptrrethrowing the original exception;broken_promise(code 4) with the libc++what()text;__executeslot runs once after the lock is released;unique_lockthat does not own its mutex;__on_zero_shareddelete;LibcxxFuture.cpp,Exports.cppand the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu).debt_fold.py --checkpasses. Not tested in the Azahar core itself.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
promise<void>andfuture<void>, including waiting, value and exception delivery, deferred work, and broken-promise handling.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T17:04:51Z.
Review: COMMENTED
Actionable comments posted: 1
899a6cb9-0d1b-419b-8e45-6ef4acdc5a9bReviewing files that changed from the base of the PR and between
4e90b6ebceand0c8edbd3d2.core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/include/Api.hppcore/libs/prx/libc/src/LibcxxFuture.cppcore/libs/prx/libc/src/exception/StandardExceptions.cppcore/libs/prx/libc/tests/cmake/guest_libcxx_future.cmakecore/libs/prx/libc/tests/cmake/guest_libcxx_system_error.cmakecore/libs/tests/GuestLibcxxFuture.cppcore/libs/tests/GuestLibcxxSystemError.cppdocs/dev/debt/changes/feat-libc-libcxx-future.mddocs/dev/debt/changes/feat-libc-libcxx-system-error.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T17:11:17Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: initialize the guest mutex and condition variable before using or destroying the associated state.
What I ran
Reviewed head
0c8edbd3d266002b464b539581211639bf92c103against the prepared diff and pinned source context usingrepo_read.pyreader tools. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libc/src/LibcxxFuture.cpp:193initializes the new state’smutexandconditionto null, thenset_value,wait, and state deletion pass those members to the libc++ mutex and condition-variable helpers. Those helpers validate the addresses and reject invalid pointers, so ordinary future operations fail and teardown cannot correctly destroy the synchronization objects. Construct valid guest mutex and condition-variable objects before the state becomes usable, with cleanup if construction fails.Non-blocking
None.
Not verified
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/include/Api.hpp,core/libs/prx/libc/src/LibcxxFuture.cpp,core/libs/prx/libc/src/exception/StandardExceptions.cpp, both changed libc test CMake files, both changed guest test files, and both debt fragments. No changed files were excluded.To get this to a good state
Initialize and destroy the state’s mutex and condition variable using the guest ABI, then rerun the future and system-error guest tests and the reported syntax checks.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:10:54Z.
Review: COMMENTED
The full GuestLibcxxFuture and GuestLibcxxSystemError fixtures passed on Linux with this head's future implementation and exception aggregate linked together. The fixtures cover exception propagation, waiter completion, broken promises, deferred execution and the associated error categories.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.