FIR: Minor. Clarify some names at FirTypeIntersectionScopeContext

This commit is contained in:
Denis.Zharkov
2022-04-22 12:16:13 +03:00
committed by teamcity
parent 20847d25cc
commit 784a911d1a
5 changed files with 25 additions and 21 deletions
@@ -120,7 +120,7 @@ class JavaClassUseSiteMemberScope(
* 2. Field from some java superclass (only one, if class have more than one superclass then we can choose * 2. Field from some java superclass (only one, if class have more than one superclass then we can choose
* just one field because this is incorrect code anyway) * just one field because this is incorrect code anyway)
*/ */
val fromSupertypes = supertypeScopeContext.collectCallables(name, FirScope::processPropertiesByName) val fromSupertypes = supertypeScopeContext.collectIntersectionResultsForCallables(name, FirScope::processPropertiesByName)
val (fieldsFromSupertype, propertiesFromSupertypes) = fromSupertypes.partition { val (fieldsFromSupertype, propertiesFromSupertypes) = fromSupertypes.partition {
it is ResultOfIntersection.SingleMember && it.chosenSymbol is FirFieldSymbol it is ResultOfIntersection.SingleMember && it.chosenSymbol is FirFieldSymbol
@@ -251,7 +251,7 @@ class JavaClassUseSiteMemberScope(
private fun FirNamedFunctionSymbol.doesOverrideRenamedBuiltins(): Boolean { private fun FirNamedFunctionSymbol.doesOverrideRenamedBuiltins(): Boolean {
// e.g. 'removeAt' or 'toInt' // e.g. 'removeAt' or 'toInt'
val builtinName = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name) ?: return false val builtinName = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name) ?: return false
val builtinSpecialFromSuperTypes = supertypeScopeContext.collectMembersByScope(builtinName, FirScope::processFunctionsByName) val builtinSpecialFromSuperTypes = supertypeScopeContext.collectMembersGroupedByScope(builtinName, FirScope::processFunctionsByName)
.flatMap { (scope, symbols) -> .flatMap { (scope, symbols) ->
symbols.filter { it.doesOverrideBuiltinWithDifferentJvmName(scope, session) } symbols.filter { it.doesOverrideBuiltinWithDifferentJvmName(scope, session) }
} }
@@ -273,7 +273,7 @@ class JavaClassUseSiteMemberScope(
*/ */
private fun FirNamedFunctionSymbol.shouldBeVisibleAsOverrideOfBuiltInWithErasedValueParameters(): Boolean { private fun FirNamedFunctionSymbol.shouldBeVisibleAsOverrideOfBuiltInWithErasedValueParameters(): Boolean {
if (!name.sameAsBuiltinMethodWithErasedValueParameters) return false if (!name.sameAsBuiltinMethodWithErasedValueParameters) return false
val candidatesToOverride = supertypeScopeContext.collectMembersByScope(name, FirScope::processFunctionsByName) val candidatesToOverride = supertypeScopeContext.collectMembersGroupedByScope(name, FirScope::processFunctionsByName)
.flatMap { (scope, symbols) -> .flatMap { (scope, symbols) ->
symbols.mapNotNull { symbols.mapNotNull {
BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(it, scope) BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(it, scope)
@@ -320,7 +320,7 @@ class JavaClassUseSiteMemberScope(
collectDeclaredFunctions(name, result) collectDeclaredFunctions(name, result)
val explicitlyDeclaredFunctions = result.toSet() val explicitlyDeclaredFunctions = result.toSet()
val functionsWithScopeFromSupertypes = supertypeScopeContext.collectMembersByScope(name, FirScope::processFunctionsByName) val functionsWithScopeFromSupertypes = supertypeScopeContext.collectMembersGroupedByScope(name, FirScope::processFunctionsByName)
if ( if (
!name.sameAsRenamedInJvmBuiltin && !name.sameAsRenamedInJvmBuiltin &&
@@ -337,13 +337,13 @@ class JavaClassUseSiteMemberScope(
} }
private fun processSpecialFunctions( private fun processSpecialFunctions(
naturalName: Name, requestedName: Name,
explicitlyDeclaredFunctionsWithNaturalName: Collection<FirNamedFunctionSymbol>, explicitlyDeclaredFunctionsWithNaturalName: Collection<FirNamedFunctionSymbol>,
functionsFromSupertypesWithNaturalName: MembersByScope<FirNamedFunctionSymbol>, // candidates for override functionsFromSupertypesWithRequestedName: MembersByScope<FirNamedFunctionSymbol>, // candidates for override
destination: MutableCollection<FirNamedFunctionSymbol> destination: MutableCollection<FirNamedFunctionSymbol>
) { ) {
val resultsOfIntersectionToSaveInCache = mutableListOf<ResultOfIntersection<FirNamedFunctionSymbol>>() val resultsOfIntersectionToSaveInCache = mutableListOf<ResultOfIntersection<FirNamedFunctionSymbol>>()
val list = supertypeScopeContext.collectCallablesImpl(functionsFromSupertypesWithNaturalName) val list = supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName)
for (resultOfIntersectionWithNaturalName in list) { for (resultOfIntersectionWithNaturalName in list) {
val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType() val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType()
val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull { val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull {
@@ -357,7 +357,7 @@ class JavaClassUseSiteMemberScope(
jvmName, jvmName,
someSymbolWithNaturalNameFromSuperType, someSymbolWithNaturalNameFromSuperType,
explicitlyDeclaredFunctionWithNaturalName, explicitlyDeclaredFunctionWithNaturalName,
naturalName, requestedName,
resultOfIntersectionWithNaturalName, resultOfIntersectionWithNaturalName,
destination, destination,
resultsOfIntersectionToSaveInCache resultsOfIntersectionToSaveInCache
@@ -367,7 +367,7 @@ class JavaClassUseSiteMemberScope(
if (processOverridesForFunctionsWithErasedValueParameter( if (processOverridesForFunctionsWithErasedValueParameter(
resultOfIntersectionWithNaturalName.overriddenMembers, resultOfIntersectionWithNaturalName.overriddenMembers,
naturalName, requestedName,
explicitlyDeclaredFunctionsWithNaturalName, explicitlyDeclaredFunctionsWithNaturalName,
destination, destination,
resultOfIntersectionWithNaturalName, resultOfIntersectionWithNaturalName,
@@ -392,7 +392,7 @@ class JavaClassUseSiteMemberScope(
} }
} }
} }
functionsFromSupertypes[naturalName] = resultsOfIntersectionToSaveInCache functionsFromSupertypes[requestedName] = resultsOfIntersectionToSaveInCache
} }
private fun processOverridesForFunctionsWithErasedValueParameter( private fun processOverridesForFunctionsWithErasedValueParameter(
@@ -521,7 +521,7 @@ class JavaClassUseSiteMemberScope(
overriddenMembers.mapTo(this) { it.baseScope to listOf(it.member) } overriddenMembers.mapTo(this) { it.baseScope to listOf(it.member) }
addAll(renamedFunctionsFromSupertypes) addAll(renamedFunctionsFromSupertypes)
} }
supertypeScopeContext.collectCallablesImpl(membersByScope) supertypeScopeContext.convertGroupedCallablesToIntersectionResults(membersByScope)
} }
} }
@@ -96,7 +96,7 @@ abstract class AbstractFirUseSiteMemberScope(
private fun getFunctionsFromSupertypesByName(name: Name): List<ResultOfIntersection<FirNamedFunctionSymbol>> { private fun getFunctionsFromSupertypesByName(name: Name): List<ResultOfIntersection<FirNamedFunctionSymbol>> {
return functionsFromSupertypes.getOrPut(name) { return functionsFromSupertypes.getOrPut(name) {
supertypeScopeContext.collectCallables(name, FirScope::processFunctionsByName) supertypeScopeContext.collectIntersectionResultsForCallables(name, FirScope::processFunctionsByName)
} }
} }
@@ -71,7 +71,7 @@ class FirClassUseSiteMemberScope(
} }
val fields = mutableListOf<FirFieldSymbol>() val fields = mutableListOf<FirFieldSymbol>()
val properties = supertypeScopeContext.collectCallables<FirPropertySymbol>(name) { propertyName, processor -> val properties = supertypeScopeContext.collectIntersectionResultsForCallables<FirPropertySymbol>(name) { propertyName, processor ->
processPropertiesByName(propertyName) { processPropertiesByName(propertyName) {
when (it) { when (it) {
is FirPropertySymbol -> processor(it) is FirPropertySymbol -> processor(it)
@@ -48,7 +48,7 @@ class FirTypeIntersectionScope private constructor(
return return
} }
val callablesWithOverridden = intersectionContext.collectCallables(name, processCallables) val callablesWithOverridden = intersectionContext.collectIntersectionResultsForCallables(name, processCallables)
if (callablesWithOverridden.isEmpty()) { if (callablesWithOverridden.isEmpty()) {
absentNames.add(name) absentNames.add(name)
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.caches.* import org.jetbrains.kotlin.fir.caches.*
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.utils.isExpect import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.declarations.utils.modality
import org.jetbrains.kotlin.fir.declarations.utils.visibility import org.jetbrains.kotlin.fir.declarations.utils.visibility
@@ -20,7 +22,9 @@ import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.scopes.impl.FirIntersectionOverrideStorage.ContextForIntersectionOverrideConstruction import org.jetbrains.kotlin.fir.scopes.impl.FirIntersectionOverrideStorage.ContextForIntersectionOverrideConstruction
import org.jetbrains.kotlin.fir.scopes.impl.FirTypeIntersectionScopeContext.ResultOfIntersection import org.jetbrains.kotlin.fir.scopes.impl.FirTypeIntersectionScopeContext.ResultOfIntersection
import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeSimpleKotlinType
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import kotlin.contracts.ExperimentalContracts import kotlin.contracts.ExperimentalContracts
@@ -109,11 +113,11 @@ class FirTypeIntersectionScopeContext(
} }
fun collectFunctions(name: Name): List<ResultOfIntersection<FirNamedFunctionSymbol>> { fun collectFunctions(name: Name): List<ResultOfIntersection<FirNamedFunctionSymbol>> {
return collectCallables(name, FirScope::processFunctionsByName) return collectIntersectionResultsForCallables(name, FirScope::processFunctionsByName)
} }
@OptIn(PrivateForInline::class) @OptIn(PrivateForInline::class)
inline fun <D : FirCallableSymbol<*>> collectMembersByScope( inline fun <D : FirCallableSymbol<*>> collectMembersGroupedByScope(
name: Name, name: Name,
processCallables: FirScope.(Name, (D) -> Unit) -> Unit processCallables: FirScope.(Name, (D) -> Unit) -> Unit
): MembersByScope<D> { ): MembersByScope<D> {
@@ -132,14 +136,14 @@ class FirTypeIntersectionScopeContext(
} }
@OptIn(PrivateForInline::class) @OptIn(PrivateForInline::class)
inline fun <D : FirCallableSymbol<*>> collectCallables( inline fun <D : FirCallableSymbol<*>> collectIntersectionResultsForCallables(
name: Name, name: Name,
processCallables: FirScope.(Name, (D) -> Unit) -> Unit processCallables: FirScope.(Name, (D) -> Unit) -> Unit
): List<ResultOfIntersection<D>> { ): List<ResultOfIntersection<D>> {
return collectCallablesImpl(collectMembersByScope(name, processCallables)) return convertGroupedCallablesToIntersectionResults(collectMembersGroupedByScope(name, processCallables))
} }
fun <D : FirCallableSymbol<*>> collectCallablesImpl( fun <D : FirCallableSymbol<*>> convertGroupedCallablesToIntersectionResults(
membersByScope: List<Pair<FirTypeScope, List<D>>> membersByScope: List<Pair<FirTypeScope, List<D>>>
): List<ResultOfIntersection<D>> { ): List<ResultOfIntersection<D>> {
if (membersByScope.isEmpty()) { if (membersByScope.isEmpty()) {