Skip to content

Commit d96760b

Browse files
Merge pull request swiftlang#36281 from aschwaighofer/wip_new_abi
New Async ABI
2 parents 29cfd3e + 5b4e056 commit d96760b

File tree

67 files changed

+1157
-1166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1157
-1166
lines changed

include/swift/ABI/Task.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,40 @@ class YieldingAsyncContext : public AsyncContext {
550550
class FutureAsyncContext : public AsyncContext {
551551
public:
552552
SwiftError **errorResult = nullptr;
553-
OpaqueValue *indirectResult;
554553

555554
using AsyncContext::AsyncContext;
556555
};
557556

558-
/// An asynchronous context within a task that describes a general "Future"
559-
/// task that was started with a closure context.
560-
class FutureClosureAsyncContext : public FutureAsyncContext {
557+
/// This matches the ABI of a closure `() async throws -> ()`
558+
using AsyncVoidClosureEntryPoint =
559+
SWIFT_CC(swiftasync)
560+
void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT HeapObject *);
561+
562+
/// This matches the ABI of a closure `<T>() async throws -> T`
563+
using AsyncGenericClosureEntryPoint =
564+
SWIFT_CC(swiftasync)
565+
void(OpaqueValue *,
566+
SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT HeapObject *);
567+
568+
class AsyncContextPrefix {
561569
public:
570+
// Async closure entry point adhering to compiler calling conv (e.g directly
571+
// passing the closure context instead of via the async context)
572+
AsyncVoidClosureEntryPoint *__ptrauth_swift_task_resume_function
573+
asyncEntryPoint;
562574
HeapObject *closureContext;
575+
};
563576

564-
using FutureAsyncContext::FutureAsyncContext;
577+
/// Storage that is allocated before the AsyncContext to be used by an adapter
578+
/// of Swift's async convention and the ResumeTask interface.
579+
class FutureAsyncContextPrefix {
580+
public:
581+
OpaqueValue *indirectResult;
582+
// Async closure entry point adhering to compiler calling conv (e.g directly
583+
// passing the closure context instead of via the async context)
584+
AsyncGenericClosureEntryPoint *__ptrauth_swift_task_resume_function
585+
asyncEntryPoint;
586+
HeapObject *closureContext;
565587
};
566588

567589
} // end namespace swift

include/swift/Runtime/Concurrency.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
117117
JobPriority
118118
swift_task_escalate(AsyncTask *task, JobPriority newPriority);
119119

120+
/// This matches the ABI of a closure `<T>(Builtin.NativeObject) async -> T`
120121
using TaskFutureWaitSignature =
121-
AsyncSignature<void(AsyncTask *, OpaqueValue *), /*throws*/ false>;
122+
SWIFT_CC(swiftasync)
123+
void(OpaqueValue *,
124+
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *);
122125

123126
/// Wait for a non-throwing future task to complete.
124127
///
@@ -129,11 +132,13 @@ using TaskFutureWaitSignature =
129132
/// -> Success
130133
/// \endcode
131134
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
132-
TaskFutureWaitSignature::FunctionType
133-
swift_task_future_wait;
135+
void swift_task_future_wait(OpaqueValue *,
136+
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *);
134137

135138
using TaskFutureWaitThrowingSignature =
136-
AsyncSignature<void(AsyncTask *, OpaqueValue *), /*throws*/ true>;
139+
SWIFT_CC(swiftasync)
140+
void(OpaqueValue *,
141+
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *);
137142

138143
/// Wait for a potentially-throwing future task to complete.
139144
///
@@ -144,11 +149,15 @@ using TaskFutureWaitThrowingSignature =
144149
/// async throws -> Success
145150
/// \endcode
146151
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
147-
TaskFutureWaitThrowingSignature::FunctionType
148-
swift_task_future_wait_throwing;
152+
void swift_task_future_wait_throwing(OpaqueValue *,
153+
SWIFT_ASYNC_CONTEXT AsyncContext *,
154+
AsyncTask *, Metadata *);
149155

150156
using TaskGroupFutureWaitThrowingSignature =
151-
AsyncSignature<void(AsyncTask *, TaskGroup *, Metadata *), /*throws*/ true>;
157+
SWIFT_CC(swiftasync)
158+
void(OpaqueValue *,
159+
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, TaskGroup *,
160+
const Metadata *successType);
152161

153162
/// Wait for a readyQueue of a Channel to become non empty.
154163
///
@@ -160,9 +169,11 @@ using TaskGroupFutureWaitThrowingSignature =
160169
/// group: UnsafeRawPointer
161170
/// ) async -> T
162171
/// \endcode
163-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
164-
TaskGroupFutureWaitThrowingSignature::FunctionType
165-
swift_taskGroup_wait_next_throwing;
172+
SWIFT_EXPORT_FROM(swift_Concurrency)
173+
SWIFT_CC(swiftasync)
174+
void swift_taskGroup_wait_next_throwing(
175+
OpaqueValue *resultPointer, SWIFT_ASYNC_CONTEXT AsyncContext *rawContext,
176+
TaskGroup *group, const Metadata *successType);
166177

167178
/// Create a new `TaskGroup`.
168179
/// The caller is responsible for retaining and managing the group's lifecycle.

lib/IRGen/Callee.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,15 @@ namespace irgen {
176176
switch (getSpecialKind()) {
177177
case SpecialKind::TaskFutureWait:
178178
case SpecialKind::TaskFutureWaitThrowing:
179+
// FIXME: I have disabled this optimization, if we bring it back we
180+
// need to debug why it currently does not work (call emission
181+
// computes an undef return pointer) and change the runtime entries to
182+
// remove the extra type parameter.
183+
//
179184
// We suppress generics from these as a code-size optimization
180185
// because the runtime can recover the success type from the
181186
// future.
182-
return true;
187+
return false;
183188
case SpecialKind::TaskGroupWaitNext:
184189
return false;
185190
}

lib/IRGen/EntryPointArgumentEmission.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class NativeCCEntryPointArgumentEmission
4343
: public virtual EntryPointArgumentEmission {
4444

4545
public:
46+
virtual void mapAsyncParameters() = 0;
4647
virtual llvm::Value *getCallerErrorResultArgument() = 0;
4748
virtual llvm::Value *getContext() = 0;
4849
virtual Explosion getArgumentExplosion(unsigned index, unsigned size) = 0;

0 commit comments

Comments
 (0)