Skip to content

Commit 86730ca

Browse files
committed
[Interop] Handle existential types in ClangTypeConverter and
the ClangImporter.
1 parent f6f53f6 commit 86730ca

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

lib/AST/ClangTypeConverter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ ClangTypeConverter::visitProtocolCompositionType(ProtocolCompositionType *type)
750750
return clangCtx.getObjCObjectPointerType(clangType);
751751
}
752752

753+
clang::QualType
754+
ClangTypeConverter::visitExistentialType(ExistentialType *type) {
755+
return visit(type->getConstraintType());
756+
}
757+
753758
clang::QualType
754759
ClangTypeConverter::visitBuiltinRawPointerType(BuiltinRawPointerType *type) {
755760
return ClangASTContext.VoidPtrTy;
@@ -828,6 +833,9 @@ clang::QualType ClangTypeConverter::convert(Type type) {
828833
return it->second;
829834

830835
// Try to do this without making cache entries for obvious cases.
836+
if (auto existential = type->getAs<ExistentialType>())
837+
type = existential->getConstraintType();
838+
831839
if (auto nominal = type->getAs<NominalType>()) {
832840
auto decl = nominal->getDecl();
833841
if (auto clangDecl = decl->getClangDecl()) {

lib/AST/ClangTypeConverter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ClangTypeConverter :
122122
clang::QualType visitEnumType(EnumType *type);
123123
clang::QualType visitFunctionType(FunctionType *type);
124124
clang::QualType visitProtocolCompositionType(ProtocolCompositionType *type);
125+
clang::QualType visitExistentialType(ExistentialType *type);
125126
clang::QualType visitBuiltinRawPointerType(BuiltinRawPointerType *type);
126127
clang::QualType visitBuiltinIntegerType(BuiltinIntegerType *type);
127128
clang::QualType visitBuiltinFloatType(BuiltinFloatType *type);

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6244,6 +6244,9 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
62446244
// Local function to add a known protocol only when the
62456245
// underlying type conforms to it.
62466246
auto computedNominal = computedPropertyUnderlyingType->getAnyNominal();
6247+
if (auto existential =
6248+
computedPropertyUnderlyingType->getAs<ExistentialType>())
6249+
computedNominal = existential->getConstraintType()->getAnyNominal();
62476250
auto transferKnown = [&](KnownProtocolKind kind) {
62486251
if (!computedNominal)
62496252
return false;

lib/ClangImporter/ImportType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,10 @@ namespace {
11831183
}
11841184
}
11851185

1186+
if (bridgedType->isConstraintType() &&
1187+
Impl.SwiftContext.LangOpts.EnableExplicitExistentialTypes)
1188+
bridgedType = ExistentialType::get(bridgedType);
1189+
11861190
return { importedType,
11871191
ImportHint(ImportHint::ObjCBridged, bridgedType) };
11881192
}
@@ -2505,6 +2509,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
25052509
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
25062510
paramTy->isObjCIdType()) {
25072511
swiftParamTy = SwiftContext.getNSCopyingType();
2512+
if (SwiftContext.LangOpts.EnableExplicitExistentialTypes)
2513+
swiftParamTy = ExistentialType::get(swiftParamTy);
25082514
if (!swiftParamTy)
25092515
return {Type(), false};
25102516
if (optionalityOfParam != OTK_None)

0 commit comments

Comments
 (0)