@@ -252,22 +252,22 @@ extension InterModuleDependencyGraph {
252252internal extension InterModuleDependencyGraph {
253253 func explainDependency( dependencyModuleName: String ) throws -> [ [ ModuleDependencyId ] ] ? {
254254 guard modules. contains ( where: { $0. key. moduleName == dependencyModuleName } ) else { return nil }
255- var results = [ [ ModuleDependencyId] ] ( )
255+ var results = Set < [ ModuleDependencyId ] > ( )
256256 try findAllPaths ( source: . swift( mainModuleName) ,
257257 to: dependencyModuleName,
258258 pathSoFar: [ . swift( mainModuleName) ] ,
259259 results: & results)
260- return Array ( results)
260+ return results. sorted ( by : { $0 . count < $1 . count } )
261261 }
262262
263263
264264 private func findAllPaths( source: ModuleDependencyId ,
265265 to moduleName: String ,
266266 pathSoFar: [ ModuleDependencyId ] ,
267- results: inout [ [ ModuleDependencyId ] ] ) throws {
267+ results: inout Set < [ ModuleDependencyId ] > ) throws {
268268 let sourceInfo = try moduleInfo ( of: source)
269269 // If the source is our target, we are done
270- guard source. moduleName != moduleName else {
270+ if source. moduleName == moduleName {
271271 // If the source is a target Swift module, also check if it
272272 // depends on a corresponding Clang module with the same name.
273273 // If it does, add it to the path as well.
@@ -276,8 +276,7 @@ internal extension InterModuleDependencyGraph {
276276 dependencies. contains ( . clang( moduleName) ) {
277277 completePath. append ( . clang( moduleName) )
278278 }
279- results. append ( completePath)
280- return
279+ results. insert ( completePath)
281280 }
282281
283282 var allDependencies = sourceInfo. directDependencies ?? [ ]
0 commit comments