[FIR] Sort HMPP dependencies topologically for symbol providers

This fixes an issue where an actual class from an intermediate module
has more supertypes than its expect declaration which leads to a
false-positive resolution error because a type reference resolves to the
expect class. The fix is to sort the dependencies topologically from
"most actual" to "most expect" when creating the list of symbol
providers.

#KT-57369 Fixed
This commit is contained in:
Kirill Rakhman
2023-03-22 12:10:48 +01:00
committed by Space Team
parent 6fe0849402
commit 60b227c519
15 changed files with 174 additions and 33 deletions
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.container
import java.util.ArrayList
import java.util.HashSet
fun <T> topologicalSort(items: Iterable<T>, dependencies: (T) -> Iterable<T>): List<T> {
fun <T> topologicalSort(items: Iterable<T>, reverseOrder: Boolean = false, dependencies: (T) -> Iterable<T>): List<T> {
val itemsInProgress = HashSet<T>()
val completedItems = HashSet<T>()
val result = ArrayList<T>()
@@ -45,7 +45,7 @@ fun <T> topologicalSort(items: Iterable<T>, dependencies: (T) -> Iterable<T>): L
for (item in items)
DfsVisit(item)
return result.apply { reverse() }
return result.apply { if (!reverseOrder) reverse() }
}
class CycleInTopoSortException : Exception()
class CycleInTopoSortException : Exception()