Skip to content

Commit 78ac825

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

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
@@ -603,8 +603,8 @@ class ClangImporter final : public ClangModuleLoader {
603603
/// Enable the symbolic import experimental feature for the given callback.
604604
void withSymbolicFeatureEnabled(llvm::function_ref<void(void)> callback);
605605

606-
static const clang::TypedefType *getTypedefForCXXCFOptionsDefinition(
607-
const clang::Decl *candidateDecl, const ASTContext &ctx);
606+
const clang::TypedefType *getTypeDefForCXXCFOptionsDefinition(
607+
const clang::Decl *candidateDecl) override;
608608

609609
SourceLoc importSourceLocation(clang::SourceLocation loc) override;
610610
};

lib/AST/ASTMangler.cpp

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

2544-
auto &ctx = decl->getASTContext();
2545-
return ClangImporter::getTypedefForCXXCFOptionsDefinition(clangDecl, ctx);
2544+
const auto &clangModuleLoader = decl->getASTContext().getClangModuleLoader();
2545+
return clangModuleLoader->getTypeDefForCXXCFOptionsDefinition(clangDecl);
25462546
}
25472547

25482548
const clang::NamedDecl *

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7023,23 +7023,26 @@ void ClangImporter::withSymbolicFeatureEnabled(
70237023
oldImportSymbolicCXXDecls.get());
70247024
}
70257025

7026-
const clang::TypedefType *ClangImporter::getTypedefForCXXCFOptionsDefinition(
7027-
const clang::Decl *candidateDecl, const ASTContext &ctx) {
7028-
if (!ctx.LangOpts.EnableCXXInterop)
7026+
const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
7027+
const clang::Decl *candidateDecl) {
7028+
7029+
if (!Impl.SwiftContext.LangOpts.EnableCXXInterop)
70297030
return nullptr;
70307031

70317032
auto enumDecl = dyn_cast<clang::EnumDecl>(candidateDecl);
70327033
if (!enumDecl)
70337034
return nullptr;
7035+
70347036
if (!enumDecl->getDeclName().isEmpty())
70357037
return nullptr;
70367038

70377039
const clang::ElaboratedType *elaboratedType =
7038-
enumDecl->getIntegerType()->getAs<clang::ElaboratedType>();
7040+
dyn_cast<clang::ElaboratedType>(enumDecl->getIntegerType().getTypePtr());
70397041
if (auto typedefType =
70407042
elaboratedType
70417043
? dyn_cast<clang::TypedefType>(elaboratedType->desugar())
7042-
: enumDecl->getIntegerType()->getAs<clang::TypedefType>()) {
7044+
: dyn_cast<clang::TypedefType>(
7045+
enumDecl->getIntegerType().getTypePtr())) {
70437046
auto enumExtensibilityAttr =
70447047
elaboratedType
70457048
? enumDecl->getAttr<clang::EnumExtensibilityAttr>()
@@ -7052,13 +7055,8 @@ const clang::TypedefType *ClangImporter::getTypedefForCXXCFOptionsDefinition(
70527055
enumExtensibilityAttr->getExtensibility() ==
70537056
clang::EnumExtensibilityAttr::Open &&
70547057
hasFlagEnumAttr) {
7055-
// Make sure the typedef is marked as unavailable in Swift.
7056-
auto typedefDecl = typedefType->getDecl();
7057-
for (auto *attr :
7058-
typedefDecl->specific_attrs<clang::AvailabilityAttr>()) {
7059-
if (attr->getPlatform()->getName() == "swift")
7060-
return typedefType;
7061-
}
7058+
return Impl.isUnavailableInSwift(typedefType->getDecl()) ? typedefType
7059+
: nullptr;
70627060
}
70637061
}
70647062

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,8 +2656,9 @@ ArgumentAttrs ClangImporter::Implementation::inferDefaultArgument(
26562656
if (declIter != declsInContext.end()) {
26572657
if (auto enumDecl = dyn_cast<clang::EnumDecl>(*declIter)) {
26582658
if (auto cfOptionsTy =
2659-
ClangImporter::getTypedefForCXXCFOptionsDefinition(
2660-
enumDecl, nameImporter.getContext())) {
2659+
nameImporter.getContext()
2660+
.getClangModuleLoader()
2661+
->getTypeDefForCXXCFOptionsDefinition(enumDecl)) {
26612662
if (cfOptionsTy->getDecl() == typedefDecl) {
26622663
auto enumName = typedefDecl->getName();
26632664
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)