@@ -252,22 +252,22 @@ extension InterModuleDependencyGraph {
252
252
internal extension InterModuleDependencyGraph {
253
253
func explainDependency( dependencyModuleName: String ) throws -> [ [ ModuleDependencyId ] ] ? {
254
254
guard modules. contains ( where: { $0. key. moduleName == dependencyModuleName } ) else { return nil }
255
- var results = [ [ ModuleDependencyId] ] ( )
255
+ var results = Set < [ ModuleDependencyId ] > ( )
256
256
try findAllPaths ( source: . swift( mainModuleName) ,
257
257
to: dependencyModuleName,
258
258
pathSoFar: [ . swift( mainModuleName) ] ,
259
259
results: & results)
260
- return Array ( results)
260
+ return results. sorted ( by : { $0 . count < $1 . count } )
261
261
}
262
262
263
263
264
264
private func findAllPaths( source: ModuleDependencyId ,
265
265
to moduleName: String ,
266
266
pathSoFar: [ ModuleDependencyId ] ,
267
- results: inout [ [ ModuleDependencyId ] ] ) throws {
267
+ results: inout Set < [ ModuleDependencyId ] > ) throws {
268
268
let sourceInfo = try moduleInfo ( of: source)
269
269
// If the source is our target, we are done
270
- guard source. moduleName != moduleName else {
270
+ if source. moduleName == moduleName {
271
271
// If the source is a target Swift module, also check if it
272
272
// depends on a corresponding Clang module with the same name.
273
273
// If it does, add it to the path as well.
@@ -276,8 +276,7 @@ internal extension InterModuleDependencyGraph {
276
276
dependencies. contains ( . clang( moduleName) ) {
277
277
completePath. append ( . clang( moduleName) )
278
278
}
279
- results. append ( completePath)
280
- return
279
+ results. insert ( completePath)
281
280
}
282
281
283
282
var allDependencies = sourceInfo. directDependencies ?? [ ]
0 commit comments