Skip to content

Commit 14c4576

Browse files
committed
[sending] Make it so that we suppress fields of Nominal Types in API notes.
rdar://129045783
1 parent 97710b4 commit 14c4576

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
@@ -647,8 +647,7 @@ UNINTERESTING_FEATURE(GroupActorErrors)
647647

648648
UNINTERESTING_FEATURE(TransferringArgsAndResults)
649649
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
650-
auto functionTypeUsesSending = [](Decl *decl) {
651-
return usesTypeMatching(decl, [](Type type) {
650+
auto isFunctionTypeWithSending = [](Type type) {
652651
auto fnType = type->getAs<AnyFunctionType>();
653652
if (!fnType)
654653
return false;
@@ -660,15 +659,17 @@ static bool usesFeatureSendingArgsAndResults(Decl *decl) {
660659
[](AnyFunctionType::Param param) {
661660
return param.getParameterFlags().isSending();
662661
});
663-
});
662+
};
663+
auto declUsesFunctionTypesThatUseSending = [&](Decl *decl) {
664+
return usesTypeMatching(decl, isFunctionTypeWithSending);
664665
};
665666

666667
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
667668
if (pd->isSending()) {
668669
return true;
669670
}
670671

671-
if (functionTypeUsesSending(pd))
672+
if (declUsesFunctionTypesThatUseSending(pd))
672673
return true;
673674
}
674675

@@ -678,10 +679,20 @@ static bool usesFeatureSendingArgsAndResults(Decl *decl) {
678679
return usesFeatureSendingArgsAndResults(pd);
679680
}))
680681
return true;
681-
if (functionTypeUsesSending(decl))
682+
if (declUsesFunctionTypesThatUseSending(decl))
682683
return true;
683684
}
684685

686+
// Check if we have a pattern binding decl for a function that has sending
687+
// parameters and results.
688+
if (auto *pbd = dyn_cast<PatternBindingDecl>(decl)) {
689+
for (auto index : range(pbd->getNumPatternEntries())) {
690+
auto *pattern = pbd->getPattern(index);
691+
if (pattern->hasType() && isFunctionTypeWithSending(pattern->getType()))
692+
return true;
693+
}
694+
}
695+
685696
return false;
686697
}
687698

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)