Skip to content

Commit 69be33d

Browse files
committed
[cxx-interop] Remove compatibility versions
This removes the C++ interop compat version mechanism. It was added in mid-2023 and was never used. It complicates the testing story, and makes it harder to reason about the compiler's behavior. It also isn't compatible with explicit module builds. The flag `-cxx-interoperability-mode` is preserved, so projects that use the flag will continue to build normally. rdar://165919353
1 parent b0ec567 commit 69be33d

File tree

6 files changed

+4
-67
lines changed

6 files changed

+4
-67
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ namespace swift {
333333
/// disabled because it is not complete.
334334
bool EnableCXXInterop = false;
335335

336-
/// The C++ interoperability source compatibility version. Defaults
337-
/// to the Swift language version.
338-
version::Version cxxInteropCompatVersion;
339-
340336
/// What version of C++ interoperability a textual interface was originally
341337
/// generated with (if at all).
342338
std::optional<version::Version> FormalCxxInteropMode;

include/swift/Basic/Version.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ StringRef getCurrentCompilerSerializationTag();
184184
/// same serialization tag.
185185
StringRef getCurrentCompilerChannel();
186186

187-
/// Retrieves the value of the upcoming C++ interoperability compatibility
188-
/// version that's going to be presented as some new concrete version to the
189-
/// users.
190-
unsigned getUpcomingCxxInteropCompatVersion();
191-
192187
/// Retrieves the version of the running compiler. It could be a tag or
193188
/// a "development" version that only has major/minor.
194189
std::string getCompilerVersion();

lib/Basic/Version.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ StringRef getCurrentCompilerChannel() {
330330
return StringRef();
331331
}
332332

333-
unsigned getUpcomingCxxInteropCompatVersion() {
334-
return SWIFT_VERSION_MAJOR + 1;
335-
}
336-
337333
std::string getCompilerVersion() {
338334
std::string buf;
339335
llvm::raw_string_ostream OS(buf);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,9 @@ static std::pair<CxxCompatMode, version::Version>
667667
validateCxxInteropCompatibilityMode(StringRef mode) {
668668
if (mode == "off")
669669
return {CxxCompatMode::off, {}};
670-
if (mode == "default")
670+
if (mode == "default" || mode == "upcoming-swift" || mode == "swift-6" ||
671+
mode == "swift-5.9")
671672
return {CxxCompatMode::enabled, {}};
672-
if (mode == "upcoming-swift")
673-
return {CxxCompatMode::enabled,
674-
version::Version({version::getUpcomingCxxInteropCompatVersion()})};
675-
if (mode == "swift-6")
676-
return {CxxCompatMode::enabled, version::Version({6})};
677-
// Swift-5.9 corresponds to the Swift 5 language mode when
678-
// Swift 5 is the default language version.
679-
if (mode == "swift-5.9")
680-
return {CxxCompatMode::enabled, version::Version({5})};
681673
// Note: If this is updated, corresponding code in
682674
// InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl needs
683675
// to be updated also.
@@ -709,13 +701,6 @@ void LangOptions::setCxxInteropFromArgs(ArgList &Args,
709701
auto interopCompatMode = validateCxxInteropCompatibilityMode(A->getValue());
710702
EnableCXXInterop |=
711703
(interopCompatMode.first == CxxCompatMode::enabled);
712-
if (EnableCXXInterop) {
713-
cxxInteropCompatVersion = interopCompatMode.second;
714-
// The default is tied to the current language version.
715-
if (cxxInteropCompatVersion.empty())
716-
cxxInteropCompatVersion =
717-
EffectiveLanguageVersion.asMajorVersion();
718-
}
719704

720705
if (interopCompatMode.first == CxxCompatMode::invalid)
721706
diagnoseCxxInteropCompatMode(A, Args, Diags);
@@ -725,11 +710,6 @@ void LangOptions::setCxxInteropFromArgs(ArgList &Args,
725710
Diags.diagnose(SourceLoc(), diag::enable_interop_flag_deprecated);
726711
Diags.diagnose(SourceLoc(), diag::swift_will_maintain_compat);
727712
EnableCXXInterop |= true;
728-
// Using the deprecated option only forces the 'swift-5.9' compat
729-
// mode.
730-
if (cxxInteropCompatVersion.empty())
731-
cxxInteropCompatVersion =
732-
validateCxxInteropCompatibilityMode("swift-5.9").second;
733713
}
734714

735715
if (Arg *A = Args.getLastArg(options::OPT_formal_cxx_interoperability_mode)) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,23 +2026,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
20262026
if (langOpts.EnableCXXInterop) {
20272027
// Modelled after a reverse of validateCxxInteropCompatibilityMode
20282028
genericSubInvocation.getLangOptions().EnableCXXInterop = true;
2029-
genericSubInvocation.getLangOptions().cxxInteropCompatVersion =
2030-
langOpts.cxxInteropCompatVersion;
2031-
std::string compatVersion;
2032-
if (langOpts.cxxInteropCompatVersion.empty())
2033-
compatVersion = "default";
2034-
else if (langOpts.cxxInteropCompatVersion[0] == 5)
2035-
compatVersion = "swift-5.9";
2036-
else if (langOpts.cxxInteropCompatVersion[0] == 6)
2037-
compatVersion = "swift-6";
2038-
else if (langOpts.cxxInteropCompatVersion[0] ==
2039-
version::getUpcomingCxxInteropCompatVersion())
2040-
compatVersion = "upcoming-swift";
2041-
else // TODO: This may need to be updated once more versions are added
2042-
compatVersion = "default";
2043-
2044-
GenericArgs.push_back(
2045-
ArgSaver.save("-cxx-interoperability-mode=" + compatVersion));
2029+
GenericArgs.push_back(ArgSaver.save("-cxx-interoperability-mode=default"));
20462030

20472031
if (!langOpts.isUsingPlatformDefaultCXXStdlib() &&
20482032
langOpts.CXXStdlib == CXXStdlibKind::Libcxx) {

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4626,23 +4626,9 @@ int main(int argc, char *argv[]) {
46264626
InitInvok.getLangOptions().EnableObjCInterop =
46274627
llvm::Triple(options::Triple).isOSDarwin();
46284628
}
4629-
if (options::EnableCxxInterop) {
4629+
if (options::EnableCxxInterop || !options::CxxInteropVersion.empty()) {
46304630
InitInvok.getLangOptions().EnableCXXInterop = true;
46314631
}
4632-
if (!options::CxxInteropVersion.empty()) {
4633-
InitInvok.getLangOptions().EnableCXXInterop = true;
4634-
if (options::CxxInteropVersion == "upcoming-swift")
4635-
InitInvok.getLangOptions().cxxInteropCompatVersion =
4636-
version::Version({version::getUpcomingCxxInteropCompatVersion()});
4637-
else if (options::CxxInteropVersion == "swift-6")
4638-
InitInvok.getLangOptions().cxxInteropCompatVersion =
4639-
version::Version({6});
4640-
else if (options::CxxInteropVersion == "swift-5.9")
4641-
InitInvok.getLangOptions().cxxInteropCompatVersion =
4642-
version::Version({5, 9});
4643-
else
4644-
llvm::errs() << "invalid CxxInteropVersion\n";
4645-
}
46464632
if (options::CxxInteropGettersSettersAsProperties) {
46474633
InitInvok.getLangOptions().CxxInteropGettersSettersAsProperties = true;
46484634
}

0 commit comments

Comments
 (0)