Skip to content

Commit 72050c5

Browse files
committed
[interop] SourceKit should retry generating module interface with C++ interop enabled
Sometimes the request might not have it enabled explicitly
1 parent 07ccee2 commit 72050c5

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
@@ -694,8 +694,26 @@ void SwiftLangSupport::editorOpenInterface(EditorConsumer &Consumer,
694694
SynthesizedExtensions,
695695
InterestedUSR);
696696
if (!IFaceGenRef) {
697-
Consumer.handleRequestError(ErrMsg.c_str());
698-
return;
697+
// Retry to generate a module interface with C++ interop enabled,
698+
// if the first attempt failed.
699+
bool retryWithCxxEnabled = true;
700+
for (const auto &arg: Args) {
701+
if (StringRef(arg).startswith("-cxx-interoperability-mode=") ||
702+
StringRef(arg).startswith("-enable-experimental-cxx-interop")) {
703+
retryWithCxxEnabled = false;
704+
break;
705+
}
706+
}
707+
if (retryWithCxxEnabled) {
708+
std::vector<const char *> AdjustedArgs(Args.begin(), Args.end());
709+
AdjustedArgs.push_back("-cxx-interoperability-mode=swift-5.9");
710+
return editorOpenInterface(Consumer, Name, ModuleName, Group, AdjustedArgs,
711+
SynthesizedExtensions, InterestedUSR);
712+
}
713+
else {
714+
Consumer.handleRequestError(ErrMsg.c_str());
715+
return;
716+
}
699717
}
700718

701719
IFaceGenRef->reportEditorInfo(Consumer);

0 commit comments

Comments
 (0)