You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove temp_await and safe_async throughout the entire codebase [part 1] (#7761)
Remove both `temp_await` and `safe_async` in favor of broader adoption of
`async`/`await`.
### Motivation:
`temp_await` is very dangerous API that blocks the current thread and is
not marked as unavailable from async methods. The only need for
temp_await is because LLBuild only supports non-async methods so any
llbuild commands that call async methods have to block waiting.
Because `temp_await` is liberally spread across the code base there are
a number of async methods that may indirectly call into `temp_await` and
indefinitely block a swift concurrency thread. This risks a deadlock. To
prevent the deadlock the `safe_async` method dispatches to a GCD
concurrent queue before executing the callback code. Because GCD will
create new threads if all existing threads are blocked (unlike swift
concurrency) this effectively prevents deadlock risks at the risk of
thread explosion.
It would be better if the codebase was free of both the risks of
deadlock and thread explosion. Additionally it would be nice if the APIs
using `temp_await` were marked async so that more parts of the code base
could safely adopt `async`/`await.`
### Modifications:
* To augment existing memoizer types new async types are added
`temp_dir` is replaced by `unsafe_await` which is limited to one used
which is called by llbuild
* `safe_async` is replaced by CheckedThrowingContinuation
* Multiple protocols have been modified to change their requirements from
sync to async
* Usage of DispatchSemaphore and DispatchGroup have been replaced with
structured concurrency
* Many methods that were non-async but used `temp_await` have been properly
marked as `async`
### Result:
No usage of `temp_dir` or `safe_async` and only one (safe) usage of`unsafe_await` from an LLBuild command
0 commit comments