Skip to content

[Dependency Scanning] Remove Unnecessary Code that Computes Module Output Path #79752

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
Mar 4, 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
15 changes: 4 additions & 11 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ExplicitModuleDependencyResolver {
SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
if (resolvingDepInfo.isSwiftInterfaceModule()) {
pruneUnusedVFSOverlay(swiftInterfaceOutputPath);
updateSwiftInterfaceModuleOutputPath(swiftInterfaceOutputPath);
addSwiftInterfaceModuleOutputPathToCommandLine(swiftInterfaceOutputPath);
}

// Update the dependency in the cache with the modified command-line.
Expand Down Expand Up @@ -455,19 +455,12 @@ class ExplicitModuleDependencyResolver {
return;
}

void updateSwiftInterfaceModuleOutputPath(
void addSwiftInterfaceModuleOutputPathToCommandLine(
const SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
StringRef outputName = outputPath.outputPath.str();

bool isOutputPath = false;
for (auto &A : commandline) {
if (isOutputPath) {
A = outputName.str();
break;
} else if (A == "-o") {
isOutputPath = true;
}
}
commandline.push_back("-o");
commandline.push_back(outputName.str());

return;
}
Expand Down
14 changes: 0 additions & 14 deletions lib/Serialization/ScanningLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
Args.push_back(candidate);
}

// Compute the output path and add it to the command line
SmallString<128> outputPathBase(moduleOutputPath);
llvm::sys::path::append(
outputPathBase,
moduleName.str() + "-" + Hash + "." +
file_types::getExtension(file_types::TY_SwiftModuleFile));
Args.push_back("-o");
Args.push_back(outputPathBase.str().str());

// Open the interface file.
auto &fs = *Ctx.SourceMgr.getFileSystem();
auto interfaceBuf = fs.getBufferForFile(moduleInterfacePath);
Expand Down Expand Up @@ -251,11 +242,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
InPath, compiledCandidatesRefs, ArgsRefs, {}, {}, linkLibraries,
isFramework, isStatic, {}, /*module-cache-key*/ "", UserModVer);

// We do NOT need the code below to set output path in the dependency
// info because it will be calculated again later. We do not want to
// create output paths that do not exist in the end.
// Result->setOutputPathAndHash(outputPathBase.str().str(), Hash);

if (Ctx.CASOpts.EnableCaching) {
std::vector<std::string> clangDependencyFiles;
auto clangImporter =
Expand Down
4 changes: 2 additions & 2 deletions test/ScanDependencies/FilterClangSearchPaths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import C
// CHECK-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}Inputs{{/|\\}}Swift{{/|\\}}A.swiftinterface",
// CHECK: "commandLine": [
// CHECK: "-fobjc-disable-direct-methods-for-testing"
// CHECK: "-o",
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule",
// CHECK-NOT: "/tmp/foo"
// CHECK-NOT: "-I/tmp/bar"
// CHECK: "-o",
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule"
// CHECK: ]
2 changes: 1 addition & 1 deletion test/ScanDependencies/ObjCStrict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import C
// CHECK: "commandLine": [
// CHECK: "-fobjc-disable-direct-methods-for-testing"
// CHECK: "-o",
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule",
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule"



12 changes: 6 additions & 6 deletions test/ScanDependencies/eliminate_unused_vfs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,30 @@ import F
// MOD-HASH-NEXT: "swift": {
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
// MOD-HASH: "commandLine": [
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH:.*]].swiftmodule",
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH:.*]].swiftmodule",
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH:.*]].swiftmodule",
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH:.*]].swiftmodule"
// MOD-HASH: ],
// MOD-HASH: "mainModuleName": "deps1",
// MOD-HASH: "linkLibraries": [],
// MOD-HASH: "details": {
// MOD-HASH-NEXT: "swift": {
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
// MOD-HASH: "commandLine": [
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule",
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH]].swiftmodule",
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH]].swiftmodule",
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule"
// MOD-HASH: ],
// MOD-HASH: "mainModuleName": "deps2",
// MOD-HASH: "linkLibraries": [],
// MOD-HASH: "details": {
// MOD-HASH-NEXT: "swift": {
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
// MOD-HASH: "commandLine": [
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule",
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH]].swiftmodule",
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH]].swiftmodule",
// MOD-HASH: "-o",
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule"
// MOD-HASH: ],
4 changes: 2 additions & 2 deletions test/ScanDependencies/explicit-swift-dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import F
// CHECK-NEXT: "-fno-implicit-modules",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "-fno-implicit-module-maps",
// CHECK-NEXT: "-o",
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"
// CHECK-DAG: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-{{.*}}.swiftmodule"
// CHECK-DAG: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-{{.*}}.swiftmodule"
// CHECK-DAG: "-fmodule-file=F={{.*}}{{/|\\}}F-{{.*}}.pcm"
// CHECK-DAG: "-fmodule-file=SwiftShims={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm"
// CHECK-NEXT: "-o",
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"