@@ -1695,26 +1695,50 @@ ImportedType ClangImporter::Implementation::importPropertyType(
1695
1695
1696
1696
// / Apply an attribute to a function type.
1697
1697
static Type applyToFunctionType (
1698
- Type type, llvm::function_ref<Type(FunctionType * )> transform) {
1698
+ Type type, llvm::function_ref<ASTExtInfo(ASTExtInfo )> transform) {
1699
1699
// Recurse into optional types.
1700
1700
if (Type objectType = type->getOptionalObjectType ()) {
1701
1701
return OptionalType::get (applyToFunctionType (objectType, transform));
1702
1702
}
1703
1703
1704
1704
// Apply @noescape to function types.
1705
- if (auto funcType = type->getAs <FunctionType>())
1706
- return transform (funcType);
1705
+ if (auto funcType = type->getAs <FunctionType>()) {
1706
+ return FunctionType::get (funcType->getParams (), funcType->getResult (),
1707
+ transform (funcType->getExtInfo ()));
1708
+ }
1707
1709
1708
1710
return type;
1709
1711
}
1710
1712
1711
- static Type applyParamAttributes (const clang::ParmVarDecl *param, Type type) {
1712
- // Map __attribute__((noescape)) to @noescape.
1713
- if (param->hasAttr <clang::NoEscapeAttr>()) {
1714
- type = applyToFunctionType (type, [](FunctionType *funcType) {
1715
- return FunctionType::get (funcType->getParams (), funcType->getResult (),
1716
- funcType->getExtInfo ().withNoEscape ());
1717
- });
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
+ }
1718
1742
}
1719
1743
1720
1744
return type;
0 commit comments