Skip to content

[Explicit Module Builds] When '-explain-module-dependency' encounters the target Swift module, continue enumerating other possible paths #1565

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 1 commit into from
Apr 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ?? []
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down