Skip to content

Commit 301ef41

Browse files
committed
Revert "[cxx-interop] Refactor: do not rely on Clang module importer being available"
This reverts commit 6a2f10a.
1 parent 102c60b commit 301ef41

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class ClangModuleLoader : public ModuleLoader {
306306
virtual EffectiveClangContext getEffectiveClangContext(
307307
const NominalTypeDecl *nominal) = 0;
308308

309+
virtual const clang::TypedefType *
310+
getTypeDefForCXXCFOptionsDefinition(const clang::Decl *candidateDecl) = 0;
311+
309312
virtual SourceLoc importSourceLocation(clang::SourceLocation loc) = 0;
310313
};
311314

include/swift/ClangImporter/ClangImporter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ class ClangImporter final : public ClangModuleLoader {
592592
/// Enable the symbolic import experimental feature for the given callback.
593593
void withSymbolicFeatureEnabled(llvm::function_ref<void(void)> callback);
594594

595-
static const clang::TypedefType *getTypedefForCXXCFOptionsDefinition(
596-
const clang::Decl *candidateDecl, const ASTContext &ctx);
595+
const clang::TypedefType *getTypeDefForCXXCFOptionsDefinition(
596+
const clang::Decl *candidateDecl) override;
597597

598598
SourceLoc importSourceLocation(clang::SourceLocation loc) override;
599599
};

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,8 +2551,8 @@ ASTMangler::getTypeDefForCXXCFOptionsDefinition(const ValueDecl *decl) {
25512551
if (!clangDecl)
25522552
return nullptr;
25532553

2554-
auto &ctx = decl->getASTContext();
2555-
return ClangImporter::getTypedefForCXXCFOptionsDefinition(clangDecl, ctx);
2554+
const auto &clangModuleLoader = decl->getASTContext().getClangModuleLoader();
2555+
return clangModuleLoader->getTypeDefForCXXCFOptionsDefinition(clangDecl);
25562556
}
25572557

25582558
const clang::NamedDecl *

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,23 +6958,26 @@ void ClangImporter::withSymbolicFeatureEnabled(
69586958
oldImportSymbolicCXXDecls.get());
69596959
}
69606960

6961-
const clang::TypedefType *ClangImporter::getTypedefForCXXCFOptionsDefinition(
6962-
const clang::Decl *candidateDecl, const ASTContext &ctx) {
6963-
if (!ctx.LangOpts.EnableCXXInterop)
6961+
const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
6962+
const clang::Decl *candidateDecl) {
6963+
6964+
if (!Impl.SwiftContext.LangOpts.EnableCXXInterop)
69646965
return nullptr;
69656966

69666967
auto enumDecl = dyn_cast<clang::EnumDecl>(candidateDecl);
69676968
if (!enumDecl)
69686969
return nullptr;
6970+
69696971
if (!enumDecl->getDeclName().isEmpty())
69706972
return nullptr;
69716973

69726974
const clang::ElaboratedType *elaboratedType =
6973-
enumDecl->getIntegerType()->getAs<clang::ElaboratedType>();
6975+
dyn_cast<clang::ElaboratedType>(enumDecl->getIntegerType().getTypePtr());
69746976
if (auto typedefType =
69756977
elaboratedType
69766978
? dyn_cast<clang::TypedefType>(elaboratedType->desugar())
6977-
: enumDecl->getIntegerType()->getAs<clang::TypedefType>()) {
6979+
: dyn_cast<clang::TypedefType>(
6980+
enumDecl->getIntegerType().getTypePtr())) {
69786981
auto enumExtensibilityAttr =
69796982
elaboratedType
69806983
? enumDecl->getAttr<clang::EnumExtensibilityAttr>()
@@ -6987,13 +6990,8 @@ const clang::TypedefType *ClangImporter::getTypedefForCXXCFOptionsDefinition(
69876990
enumExtensibilityAttr->getExtensibility() ==
69886991
clang::EnumExtensibilityAttr::Open &&
69896992
hasFlagEnumAttr) {
6990-
// Make sure the typedef is marked as unavailable in Swift.
6991-
auto typedefDecl = typedefType->getDecl();
6992-
for (auto *attr :
6993-
typedefDecl->specific_attrs<clang::AvailabilityAttr>()) {
6994-
if (attr->getPlatform()->getName() == "swift")
6995-
return typedefType;
6996-
}
6993+
return Impl.isUnavailableInSwift(typedefType->getDecl()) ? typedefType
6994+
: nullptr;
69976995
}
69986996
}
69996997

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,8 +2652,9 @@ ArgumentAttrs ClangImporter::Implementation::inferDefaultArgument(
26522652
if (declIter != declsInContext.end()) {
26532653
if (auto enumDecl = dyn_cast<clang::EnumDecl>(*declIter)) {
26542654
if (auto cfOptionsTy =
2655-
ClangImporter::getTypedefForCXXCFOptionsDefinition(
2656-
enumDecl, nameImporter.getContext())) {
2655+
nameImporter.getContext()
2656+
.getClangModuleLoader()
2657+
->getTypeDefForCXXCFOptionsDefinition(enumDecl)) {
26572658
if (cfOptionsTy->getDecl() == typedefDecl) {
26582659
auto enumName = typedefDecl->getName();
26592660
ArgumentAttrs argumentAttrs(DefaultArgumentKind::None, true,
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
// RUN: rm -rf %t
2-
// RUN: mkdir -p %t/pch
3-
41
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -enable-objc-interop -enable-experimental-cxx-interop
5-
6-
// RUN: %target-swift-frontend -emit-pch -enable-objc-interop -enable-experimental-cxx-interop -o %t/pch/customNSOptions.pch %S/Inputs/customNSOptions.h
7-
// RUN: %target-typecheck-verify-swift -D BRIDGING_HEADER -I %S/Inputs -import-objc-header %t/pch/customNSOptions.pch -enable-objc-interop -enable-experimental-cxx-interop %s
8-
92
// REQUIRES: objc_interop
103

11-
#if !BRIDGING_HEADER
124
import CustomNSOptions
13-
#endif
145

156
let flags1: MyControlFlags = []
167
let flags2: MyControlFlags = [.first]

0 commit comments

Comments
 (0)