Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,6 @@ EXPERIMENTAL_FEATURE(AssumeResilientCxxTypes, true)
/// Import inherited non-public members when importing C++ classes.
EXPERIMENTAL_FEATURE(ImportNonPublicCxxMembers, true)

/// Suppress the synthesis of static factory methods for C++ foreign reference
/// types and importing them as Swift initializers.
EXPERIMENTAL_FEATURE(SuppressCXXForeignReferenceTypeInitializers, true)

/// Emit a warning when a C++ API returns a SWIFT_SHARED_REFERENCE type
/// without being explicitly annotated with either SWIFT_RETURNS_RETAINED
/// or SWIFT_RETURNS_UNRETAINED.
Expand Down
1 change: 0 additions & 1 deletion lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ UNINTERESTING_FEATURE(LibraryEvolution)
UNINTERESTING_FEATURE(SafeInteropWrappers)
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
UNINTERESTING_FEATURE(SuppressCXXForeignReferenceTypeInitializers)
UNINTERESTING_FEATURE(WarnUnannotatedReturnOfCxxFrt)
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)
Expand Down
52 changes: 24 additions & 28 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2597,34 +2597,30 @@ namespace {
result->addMember(ctor);
}
} else {
if (!Impl.SwiftContext.LangOpts.hasFeature(
Feature::SuppressCXXForeignReferenceTypeInitializers)) {
assert(
isa<ClassDecl>(result) &&
"Expected result to be a ClassDecl as it cannot be a StructDecl");
// When we add full support for C foreign reference types then we
// should synthesize static factories for them as well
if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
bool hasUserProvidedStaticFactory = llvm::any_of(
cxxRecordDecl->methods(),
[](const clang::CXXMethodDecl *method) {
return method->isStatic() &&
llvm::any_of(
method->specific_attrs<clang::SwiftNameAttr>(),
[](const auto *attr) {
return attr->getName().starts_with("init(");
});
});
if (!hasUserProvidedStaticFactory) {
auto generatedCxxMethodDecls =
synthesizer.synthesizeStaticFactoryForCXXForeignRef(
cxxRecordDecl);
for (auto *methodDecl : generatedCxxMethodDecls) {
if (Decl *importedInitDecl =
Impl.SwiftContext.getClangModuleLoader()
->importDeclDirectly(methodDecl))
result->addMember(importedInitDecl);
}
assert(
isa<ClassDecl>(result) &&
"Expected result to be a ClassDecl as it cannot be a StructDecl");
// When we add full support for C foreign reference types then we
// should synthesize static factories for them as well
if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
bool hasUserProvidedStaticFactory = llvm::any_of(
cxxRecordDecl->methods(), [](const clang::CXXMethodDecl *method) {
return method->isStatic() &&
llvm::any_of(
method->specific_attrs<clang::SwiftNameAttr>(),
[](const auto *attr) {
return attr->getName().starts_with("init(");
});
});
if (!hasUserProvidedStaticFactory) {
auto generatedCxxMethodDecls =
synthesizer.synthesizeStaticFactoryForCXXForeignRef(
cxxRecordDecl);
for (auto *methodDecl : generatedCxxMethodDecls) {
if (Decl *importedInitDecl =
Impl.SwiftContext.getClangModuleLoader()
->importDeclDirectly(methodDecl))
result->addMember(importedInitDecl);
}
}
}
Expand Down