Skip to content

Commit 7bbca2c

Browse files
authored
Merge pull request swiftlang#79228 from rjmccall/trivial-isolated-any-autoclosure
Be sure to clear `@isolated(any)` from the constant function type
2 parents 996408c + b099009 commit 7bbca2c

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
@@ -2031,7 +2031,8 @@ static void
20312031
lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20322032
CanGenericSignature genericSig,
20332033
TypeExpansionContext expansion,
2034-
SmallVectorImpl<SILParameterInfo> &inputs) {
2034+
SmallVectorImpl<SILParameterInfo> &inputs,
2035+
SILExtInfoBuilder &extInfo) {
20352036

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

@@ -2574,7 +2576,7 @@ static CanSILFunctionType getSILFunctionType(
25742576
// don't need to keep its capture types opaque.
25752577
lowerCaptureContextParameters(TC, *constant, genericSig,
25762578
TC.getCaptureTypeExpansionContext(*constant),
2577-
inputs);
2579+
inputs, extInfoBuilder);
25782580
}
25792581

25802582
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)