@@ -1754,63 +1754,58 @@ ImportedType ClangImporter::Implementation::importPropertyType(
17541754 Bridgeability::Full, optionality);
17551755}
17561756
1757- // / Apply an attribute to a function type.
1758- static Type applyToFunctionType (
1759- Type type, llvm::function_ref<ASTExtInfo(ASTExtInfo)> transform) {
1760- // Recurse into optional types.
1761- if (Type objectType = type->getOptionalObjectType ()) {
1762- return OptionalType::get (applyToFunctionType (objectType, transform));
1763- }
1764-
1765- // Apply @noescape to function types.
1766- if (auto funcType = type->getAs <FunctionType>()) {
1767- return FunctionType::get (funcType->getParams (), funcType->getResult (),
1768- transform (funcType->getExtInfo ()));
1769- }
1770-
1771- return type;
1772- }
1773-
17741757Type ClangImporter::Implementation::applyParamAttributes (
1775- const clang::ParmVarDecl *param, Type type) {
1776- if (!param->hasAttrs ())
1777- return type;
1758+ const clang::ParmVarDecl *param, Type type, bool sendableByDefault) {
1759+ bool sendableRequested = sendableByDefault;
1760+ bool sendableDisqualified = false ;
1761+
1762+ if (param->hasAttrs ()) {
1763+ for (auto attr : param->getAttrs ()) {
1764+ // Map __attribute__((noescape)) to @noescape.
1765+ if (isa<clang::NoEscapeAttr>(attr)) {
1766+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1767+ return extInfo.withNoEscape ();
1768+ });
17781769
1779- for (auto attr : param->getAttrs ()) {
1780- // Map __attribute__((noescape)) to @noescape.
1781- if (isa<clang::NoEscapeAttr>(attr)) {
1782- type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1783- return extInfo.withNoEscape ();
1784- });
1770+ continue ;
1771+ }
17851772
1786- continue ;
1787- }
1773+ auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
1774+ if (!swiftAttr)
1775+ continue ;
17881776
1789- auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
1790- if (!swiftAttr)
1791- continue ;
1777+ // Map the main-actor attribute.
1778+ if (isMainActorAttr (swiftAttr)) {
1779+ if (Type mainActor = SwiftContext.getMainActorType ()) {
1780+ type = applyToFunctionType (type, [&](ASTExtInfo extInfo) {
1781+ return extInfo.withGlobalActor (mainActor);
1782+ });
1783+ sendableDisqualified = true ;
1784+ }
17921785
1793- // Map the main-actor attribute.
1794- if (isMainActorAttr (swiftAttr)) {
1795- if (Type mainActor = SwiftContext.getMainActorType ()) {
1796- type = applyToFunctionType (type, [&](ASTExtInfo extInfo) {
1797- return extInfo.withGlobalActor (mainActor);
1798- });
1786+ continue ;
17991787 }
18001788
1801- continue ;
1802- }
1803-
1804- // Map @Sendable.
1805- if (swiftAttr->getAttribute () == " @Sendable" ) {
1806- type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1807- return extInfo.withConcurrent ();
1808- });
1789+ // Map @Sendable.
1790+ if (swiftAttr->getAttribute () == " @Sendable" ) {
1791+ sendableRequested = true ;
1792+ continue ;
1793+ }
18091794
1810- continue ;
1795+ // Map @_nonSendable.
1796+ if (swiftAttr->getAttribute () == " @_nonSendable" ) {
1797+ sendableDisqualified = true ;
1798+ continue ;
1799+ }
18111800 }
18121801 }
18131802
1803+ if (!sendableDisqualified && sendableRequested) {
1804+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1805+ return extInfo.withConcurrent ();
1806+ });
1807+ }
1808+
18141809 return type;
18151810}
18161811
@@ -2015,7 +2010,7 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
20152010
20162011 // Apply attributes to the type.
20172012 swiftParamTy = applyParamAttributes (
2018- param, swiftParamTy);
2013+ param, swiftParamTy, /* sendableByDefault= */ false );
20192014
20202015 // Figure out the name for this parameter.
20212016 Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2401,6 +2396,10 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
24012396 Optional<ForeignErrorConvention::Info> errorInfo =
24022397 importedName.getErrorInfo ();
24032398 auto asyncInfo = importedName.getAsyncInfo ();
2399+ bool isAsync = asyncInfo.hasValue ();
2400+ if (!isAsync)
2401+ asyncInfo = importedName.getAsyncAlternateInfo ();
2402+
24042403 OptionalTypeKind OptionalityOfReturn;
24052404 if (clangDecl->hasAttr <clang::ReturnsNonNullAttr>()) {
24062405 OptionalityOfReturn = OTK_None;
@@ -2547,7 +2546,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25472546 // Figure out if this is a completion handler parameter whose error
25482547 // parameter is used to indicate throwing.
25492548 Optional<unsigned > completionHandlerErrorParamIndex;
2550- if (paramIsCompletionHandler) {
2549+ if (isAsync && paramIsCompletionHandler) {
25512550 completionHandlerErrorParamIndex =
25522551 asyncInfo->completionHandlerErrorParamIndex ();
25532552 }
@@ -2592,7 +2591,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25922591
25932592 // If this is a completion handler, figure out it's effect on the result
25942593 // type but don't build it into the parameter type.
2595- if (paramIsCompletionHandler) {
2594+ if (isAsync && paramIsCompletionHandler) {
25962595 if (Type replacedSwiftResultTy =
25972596 decomposeCompletionHandlerType (swiftParamTy, *asyncInfo)) {
25982597 swiftResultTy = replacedSwiftResultTy;
@@ -2611,7 +2610,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
26112610 }
26122611
26132612 // Apply Clang attributes to the parameter type.
2614- swiftParamTy = applyParamAttributes (param, swiftParamTy);
2613+ swiftParamTy = applyParamAttributes (param, swiftParamTy,
2614+ /* sendableByDefault=*/ paramIsCompletionHandler);
26152615
26162616 // Figure out the name for this parameter.
26172617 Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2686,7 +2686,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
26862686 swiftResultTy = SwiftContext.getNeverType ();
26872687 }
26882688
2689- if (asyncInfo ) {
2689+ if (isAsync ) {
26902690 asyncConvention = ForeignAsyncConvention (
26912691 completionHandlerType, asyncInfo->completionHandlerParamIndex (),
26922692 asyncInfo->completionHandlerErrorParamIndex (),
0 commit comments