From 89cbe9bf93c898f03097fa936f5149627cd8f39e Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 9 Jun 2020 16:16:53 +0300 Subject: [PATCH] FIR: Pull down FirScope.processOverriddenFunctions --- .../kotlin/fir/scopes/FirIterableScope.kt | 8 ----- .../jetbrains/kotlin/fir/scopes/FirScope.kt | 30 ----------------- .../kotlin/fir/scopes/FirTypeScope.kt | 33 ++++++++++++++----- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirIterableScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirIterableScope.kt index 2c00ed1a5d2..daba0234f17 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirIterableScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirIterableScope.kt @@ -45,12 +45,4 @@ abstract class FirIterableScope : FirScope() { override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) { return processComposite(FirScope::processPropertiesByName, name, processor) } - - override fun processOverriddenFunctions(functionSymbol: FirFunctionSymbol<*>, processor: (FirFunctionSymbol<*>) -> ProcessorAction): ProcessorAction { - for (scope in scopes) { - if (!scope.processOverriddenFunctions(functionSymbol, processor)) return ProcessorAction.STOP - } - - return ProcessorAction.NEXT - } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt index 7fb38693710..a4b3da3f979 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt @@ -34,36 +34,6 @@ abstract class FirScope { open fun mayContainName(name: Name) = true - // Currently, this function has very weak guarantees - // - It may silently do nothing on symbols originated from different scope instance - // - It may return the same overridden symbols more then once in case of substitution - // - It doesn't guarantee any specific order in which overridden tree will be traversed - // But if the scope instance is the same as the one from which the symbol was originated, this function will enumarate all members - // of the overridden tree - // TODO: Consider extracting this function to a separate abstract class/interface, so only limited types of scopes would be supporing it - // on interface level - open fun processOverriddenFunctions( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>) -> ProcessorAction - ): ProcessorAction = ProcessorAction.NONE - - // This is just a helper for a common implementation - protected fun doProcessOverriddenFunctions( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>) -> ProcessorAction, - directOverriddenMap: Map, Collection>>, - baseScope: FirScope - ): ProcessorAction { - val directOverridden = - directOverriddenMap[functionSymbol] ?: return baseScope.processOverriddenFunctions(functionSymbol, processor) - - for (overridden in directOverridden) { - if (!processor(overridden)) return ProcessorAction.STOP - if (!baseScope.processOverriddenFunctions(overridden, processor)) return ProcessorAction.STOP - } - - return ProcessorAction.NEXT - } } fun FirTypeScope.processOverriddenFunctionsAndSelf( diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt index 78a163be980..fc5052851a2 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt @@ -8,15 +8,32 @@ package org.jetbrains.kotlin.fir.scopes import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol abstract class FirTypeScope : FirScope() { - // Initially, this method is intended to belong only to this class, but not to FirScope - // But the main-use case (FirSyntheticPropertiesScope) uses it on arbitrary type (intersection and others) that currently use - // scope implementations for type-unrelated scopes as well - // One of the idea how to fix it is considered extracting it to the interface - // - // The idea behind this class and abstract override is to explicitly state that those implementations should implement this method properly - // and use other FirOverrideAwareScope when delegating to them (as in FirClassSubstitutionScope) - abstract override fun processOverriddenFunctions( + // Currently, this function has very weak guarantees + // - It may silently do nothing on symbols originated from different scope instance + // - It may return the same overridden symbols more then once in case of substitution + // - It doesn't guarantee any specific order in which overridden tree will be traversed + // But if the scope instance is the same as the one from which the symbol was originated, this function will enumarate all members + // of the overridden tree + abstract fun processOverriddenFunctions( functionSymbol: FirFunctionSymbol<*>, processor: (FirFunctionSymbol<*>) -> ProcessorAction ): ProcessorAction + + // This is just a helper for a common implementation + protected fun doProcessOverriddenFunctions( + functionSymbol: FirFunctionSymbol<*>, + processor: (FirFunctionSymbol<*>) -> ProcessorAction, + directOverriddenMap: Map, Collection>>, + baseScope: FirTypeScope + ): ProcessorAction { + val directOverridden = + directOverriddenMap[functionSymbol] ?: return baseScope.processOverriddenFunctions(functionSymbol, processor) + + for (overridden in directOverridden) { + if (!processor(overridden)) return ProcessorAction.STOP + if (!baseScope.processOverriddenFunctions(overridden, processor)) return ProcessorAction.STOP + } + + return ProcessorAction.NEXT + } }