Skip to content

Commit 9efb6d6

Browse files
committed
[interop][sourcekit] report a module error for any unconditional module loading failure
This ensures that interface gen reports an error when importing a framework Swift module that also imports the underlying C++ module into Swift, when interop is disabled, so that we can retry the interface gen with interop enabled. (cherry picked from commit 3b143d7)
1 parent c28d0b2 commit 9efb6d6

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module %t/TestFmSwift.swift -module-name TestFm -enable-experimental-cxx-interop -F %t -o %t/TestFm.swiftmodule -import-underlying-module
5+
6+
// RUN: %sourcekitd-test -req=interface-gen -module TestFm -- -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck %s
7+
8+
//--- TestFm.framework/Headers/TestFm.h
9+
#pragma once
10+
11+
namespace ns {
12+
void testFunction();
13+
}
14+
15+
//--- TestFm.framework/Modules/module.modulemap
16+
framework module TestFm {
17+
umbrella header "TestFm.h"
18+
19+
export *
20+
module * { export * }
21+
}
22+
23+
//--- TestFmSwift.swift
24+
25+
public func testSwiftFunc() {
26+
}
27+
28+
// CHECK: public enum ns {
29+
// CHECK: public static func testFunction()
30+
// CHECK: }
31+
32+
// CHECK: public func testSwiftFunc()

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,12 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx,
287287
ErrMsg += ModuleName;
288288
return true;
289289
}
290-
if (Mod->failedToLoad() && ModuleName == "CxxStdlib") {
290+
if (Mod->failedToLoad()) {
291291
// We might fail to load the underlying Clang module
292-
// for a Swift overlay module like 'CxxStdlib'. Make sure an error is reported in this case, so that we can either retry to load with C++ interoperability enabled, and if that fails, we can report this to the user.
292+
// for a Swift overlay module like 'CxxStdlib', or a mixed-language
293+
// framework. Make sure an error is reported in this case, so that we can
294+
// either retry to load with C++ interoperability enabled, and if that
295+
// fails, we can report this to the user.
293296
ErrMsg = "Could not load underlying module for: ";
294297
ErrMsg += ModuleName;
295298
return true;

0 commit comments

Comments
 (0)