From 855d8b07dc68012a907521ceeb4926331cbcecba Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Mon, 18 Mar 2024 10:23:10 -0700 Subject: [PATCH] [Explicit Module Builds] When '-explain-module-dependency' encounters the target Swift module, continue enumerating other possible paths --- .../CommonDependencyOperations.swift | 11 +++++------ Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift index a4c742a07..eaad3543d 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift @@ -252,22 +252,22 @@ extension InterModuleDependencyGraph { internal extension InterModuleDependencyGraph { func explainDependency(dependencyModuleName: String) throws -> [[ModuleDependencyId]]? { guard modules.contains(where: { $0.key.moduleName == dependencyModuleName }) else { return nil } - var results = [[ModuleDependencyId]]() + var results = Set<[ModuleDependencyId]>() try findAllPaths(source: .swift(mainModuleName), to: dependencyModuleName, pathSoFar: [.swift(mainModuleName)], results: &results) - return Array(results) + return results.sorted(by: { $0.count < $1.count }) } private func findAllPaths(source: ModuleDependencyId, to moduleName: String, pathSoFar: [ModuleDependencyId], - results: inout [[ModuleDependencyId]]) throws { + results: inout Set<[ModuleDependencyId]>) throws { let sourceInfo = try moduleInfo(of: source) // If the source is our target, we are done - guard source.moduleName != moduleName else { + if source.moduleName == moduleName { // If the source is a target Swift module, also check if it // depends on a corresponding Clang module with the same name. // If it does, add it to the path as well. @@ -276,8 +276,7 @@ internal extension InterModuleDependencyGraph { dependencies.contains(.clang(moduleName)) { completePath.append(.clang(moduleName)) } - results.append(completePath) - return + results.insert(completePath) } var allDependencies = sourceInfo.directDependencies ?? [] diff --git a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift index 73e0719d3..a45831e4e 100644 --- a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift +++ b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift @@ -1923,6 +1923,7 @@ final class ExplicitModuleBuildTests: XCTestCase { print(diag.behavior) print(diag.message) } + XCTAssertEqual(driver.diagnosticEngine.diagnostics.filter { $0.behavior == .note}.count, 2) XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .note && $0.message.text == "[testTraceDependency] -> [A] -> [A](ObjC)"}) XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .note &&