Skip to content

Commit 1506a0d

Browse files
[Caching] Remove capture clang extra files
After removing the CASFS implementation for clang modules, there is no need to capture clang extra file that sets up the VFS for the clang modules since all content imported by ClangImporter is dependency scanned and available via include-tree. This saves more ClangImporter instance when caching is enabled. Update the test to check that clang content found via `-Xcc` VFS options can currently work without capture the headermaps and vfs overlays.
1 parent 3c81c1c commit 1506a0d

File tree

6 files changed

+69
-69
lines changed

6 files changed

+69
-69
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,6 @@ class ClangImporter final : public ClangModuleLoader {
474474
/// Reads the original source file name from PCH.
475475
std::string getOriginalSourceFile(StringRef PCHFilename);
476476

477-
/// Add clang dependency file names.
478-
///
479-
/// \param files The list of file to append dependencies to.
480-
void addClangInvovcationDependencies(std::vector<std::string> &files);
481-
482477
/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
483478
/// module map into the replica and emits a PCM file for one of the modules it
484479
/// declares. Delegates to clang for everything except construction of the

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,27 +1038,6 @@ std::string ClangImporter::getOriginalSourceFile(StringRef PCHFilename) {
10381038
Impl.Instance->getPCHContainerReader(), Impl.Instance->getDiagnostics());
10391039
}
10401040

