Skip to content

Commit 140fcf3

Browse files
committed
[sending] Make it so that we suppress fields of Nominal Types in API notes.
rdar://129045783 (cherry picked from commit 14c4576)
1 parent c4bdb9a commit 140fcf3

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

lib/AST/FeatureSet.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,7 @@ UNINTERESTING_FEATURE(GroupActorErrors)
643643

644644
UNINTERESTING_FEATURE(TransferringArgsAndResults)
645645
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
646-
auto functionTypeUsesSending = [](Decl *decl) {
647-
return usesTypeMatching(decl, [](Type type) {
646+
auto isFunctionTypeWithSending = [](Type type) {
648647
auto fnType = type->getAs<AnyFunctionType>();
649648
if (!fnType)
650649
return false;
@@ -656,15 +655,17 @@ static bool usesFeatureSendingArgsAndResults(Decl *decl) {
656655
[](AnyFunctionType::Param param) {
657656
return param.getParameterFlags().isSending();
658657
});
659-
});
658+
};
659+
auto declUsesFunctionTypesThatUseSending = [&](Decl *decl) {
660+
return usesTypeMatching(decl, isFunctionTypeWithSending);
660661
};
661662

662663
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
663664
if (pd->isSending()) {
664665
return true;
665666
}
666667

667-
if (functionTypeUsesSending(pd))
668+
if (declUsesFunctionTypesThatUseSending(pd))
668669
return true;
669670
}
670671

@@ -674,10 +675,20 @@ static bool usesFeatureSendingArgsAndResults(Decl *decl) {
674675
return usesFeatureSendingArgsAndResults(pd);
675676
}))
676677
return true;
677-
if (functionTypeUsesSending(decl))
678+
if (declUsesFunctionTypesThatUseSending(decl))
678679
return true;
679680
}
680681

682+
// Check if we have a pattern binding decl for a function that has sending
683+
// parameters and results.
684+
if (auto *pbd = dyn_cast<PatternBindingDecl>(decl)) {
685+
for (auto index : range(pbd->getNumPatternEntries())) {
686+
auto *pattern = pbd->getPattern(index);
687+
if (pattern->hasType() && isFunctionTypeWithSending(pattern->getType()))
688+
return true;
689+
}
690+
}
691+
681692
return false;
682693
}
683694

test/Concurrency/sending_conditional_suppression.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,40 @@ public struct TestInStruct {
153153
// CHECK-NEXT: #endif
154154
@usableFromInline
155155
func testUsableFromInlineFunctionResult() -> (() -> sending NonSendableKlass) { fatalError() }
156+
157+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
158+
// CHECK-NEXT: public var publicVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
159+
// CHECK-NEXT: #else
160+
// CHECK-NEXT: public var publicVarFieldFunctionArg: (test.NonSendableKlass) -> ()
161+
// CHECK-NEXT: #endif
162+
public var publicVarFieldFunctionArg: (sending NonSendableKlass) -> ()
163+
164+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
165+
// CHECK-NEXT: @usableFromInline
166+
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (sending test.NonSendableKlass) -> ()
167+
// CHECK-NEXT: #else
168+
// CHECK-NEXT: @usableFromInline
169+
// CHECK-NEXT: internal var internalVarFieldFunctionArg: (test.NonSendableKlass) -> ()
170+
// CHECK-NEXT: #endif
171+
@usableFromInline
172+
var internalVarFieldFunctionArg: (sending NonSendableKlass) -> ()
173+
174+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
175+
// CHECK-NEXT: public let publicLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
176+
// CHECK-NEXT: #else
177+
// CHECK-NEXT: public let publicLetFieldFunctionArg: (test.NonSendableKlass) -> ()
178+
// CHECK-NEXT: #endif
179+
public let publicLetFieldFunctionArg: (sending NonSendableKlass) -> ()
180+
181+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults
182+
// CHECK-NEXT: @usableFromInline
183+
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (sending test.NonSendableKlass) -> ()
184+
// CHECK-NEXT: #else
185+
// CHECK-NEXT: @usableFromInline
186+
// CHECK-NEXT: internal let internalLetFieldFunctionArg: (test.NonSendableKlass) -> ()
187+
// CHECK-NEXT: #endif
188+
@usableFromInline
189+
let internalLetFieldFunctionArg: (sending NonSendableKlass) -> ()
156190
}
157191

158192
// Make sure that we emit compiler(>= 5.3) when emitting the suppressing check

0 commit comments

Comments
 (0)