Skip to content

Commit 37d242c

Browse files
authored
Merge pull request #64372 from hyp/eng/igen-cxx
[interop] SourceKit should retry generating module interface with C++…
2 parents 490c73c + 72050c5 commit 37d242c

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %sourcekitd-test -req=interface-gen -module CxxModule -- -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -I %t/Inputs -target %target-triple %clang-importer-sdk-nosource | %FileCheck %s
5+
// RUN: %sourcekitd-test -req=interface-gen -module CxxModule -- -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -cxx-interoperability-mode=swift-5.9 -I %t/Inputs -target %target-triple %clang-importer-sdk-nosource | %FileCheck %s
6+
7+
8+
// RUN: not %sourcekitd-test -req=interface-gen -module CxxModule -- -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xcc -DERROR -I %t/Inputs -target %target-triple %clang-importer-sdk-nosource 2>&1 | %FileCheck --check-prefix=NOLOAD %s
9+
10+
11+
//--- Inputs/module.modulemap
12+
module CxxModule {
13+
header "headerA.h"
14+
requires cplusplus
15+
}
16+
17+
//--- Inputs/headerA.h
18+
19+
namespace ns {
20+
21+
#ifdef ERROR
22+
#error "Unluckee"
23+
#endif
24+
25+
class CxxClass {
26+
public:
27+
int x;
28+
29+
CxxClass(): x(0) {}
30+
31+
inline void method() const {}
32+
};
33+
34+
} // ns
35+
36+
using ClassType = ns::CxxClass;
37+
38+
// CHECK: public enum ns {
39+
// CHECK: public struct CxxClass {
40+
// CHECK: public init()
41+
// CHECK: public func method()
42+
// CHECK: public typealias ClassType = ns.CxxClass
43+
44+
// NOLOAD: Could not load module: CxxModule

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,26 @@ void SwiftLangSupport::editorOpenInterface(EditorConsumer &Consumer,
699699
SynthesizedExtensions,
700700
InterestedUSR);
701701
if (!IFaceGenRef) {
702-
Consumer.handleRequestError(ErrMsg.c_str());
703-
return;
702+
// Retry to generate a module interface with C++ interop enabled,
703+
// if the first attempt failed.
704+
bool retryWithCxxEnabled = true;
705+
for (const auto &arg: Args) {
706+
if (StringRef(arg).startswith("-cxx-interoperability-mode=") ||
707+
StringRef(arg).startswith("-enable-experimental-cxx-interop")) {
708+
retryWithCxxEnabled = false;
709+
break;
710+
}
711+
}
712+
if (retryWithCxxEnabled) {
713+
std::vector<const char *> AdjustedArgs(Args.begin(), Args.end());
714+
AdjustedArgs.push_back("-cxx-interoperability-mode=swift-5.9");
715+
return editorOpenInterface(Consumer, Name, ModuleName, Group, AdjustedArgs,
716+
SynthesizedExtensions, InterestedUSR);
717+
}
718+
else {
719+
Consumer.handleRequestError(ErrMsg.c_str());
720+
return;
721+
}
704722
}
705723

706724
IFaceGenRef->reportEditorInfo(Consumer);

0 commit comments

Comments
 (0)