@@ -97,6 +97,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
97
97
SmallVector<const TypeInfo *, 4 > typeInfos;
98
98
SmallVector<SILType, 4 > valTypes;
99
99
SmallVector<AsyncContextLayout::ArgumentInfo, 4 > paramInfos;
100
+ bool isCoroutine = originalType->isCoroutine ();
101
+ SmallVector<SILYieldInfo, 4 > yieldInfos;
100
102
SmallVector<SILResultInfo, 4 > indirectReturnInfos;
101
103
SmallVector<SILResultInfo, 4 > directReturnInfos;
102
104
@@ -141,6 +143,11 @@ AsyncContextLayout irgen::getAsyncContextLayout(
141
143
typeInfos.push_back (&ti);
142
144
}
143
145
146
+ if (isCoroutine) {
147
+ // SwiftPartialFunction * __ptrauth(...) yieldToCaller?;
148
+ addTaskContinuationFunction ();
149
+ }
150
+
144
151
// SwiftError *errorResult;
145
152
auto errorCanType = IGF.IGM .Context .getExceptionType ();
146
153
auto errorType = SILType::getPrimitiveObjectType (errorCanType);
@@ -160,15 +167,33 @@ AsyncContextLayout irgen::getAsyncContextLayout(
160
167
indirectReturnInfos.push_back (indirectResult);
161
168
}
162
169
163
- // ResultTypes directResults...;
164
- auto directResults = fnConv.getDirectSILResults ();
165
- for (auto result : directResults) {
166
- auto ty =
167
- fnConv.getSILType (result, IGF.IGM .getMaximalTypeExpansionContext ());
168
- auto &ti = IGF.getTypeInfoForLowered (ty.getASTType ());
169
- valTypes.push_back (ty);
170
- typeInfos.push_back (&ti);
171
- directReturnInfos.push_back (result);
170
+ // union {
171
+ if (isCoroutine) {
172
+ // SwiftPartialFunction * __ptrauth(...) resumeFromYield?
173
+ addTaskContinuationFunction ();
174
+ // SwiftPartialFunction * __ptrauth(...) abortFromYield?
175
+ addTaskContinuationFunction ();
176
+ // SwiftActor * __ptrauth(...) calleeActorDuringYield?
177
+ addExecutor ();
178
+ // YieldTypes yieldValues...
179
+ for (auto yield : fnConv.getYields ()) {
180
+ auto ty =
181
+ fnConv.getSILType (yield, IGF.IGM .getMaximalTypeExpansionContext ());
182
+ auto &ti = IGF.getTypeInfoForLowered (ty.getASTType ());
183
+ valTypes.push_back (ty);
184
+ typeInfos.push_back (&ti);
185
+ yieldInfos.push_back (yield);
186
+ }
187
+ } else {
188
+ // ResultTypes directResults...;
189
+ for (auto result : fnConv.getDirectSILResults ()) {
190
+ auto ty =
191
+ fnConv.getSILType (result, IGF.IGM .getMaximalTypeExpansionContext ());
192
+ auto &ti = IGF.getTypeInfoForLowered (ty.getASTType ());
193
+ valTypes.push_back (ty);
194
+ typeInfos.push_back (&ti);
195
+ directReturnInfos.push_back (result);
196
+ }
172
197
}
173
198
174
199
// SelfType self?;
@@ -257,7 +282,8 @@ AsyncContextLayout irgen::getAsyncContextLayout(
257
282
IGF.IGM , LayoutStrategy::Optimal, valTypes, typeInfos, IGF, originalType,
258
283
substitutedType, substitutionMap, std::move (bindings),
259
284
trailingWitnessInfo, errorType, canHaveValidError, paramInfos,
260
- indirectReturnInfos, directReturnInfos, localContextInfo);
285
+ isCoroutine, yieldInfos, indirectReturnInfos, directReturnInfos,
286
+ localContextInfo);
261
287
}
262
288
263
289
AsyncContextLayout::AsyncContextLayout (
@@ -267,14 +293,16 @@ AsyncContextLayout::AsyncContextLayout(
267
293
SubstitutionMap substitutionMap, NecessaryBindings &&bindings,
268
294
Optional<TrailingWitnessInfo> trailingWitnessInfo, SILType errorType,
269
295
bool canHaveValidError, ArrayRef<ArgumentInfo> argumentInfos,
296
+ bool isCoroutine, ArrayRef<SILYieldInfo> yieldInfos,
270
297
ArrayRef<SILResultInfo> indirectReturnInfos,
271
298
ArrayRef<SILResultInfo> directReturnInfos,
272
299
Optional<AsyncContextLayout::ArgumentInfo> localContextInfo)
273
300
: StructLayout(IGM, /* decl=*/ nullptr , LayoutKind::NonHeapObject, strategy,
274
301
fieldTypeInfos, /* typeToFill*/ nullptr ),
275
302
IGF(IGF), originalType(originalType), substitutedType(substitutedType),
276
303
substitutionMap(substitutionMap), errorType(errorType),
277
- canHaveValidError(canHaveValidError),
304
+ canHaveValidError(canHaveValidError), isCoroutine(isCoroutine),
305
+ yieldInfos(yieldInfos.begin(), yieldInfos.end()),
278
306
directReturnInfos(directReturnInfos.begin(), directReturnInfos.end()),
279
307
indirectReturnInfos(indirectReturnInfos.begin(),
280
308
indirectReturnInfos.end()),
@@ -284,6 +312,11 @@ AsyncContextLayout::AsyncContextLayout(
284
312
#ifndef NDEBUG
285
313
assert (fieldTypeInfos.size () == fieldTypes.size () &&
286
314
" type infos don't match types" );
315
+ if (isCoroutine) {
316
+ assert (directReturnInfos.empty ());
317
+ } else {
318
+ assert (yieldInfos.empty ());
319
+ }
287
320
if (!bindings.empty ()) {
288
321
assert (fieldTypeInfos.size () >= 2 && " no field for bindings" );
289
322
auto fixedBindingsField =
0 commit comments