@@ -1725,63 +1725,58 @@ ImportedType ClangImporter::Implementation::importPropertyType(
17251725 Bridgeability::Full, optionality);
17261726}
17271727
1728- // / Apply an attribute to a function type.
1729- static Type applyToFunctionType (
1730- Type type, llvm::function_ref<ASTExtInfo(ASTExtInfo)> transform) {
1731- // Recurse into optional types.
1732- if (Type objectType = type->getOptionalObjectType ()) {
1733- return OptionalType::get (applyToFunctionType (objectType, transform));
1734- }
1735-
1736- // Apply @noescape to function types.
1737- if (auto funcType = type->getAs <FunctionType>()) {
1738- return FunctionType::get (funcType->getParams (), funcType->getResult (),
1739- transform (funcType->getExtInfo ()));
1740- }
1741-
1742- return type;
1743- }
1744-
17451728Type ClangImporter::Implementation::applyParamAttributes (
1746- const clang::ParmVarDecl *param, Type type) {
1747- if (!param->hasAttrs ())
1748- return type;
1729+ const clang::ParmVarDecl *param, Type type, bool sendableByDefault) {
1730+ bool sendableRequested = sendableByDefault;
1731+ bool sendableDisqualified = false ;
1732+
1733+ if (param->hasAttrs ()) {
1734+ for (auto attr : param->getAttrs ()) {
1735+ // Map __attribute__((noescape)) to @noescape.
1736+ if (isa<clang::NoEscapeAttr>(attr)) {
1737+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1738+ return extInfo.withNoEscape ();
1739+ });
17491740
1750- for (auto attr : param->getAttrs ()) {
1751- // Map __attribute__((noescape)) to @noescape.
1752- if (isa<clang::NoEscapeAttr>(attr)) {
1753- type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1754- return extInfo.withNoEscape ();
1755- });
1741+ continue ;
1742+ }
17561743
1757- continue ;
1758- }
1744+ auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
1745+ if (!swiftAttr)
1746+ continue ;
17591747
1760- auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
1761- if (!swiftAttr)
1762- continue ;
1748+ // Map the main-actor attribute.
1749+ if (isMainActorAttr (swiftAttr)) {
1750+ if (Type mainActor = SwiftContext.getMainActorType ()) {
1751+ type = applyToFunctionType (type, [&](ASTExtInfo extInfo) {
1752+ return extInfo.withGlobalActor (mainActor);
1753+ });
1754+ sendableDisqualified = true ;
1755+ }
17631756
1764- // Map the main-actor attribute.
1765- if (isMainActorAttr (swiftAttr)) {
1766- if (Type mainActor = SwiftContext.getMainActorType ()) {
1767- type = applyToFunctionType (type, [&](ASTExtInfo extInfo) {
1768- return extInfo.withGlobalActor (mainActor);
1769- });
1757+ continue ;
17701758 }
17711759
1772- continue ;
1773- }
1774-
1775- // Map @Sendable.
1776- if (swiftAttr->getAttribute () == " @Sendable" ) {
1777- type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1778- return extInfo.withConcurrent ();
1779- });
1760+ // Map @Sendable.
1761+ if (swiftAttr->getAttribute () == " @Sendable" ) {
1762+ sendableRequested = true ;
1763+ continue ;
1764+ }
17801765
1781- continue ;
1766+ // Map @_nonSendable.
1767+ if (swiftAttr->getAttribute () == " @_nonSendable" ) {
1768+ sendableDisqualified = true ;
1769+ continue ;
1770+ }
17821771 }
17831772 }
17841773
1774+ if (!sendableDisqualified && sendableRequested) {
1775+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1776+ return extInfo.withConcurrent ();
1777+ });
1778+ }
1779+
17851780 return type;
17861781}
17871782
@@ -1986,7 +1981,7 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
19861981
19871982 // Apply attributes to the type.
19881983 swiftParamTy = applyParamAttributes (
1989- param, swiftParamTy);
1984+ param, swiftParamTy, /* sendableByDefault= */ false );
19901985
19911986 // Figure out the name for this parameter.
19921987 Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2372,6 +2367,10 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
23722367 Optional<ForeignErrorConvention::Info> errorInfo =
23732368 importedName.getErrorInfo ();
23742369 auto asyncInfo = importedName.getAsyncInfo ();
2370+ bool isAsync = asyncInfo.hasValue ();
2371+ if (!isAsync)
2372+ asyncInfo = importedName.getAsyncAlternateInfo ();
2373+
23752374 OptionalTypeKind OptionalityOfReturn;
23762375 if (clangDecl->hasAttr <clang::ReturnsNonNullAttr>()) {
23772376 OptionalityOfReturn = OTK_None;
@@ -2518,7 +2517,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25182517 // Figure out if this is a completion handler parameter whose error
25192518 // parameter is used to indicate throwing.
25202519 Optional<unsigned > completionHandlerErrorParamIndex;
2521- if (paramIsCompletionHandler) {
2520+ if (isAsync && paramIsCompletionHandler) {
25222521 completionHandlerErrorParamIndex =
25232522 asyncInfo->completionHandlerErrorParamIndex ();
25242523 }
@@ -2563,7 +2562,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25632562
25642563 // If this is a completion handler, figure out it's effect on the result
25652564 // type but don't build it into the parameter type.
2566- if (paramIsCompletionHandler) {
2565+ if (isAsync && paramIsCompletionHandler) {
25672566 if (Type replacedSwiftResultTy =
25682567 decomposeCompletionHandlerType (swiftParamTy, *asyncInfo)) {
25692568 swiftResultTy = replacedSwiftResultTy;
@@ -2582,7 +2581,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25822581 }
25832582
25842583 // Apply Clang attributes to the parameter type.
2585- swiftParamTy = applyParamAttributes (param, swiftParamTy);
2584+ swiftParamTy = applyParamAttributes (param, swiftParamTy,
2585+ /* sendableByDefault=*/ paramIsCompletionHandler);
25862586
25872587 // Figure out the name for this parameter.
25882588 Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2657,7 +2657,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
26572657 swiftResultTy = SwiftContext.getNeverType ();
26582658 }
26592659
2660- if (asyncInfo ) {
2660+ if (isAsync ) {
26612661 asyncConvention = ForeignAsyncConvention (
26622662 completionHandlerType, asyncInfo->completionHandlerParamIndex (),
26632663 asyncInfo->completionHandlerErrorParamIndex (),
0 commit comments