Memoize absent function/property names in FirSuperTypeScope

This commit is contained in:
Mikhail Glukhikh
2019-10-02 14:33:47 +03:00
parent 840ecf1a77
commit 7ba40ac963
3 changed files with 27 additions and 7 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.*
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractProviderBasedScope
import org.jetbrains.kotlin.fir.scopes.impl.FirSuperTypeScope
import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.typeContext
@@ -27,7 +28,7 @@ import org.jetbrains.kotlin.name.Name
class JavaClassUseSiteScope(
klass: FirRegularClass,
session: FirSession,
private val superTypesScope: FirScope,
private val superTypesScope: FirSuperTypeScope,
private val declaredMemberScope: FirScope
) : FirAbstractProviderBasedScope(session, lookupInFir = true) {
internal val symbol = klass.symbol
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.name.Name
class FirClassUseSiteScope(
session: FirSession,
private val superTypesScope: FirScope,
private val superTypesScope: FirSuperTypeScope,
private val declaredMemberScope: FirScope
) : AbstractFirOverrideScope(session) {
@@ -17,15 +17,23 @@ class FirSuperTypeScope(
val scopes: List<FirScope>
) : AbstractFirOverrideScope(session) {
private val absentFunctions = mutableSetOf<Name>()
private val absentProperties = mutableSetOf<Name>()
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction {
if (name in absentFunctions) {
return ProcessorAction.NEXT
}
val accepted = HashSet<FirFunctionSymbol<*>>()
val pending = mutableListOf<FirFunctionSymbol<*>>()
var empty = true
for (scope in scopes) {
if (scope.processFunctionsByName(name) {
if (it !in accepted && it.isOverridden(accepted) == null) {
pending += it
processor(it)
if (scope.processFunctionsByName(name) { functionSymbol ->
empty = false
if (functionSymbol !in accepted && functionSymbol.isOverridden(accepted) == null) {
pending += functionSymbol
processor(functionSymbol)
} else {
ProcessorAction.NEXT
}
@@ -36,14 +44,22 @@ class FirSuperTypeScope(
accepted += pending
pending.clear()
}
if (empty) {
absentFunctions += name
}
return super.processFunctionsByName(name, processor)
}
override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> ProcessorAction): ProcessorAction {
if (name in absentProperties) {
return ProcessorAction.NEXT
}
val accepted = HashSet<FirCallableSymbol<*>>()
val pending = mutableListOf<FirCallableSymbol<*>>()
var empty = true
for (scope in scopes) {
if (scope.processPropertiesByName(name) {
empty = false
if (it !in accepted && it.isOverridden(accepted) == null) {
pending += it
processor(it)
@@ -57,6 +73,9 @@ class FirSuperTypeScope(
accepted += pending
pending.clear()
}
if (empty) {
absentProperties += name
}
return super.processPropertiesByName(name, processor)
}
}