Skip to content

Commit b099009

Browse files
committed
Be sure to clear @isolated(any) from the constant function type.
I'm not completely sure why this code pattern triggers this --- or really, why other code patterns don't --- but it's easy to fix. Fixes rdar://142636640
1 parent 4937d0a commit b099009

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,8 @@ static void
20302030
lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20312031
CanGenericSignature genericSig,
20322032
TypeExpansionContext expansion,
2033-
SmallVectorImpl<SILParameterInfo> &inputs) {
2033+
SmallVectorImpl<SILParameterInfo> &inputs,
2034+
SILExtInfoBuilder &extInfo) {
20342035

20352036
// If the function is a closure being converted to an @isolated(any) type,
20362037
// add the implicit isolation parameter.
@@ -2039,6 +2040,7 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20392040
auto isolationTy = SILType::getOpaqueIsolationType(TC.Context);
20402041
inputs.push_back({isolationTy.getASTType(),
20412042
ParameterConvention::Direct_Guaranteed});
2043+
extInfo = extInfo.withErasedIsolation(false);
20422044
}
20432045
}
20442046

@@ -2573,7 +2575,7 @@ static CanSILFunctionType getSILFunctionType(
25732575
// don't need to keep its capture types opaque.
25742576
lowerCaptureContextParameters(TC, *constant, genericSig,
25752577
TC.getCaptureTypeExpansionContext(*constant),
2576-
inputs);
2578+
inputs, extInfoBuilder);
25772579
}
25782580

25792581
auto calleeConvention = ParameterConvention::Direct_Unowned;

test/SILGen/isolated_any.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ actor MyActor {
247247
func asyncAction() async {}
248248

249249
func takeAsyncIsolatedAny(fn: @escaping @isolated(any) @Sendable () async -> ()) {}
250+
func takeAsyncIsolatedAnyAutoclosure(_: @autoclosure @isolated(any) () async -> Void) async {}
250251
func takeInheritingAsyncIsolatedAny(@_inheritActorContext fn: @escaping @isolated(any) @Sendable () async -> ()) {}
251252

252253
// CHECK-LABEL: sil hidden [ossa] @$s4test0A28EraseAsyncNonIsolatedClosureyyF
@@ -326,6 +327,17 @@ func testEraseInheritingAsyncMainActorClosure() {
326327
}
327328
}
328329

330+
// rdar://142636640
331+
// CHECK-LABEL: sil hidden [ossa] @$s4test0A30EraseAsyncMainActorAutoclosureyyYaF
332+
// CHECK: [[CLOSURE_FN:%.*]] = function_ref @$s4test0A30EraseAsyncMainActorAutoclosureyyYaFyyYaYAXEfu_ : $@convention(thin) @async (@guaranteed Optional<any Actor>) -> ()
333+
// CHECK-NEXT: metatype $@thick MainActor.Type
334+
// CHECK-NEXT: // function_ref static MainActor.shared.getter
335+
// ...followed by the standard "get the main actor instance" stuff
336+
@MainActor
337+
func testEraseAsyncMainActorAutoclosure() async {
338+
await takeAsyncIsolatedAnyAutoclosure(await asyncAction())
339+
}
340+
329341
// Define a global actor that doesn't use Self as its instance type
330342
actor MyGlobalActorInstance {}
331343
@globalActor struct MyGlobalActor {

0 commit comments

Comments
 (0)