FIR: Simplify supertypes scopes computation

This commit is contained in:
Denis.Zharkov
2021-02-03 20:29:18 +03:00
parent 31b9be2d01
commit 6766c8fe47
2 changed files with 47 additions and 22 deletions
@@ -42,6 +42,39 @@ fun lookupSuperTypes(
}
}
fun FirClass<*>.isThereLoopInSupertypes(session: FirSession): Boolean {
val visitedSymbols: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
val inProcess: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
var isThereLoop = false
fun dfs(current: FirClassifierSymbol<*>) {
if (current in visitedSymbols) return
if (!inProcess.add(current)) {
isThereLoop = true
return
}
when (val fir = current.fir) {
is FirClass<*> -> {
fir.superConeTypes.forEach {
it.lookupTag.toSymbol(session)?.let(::dfs)
}
}
is FirTypeAlias -> {
fir.expandedConeType?.lookupTag?.toSymbol(session)?.let(::dfs)
}
}
visitedSymbols.add(current)
inProcess.remove(current)
}
dfs(symbol)
return isThereLoop
}
fun lookupSuperTypes(
symbol: FirClassifierSymbol<*>,
lookupInterfaces: Boolean,