Skip to content

Commit 17ec817

Browse files
authored
Merge pull request swiftlang#78129 from artemcm/61_NoIndexBlocklistedInterfaceModulesOnEBM
[6.1 🍒][Indexing] Disable indexing textual-interface-blocklisted modules during Explicit Module Builds
2 parents a8982e0 + b7d0335 commit 17ec817

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

lib/Index/IndexRecord.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
761761
SourceFile *initialFile) {
762762
StringRef filename = module->getModuleSourceFilename();
763763
std::string moduleName = module->getNameStr().str();
764+
auto &ctx = module->getASTContext();
764765

765766
// If this is a cross-import overlay, make sure we use the name of the
766767
// underlying module instead.
@@ -786,7 +787,6 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
786787
module->getResilienceStrategy() == ResilienceStrategy::Resilient &&
787788
!module->isBuiltFromInterface() &&
788789
!module->isStdlibModule()) {
789-
auto &ctx = module->getASTContext();
790790
llvm::SaveAndRestore<bool> S(ctx.IgnoreAdjacentModules, true);
791791

792792
ImportPath::Module::Builder builder(module->getName());
@@ -801,6 +801,22 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
801801
}
802802
}
803803

804+
// If this module is blocklisted from us using its textual interface,
805+
// then under Implicitly-Built modules it will not get indexed, since
806+
// indexing will not be able to spawn swiftinterface compilation.
807+
// With explicitly-built modules, none of the dependency modules get built
808+
// from interface during indexing, which means we directly index input
809+
// binary modules.
810+
//
811+
// For now, for functional parity with Implicit Module Builds, disable indexing
812+
// of modules during Explicit Module Builds which would not get indexed during
813+
// Implicit Module Builds.
814+
if (explicitModuleBuild &&
815+
ctx.blockListConfig.hasBlockListAction(moduleName,
816+
BlockListKeyKind::ModuleName,
817+
BlockListAction::ShouldUseBinaryModule))
818+
skipIndexingModule = true;
819+
804820
if (module->getASTContext().LangOpts.EnableIndexingSystemModuleRemarks) {
805821
diags.diagnose(SourceLoc(),
806822
diag::remark_indexing_system_module,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/ModCache)
4+
// RUN: %empty-directory(%t/ModInputs)
5+
// RUN: %empty-directory(%t/mock.sdk/SystemFrameworks/Foo.framework/modules)
6+
// RUN: split-file %s %t
7+
8+
// - Fixup the input module file map
9+
// RUN: sed -e "s|INPUTSDIR|%/t/ModInputs|g" %t/map.json.template > %t/map.json.template1
10+
// RUN: sed -e "s|STDLIBMOD|%/stdlib_module|g" %t/map.json.template1 > %t/map.json.template2
11+
// RUN: sed -e "s|ONONEMOD|%/ononesupport_module|g" %t/map.json.template2 > %t/map.json.template3
12+
// RUN: sed -e "s|FOOMOD|%t/mock.sdk/SystemFrameworks/Foo.framework/modules/Foo.swiftmodule/%target-swiftmodule-name|g" %t/map.json.template3 > %t/map.json.template4
13+
// RUN: sed -e "s|SWIFTLIBDIR|%swift-lib-dir|g" %t/map.json.template4 > %t/map.json
14+
15+
// - Set up explicit dependencies for Foo
16+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/ModInputs/SwiftShims.pcm -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules
17+
18+
// - Build Foo module dependency
19+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/mock.sdk/SystemFrameworks/Foo.framework/modules/Foo.swiftmodule/%target-swiftmodule-name -module-name Foo -emit-module-interface-path %t/mock.sdk/SystemFrameworks/Foo.framework/modules/Foo.swiftmodule/%target-swiftinterface-name -module-cache-path %t/ModCache %t/Foo.swift -module-name Foo -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules -explicit-swift-module-map-file %t/map.json
20+
21+
// - Build with indexing the main test module importing Foo, ensure system module Foo gets indexed
22+
// RUN: %target-swift-frontend -typecheck -swift-version 5 -index-system-modules -index-store-path %t/idx1 -index-ignore-stdlib -module-cache-path %t/ModCache -Rindexing-system-module %t/Client.swift -disable-deserialization-recovery -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -Fsystem %t/SystemFrameworks/ -sdk '' -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules -explicit-swift-module-map-file %t/map.json &> %t.indexed.out
23+
// RUN: %FileCheck %s -input-file=%t.indexed.out --check-prefix=CHECK-INDEXED
24+
25+
// - Build with indexing the main test module importing Foo, which is blocklisted and ensure Foo does not get indexed because it is blocklisted
26+
// RUN: %target-swift-frontend -typecheck -swift-version 5 -index-system-modules -index-store-path %t/idx2 -index-ignore-stdlib -module-cache-path %t/ModCache -Rindexing-system-module %t/Client.swift -disable-deserialization-recovery -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -Fsystem %t/SystemFrameworks/ -sdk '' -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules -explicit-swift-module-map-file %t/map.json -blocklist-file %t/blocklist.yml &> %t.blocklisted.out
27+
// RUN: %FileCheck %s -input-file=%t.blocklisted.out --check-prefix=CHECK-BLOCKLISTED
28+
29+
// CHECK-INDEXED-NOT: skipping because of a broken swiftinterface
30+
// CHECK-BLOCKLISTED: remark: indexing system module at {{.*}}Foo.swiftmodule{{/|\\}}{{.*}}.swiftmodule; skipping because of a broken swiftinterface
31+
32+
//--- blocklist.yml
33+
---
34+
ShouldUseBinaryModule:
35+
ModuleName:
36+
- Foo # for tests
37+
38+
//--- map.json.template
39+
[
40+
{
41+
"moduleName": "Swift",
42+
"modulePath": "STDLIBMOD",
43+
"isFramework": false
44+
},
45+
{
46+
"moduleName": "SwiftOnoneSupport",
47+
"modulePath": "ONONEMOD",
48+
"isFramework": false
49+
},
50+
{
51+
"moduleName": "Foo",
52+
"modulePath": "FOOMOD",
53+
"isFramework": false,
54+
"isSystem": true
55+
},
56+
{
57+
"moduleName": "SwiftShims",
58+
"isFramework": false,
59+
"clangModuleMapPath": "SWIFTLIBDIR/swift/shims/module.modulemap",
60+
"clangModulePath": "INPUTSDIR/SwiftShims.pcm"
61+
}]
62+
63+
//--- Foo.swift
64+
struct Foo {}
65+
66+
//--- Client.swift
67+
import Foo

0 commit comments

Comments
 (0)