Skip to content

Commit 83d629d

Browse files
authored
Merge pull request #86365 from xedin/rdar-167050741-6.3
[6.3][AST] ASTPrinter: Don't attempt to print `nonisolated(nonsending)` on…
2 parents a1b9cf3 + 0ad8dc9 commit 83d629d

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,12 +3897,6 @@ static bool isEscaping(Type type) {
38973897
return false;
38983898
}
38993899

3900-
static bool isNonisolatedCaller(Type type) {
3901-
if (auto *funcTy = type->getAs<AnyFunctionType>())
3902-
return funcTy->getIsolation().isNonIsolatedCaller();
3903-
return false;
3904-
}
3905-
39063900
static void printParameterFlags(ASTPrinter &printer,
39073901
const PrintOptions &options,
39083902
const ParamDecl *param,
@@ -4101,11 +4095,14 @@ void PrintAST::printOneParameter(const ParamDecl *param,
41014095
!willUseTypeReprPrinting(TheTypeLoc, CurrentType, Options)) {
41024096
auto type = TheTypeLoc.getType();
41034097

4098+
bool isCallerIsolated = false;
4099+
if (auto *funcTy = dyn_cast<AnyFunctionType>(interfaceTy.getPointer()))
4100+
isCallerIsolated = funcTy->getIsolation().isNonIsolatedCaller();
4101+
41044102
// We suppress `@escaping` on enum element parameters because it cannot
41054103
// be written explicitly in this position.
41064104
printParameterFlags(Printer, Options, param, paramFlags,
4107-
isEscaping(type) && !isEnumElement,
4108-
isNonisolatedCaller(interfaceTy));
4105+
isEscaping(type) && !isEnumElement, isCallerIsolated);
41094106
}
41104107

41114108
printTypeLoc(TheTypeLoc, getNonRecursiveOptions(param));

test/Concurrency/attr_execution/nonisolated_cross_module_with_flag_enabled.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ nonisolated public class NoinsolatedClassTest {
7777
public func test() async {}
7878
}
7979

80+
// CHECK: public typealias F = nonisolated(nonsending) () async -> Swift.Void
81+
public typealias F = () async -> Void
82+
// CHECK: public typealias G<T> = nonisolated(nonsending) () async -> T
83+
public typealias G<T> = () async -> T
84+
85+
// CHECK: public func testTypeAlias(_: @escaping A.F)
86+
public func testTypeAlias(_: @escaping F) {}
87+
88+
// CHECK: public struct TestGenericTypeAlias {
89+
// CHECK: public subscript<U>(_: nonisolated(nonsending) () async -> U) -> Swift.Bool {
90+
// CHECK: get
91+
// CHECK: }
92+
// CHECK: }
93+
public struct TestGenericTypeAlias {
94+
public subscript<U>(_: G<U>) -> Bool { false }
95+
}
96+
8097
//--- Client.swift
8198
import A
8299

@@ -141,3 +158,26 @@ func testWitnessWithNonisolated(t: WitnessTest) async {
141158
func testNonisolatedClass(t: NoinsolatedClassTest) async {
142159
await t.test()
143160
}
161+
162+
// CHECK-LABEL: sil hidden @$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tF : $@convention(thin) (@in_guaranteed TestGenericTypeAlias) -> ()
163+
// CHECK: [[CLOSURE:%.*]] = function_ref @$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tFyyYaYCcfU_ : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
164+
// CHECK: [[THICK_CLOSURE:%.*]] = thin_to_thick_function [[CLOSURE]] to $@async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
165+
// CHECK: [[TEST_TYPEALIAS:%.*]] = function_ref @$s1A13testTypeAliasyyyyYaYCcF : $@convention(thin) (@guaranteed @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> ()
166+
// CHECK: apply [[TEST_TYPEALIAS]]([[THICK_CLOSURE]]) : $@convention(thin) (@guaranteed @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> ()
167+
// CHECK: [[CLOSURE_2:%.*]] = convert_function {{.*}} to $@noescape @async @callee_guaranteed @substituted <τ_0_0> (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> @out τ_0_0 for <Int>
168+
// CHECK: [[SUBSCRIPT:%.*]] = function_ref @$s1A20TestGenericTypeAliasVySbxyYaYCXEcluig : $@convention(method) <τ_0_0> (@guaranteed @noescape @async @callee_guaranteed @substituted <τ_0_0> (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> @out τ_0_0 for <τ_0_0>, @in_guaranteed TestGenericTypeAlias) -> Bool
169+
// CHECK: apply [[SUBSCRIPT]]<Int>([[CLOSURE_2]], {{.*}}) : $@convention(method) <τ_0_0> (@guaranteed @noescape @async @callee_guaranteed @substituted <τ_0_0> (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> @out τ_0_0 for <τ_0_0>, @in_guaranteed TestGenericTypeAlias) -> Bool
170+
// CHECK: } // end sil function '$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tF'
171+
func testTypeAliasParam(t: TestGenericTypeAlias) {
172+
// CHECK: closure #1 in testTypeAliasParam(t:)
173+
// CHECK: Isolation: caller_isolation_inheriting
174+
// CHECK-LABEL: sil private @$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tFyyYaYCcfU_ : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
175+
// CHECK: } // end sil function '$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tFyyYaYCcfU_'
176+
testTypeAlias { }
177+
178+
// CHECK: // closure #2 in testTypeAliasParam(t:)
179+
// CHECK: // Isolation: caller_isolation_inheriting
180+
// CHECK-LABEL: sil private @$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tFSiyYaYCXEfU0_ : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> Int
181+
// CHECK: } // end sil function '$s6Client18testTypeAliasParam1ty1A011TestGenericcD0V_tFSiyYaYCXEfU0_'
182+
_ = t[{ 42 }]
183+
}

0 commit comments

Comments
 (0)