Skip to content

Commit c539f7e

Browse files
authored
Merge pull request #79588 from xymus/ignore-more-swiftmodules
Frontend: Ignore resilient binary swiftmodules under usr/lib/swift
2 parents 468371f + f6ef819 commit c539f7e

File tree

6 files changed

+96
-8
lines changed

6 files changed

+96
-8
lines changed

include/swift/AST/DiagnosticsFrontend.def

+1
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

+29-1
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,
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,82 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %empty-directory(%t/cache)
2+
// RUN: %empty-directory(%t/cache0)
3+
// RUN: %empty-directory(%t/cache1)
4+
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
35
// REQUIRES: VENDOR=apple
46

57
/// Prepare the SDK.
6-
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
8+
//// stdlib
9+
// RUN: %target-swift-frontend -emit-module -module-name Swift -enable-library-evolution -swift-version 5 \
10+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize \
11+
// RUN: %t/sdk/usr/lib/swift/Swift.swiftmodule/source.swift \
12+
// RUN: -o %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftmodule-name \
13+
// RUN: -emit-module-interface-path %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftinterface-name \
14+
// RUN: -parse-stdlib
15+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftinterface-name) -module-name Swift -parse-stdlib
16+
17+
//// Public framework
718
// RUN: %target-swift-frontend -emit-module -module-name PublicSwift -enable-library-evolution -swift-version 5 \
19+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
820
// RUN: %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/source.swift \
921
// RUN: -o %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name \
1022
// RUN: -emit-module-interface-path %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name
1123
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name) -module-name PublicSwift
24+
25+
//// Private framework
1226
// RUN: %target-swift-frontend -emit-module -module-name PrivateSwift -enable-library-evolution -swift-version 5 \
27+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
1328
// RUN: %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/source.swift \
1429
// RUN: -o %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name \
1530
// RUN: -emit-module-interface-path %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name
1631
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name) -module-name PrivateSwift
1732

33+
//// Public library
34+
// RUN: %target-swift-frontend -emit-module -module-name PublicSwiftLibrary -enable-library-evolution -swift-version 5 \
35+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
36+
// RUN: %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/source.swift \
37+
// RUN: -o %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name \
38+
// RUN: -emit-module-interface-path %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name
39+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name) -module-name PublicSwiftLibrary
40+
41+
//// Public subframework
42+
// RUN: %target-swift-frontend -emit-module -module-name SubSwift -enable-library-evolution -swift-version 5 \
43+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
44+
// RUN: %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/source.swift \
45+
// RUN: -o %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name \
46+
// RUN: -emit-module-interface-path %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name
47+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name) -module-name SubSwift
48+
1849
/// Break the swiftmodules.
1950
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name
2051
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name
52+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name
53+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name
2154

22-
/// There should be no attempt at loading the malformed PublicSwift swiftmodule.
23-
/// This means no notes about:
55+
/// Check the loading behavior from attempts at loading the malformed swiftmodules,
56+
/// printing the notes:
2457
/// * compiled module is out of date
2558
/// * unable to load compiled module '*': malformed
59+
60+
/// Check diagnostics in the local file:
2661
// RUN: %target-swift-frontend -typecheck %s -sdk %t/sdk \
27-
// RUN: -module-name Main -module-cache-path %t/cache \
28-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
29-
// RUN: -verify -Rmodule-interface-rebuild
62+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import \
63+
// RUN: -module-name Main -module-cache-path %t/cache0 \
64+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -resource-dir "" \
65+
// RUN: -verify -verify-ignore-unknown -Rmodule-interface-rebuild -diagnostic-style=llvm
66+
67+
/// Check diagnostic for implicit imports:
68+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftmodule-name
69+
// RUN: %target-swift-frontend -typecheck %s -sdk %t/sdk \
70+
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import \
71+
// RUN: -module-name Main -module-cache-path %t/cache1 \
72+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -resource-dir "" \
73+
// RUN: -Rmodule-interface-rebuild -Rmodule-loading -diagnostic-style=llvm 2> %t/out
74+
// RUN: %FileCheck --input-file %t/out %s
75+
76+
import Swift
77+
// CHECK: rebuilding module 'Swift' from interface
78+
// CHECK-NEXT: compiled module is out of date
79+
// CHECK-NEXT: : malformed
3080

3181
import PublicSwift // expected-remark {{rebuilding module 'PublicSwift' from interface}}
3282
// expected-note @-1 {{was ignored because it belongs to a framework in the SDK}}
@@ -36,3 +86,9 @@ import PrivateSwift
3686
// expected-remark @-1 {{rebuilding module 'PrivateSwift' from interface}}
3787
// expected-note @-2 {{compiled module is out of date}}
3888
// expected-note @-3 {{: malformed}}
89+
90+
import PublicSwiftLibrary // expected-remark {{rebuilding module 'PublicSwiftLibrary' from interface}}
91+
// expected-note @-1 {{was ignored because it's a library module in the SDK}}
92+
93+
import SubSwift // expected-remark {{rebuilding module 'SubSwift' from interface}}
94+
// 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() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func foo() {}

0 commit comments

Comments
 (0)