Skip to content

Commit b6dda90

Browse files
authored
Merge pull request #84881 from egorzhdan/egorzhdan/remove-opt-out-flag
[cxx-interop] Remove opt-out flag for constructors of foreign reference types
2 parents 54d193a + 4e6e462 commit b6dda90

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

0 commit comments

Comments
 (0)