@@ -1693,17 +1693,28 @@ 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<Type(FunctionType *)> 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
- if (auto funcType = type->getAs <FunctionType>()) {
1705
- return FunctionType::get (funcType->getParams (), funcType->getResult (),
1706
- funcType->getExtInfo ().withNoEscape ());
1705
+ if (auto funcType = type->getAs <FunctionType>())
1706
+ return transform (funcType);
1707
+
1708
+ return type;
1709
+ }
1710
+
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
+ });
1707
1718
}
1708
1719
1709
1720
return type;
@@ -1883,13 +1894,8 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
1883
1894
swiftParamTy = importedType.getType ();
1884
1895
}
1885
1896
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
- }
1897
+ // Apply attributes to the type.
1898
+ swiftParamTy = applyParamAttributes (param, swiftParamTy);
1893
1899
1894
1900
// Figure out the name for this parameter.
1895
1901
Identifier bodyName = importFullName (param, CurrentVersion)
@@ -2384,15 +2390,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
2384
2390
llvm_unreachable (" async info computed incorrectly?" );
2385
2391
}
2386
2392
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
- }
2393
+ // Apply Clang attributes to the parameter type.
2394
+ swiftParamTy = applyParamAttributes (param, swiftParamTy);
2396
2395
2397
2396
// Figure out the name for this parameter.
2398
2397
Identifier bodyName = importFullName (param, CurrentVersion)
0 commit comments