Skip to content

Commit 40244a2

Browse files
committed
Frontend: Ignore resilient binary swiftmodules under usr/lib/swift
Most SDKs use only swiftinterfaces under usr/lib/swift. Let's make sure we standardize this behavior and use only swiftinterface when they are present, even if there are also binary swiftmodule files available. Apply the same logic to SubFrameworks as well while we're at it. rdar://145316821
1 parent a619daf commit 40244a2

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ NOTE(sdk_version_pbm_version,none,
440440
NOTE(compiled_module_ignored_reason,none,
441441
"compiled module '%0' was ignored because %select{%error"
442442
"|it belongs to a framework in the SDK"
443+
"|it's a library module in the SDK"
443444
"|loading from module interfaces is preferred"
444445
"|it's a compiler host module"
445446
"|the module name is blocklisted,"

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct ModuleRebuildInfo {
237237
enum class ReasonIgnored {
238238
NotIgnored,
239239
PublicFramework,
240+
PublicLibrary,
240241
InterfacePreferred,
241242
CompilerHostModule,
242243
Blocklisted,
@@ -762,6 +763,28 @@ class ModuleInterfaceLoaderImpl {
762763
return pathStartsWith(frameworksPath, path);
763764
}
764765

766+
bool isInSystemSubFrameworks(StringRef path) {
767+
StringRef sdkPath = ctx.SearchPathOpts.getSDKPath();
768+
if (sdkPath.empty()) return false;
769+
770+
SmallString<128> frameworksPath;
771+
llvm::sys::path::append(frameworksPath,
772+
sdkPath, "System", "Library", "SubFrameworks");
773+
774+
return pathStartsWith(frameworksPath, path);
775+
}
776+
777+
bool isInSystemLibraries(StringRef path) {
778+
StringRef sdkPath = ctx.SearchPathOpts.getSDKPath();
779+
if (sdkPath.empty()) return false;
780+
781+
SmallString<128> frameworksPath;
782+
llvm::sys::path::append(frameworksPath,
783+
sdkPath, "usr", "lib", "swift");
784+
785+
return pathStartsWith(frameworksPath, path);
786+
}
787+
765788
std::pair<std::string, std::string> getCompiledModuleCandidates() {
766789
using ReasonIgnored = ModuleRebuildInfo::ReasonIgnored;
767790
using ReasonModuleInterfaceIgnored =
@@ -813,10 +836,15 @@ class ModuleInterfaceLoaderImpl {
813836

814837
// Don't use the adjacent swiftmodule for frameworks from the public
815838
// Frameworks folder of the SDK.
816-
if (isInSystemFrameworks(modulePath, /*publicFramework*/true)) {
839+
if (isInSystemFrameworks(modulePath, /*publicFramework*/true) ||
840+
isInSystemSubFrameworks(modulePath)) {
817841
shouldLoadAdjacentModule = false;
818842
rebuildInfo.addIgnoredModule(modulePath,
819843
ReasonIgnored::PublicFramework);
844+
} else if (isInSystemLibraries(modulePath) && moduleName != STDLIB_NAME) {
845+
shouldLoadAdjacentModule = false;
846+
rebuildInfo.addIgnoredModule(modulePath,
847+
ReasonIgnored::PublicLibrary);
820848
} else if (isInResourceHostDir(modulePath)) {
821849
shouldLoadAdjacentModule = false;
822850
rebuildInfo.addIgnoredModule(modulePath,

test/ModuleInterface/ignore-adjacent-swiftmodules.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,40 @@
33
// REQUIRES: VENDOR=apple
44

55
/// Prepare the SDK.
6+
//// Public framework
67
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
78
// RUN: %target-swift-frontend -emit-module -module-name PublicSwift -enable-library-evolution -swift-version 5 \
89
// RUN: %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/source.swift \
910
// RUN: -o %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name \
1011
// RUN: -emit-module-interface-path %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name
1112
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name) -module-name PublicSwift
13+
14+
//// Private framework
1215
// RUN: %target-swift-frontend -emit-module -module-name PrivateSwift -enable-library-evolution -swift-version 5 \
1316
// RUN: %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/source.swift \
1417
// RUN: -o %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name \
1518
// RUN: -emit-module-interface-path %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name
1619
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name) -module-name PrivateSwift
1720

21+
//// Public library
22+
// RUN: %target-swift-frontend -emit-module -module-name PublicSwiftLibrary -enable-library-evolution -swift-version 5 \
23+
// RUN: %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/source.swift \
24+
// RUN: -o %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name \
25+
// RUN: -emit-module-interface-path %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name
26+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name) -module-name PublicSwiftLibrary
27+
28+
//// Public subframework
29+
// RUN: %target-swift-frontend -emit-module -module-name SubSwift -enable-library-evolution -swift-version 5 \
30+
// RUN: %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/source.swift \
31+
// RUN: -o %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name \
32+
// RUN: -emit-module-interface-path %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name
33+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name) -module-name SubSwift
34+
1835
/// Break the swiftmodules.
1936
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name
2037
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name
38+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name
39+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name
2140

2241
/// There should be no attempt at loading the malformed PublicSwift swiftmodule.
2342
/// This means no notes about:
@@ -36,3 +55,9 @@ import PrivateSwift
3655
// expected-remark @-1 {{rebuilding module 'PrivateSwift' from interface}}
3756
// expected-note @-2 {{compiled module is out of date}}
3857
// expected-note @-3 {{: malformed}}
58+
59+
import PublicSwiftLibrary // expected-remark {{rebuilding module 'PublicSwiftLibrary' from interface}}
60+
// expected-note @-1 {{was ignored because it's a library module in the SDK}}
61+
62+
import SubSwift // expected-remark {{rebuilding module 'SubSwift' from interface}}
63+
// expected-note @-1 {{was ignored because it belongs to a framework in the SDK}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func foo() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func foo() {}

0 commit comments

Comments
 (0)