Skip to content

Commit 4e6e462

Browse files
committed
[cxx-interop] Remove opt-out flag for constructors of foreign reference types
The opt-out flag was never used or tested, let's remove it. rdar://148285972
1 parent bf07c4b commit 4e6e462

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

include/swift/Basic/Features.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ EXPERIMENTAL_FEATURE(AssumeResilientCxxTypes, true)
498498
/// Import inherited non-public members when importing C++ classes.
499499
EXPERIMENTAL_FEATURE(ImportNonPublicCxxMembers, true)
500500

501-
/// Suppress the synthesis of static factory methods for C++ foreign reference
502-
/// types and importing them as Swift initializers.
503-
EXPERIMENTAL_FEATURE(SuppressCXXForeignReferenceTypeInitializers, true)
504-
505501
/// Emit a warning when a C++ API returns a SWIFT_SHARED_REFERENCE type
506502
/// without being explicitly annotated with either SWIFT_RETURNS_RETAINED
507503
/// or SWIFT_RETURNS_UNRETAINED.

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ UNINTERESTING_FEATURE(LibraryEvolution)
332332
UNINTERESTING_FEATURE(SafeInteropWrappers)
333333
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
334334
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
335-
UNINTERESTING_FEATURE(SuppressCXXForeignReferenceTypeInitializers)
336335
UNINTERESTING_FEATURE(WarnUnannotatedReturnOfCxxFrt)
337336
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
338337
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)

lib/ClangImporter/ImportDecl.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,34 +2597,30 @@ namespace {
25972597
result->addMember(ctor);
25982598
}
25992599
} else {
2600-
if (!Impl.SwiftContext.LangOpts.hasFeature(
2601-
Feature::SuppressCXXForeignReferenceTypeInitializers)) {
2602-
assert(
2603-
isa<ClassDecl>(result) &&
2604-
"Expected result to be a ClassDecl as it cannot be a StructDecl");
2605-
// When we add full support for C foreign reference types then we
2606-
// should synthesize static factories for them as well
2607-
if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
2608-
bool hasUserProvidedStaticFactory = llvm::any_of(
2609-
cxxRecordDecl->methods(),
2610-
[](const clang::CXXMethodDecl *method) {
2611-
return method->isStatic() &&
2612-
llvm::any_of(
2613-
method->specific_attrs<clang::SwiftNameAttr>(),
2614-
[](const auto *attr) {
2615-
return attr->getName().starts_with("init(");
2616-
});
2617-
});
2618-
if (!hasUserProvidedStaticFactory) {
2619-
auto generatedCxxMethodDecls =
2620-
synthesizer.synthesizeStaticFactoryForCXXForeignRef(
2621-
cxxRecordDecl);
2622-
for (auto *methodDecl : generatedCxxMethodDecls) {
2623-
if (Decl *importedInitDecl =
2624-
Impl.SwiftContext.getClangModuleLoader()
2625-
->importDeclDirectly(methodDecl))
2626-
result->addMember(importedInitDecl);
2627-
}
2600+
assert(
2601+
isa<ClassDecl>(result) &&
2602+
"Expected result to be a ClassDecl as it cannot be a StructDecl");
2603+
// When we add full support for C foreign reference types then we
2604+
// should synthesize static factories for them as well
2605+
if (auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(decl)) {
2606+
bool hasUserProvidedStaticFactory = llvm::any_of(
2607+
cxxRecordDecl->methods(), [](const clang::CXXMethodDecl *method) {
2608+
return method->isStatic() &&
2609+
llvm::any_of(
2610+
method->specific_attrs<clang::SwiftNameAttr>(),
2611+
[](const auto *attr) {
2612+
return attr->getName().starts_with("init(");
2613+
});
2614+
});
2615+
if (!hasUserProvidedStaticFactory) {
2616+
auto generatedCxxMethodDecls =
2617+
synthesizer.synthesizeStaticFactoryForCXXForeignRef(
2618+
cxxRecordDecl);
2619+
for (auto *methodDecl : generatedCxxMethodDecls) {
2620+
if (Decl *importedInitDecl =
2621+
Impl.SwiftContext.getClangModuleLoader()
2622+
->importDeclDirectly(methodDecl))
2623+
result->addMember(importedInitDecl);
26282624
}
26292625
}
26302626
}

0 commit comments

Comments
 (0)