Skip to content

Commit b51cfa5

Browse files
committed
[cxx-interop] Remove symbolic import mode
Importing C++ class templates in symbolic mode has proven to be problematic in interaction with other compiler features, and it isn't used widely. This change removes the feature. rdar://150528798
1 parent 9de2419 commit b51cfa5

20 files changed

+14
-857
lines changed

include/swift/Basic/Features.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,6 @@ EXPERIMENTAL_FEATURE(ParserASTGen, false)
376376
/// corresponding syntax tree.
377377
EXPERIMENTAL_FEATURE(BuiltinMacros, false)
378378

379-
/// Import C++ class templates as semantically-meaningless symbolic
380-
/// Swift types and C++ methods as symbolic functions with blank
381-
/// signatures.
382-
EXPERIMENTAL_FEATURE(ImportSymbolicCXXDecls, false)
383-
384379
/// Generate bindings for functions that 'throw' in the C++ section of the generated Clang header.
385380
EXPERIMENTAL_FEATURE(GenerateBindingsForThrowingFunctionsInCXX, false)
386381

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,6 @@ class ClangImporter final : public ClangModuleLoader {
690690
/// of the provided baseType.
691691
void diagnoseMemberValue(const DeclName &name, const Type &baseType) override;
692692

693-
/// Enable the symbolic import experimental feature for the given callback.
694-
void withSymbolicFeatureEnabled(llvm::function_ref<void(void)> callback);
695-
696-
/// Returns true when the symbolic import experimental feature is enabled.
697-
bool isSymbolicImportEnabled() const;
698-
699693
const clang::TypedefType *getTypeDefForCXXCFOptionsDefinition(
700694
const clang::Decl *candidateDecl) override;
701695

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ UNINTERESTING_FEATURE(UnqualifiedLookupValidation)
109109
UNINTERESTING_FEATURE(ImplicitSome)
110110
UNINTERESTING_FEATURE(ParserASTGen)
111111
UNINTERESTING_FEATURE(BuiltinMacros)
112-
UNINTERESTING_FEATURE(ImportSymbolicCXXDecls)
113112
UNINTERESTING_FEATURE(GenerateBindingsForThrowingFunctionsInCXX)
114113
UNINTERESTING_FEATURE(ReferenceBindings)
115114
UNINTERESTING_FEATURE(BuiltinModule)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,8 +2726,6 @@ ClangImporter::Implementation::Implementation(
27262726
DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules),
27272727
EnableClangSPI(ctx.ClangImporterOpts.EnableClangSPI),
27282728
UseClangIncludeTree(ctx.ClangImporterOpts.UseClangIncludeTree),
2729-
importSymbolicCXXDecls(
2730-
ctx.LangOpts.hasFeature(Feature::ImportSymbolicCXXDecls)),
27312729
IsReadingBridgingPCH(false),
27322730
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
27332731
Walker(DiagnosticWalker(*this)), BuffersForDiagnostics(ctx.SourceMgr),
@@ -8569,23 +8567,6 @@ bool ClangDeclExplicitSafety::isCached() const {
85698567
return isa<clang::RecordDecl>(std::get<0>(getStorage()).decl);
85708568
}
85718569

8572-
void ClangImporter::withSymbolicFeatureEnabled(
8573-
llvm::function_ref<void(void)> callback) {
8574-
llvm::SaveAndRestore<bool> oldImportSymbolicCXXDecls(
8575-
Impl.importSymbolicCXXDecls, true);
8576-
Impl.nameImporter->enableSymbolicImportFeature(true);
8577-
auto importedDeclsCopy = Impl.ImportedDecls;
8578-
Impl.ImportedDecls.clear();
8579-
callback();
8580-
Impl.ImportedDecls = std::move(importedDeclsCopy);
8581-
Impl.nameImporter->enableSymbolicImportFeature(
8582-
oldImportSymbolicCXXDecls.get());
8583-
}
8584-
8585-
bool ClangImporter::isSymbolicImportEnabled() const {
8586-
return Impl.importSymbolicCXXDecls;
8587-
}
8588-
85898570
const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
85908571
const clang::Decl *candidateDecl) {
85918572

lib/ClangImporter/ImportDecl.cpp

Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,8 +2141,7 @@ namespace {
21412141
}
21422142

21432143
// TODO(https://github.com/apple/swift/issues/56206): Fix this once we support dependent types.
2144-
if (decl->getTypeForDecl()->isDependentType() &&
2145-
!Impl.importSymbolicCXXDecls) {
2144+
if (decl->getTypeForDecl()->isDependentType()) {
21462145
Impl.addImportDiagnostic(
21472146
decl, Diagnostic(
21482147
diag::record_is_dependent,
@@ -3068,11 +3067,8 @@ namespace {
30683067
auto semanticsKind = evaluateOrDefault(
30693068
Impl.SwiftContext.evaluator,
30703069
CxxRecordSemantics({decl, Impl.SwiftContext, &Impl}), {});
3071-
if ((semanticsKind == CxxRecordSemanticsKind::MissingLifetimeOperation ||
3072-
semanticsKind == CxxRecordSemanticsKind::UnavailableConstructors) &&
3073-
// Let un-specialized class templates through. We'll sort out their
3074-
// members once they're instantiated.
3075-
!Impl.importSymbolicCXXDecls) {
3070+
if (semanticsKind == CxxRecordSemanticsKind::MissingLifetimeOperation ||
3071+
semanticsKind == CxxRecordSemanticsKind::UnavailableConstructors) {
30763072

30773073
HeaderLoc loc(decl->getLocation());
30783074
if (hasUnsafeAPIAttr(decl))
@@ -3267,12 +3263,6 @@ namespace {
32673263

32683264
Decl *VisitClassTemplateSpecializationDecl(
32693265
const clang::ClassTemplateSpecializationDecl *decl) {
3270-
// Treat a specific specialization like the unspecialized class template
3271-
// when importing it in symbolic mode.
3272-
if (Impl.importSymbolicCXXDecls)
3273-
return Impl.importDecl(decl->getSpecializedTemplate(),
3274-
Impl.CurrentVersion);
3275-
32763266
bool isPair = decl->getSpecializedTemplate()->isInStdNamespace() &&
32773267
decl->getSpecializedTemplate()->getName() == "pair";
32783268

@@ -3953,8 +3943,6 @@ namespace {
39533943
Impl.SwiftContext, SourceLoc(), templateParams, SourceLoc());
39543944
}
39553945

3956-
bool importFuncWithoutSignature =
3957-
isa<clang::CXXMethodDecl>(decl) && Impl.importSymbolicCXXDecls;
39583946
if (!dc->isModuleScopeContext() && !isClangNamespace(dc) &&
39593947
!isa<clang::CXXMethodDecl>(decl)) {
39603948
// Handle initializers.
@@ -4021,39 +4009,12 @@ namespace {
40214009
importedType =
40224010
Impl.importFunctionReturnType(dc, decl, allowNSUIntegerAsInt);
40234011
} else {
4024-
if (importFuncWithoutSignature) {
4025-
importedType = ImportedType{Impl.SwiftContext.getVoidType(), false};
4026-
if (decl->param_empty())
4027-
bodyParams = ParameterList::createEmpty(Impl.SwiftContext);
4028-
else {
4029-
llvm::SmallVector<ParamDecl *, 4> params;
4030-
for (const auto &param : decl->parameters()) {
4031-
4032-
Identifier bodyName =
4033-
Impl.importFullName(param, Impl.CurrentVersion)
4034-
.getBaseIdentifier(Impl.SwiftContext);
4035-
auto paramInfo = Impl.createDeclWithClangNode<ParamDecl>(
4036-
param, AccessLevel::Private, SourceLoc(), SourceLoc(),
4037-
Identifier(), Impl.importSourceLoc(param->getLocation()),
4038-
bodyName, Impl.ImportedHeaderUnit);
4039-
paramInfo->setSpecifier(ParamSpecifier::Default);
4040-
paramInfo->setInterfaceType(Impl.SwiftContext.TheAnyType);
4041-
if (param->hasDefaultArg()) {
4042-
paramInfo->setDefaultArgumentKind(DefaultArgumentKind::Normal);
4043-
paramInfo->setDefaultValueStringRepresentation("cxxDefaultArg");
4044-
}
4045-
params.push_back(paramInfo);
4046-
}
4047-
bodyParams = ParameterList::create(Impl.SwiftContext, params);
4048-
}
4049-
} else {
4050-
// Import the function type. If we have parameters, make sure their
4051-
// names get into the resulting function type.
4052-
importedType = Impl.importFunctionParamsAndReturnType(
4053-
dc, decl, {decl->param_begin(), decl->param_size()},
4054-
decl->isVariadic(), isInSystemModule(dc), name, bodyParams,
4055-
templateParams);
4056-
}
4012+
// Import the function type. If we have parameters, make sure their
4013+
// names get into the resulting function type.
4014+
importedType = Impl.importFunctionParamsAndReturnType(
4015+
dc, decl, {decl->param_begin(), decl->param_size()},
4016+
decl->isVariadic(), isInSystemModule(dc), name, bodyParams,
4017+
templateParams);
40574018

40584019
if (auto *mdecl = dyn_cast<clang::CXXMethodDecl>(decl)) {
40594020
if (mdecl->isStatic()) {
@@ -4160,12 +4121,10 @@ namespace {
41604121
}
41614122
func->setAccess(importer::convertClangAccess(decl->getAccess()));
41624123

4163-
if (!importFuncWithoutSignature) {
4164-
bool success = processSpecialImportedFunc(
4165-
func, importedName, decl->getOverloadedOperator());
4166-
if (!success)
4167-
return nullptr;
4168-
}
4124+
bool success = processSpecialImportedFunc(
4125+
func, importedName, decl->getOverloadedOperator());
4126+
if (!success)
4127+
return nullptr;
41694128
}
41704129

41714130
result->setIsObjC(false);
@@ -4480,8 +4439,7 @@ namespace {
44804439
}
44814440

44824441
Decl *VisitFieldDecl(const clang::FieldDecl *decl) {
4483-
if (!Impl.importSymbolicCXXDecls &&
4484-
decl->hasAttr<clang::NoUniqueAddressAttr>()) {
4442+
if (decl->hasAttr<clang::NoUniqueAddressAttr>()) {
44854443
if (const auto *rd = decl->getType()->getAsRecordDecl()) {
44864444
// Clang can store the next field in the padding of this one. Swift
44874445
// does not support this yet so let's not import the field and
@@ -4743,11 +4701,6 @@ namespace {
47434701
if (name.empty())
47444702
return nullptr;
47454703

4746-
if (Impl.importSymbolicCXXDecls)
4747-
// Import an unspecialized C++ class template as a Swift value/class
4748-
// type in symbolic mode.
4749-
return Impl.importDecl(decl->getTemplatedDecl(), Impl.CurrentVersion);
4750-
47514704
auto loc = Impl.importSourceLoc(decl->getLocation());
47524705
auto dc = Impl.importDeclContextOf(
47534706
decl, importedName.getEffectiveContext());

lib/ClangImporter/ImportName.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,11 +2274,6 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
22742274

22752275
if (auto classTemplateSpecDecl =
22762276
dyn_cast<clang::ClassTemplateSpecializationDecl>(D)) {
2277-
/// Symbolic specializations get imported as the symbolic class template
2278-
/// type.
2279-
if (importSymbolicCXXDecls)
2280-
return importNameImpl(classTemplateSpecDecl->getSpecializedTemplate(),
2281-
version, givenName);
22822277
if (!isa<clang::ClassTemplatePartialSpecializationDecl>(D)) {
22832278
auto name = printClassTemplateSpecializationName(classTemplateSpecDecl,
22842279
swiftCtx, this, version);

lib/ClangImporter/ImportName.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,13 @@ class NameImporter {
423423
llvm::DenseMap<std::pair<const clang::ObjCInterfaceDecl *, char>,
424424
std::unique_ptr<InheritedNameSet>> allProperties;
425425

426-
bool importSymbolicCXXDecls;
427-
428426
ClangImporter::Implementation *importerImpl;
429427

430428
public:
431429
NameImporter(ASTContext &ctx, const PlatformAvailability &avail,
432430
clang::Sema &cSema, ClangImporter::Implementation *importerImpl)
433431
: swiftCtx(ctx), availability(avail), clangSema(cSema),
434432
enumInfos(clangSema.getPreprocessor()),
435-
importSymbolicCXXDecls(
436-
ctx.LangOpts.hasFeature(Feature::ImportSymbolicCXXDecls)),
437433
importerImpl(importerImpl) {}
438434

439435
/// Determine the Swift name for a Clang decl
@@ -498,10 +494,6 @@ class NameImporter {
498494
clang::ObjCInterfaceDecl *classDecl,
499495
bool forInstance);
500496

501-
inline void enableSymbolicImportFeature(bool isEnabled) {
502-
importSymbolicCXXDecls = isEnabled;
503-
}
504-
505497
/// Retrieve a purported custom name even if it is invalid.
506498
static std::optional<StringRef>
507499
findCustomName(const clang::Decl *decl, ImportNameVersion version);

lib/ClangImporter/ImportType.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ bool ClangImporter::Implementation::isOverAligned(const clang::TypeDecl *decl) {
7575
}
7676

7777
bool ClangImporter::Implementation::isOverAligned(clang::QualType type) {
78-
// Do not check type layout for a clang type in symbolic mode as the
79-
// type could be a dependent type.
80-
if (importSymbolicCXXDecls)
81-
return false;
8278
auto align = getClangASTContext().getTypeAlignInChars(type);
8379
return align > clang::CharUnits::fromQuantity(MaximumAlignment);
8480
}
@@ -2348,10 +2344,6 @@ findGenericTypeInGenericDecls(ClangImporter::Implementation &impl,
23482344
llvm::find_if(genericParams, [name](GenericTypeParamDecl *generic) {
23492345
return generic->getName().str() == name;
23502346
});
2351-
// We sometimes are unable compute the exact Swift type
2352-
// of symbolic declarations. Fallback to using `Any` in that case.
2353-
if (impl.importSymbolicCXXDecls && genericParamIter == genericParams.end())
2354-
return impl.SwiftContext.TheAnyType;
23552347
// TODO: once we support generics in class types, replace this with
23562348
// "return nullptr". Once support for template classes, this will need to
23572349
// be updated, though. I'm leaving the assert here to make it easier to

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
475475
const bool DisableOverlayModules;
476476
const bool EnableClangSPI;
477477
const bool UseClangIncludeTree;
478-
bool importSymbolicCXXDecls;
479478

480479
bool IsReadingBridgingPCH;
481480
llvm::SmallVector<clang::serialization::SubmoduleID, 2> PCHImportedSubmodules;

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,11 +2020,6 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
20202020
assert(!method->isStatic() ||
20212021
method->getNameInfo().getName().getCXXOverloadedOperator() ==
20222022
clang::OO_Call);
2023-
// When emitting symbolic decls, the method might not have a concrete
2024-
// record type as this type.
2025-
if (ImporterImpl.importSymbolicCXXDecls && !method->isStatic() &&
2026-
!method->getThisType()->getPointeeCXXRecordDecl())
2027-
return nullptr;
20282023

20292024
// Create a new method in the derived class that calls the base method.
20302025
clang::DeclarationName name = method->getNameInfo().getName();

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -836,27 +836,3 @@ void swift::ide::printHeaderInterface(
836836
}
837837
Printer.forceNewlines();
838838
}
839-
840-
void swift::ide::printSymbolicSwiftClangModuleInterface(
841-
ModuleDecl *M, ASTPrinter &Printer, const clang::Module *clangModule) {
842-
std::string headerComment;
843-
llvm::raw_string_ostream(headerComment)
844-
<< "// Swift interface for " << (clangModule->IsSystem ? "system " : "")
845-
<< "module '" << clangModule->Name << "'\n";
846-
Printer.printText(headerComment);
847-
848-
ModuleTraversalOptions opts;
849-
opts |= ModuleTraversal::VisitSubmodules;
850-
auto popts =
851-
PrintOptions::printModuleInterface(/*printFullConvention=*/false);
852-
popts.PrintDocumentationComments = false;
853-
popts.SkipInlineCXXNamespace = true;
854-
855-
auto &SwiftContext = M->getTopLevelModule()->getASTContext();
856-
auto &Importer =
857-
static_cast<ClangImporter &>(*SwiftContext.getClangModuleLoader());
858-
Importer.withSymbolicFeatureEnabled([&]() {
859-
printModuleInterface(M, {}, opts, Printer, popts,
860-
/*SynthesizeExtensions=*/false);
861-
});
862-
}

0 commit comments

Comments
 (0)