Skip to content

Commit 6349f78

Browse files
committed
[cxx-interop] Enable foreign reference types in C interop
Most of the logic for C++ foreign reference types can be applied to C types as well. Swift had a compiler flag `-Xfrontend -experimental-c-foreign-reference-types` for awhile now which enables foreign reference types without having to enable C++ interop. This change makes it the default behavior. Since we don't expect anyone to pass `experimental-c-foreign-reference-types` currently, this also removes the frontend flag. rdar://150308819
1 parent 1cf426c commit 6349f78

File tree

5 files changed

+5
-18
lines changed

5 files changed

+5
-18
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ namespace swift {
355355
return CXXStdlib == PlatformDefaultCXXStdlib;
356356
}
357357

358-
bool CForeignReferenceTypes = false;
359-
360358
/// Imports getters and setters as computed properties.
361359
bool CxxInteropGettersSettersAsProperties = false;
362360

include/swift/Option/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,6 @@ def cxx_interoperability_mode :
864864
SwiftSynthesizeInterfaceOption]>,
865865
HelpText<"Enables C++ interoperability; pass 'default' to enable or 'off' to disable">;
866866

867-
def experimental_c_foreign_reference_types :
868-
Flag<["-"], "experimental-c-foreign-reference-types">,
869-
Flags<[FrontendOption, HelpHidden, ModuleInterfaceOption]>,
870-
HelpText<"Enable experimental C foreign references types (with reference counting).">;
871-
872867
def experimental_hermetic_seal_at_link:
873868
Flag<["-"], "experimental-hermetic-seal-at-link">,
874869
Flags<[FrontendOption, HelpHidden]>,

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ void ClangImporter::Implementation::makeComputed(AbstractStorageDecl *storage,
169169
bool importer::recordHasReferenceSemantics(
170170
const clang::RecordDecl *decl,
171171
ClangImporter::Implementation *importerImpl) {
172-
if (!isa<clang::CXXRecordDecl>(decl) &&
173-
!importerImpl->SwiftContext.LangOpts.CForeignReferenceTypes)
174-
return false;
175-
176172
// At this point decl might not be fully imported into Swift yet, which
177173
// means we might not have asked Clang to generate its implicit members, such
178174
// as copy or move constructors. This would cause CxxRecordSemanticsRequest to

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15801580
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,
15811581
Target.isOSDarwin() && !Opts.hasFeature(Feature::Embedded));
15821582

1583-
Opts.CForeignReferenceTypes =
1584-
Args.hasArg(OPT_experimental_c_foreign_reference_types);
1585-
15861583
Opts.CxxInteropGettersSettersAsProperties = Args.hasArg(OPT_cxx_interop_getters_setters_as_properties);
15871584
Opts.RequireCxxInteropToImportCxxInteropModule =
15881585
!Args.hasArg(OPT_cxx_interop_disable_requirement_at_import);

test/Interop/C/struct/foreign-reference.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Xfrontend -experimental-c-foreign-reference-types -Onone -D NO_OPTIMIZATIONS)
2-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Xfrontend -experimental-c-foreign-reference-types -O)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Onone -D NO_OPTIMIZATIONS)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -O)
33
//
44
// REQUIRES: executable_test
5-
// TODO: This should work without ObjC interop in the future rdar://97497120
6-
// REQUIRES: objc_interop
5+
6+
// XFAIL: OS=windows-msvc
7+
// FIXME: Runtime support for C++ foreign reference types is missing on Windows (https://github.com/swiftlang/swift/issues/82643)
78

89
import StdlibUnittest
910
import ForeignReference

0 commit comments

Comments
 (0)