Skip to content

ModuleInterface: allow blocklist to configure module names from SDKs that we use textual interfaces exclusively #69480

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
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
3 changes: 2 additions & 1 deletion include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ NOTE(compiled_module_ignored_reason,none,
"compiled module '%0' was ignored because %select{%error"
"|it belongs to a framework in the SDK"
"|loading from module interfaces is preferred"
"|it's a compiler host module}1",
"|it's a compiler host module"
"|the module name is blocklisted}1",
(StringRef, unsigned))
NOTE(out_of_date_module_here,none,
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
Expand Down
9 changes: 9 additions & 0 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ struct ModuleRebuildInfo {
PublicFramework,
InterfacePreferred,
CompilerHostModule,
Blocklisted,
};
struct CandidateModule {
std::string path;
Expand Down Expand Up @@ -758,6 +759,14 @@ class ModuleInterfaceLoaderImpl {
// Should we attempt to load a swiftmodule adjacent to the swiftinterface?
bool shouldLoadAdjacentModule = !ctx.IgnoreAdjacentModules;

if (modulePath.contains(".sdk")) {
if (ctx.blockListConfig.hasBlockListAction(moduleName,
BlockListKeyKind::ModuleName, BlockListAction::ShouldUseTextualModule)) {
shouldLoadAdjacentModule = false;
rebuildInfo.addIgnoredModule(modulePath, ReasonIgnored::Blocklisted);
}
}

// Don't use the adjacent swiftmodule for frameworks from the public
// Frameworks folder of the SDK.
if (isInSystemFrameworks(modulePath, /*publicFramework*/true)) {
Expand Down
35 changes: 35 additions & 0 deletions test/ModuleInterface/block_list_textual_interface.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t.sdk)
// RUN: %empty-directory(%t/modulecache)
// RUN: %target-swift-frontend -emit-module -o %t.sdk/Foo.swiftmodule -emit-module-interface-path %t.sdk/Foo.swiftinterface -module-name Foo %s -D FOO -enable-library-evolution
// RUN: %target-swift-frontend -emit-module -o %t.sdk/Bar.swiftmodule -emit-module-interface-path %t.sdk/Bar.swiftinterface -module-name Bar %s -D BAR -enable-library-evolution -I %t.sdk

#if FOO

public func fooFunc() {}

#elseif BAR

import Foo
public func barFunc() { fooFunc() }

#elseif BAZ

import Bar
public func bazFunc() { barFunc() }

#endif


// RUN: echo "---" > %t/blocklist.yml
// RUN: echo "DowngradeInterfaceVerificationFailure:" >> %t/blocklist.yml
// RUN: echo " ModuleName:" >> %t/blocklist.yml
// RUN: echo " - TestBlocklistedModule # For tests" >> %t/blocklist.yml
// RUN: echo "ShouldUseTextualModule:" >> %t/blocklist.yml
// RUN: echo " ModuleName:" >> %t/blocklist.yml
// RUN: echo " - Foo # for tests" >> %t/blocklist.yml

// RUN: %target-swift-frontend -typecheck %s -D BAZ -I %t.sdk -blocklist-file %t/blocklist.yml -module-cache-path %t/modulecache -Rmodule-interface-rebuild &> %t/notes.txt
// RUN: %FileCheck -check-prefix CHECK-NOTES --input-file %t/notes.txt %s
// CHECK-NOTES: Foo.swiftmodule' was ignored because the module name is blocklisted