@@ -1693,17 +1693,61 @@ ImportedType ClangImporter::Implementation::importPropertyType(
1693
1693
Bridgeability::Full, optionality);
1694
1694
}
1695
1695
1696
- // / Apply the @noescape attribute
1697
- static Type applyNoEscape (Type type) {
1696
+ // / Apply an attribute to a function type.
1697
+ static Type applyToFunctionType (
1698
+ Type type, llvm::function_ref<ASTExtInfo(ASTExtInfo)> transform) {
1698
1699
// Recurse into optional types.
1699
1700
if (Type objectType = type->getOptionalObjectType ()) {
1700
- return OptionalType::get (applyNoEscape (objectType));
1701
+ return OptionalType::get (applyToFunctionType (objectType, transform ));
1701
1702
}
1702
1703
1703
1704
// Apply @noescape to function types.
1704
1705
if (auto funcType = type->getAs <FunctionType>()) {
1705
1706
return FunctionType::get (funcType->getParams (), funcType->getResult (),
1706
- funcType->getExtInfo ().withNoEscape ());
1707
+ transform (funcType->getExtInfo ()));
1708
+ }
1709
+
1710
+ return type;
1711
+ }
1712
+
1713
+ Type ClangImporter::Implementation::applyParamAttributes (
1714
+ const clang::ParmVarDecl *param, Type type) {
1715
+ if (!param->hasAttrs ())
1716
+ return type;
1717
+
1718
+ for (auto attr : param->getAttrs ()) {
1719
+ // Map __attribute__((noescape)) to @noescape.
1720
+ if (isa<clang::NoEscapeAttr>(attr)) {
1721
+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1722
+ return extInfo.withNoEscape ();
1723
+ });
1724
+
1725
+ continue ;
1726
+ }
1727
+
1728
+ auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
1729
+ if (!swiftAttr)
1730
+ continue ;
1731
+
1732
+ // Map the main-actor attribute.
1733
+ if (isMainActorAttr (SwiftContext, swiftAttr)) {
1734
+ if (Type mainActor = getMainActorType ()) {
1735
+ type = applyToFunctionType (type, [&](ASTExtInfo extInfo) {
1736
+ return extInfo.withGlobalActor (mainActor);
1737
+ });
1738
+ }
1739
+
1740
+ continue ;
1741
+ }
1742
+
1743
+ // Map @Sendable.
1744
+ if (swiftAttr->getAttribute () == " @Sendable" ) {
1745
+ type = applyToFunctionType (type, [](ASTExtInfo extInfo) {
1746
+ return extInfo.withConcurrent ();
1747
+ });
1748
+
1749
+ continue ;
1750
+ }
1707
1751
}
1708
1752
1709
1753
return type;
@@ -1883,13 +1927,8 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
1883
1927
swiftParamTy = importedType.getType ();
1884
1928
}
1885
1929
1886
- // Map __attribute__((noescape)) to @noescape.
1887
- if (param->hasAttr <clang::NoEscapeAttr>()) {
1888
- Type newParamTy = applyNoEscape (swiftParamTy);
1889
- if (newParamTy.getPointer () != swiftParamTy.getPointer ()) {
1890
- swiftParamTy = newParamTy;
1891
- }
1892
- }
1930
+ // Apply attributes to the type.
1931
+ swiftParamTy = applyParamAttributes (param, swiftParamTy);
1893
1932
1894
1933
// Figure out the name for this parameter.
1895
1934
Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2384,15 +2423,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2384
2423
llvm_unreachable (" async info computed incorrectly?" );
2385
2424
}
2386
2425
2387
- // Map __attribute__((noescape)) to @noescape.
2388
- bool addNoEscapeAttr = false ;
2389
- if (param->hasAttr <clang::NoEscapeAttr>()) {
2390
- Type newParamTy = applyNoEscape (swiftParamTy);
2391
- if (newParamTy.getPointer () != swiftParamTy.getPointer ()) {
2392
- swiftParamTy = newParamTy;
2393
- addNoEscapeAttr = true ;
2394
- }
2395
- }
2426
+ // Apply Clang attributes to the parameter type.
2427
+ swiftParamTy = applyParamAttributes (param, swiftParamTy);
2396
2428
2397
2429
// Figure out the name for this parameter.
2398
2430
Identifier bodyName = importFullName (param, CurrentVersion)
0 commit comments