From 7ba40ac963ebd610a5d18dd121b6d746200ef7e4 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 2 Oct 2019 14:33:47 +0300 Subject: [PATCH] Memoize absent function/property names in FirSuperTypeScope --- .../fir/java/scopes/JavaClassUseSiteScope.kt | 3 +- .../fir/scopes/impl/FirClassUseSiteScope.kt | 2 +- .../fir/scopes/impl/FirSuperTypeScope.kt | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt index b5a02cdbe57..0dd75f30251 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt @@ -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 diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteScope.kt index 2831eee05ce..01555e58030 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassUseSiteScope.kt @@ -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) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirSuperTypeScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirSuperTypeScope.kt index 9383010e83c..cc9d53eb528 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirSuperTypeScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirSuperTypeScope.kt @@ -17,15 +17,23 @@ class FirSuperTypeScope( val scopes: List ) : AbstractFirOverrideScope(session) { + private val absentFunctions = mutableSetOf() + + private val absentProperties = mutableSetOf() + override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction { + if (name in absentFunctions) { + return ProcessorAction.NEXT + } val accepted = HashSet>() val pending = mutableListOf>() + 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>() val pending = mutableListOf>() + 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) } } \ No newline at end of file