Skip to content

Frontend: Ignore resilient binary swiftmodules under usr/lib/swift #79588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ NOTE(sdk_version_pbm_version,none,
NOTE(compiled_module_ignored_reason,none,
"compiled module '%0' was ignored because %select{%error"
"|it belongs to a framework in the SDK"
"|it's a library module in the SDK"
"|loading from module interfaces is preferred"
"|it's a compiler host module"
"|the module name is blocklisted,"
Expand Down
30 changes: 29 additions & 1 deletion lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ struct ModuleRebuildInfo {
enum class ReasonIgnored {
NotIgnored,
PublicFramework,
PublicLibrary,
InterfacePreferred,
CompilerHostModule,
Blocklisted,
Expand Down Expand Up @@ -762,6 +763,28 @@ class ModuleInterfaceLoaderImpl {
return pathStartsWith(frameworksPath, path);
}

bool isInSystemSubFrameworks(StringRef path) {
StringRef sdkPath = ctx.SearchPathOpts.getSDKPath();
if (sdkPath.empty()) return false;

SmallString<128> frameworksPath;
llvm::sys::path::append(frameworksPath,
sdkPath, "System", "Library", "SubFrameworks");

return pathStartsWith(frameworksPath, path);
}

bool isInSystemLibraries(StringRef path) {
StringRef sdkPath = ctx.SearchPathOpts.getSDKPath();
if (sdkPath.empty()) return false;

SmallString<128> frameworksPath;
llvm::sys::path::append(frameworksPath,
sdkPath, "usr", "lib", "swift");

return pathStartsWith(frameworksPath, path);
}

std::pair<std::string, std::string> getCompiledModuleCandidates() {
using ReasonIgnored = ModuleRebuildInfo::ReasonIgnored;
using ReasonModuleInterfaceIgnored =
Expand Down Expand Up @@ -813,10 +836,15 @@ class ModuleInterfaceLoaderImpl {

// Don't use the adjacent swiftmodule for frameworks from the public
// Frameworks folder of the SDK.
if (isInSystemFrameworks(modulePath, /*publicFramework*/true)) {
if (isInSystemFrameworks(modulePath, /*publicFramework*/true) ||
isInSystemSubFrameworks(modulePath)) {
shouldLoadAdjacentModule = false;
rebuildInfo.addIgnoredModule(modulePath,
ReasonIgnored::PublicFramework);
} else if (isInSystemLibraries(modulePath) && moduleName != STDLIB_NAME) {
shouldLoadAdjacentModule = false;
rebuildInfo.addIgnoredModule(modulePath,
ReasonIgnored::PublicLibrary);
} else if (isInResourceHostDir(modulePath)) {
shouldLoadAdjacentModule = false;
rebuildInfo.addIgnoredModule(modulePath,
Expand Down
70 changes: 63 additions & 7 deletions test/ModuleInterface/ignore-adjacent-swiftmodules.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/cache)
// RUN: %empty-directory(%t/cache0)
// RUN: %empty-directory(%t/cache1)
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
// REQUIRES: VENDOR=apple

/// Prepare the SDK.
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
//// stdlib
// RUN: %target-swift-frontend -emit-module -module-name Swift -enable-library-evolution -swift-version 5 \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize \
// RUN: %t/sdk/usr/lib/swift/Swift.swiftmodule/source.swift \
// RUN: -o %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftmodule-name \
// RUN: -emit-module-interface-path %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftinterface-name \
// RUN: -parse-stdlib
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftinterface-name) -module-name Swift -parse-stdlib

//// Public framework
// RUN: %target-swift-frontend -emit-module -module-name PublicSwift -enable-library-evolution -swift-version 5 \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
// RUN: %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/source.swift \
// RUN: -o %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name \
// RUN: -emit-module-interface-path %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name) -module-name PublicSwift

//// Private framework
// RUN: %target-swift-frontend -emit-module -module-name PrivateSwift -enable-library-evolution -swift-version 5 \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
// RUN: %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/source.swift \
// RUN: -o %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name \
// RUN: -emit-module-interface-path %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name) -module-name PrivateSwift

//// Public library
// RUN: %target-swift-frontend -emit-module -module-name PublicSwiftLibrary -enable-library-evolution -swift-version 5 \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
// RUN: %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/source.swift \
// RUN: -o %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name \
// RUN: -emit-module-interface-path %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftinterface-name) -module-name PublicSwiftLibrary

//// Public subframework
// RUN: %target-swift-frontend -emit-module -module-name SubSwift -enable-library-evolution -swift-version 5 \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -Osize -sdk %t/sdk \
// RUN: %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/source.swift \
// RUN: -o %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name \
// RUN: -emit-module-interface-path %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftinterface-name) -module-name SubSwift

/// Break the swiftmodules.
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/SubFrameworks/SubSwift.framework/Modules/SubSwift.swiftmodule/%target-swiftmodule-name
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/usr/lib/swift/PublicSwiftLibrary.swiftmodule/%target-swiftmodule-name

/// There should be no attempt at loading the malformed PublicSwift swiftmodule.
/// This means no notes about:
/// Check the loading behavior from attempts at loading the malformed swiftmodules,
/// printing the notes:
/// * compiled module is out of date
/// * unable to load compiled module '*': malformed

/// Check diagnostics in the local file:
// RUN: %target-swift-frontend -typecheck %s -sdk %t/sdk \
// RUN: -module-name Main -module-cache-path %t/cache \
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
// RUN: -verify -Rmodule-interface-rebuild
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import \
// RUN: -module-name Main -module-cache-path %t/cache0 \
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -resource-dir "" \
// RUN: -verify -verify-ignore-unknown -Rmodule-interface-rebuild -diagnostic-style=llvm

/// Check diagnostic for implicit imports:
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/usr/lib/swift/Swift.swiftmodule/%target-swiftmodule-name
// RUN: %target-swift-frontend -typecheck %s -sdk %t/sdk \
// RUN: -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import \
// RUN: -module-name Main -module-cache-path %t/cache1 \
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -resource-dir "" \
// RUN: -Rmodule-interface-rebuild -Rmodule-loading -diagnostic-style=llvm 2> %t/out
// RUN: %FileCheck --input-file %t/out %s

import Swift
// CHECK: rebuilding module 'Swift' from interface
// CHECK-NEXT: compiled module is out of date
// CHECK-NEXT: : malformed

import PublicSwift // expected-remark {{rebuilding module 'PublicSwift' from interface}}
// expected-note @-1 {{was ignored because it belongs to a framework in the SDK}}
Expand All @@ -36,3 +86,9 @@ import PrivateSwift
// expected-remark @-1 {{rebuilding module 'PrivateSwift' from interface}}
// expected-note @-2 {{compiled module is out of date}}
// expected-note @-3 {{: malformed}}

import PublicSwiftLibrary // expected-remark {{rebuilding module 'PublicSwiftLibrary' from interface}}
// expected-note @-1 {{was ignored because it's a library module in the SDK}}

import SubSwift // expected-remark {{rebuilding module 'SubSwift' from interface}}
// expected-note @-1 {{was ignored because it belongs to a framework in the SDK}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func foo() {}