1041-
void ClangImporter::addClangInvovcationDependencies(
1042-
std::vector<std::string> &files) {
1043-
auto addFiles = [&files](const auto &F) {
1044-
files.insert(files.end(), F.begin(), F.end());
1045-
};
1046-
auto &invocation = *Impl.Invocation;
1047-
// FIXME: Add file dependencies that are not accounted. The long term solution
1048-
// is to do a dependency scanning for clang importer and use that directly.
1049-
SmallVector<std::string, 4> HeaderMapFileNames;
1050-
Impl.Instance->getPreprocessor().getHeaderSearchInfo().getHeaderMapFileNames(
1051-
HeaderMapFileNames);
1052-
addFiles(HeaderMapFileNames);
1053-
addFiles(invocation.getHeaderSearchOpts().VFSOverlayFiles);
1054-
// FIXME: Should not depend on working directory. Build system/swift driver
1055-
// should not pass working directory here but if that option is passed,
1056-
// repect that and add that into CASFS.
1057-
auto CWD = invocation.getFileSystemOpts().WorkingDir;
1058-
if (!CWD.empty())
1059-
files.push_back(CWD);
1060-
}
1061-
10621041
std::optional<std::string>
10631042
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
10641043
StringRef SwiftPCHHash, bool &isExplicit) {

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,6 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
595595
auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule(
596596
{}, buildCommands, {}, {}, {});
597597

598-
if (ScanASTContext.CASOpts.EnableCaching) {
599-
std::vector<std::string> clangDependencyFiles;
600-
clangImporter->addClangInvovcationDependencies(clangDependencyFiles);
601-
llvm::for_each(clangDependencyFiles, [&](std::string &file) {
602-
mainDependencies.addAuxiliaryFile(file);
603-
});
604-
}
605-
606598
llvm::StringSet<> alreadyAddedModules;
607599
// Compute Implicit dependencies of the main module
608600
{

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -783,15 +783,6 @@ bool CompilerInstance::setUpModuleLoaders() {
783783
this->DefaultSerializedLoader = ISML.get();
784784
Context->addModuleLoader(std::move(ISML));
785785

786-
// When caching is enabled, we rely on ClangImporter for
787-
// 'addClangInvovcationDependencies'
788-
if (Invocation.getCASOptions().EnableCaching) {
789-
std::unique_ptr<ClangImporter> clangImporter =
790-
ClangImporter::create(*Context, Invocation.getPCHHash(),
791-
getDependencyTracker());
792-
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
793-
}
794-
795786
return false;
796787
}
797788

lib/Serialization/ScanningLoaders.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
231231
InPath, compiledCandidatesRefs, ArgsRefs, {}, {}, linkLibraries,
232232
isFramework, isStatic, {}, /*module-cache-key*/ "", UserModVer);
233233

234-
if (Ctx.CASOpts.EnableCaching) {
235-
std::vector<std::string> clangDependencyFiles;
236-
auto clangImporter =
237-
static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
238-
clangImporter->addClangInvovcationDependencies(clangDependencyFiles);
239-
llvm::for_each(clangDependencyFiles, [&](std::string &file) {
240-
Result->addAuxiliaryFile(file);
241-
});
242-
}
243-
244234
// Walk the source file to find the import declarations.
245235
llvm::StringSet<> alreadyAddedModules;
246236
Result->addModuleImports(*sourceFile, alreadyAddedModules,

test/CAS/module_deps_clang_extras.swift

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,99 @@
44
// RUN: mkdir -p %t/clang-module-cache
55
// RUN: mkdir -p %t/cas
66
// RUN: split-file %s %t
7-
// RUN: %hmaptool write %t/hmap.json %t/empty.hmap
7+
// RUN: sed "s|DIR|%/t|g" %t/hmap.json.template > %t/hmap.json
8+
// RUN: sed "s|DIR|%/t|g" %t/test.yaml.template > %t/test.yaml
9+
// RUN: %hmaptool write %t/hmap.json %t/test.hmap
810

911
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache \
10-
// RUN: %t/Test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas \
11-
// RUN: -Xcc -fmodule-map-file=%t/module.modulemap -Xcc -ivfsoverlay -Xcc %t/empty.yaml \
12-
// RUN: -Xcc -I%t/empty.hmap
12+
// RUN: %t/Test.swift -module-name Test -o %t/deps.json -cache-compile-job -cas-path %t/cas \
13+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
14+
// RUN: -Xcc -fmodule-map-file=%t/include/module.modulemap -Xcc -ivfsoverlay -Xcc %t/test.yaml \
15+
// RUN: -Xcc -I%t/test.hmap -module-load-mode prefer-serialized -scanner-output-dir %t \
16+
// RUN: -import-objc-header %t/Bridge.h -auto-bridging-header-chaining
1317
// RUN: %validate-json %t/deps.json &>/dev/null
1418

15-
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json deps casFSRootID > %t/fs.casid
19+
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json Test casFSRootID > %t/fs.casid
1620
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-include-tree-list @%t/fs.casid | %FileCheck %s -DDIR=%basename_t -check-prefix FS_ROOT
17-
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:Dummy clangIncludeTree > %t/tree.casid
18-
// RUN: clang-cas-test --cas %t/cas --print-include-tree @%t/tree.casid | %FileCheck %s -DDIR=%basename_t -check-prefix INCLUDE_TREE
1921

20-
// FS_ROOT: [[DIR]].tmp/empty.hmap
21-
// FS_ROOT: [[DIR]].tmp/empty.yaml
22+
// FS_ROOT: [[DIR]].tmp/hidden/Dummy.h
23+
// FS_ROOT: [[DIR]].tmp/hidden/a.h
24+
// FS_ROOT: [[DIR]].tmp/hidden/b.h
2225

23-
// INCLUDE_TREE: [[DIR]].tmp/Dummy.h
26+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd
27+
// RUN: %swift_frontend_plain @%t/shim.cmd
28+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:Dummy > %t/dummy.cmd
29+
// RUN: %swift_frontend_plain @%t/dummy.cmd
30+
31+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json bridgingHeader > %t/header.cmd
32+
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch
33+
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
34+
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch > %t/keys.json
35+
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys.json > %t/key
36+
37+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
38+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
39+
40+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
41+
// RUN: echo "\"-disable-implicit-string-processing-module-import\"" >> %t/MyApp.cmd
42+
// RUN: echo "\"-disable-implicit-concurrency-module-import\"" >> %t/MyApp.cmd
43+
// RUN: echo "\"-disable-implicit-swift-modules\"" >> %t/MyApp.cmd
44+
// RUN: echo "\"-import-objc-header\"" >> %t/MyApp.cmd
45+
// RUN: echo "\"%t/objc.pch\"" >> %t/MyApp.cmd
46+
// RUN: echo "\"-bridging-header-pch-key\"" >> %t/MyApp.cmd
47+
// RUN: echo "\"@%t/key\"" >> %t/MyApp.cmd
48+
// RUN: echo "\"-explicit-swift-module-map-file\"" >> %t/MyApp.cmd
49+
// RUN: echo "\"@%t/map.casid\"" >> %t/MyApp.cmd
50+
51+
// RUN: %target-swift-frontend -cache-compile-job -module-name Test -O -cas-path %t/cas @%t/MyApp.cmd %t/Test.swift \
52+
// RUN: -emit-module -o %t/test.swiftmodule
2453

2554
//--- Test.swift
2655
import Dummy
2756
func test() {}
2857

29-
//--- module.modulemap
58+
//--- Bridge.h
59+
#include "b.h"
60+
61+
//--- hidden/module.modulemap
3062
module Dummy {
3163
umbrella header "Dummy.h"
3264
}
3365

34-
//--- Dummy.h
66+
//--- hidden/Dummy.h
67+
#include "a.h"
3568
void dummy(void);
3669

37-
//--- hmap.json
70+
//--- hidden/a.h
71+
/* empty file */
72+
73+
//--- hidden/b.h
74+
/* empty file */
75+
76+
//--- hmap.json.template
3877
{
39-
"mappings": {}
78+
"mappings": {
79+
"a.h": "DIR/hidden/a.h",
80+
"b.h": "DIR/hidden/b.h"
81+
}
4082
}
4183

42-
//--- empty.yaml
84+
//--- test.yaml.template
4385
{
4486
"version": 0,
4587
"case-sensitive": "false",
4688
"use-external-names": true,
47-
"roots": []
89+
"roots": [
90+
{
91+
"type": "file",
92+
"name": "DIR/include/module.modulemap",
93+
"external-contents": "DIR/hidden/module.modulemap"
94+
},
95+
{
96+
"type": "file",
97+
"name": "DIR/include/Dummy.h",
98+
"external-contents": "DIR/hidden/Dummy.h"
99+
},
100+
]
48101
}
49102

0 commit comments

Comments
 (0)