@@ -156,6 +156,8 @@ irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType,
156
156
typeInfos.push_back (&errorTypeInfo);
157
157
valTypes.push_back (errorType);
158
158
159
+ bool canHaveValidError = substitutedType->hasErrorResult ();
160
+
159
161
// IndirectResultTypes *indirectResults...;
160
162
auto indirectResults = fnConv.getIndirectSILResults ();
161
163
for (auto indirectResult : indirectResults) {
@@ -196,15 +198,35 @@ irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType,
196
198
}
197
199
198
200
// SelfType self?;
199
- bool hasLocalContextParameter = hasSelfContextParameter (substitutedType);
200
- bool canHaveValidError = substitutedType->hasErrorResult ();
201
- bool hasLocalContext = (hasLocalContextParameter || canHaveValidError);
201
+ bool hasSelf = hasSelfContextParameter (substitutedType);
202
202
SILParameterInfo localContextParameter =
203
- hasLocalContextParameter ? parameters.back () : SILParameterInfo ();
204
- if (hasLocalContextParameter ) {
203
+ hasSelf ? parameters.back () : SILParameterInfo ();
204
+ if (hasSelf ) {
205
205
parameters = parameters.drop_back ();
206
206
}
207
207
208
+ Optional<AsyncContextLayout::ArgumentInfo> localContextInfo = llvm::None;
209
+ if (hasSelf) {
210
+ assert (originalType->getRepresentation () !=
211
+ SILFunctionTypeRepresentation::Thick);
212
+ SILType ty = IGM.silConv .getSILType (localContextParameter, substitutedType,
213
+ IGM.getMaximalTypeExpansionContext ());
214
+ auto argumentLoweringType =
215
+ getArgumentLoweringType (ty.getASTType (), localContextParameter,
216
+ /* isNoEscape*/ true );
217
+
218
+ auto &ti = IGM.getTypeInfoForLowered (argumentLoweringType);
219
+ valTypes.push_back (ty);
220
+ typeInfos.push_back (&ti);
221
+ localContextInfo = {ty, localContextParameter.getConvention ()};
222
+ } else {
223
+ auto &ti = IGM.getNativeObjectTypeInfo ();
224
+ SILType ty = SILType::getNativeObjectType (IGM.Context );
225
+ valTypes.push_back (ty);
226
+ typeInfos.push_back (&ti);
227
+ localContextInfo = {ty, substitutedType->getCalleeConvention ()};
228
+ }
229
+
208
230
// ArgTypes formalArguments...;
209
231
for (auto parameter : parameters) {
210
232
SILType ty = IGM.silConv .getSILType (parameter, substitutedType,
@@ -230,31 +252,6 @@ irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType,
230
252
typeInfos.push_back (&bindingsTI);
231
253
}
232
254
233
- Optional<AsyncContextLayout::ArgumentInfo> localContextInfo = llvm::None;
234
- if (hasLocalContext) {
235
- if (hasLocalContextParameter) {
236
- SILType ty =
237
- IGM.silConv .getSILType (localContextParameter, substitutedType,
238
- IGM.getMaximalTypeExpansionContext ());
239
- auto argumentLoweringType =
240
- getArgumentLoweringType (ty.getASTType (), localContextParameter,
241
- /* isNoEscape*/ true );
242
-
243
- auto &ti = IGM.getTypeInfoForLowered (argumentLoweringType);
244
- valTypes.push_back (ty);
245
- typeInfos.push_back (&ti);
246
- localContextInfo = {ty, localContextParameter.getConvention ()};
247
- } else {
248
- // TODO: DETERMINE: Is there a field in this case to match the sync ABI?
249
- auto &ti = IGM.getNativeObjectTypeInfo ();
250
- SILType ty = SILType::getNativeObjectType (IGM.Context );
251
- valTypes.push_back (ty);
252
- typeInfos.push_back (&ti);
253
- localContextInfo = {ty, substitutedType->getCalleeConvention ()};
254
- }
255
- }
256
-
257
-
258
255
Optional<AsyncContextLayout::TrailingWitnessInfo> trailingWitnessInfo;
259
256
if (originalType->getRepresentation () ==
260
257
SILFunctionTypeRepresentation::WitnessMethod) {
@@ -778,10 +775,6 @@ void SignatureExpansion::addAsyncParameters() {
778
775
ParamIRTypes.push_back (IGM.SwiftTaskPtrTy );
779
776
ParamIRTypes.push_back (IGM.SwiftExecutorPtrTy );
780
777
ParamIRTypes.push_back (IGM.SwiftContextPtrTy );
781
- if (FnType->getRepresentation () == SILFunctionTypeRepresentation::Thick) {
782
- IGM.addSwiftSelfAttributes (Attrs, ParamIRTypes.size ());
783
- ParamIRTypes.push_back (IGM.RefCountedPtrTy );
784
- }
785
778
}
786
779
787
780
void SignatureExpansion::addCoroutineContextParameter () {
@@ -2314,10 +2307,6 @@ class AsyncCallEmission final : public CallEmission {
2314
2307
asyncExplosion.add (IGF.getAsyncTask ());
2315
2308
asyncExplosion.add (IGF.getAsyncExecutor ());
2316
2309
asyncExplosion.add (contextBuffer.getAddress ());
2317
- if (getCallee ().getRepresentation () ==
2318
- SILFunctionTypeRepresentation::Thick) {
2319
- asyncExplosion.add (getCallee ().getSwiftContext ());
2320
- }
2321
2310
super::setArgs (asyncExplosion, false , witnessMetadata);
2322
2311
SILFunctionConventions fnConv (getCallee ().getSubstFunctionType (),
2323
2312
IGF.getSILModule ());
@@ -2380,11 +2369,18 @@ class AsyncCallEmission final : public CallEmission {
2380
2369
auto bindingsAddr = bindingLayout.project (IGF, context, /* offsets*/ None);
2381
2370
layout.getBindings ().save (IGF, bindingsAddr, llArgs);
2382
2371
}
2383
- if (selfValue) {
2384
- Explosion selfExplosion;
2385
- selfExplosion.add (selfValue);
2372
+ auto isThick =
2373
+ getCallee ().getRepresentation () == SILFunctionTypeRepresentation::Thick;
2374
+ if (selfValue || isThick) {
2375
+ Explosion localExplosion;
2376
+ if (selfValue) {
2377
+ assert (!isThick);
2378
+ localExplosion.add (selfValue);
2379
+ } else {
2380
+ localExplosion.add (getCallee ().getSwiftContext ());
2381
+ }
2386
2382
auto fieldLayout = layout.getLocalContextLayout ();
2387
- saveValue (fieldLayout, selfExplosion , isOutlined);
2383
+ saveValue (fieldLayout, localExplosion , isOutlined);
2388
2384
}
2389
2385
}
2390
2386
void emitCallToUnmappedExplosion (llvm::CallInst *call, Explosion &out) override {
0 commit comments