Skip to content

Commit da97c9a

Browse files
committed
[Indexing] Disable indexing textual-interface-blocklisted modules during Explicit Module Builds
If a module is blocklisted from the compiler using its textual interface, then under Implicitly-Built modules it will not get indexed, since indexing will not be able to spawn swiftinterface compilation. With explicitly-built modules, none of the dependency modules get built from interface during indexing, which means we directly index input binary modules. For now, for functional parity with Implicit Module Builds, disable indexing of modules during Explicit Module Builds which would not get indexed during Implicit Module Builds.
1 parent bfae734 commit da97c9a

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/ModCache)
3+
// RUN: %empty-directory(%t/ModInputs)
4+
// RUN: %empty-directory(%t/mock.sdk/SystemFrameworks/Foo.framework/modules)
5+
// RUN: split-file %s %t
6+
7+
// - Fixup the input module file map
8+
// RUN: sed -e "s|INPUTSDIR|%/t/ModInputs|g" %t/map.json.template > %t/map.json.template1
9+
// RUN: sed -e "s|STDLIBMOD|%/stdlib_module|g" %t/map.json.template1 > %t/map.json.template2
10+
// RUN: sed -e "s|ONONEMOD|%/ononesupport_module|g" %t/map.json.template2 > %t/map.json.template3
11+
// 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
12+
// RUN: sed -e "s|SWIFTLIBDIR|%swift-lib-dir|g" %t/map.json.template4 > %t/map.json
13+
14+
// - Set up explicit dependencies for Foo
15+
// 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
16+
17+
// - Build Foo module dependency
18+
// 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
19+
20+
// - Build with indexing the main test module importing Foo, ensure system module Foo gets indexed
21+
// 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
22+
// RUN: %FileCheck %s -input-file=%t.indexed.out --check-prefix=CHECK-INDEXED
23+
24+
// - Build with indexing the main test module importing Foo, which is blocklisted and ensure Foo does not get indexed because it is blocklisted
25+
// 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
26+
// RUN: %FileCheck %s -input-file=%t.blocklisted.out --check-prefix=CHECK-BLOCKLISTED
27+
28+
// CHECK-INDEXED-NOT: skipping because of a broken swiftinterface
29+
// CHECK-BLOCKLISTED: remark: indexing system module at {{.*}}Foo.swiftmodule{{/|\\}}{{.*}}.swiftmodule; skipping because of a broken swiftinterface
30+
31+
//--- blocklist.yml
32+
---
33+
ShouldUseBinaryModule:
34+
ModuleName:
35+
- Foo # for tests
36+
37+
//--- map.json.template
38+
[
39+
{
40+
"moduleName": "Swift",
41+
"modulePath": "STDLIBMOD",
42+
"isFramework": false
43+
},
44+
{
45+
"moduleName": "SwiftOnoneSupport",
46+
"modulePath": "ONONEMOD",
47+
"isFramework": false
48+
},
49+
{
50+
"moduleName": "Foo",
51+
"modulePath": "FOOMOD",
52+
"isFramework": false,
53+
"isSystem": true
54+
},
55+
{
56+
"moduleName": "SwiftShims",
57+
"isFramework": false,
58+
"clangModuleMapPath": "SWIFTLIBDIR/swift/shims/module.modulemap",
59+
"clangModulePath": "INPUTSDIR/SwiftShims.pcm"
60+
}]
61+
62+
//--- Foo.swift
63+
struct Foo {}
64+
65+
//--- Client.swift
66+
import Foo

0 commit comments

Comments
 (0)