Skip to content

Commit 294e4cf

Browse files
authored
Merge pull request #81257 from swiftlang/egorzhdan/remove-symbolic-mode
[cxx-interop] Remove symbolic import mode
2 parents 3a788a4 + b51cfa5 commit 294e4cf

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
@@ -692,12 +692,6 @@ class ClangImporter final : public ClangModuleLoader {
692692
/// of the provided baseType.
693693
void diagnoseMemberValue(const DeclName &name, const Type &baseType) override;
694694

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

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
@@ -2733,8 +2733,6 @@ ClangImporter::Implementation::Implementation(
27332733
DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules),
27342734
EnableClangSPI(ctx.ClangImporterOpts.EnableClangSPI),
27352735
UseClangIncludeTree(ctx.ClangImporterOpts.UseClangIncludeTree),
2736-
importSymbolicCXXDecls(
2737-
ctx.LangOpts.hasFeature(Feature::ImportSymbolicCXXDecls)),
27382736
IsReadingBridgingPCH(false),
27392737
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
27402738
Walker(DiagnosticWalker(*this)), BuffersForDiagnostics(ctx.SourceMgr),
@@ -8576,23 +8574,6 @@ bool ClangDeclExplicitSafety::isCached() const {
85768574
return isa<clang::RecordDecl>(std::get<0>(getStorage()).decl);
85778575
}
85788576

8579-
void ClangImporter::withSymbolicFeatureEnabled(
8580-
llvm::function_ref<void(void)> callback) {
8581-
llvm::SaveAndRestore<bool> oldImportSymbolicCXXDecls(
8582-
Impl.importSymbolicCXXDecls, true);
8583-
Impl.nameImporter->enableSymbolicImportFeature(true);
8584-
auto importedDeclsCopy = Impl.ImportedDecls;
8585-
Impl.ImportedDecls.clear();
8586-
callback();
8587-
Impl.ImportedDecls = std::move(importedDeclsCopy);
8588-
Impl.nameImporter->enableSymbolicImportFeature(
8589-
oldImportSymbolicCXXDecls.get());
8590-
}
8591-
8592-
bool ClangImporter::isSymbolicImportEnabled() const {
8593-
return Impl.importSymbolicCXXDecls;
8594-
}
8595-
85968577
const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
85978578
const clang::Decl *candidateDecl) {
85988579

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

@@ -3959,8 +3949,6 @@ namespace {
39593949
Impl.SwiftContext, SourceLoc(), templateParams, SourceLoc());
39603950
}
39613951

3962-
bool importFuncWithoutSignature =
3963-
isa<clang::CXXMethodDecl>(decl) && Impl.importSymbolicCXXDecls;
39643952
if (!dc->isModuleScopeContext() && !isClangNamespace(dc) &&
39653953
!isa<clang::CXXMethodDecl>(decl)) {
39663954
// Handle initializers.
@@ -4027,39 +4015,12 @@ namespace {
40274015
importedType =
40284016
Impl.importFunctionReturnType(dc, decl, allowNSUIntegerAsInt);
40294017
} else {
4030-
if (importFuncWithoutSignature) {
4031-
importedType = ImportedType{Impl.SwiftContext.getVoidType(), false};
4032-
if (decl->param_empty())
4033-
bodyParams = ParameterList::createEmpty(Impl.SwiftContext);
4034-
else {
4035-
llvm::SmallVector<ParamDecl *, 4> params;
4036-
for (const auto &param : decl->parameters()) {
4037-
4038-
Identifier bodyName =
4039-
Impl.importFullName(param, Impl.CurrentVersion)
4040-
.getBaseIdentifier(Impl.SwiftContext);
4041-
auto paramInfo = Impl.createDeclWithClangNode<ParamDecl>(
4042-
param, AccessLevel::Private, SourceLoc(), SourceLoc(),
4043-
Identifier(), Impl.importSourceLoc(param->getLocation()),
4044-
bodyName, Impl.ImportedHeaderUnit);
4045-
paramInfo->setSpecifier(ParamSpecifier::Default);
4046-
paramInfo->setInterfaceType(Impl.SwiftContext.TheAnyType);
4047-
if (param->hasDefaultArg()) {
4048-
paramInfo->setDefaultArgumentKind(DefaultArgumentKind::Normal);
4049-
paramInfo->setDefaultValueStringRepresentation("cxxDefaultArg");
4050-
}
4051-
params.push_back(paramInfo);
4052-
}
4053-
bodyParams = ParameterList::create(Impl.SwiftContext, params);
4054-
}
4055-
} else {
4056-
// Import the function type. If we have parameters, make sure their
4057-
// names get into the resulting function type.
4058-
importedType = Impl.importFunctionParamsAndReturnType(
4059-
dc, decl, {decl->param_begin(), decl->param_size()},
4060-
decl->isVariadic(), isInSystemModule(dc), name, bodyParams,
4061-
templateParams);
4062-
}
4018+
// Import the function type. If we have parameters, make sure their
4019+
// names get into the resulting function type.
4020+
importedType = Impl.importFunctionParamsAndReturnType(
4021+
dc, decl, {decl->param_begin(), decl->param_size()},
4022+
decl->isVariadic(), isInSystemModule(dc), name, bodyParams,
4023+
templateParams);
40634024

40644025
if (auto *mdecl = dyn_cast<clang::CXXMethodDecl>(decl)) {
40654026
if (mdecl->isStatic()) {
@@ -4166,12 +4127,10 @@ namespace {
41664127
}
41674128
func->setAccess(importer::convertClangAccess(decl->getAccess()));
41684129

4169-
if (!importFuncWithoutSignature) {
4170-
bool success = processSpecialImportedFunc(
4171-
func, importedName, decl->getOverloadedOperator());
4172-
if (!success)
4173-
return nullptr;
4174-
}
4130+
bool success = processSpecialImportedFunc(
4131+
func, importedName, decl->getOverloadedOperator());
4132+
if (!success)
4133+
return nullptr;
41754134
}
41764135

41774136
result->setIsObjC(false);
@@ -4486,8 +4445,7 @@ namespace {
44864445
}
44874446

44884447
Decl *VisitFieldDecl(const clang::FieldDecl *decl) {
4489-
if (!Impl.importSymbolicCXXDecls &&
4490-
decl->hasAttr<clang::NoUniqueAddressAttr>()) {
4448+
if (decl->hasAttr<clang::NoUniqueAddressAttr>()) {
44914449
if (const auto *rd = decl->getType()->getAsRecordDecl()) {
44924450
// Clang can store the next field in the padding of this one. Swift
44934451
// does not support this yet so let's not import the field and
@@ -4749,11 +4707,6 @@ namespace {
47494707
if (name.empty())
47504708
return nullptr;
47514709

4752-
if (Impl.importSymbolicCXXDecls)
4753-
// Import an unspecialized C++ class template as a Swift value/class
4754-
// type in symbolic mode.
4755-
return Impl.importDecl(decl->getTemplatedDecl(), Impl.CurrentVersion);
4756-
47574710
auto loc = Impl.importSourceLoc(decl->getLocation());
47584711
auto dc = Impl.importDeclContextOf(
47594712
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)