Skip to content

Commit 9a28061

Browse files
authored
Merge pull request #73963 from apple/cxx-swift-symbolgraph-extract
[SymbolGraphGen] Handle cxx module imports in swift-symbolgraph-extract
2 parents 135e3f2 + 808ccd4 commit 9a28061

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_BASIC_LANGOPTIONS_H
1919
#define SWIFT_BASIC_LANGOPTIONS_H
2020

21+
#include "swift/AST/DiagnosticsFrontend.h"
2122
#include "swift/Basic/Feature.h"
2223
#include "swift/Basic/FixedBitSet.h"
2324
#include "swift/Basic/FunctionBodySkipping.h"
@@ -31,6 +32,7 @@
3132
#include "llvm/ADT/SmallString.h"
3233
#include "llvm/ADT/SmallVector.h"
3334
#include "llvm/ADT/StringRef.h"
35+
#include "llvm/Option/ArgList.h"
3436
#include "llvm/Support/Regex.h"
3537
#include "llvm/Support/VersionTuple.h"
3638
#include "llvm/Support/raw_ostream.h"
@@ -319,6 +321,9 @@ namespace swift {
319321
/// to the Swift language version.
320322
version::Version cxxInteropCompatVersion;
321323

324+
void setCxxInteropFromArgs(llvm::opt::ArgList &Args,
325+
swift::DiagnosticEngine &Diags);
326+
322327
bool CForeignReferenceTypes = false;
323328

324329
/// Imports getters and setters as computed properties.

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def enable_experimental_cxx_interop :
764764

765765
def cxx_interoperability_mode :
766766
Joined<["-"], "cxx-interoperability-mode=">,
767-
Flags<[FrontendOption, ModuleInterfaceOption]>,
767+
Flags<[FrontendOption, ModuleInterfaceOption, SwiftSymbolGraphExtractOption]>,
768768
HelpText<"Enables C++ interoperability; pass 'default' to enable or 'off' to disable">;
769769

770770
def experimental_c_foreign_reference_types :

lib/DriverTool/swift_symbolgraph_extract_main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
196196
.Default(AccessLevel::Public);
197197
}
198198

199+
Invocation.getLangOptions().setCxxInteropFromArgs(ParsedArgs, Diags);
200+
199201
std::string InstanceSetupError;
200202
if (CI.setup(Invocation, InstanceSetupError)) {
201203
llvm::outs() << InstanceSetupError << '\n';

lib/Frontend/CompilerInvocation.cpp

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,40 @@ static void diagnoseCxxInteropCompatMode(Arg *verArg, ArgList &Args,
533533
diags.diagnose(SourceLoc(), diag::valid_cxx_interop_modes, versStr);
534534
}
535535

536+
void LangOptions::setCxxInteropFromArgs(ArgList &Args,
537+
swift::DiagnosticEngine &Diags) {
538+
if (Arg *A = Args.getLastArg(options::OPT_cxx_interoperability_mode)) {
539+
if (Args.hasArg(options::OPT_enable_experimental_cxx_interop)) {
540+
Diags.diagnose(SourceLoc(), diag::dont_enable_interop_and_compat);
541+
}
542+
543+
auto interopCompatMode = validateCxxInteropCompatibilityMode(A->getValue());
544+
EnableCXXInterop |=
545+
(interopCompatMode.first == CxxCompatMode::enabled);
546+
if (EnableCXXInterop) {
547+
cxxInteropCompatVersion = interopCompatMode.second;
548+
// The default is tied to the current language version.
549+
if (cxxInteropCompatVersion.empty())
550+
cxxInteropCompatVersion =
551+
EffectiveLanguageVersion.asMajorVersion();
552+
}
553+
554+
if (interopCompatMode.first == CxxCompatMode::invalid)
555+
diagnoseCxxInteropCompatMode(A, Args, Diags);
556+
}
557+
558+
if (Args.hasArg(options::OPT_enable_experimental_cxx_interop)) {
559+
Diags.diagnose(SourceLoc(), diag::enable_interop_flag_deprecated);
560+
Diags.diagnose(SourceLoc(), diag::swift_will_maintain_compat);
561+
EnableCXXInterop |= true;
562+
// Using the deprecated option only forces the 'swift-5.9' compat
563+
// mode.
564+
if (cxxInteropCompatVersion.empty())
565+
cxxInteropCompatVersion =
566+
validateCxxInteropCompatibilityMode("swift-5.9").second;
567+
}
568+
}
569+
536570
static std::optional<swift::StrictConcurrency>
537571
parseStrictConcurrency(StringRef value) {
538572
return llvm::StringSwitch<std::optional<swift::StrictConcurrency>>(value)
@@ -1263,37 +1297,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
12631297
if (const Arg *A = Args.getLastArg(OPT_clang_target)) {
12641298
Opts.ClangTarget = llvm::Triple(A->getValue());
12651299
}
1266-
1267-
if (Arg *A = Args.getLastArg(OPT_cxx_interoperability_mode)) {
1268-
if (Args.hasArg(OPT_enable_experimental_cxx_interop)) {
1269-
Diags.diagnose(SourceLoc(), diag::dont_enable_interop_and_compat);
1270-
}
1271-
1272-
auto interopCompatMode = validateCxxInteropCompatibilityMode(A->getValue());
1273-
Opts.EnableCXXInterop |=
1274-
(interopCompatMode.first == CxxCompatMode::enabled);
1275-
if (Opts.EnableCXXInterop) {
1276-
Opts.cxxInteropCompatVersion = interopCompatMode.second;
1277-
// The default is tied to the current language version.
1278-
if (Opts.cxxInteropCompatVersion.empty())
1279-
Opts.cxxInteropCompatVersion =
1280-
Opts.EffectiveLanguageVersion.asMajorVersion();
1281-
}
1282-
1283-
if (interopCompatMode.first == CxxCompatMode::invalid)
1284-
diagnoseCxxInteropCompatMode(A, Args, Diags);
1285-
}
1286-
1287-
if (Args.hasArg(OPT_enable_experimental_cxx_interop)) {
1288-
Diags.diagnose(SourceLoc(), diag::enable_interop_flag_deprecated);
1289-
Diags.diagnose(SourceLoc(), diag::swift_will_maintain_compat);
1290-
Opts.EnableCXXInterop |= true;
1291-
// Using the deprecated option only forces the 'swift-5.9' compat
1292-
// mode.
1293-
if (Opts.cxxInteropCompatVersion.empty())
1294-
Opts.cxxInteropCompatVersion =
1295-
validateCxxInteropCompatibilityMode("swift-5.9").second;
1296-
}
1300+
1301+
Opts.setCxxInteropFromArgs(Args, Diags);
12971302

12981303
Opts.EnableObjCInterop =
12991304
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,

0 commit comments

Comments
 (0)