Skip to content

Commit 578f82f

Browse files
committed
[ClangImporter] Introduce a new kind of parameter - completion handler
1 parent 41ef9b6 commit 578f82f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
12821282
case ImportTypeKind::Result:
12831283
case ImportTypeKind::AuditedResult:
12841284
case ImportTypeKind::Parameter:
1285+
case ImportTypeKind::CompletionHandlerParameter:
12851286
case ImportTypeKind::CompletionHandlerResultParameter:
12861287
case ImportTypeKind::Property:
12871288
case ImportTypeKind::PropertyWithReferenceSemantics:
@@ -1308,6 +1309,7 @@ static bool isCFAudited(ImportTypeKind importKind) {
13081309
case ImportTypeKind::AuditedVariable:
13091310
case ImportTypeKind::AuditedResult:
13101311
case ImportTypeKind::Parameter:
1312+
case ImportTypeKind::CompletionHandlerParameter:
13111313
case ImportTypeKind::CompletionHandlerResultParameter:
13121314
case ImportTypeKind::Property:
13131315
case ImportTypeKind::PropertyWithReferenceSemantics:
@@ -2299,11 +2301,6 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
22992301
return {swiftResultTy, importedType.isImplicitlyUnwrapped()};
23002302
}
23012303

2302-
static ImportTypeKind
2303-
getImportTypeKindForParam(const clang::ParmVarDecl *param) {
2304-
return ImportTypeKind::Parameter;
2305-
}
2306-
23072304
llvm::Optional<ClangImporter::Implementation::ImportParameterTypeResult>
23082305
ClangImporter::Implementation::importParameterType(
23092306
const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
@@ -2316,7 +2313,9 @@ ClangImporter::Implementation::importParameterType(
23162313
if (auto elaborated = dyn_cast<clang::ElaboratedType>(paramTy))
23172314
paramTy = elaborated->desugar();
23182315

2319-
ImportTypeKind importKind = getImportTypeKindForParam(param);
2316+
ImportTypeKind importKind = paramIsCompletionHandler
2317+
? ImportTypeKind::CompletionHandlerParameter
2318+
: ImportTypeKind::Parameter;
23202319

23212320
// Import the parameter type into Swift.
23222321
auto attrs = getImportTypeAttrs(param, /*isParam=*/true);
@@ -3204,17 +3203,16 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
32043203
decomposeCompletionHandlerType(swiftParamTy, *asyncInfo)) {
32053204
swiftResultTy = replacedSwiftResultTy;
32063205

3207-
ImportTypeKind importKind = getImportTypeKindForParam(param);
3208-
32093206
// Import the original completion handler type without adjustments.
32103207
Type origSwiftParamTy =
3211-
importType(paramTy, importKind, paramAddDiag,
3212-
allowNSUIntegerAsIntInParam, Bridgeability::Full,
3213-
ImportTypeAttrs(), optionalityOfParam,
3208+
importType(paramTy, ImportTypeKind::CompletionHandlerParameter,
3209+
paramAddDiag, allowNSUIntegerAsIntInParam,
3210+
Bridgeability::Full, ImportTypeAttrs(),
3211+
optionalityOfParam,
32143212
/*resugarNSErrorPointer=*/!paramIsError, llvm::None)
32153213
.getType();
3216-
completionHandlerType = mapGenericArgs(origDC, dc, origSwiftParamTy)
3217-
->getCanonicalType();
3214+
completionHandlerType =
3215+
mapGenericArgs(origDC, dc, origSwiftParamTy)->getCanonicalType();
32183216
continue;
32193217
}
32203218

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ enum class ImportTypeKind {
150150
/// Parameters are always considered CF-audited.
151151
Parameter,
152152

153+
/// Import the type of a special "completion handler" function parameter.
154+
CompletionHandlerParameter,
155+
153156
/// Import the type of a parameter to a completion handler that can indicate
154157
/// a thrown error.
155158
///

0 commit comments

Comments
 (0)