Add missing definitelyDoesNotContainName methods
Some implementations of definitelyDoesNotContainName method were missing that led to performance problems during symbols resolution using TowerResolver. Relates to KT-39139.
This commit is contained in:
committed by
Ilya Chernikov
parent
262e21fcbc
commit
b74692e96b
+33
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.storage.getValue
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
open class LazyClassMemberScope(
|
open class LazyClassMemberScope(
|
||||||
@@ -118,6 +119,7 @@ open class LazyClassMemberScope(
|
|||||||
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
mutableSetOf<Name>().apply {
|
mutableSetOf<Name>().apply {
|
||||||
addAll(declarationProvider.getDeclarationNames())
|
addAll(declarationProvider.getDeclarationNames())
|
||||||
|
addAll(c.syntheticResolveExtension.getSyntheticFunctionNames(thisDescriptor))
|
||||||
supertypes.flatMapTo(this) {
|
supertypes.flatMapTo(this) {
|
||||||
it.memberScope.getFunctionNames()
|
it.memberScope.getFunctionNames()
|
||||||
}
|
}
|
||||||
@@ -126,6 +128,32 @@ open class LazyClassMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val _classifierNames: Set<Name>?
|
||||||
|
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
|
mutableSetOf<Name>().apply {
|
||||||
|
supertypes.flatMapToNullable(this) {
|
||||||
|
it.memberScope.getClassifierNames()
|
||||||
|
} ?: return@lazy null
|
||||||
|
|
||||||
|
addAll(declarationProvider.getDeclarationNames())
|
||||||
|
with(c.syntheticResolveExtension) {
|
||||||
|
getSyntheticCompanionObjectNameIfNeeded(thisDescriptor)?.let { add(it) }
|
||||||
|
addAll(getSyntheticNestedClassNames(thisDescriptor))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _allNames: Set<Name>?
|
||||||
|
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
|
val classifiers = getClassifierNames() ?: return@lazy null
|
||||||
|
|
||||||
|
mutableSetOf<Name>().apply {
|
||||||
|
addAll(getVariableNames())
|
||||||
|
addAll(getFunctionNames())
|
||||||
|
addAll(classifiers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getDataClassRelatedFunctionNames(): Collection<Name> {
|
private fun getDataClassRelatedFunctionNames(): Collection<Name> {
|
||||||
val declarations = mutableListOf<DeclarationDescriptor>()
|
val declarations = mutableListOf<DeclarationDescriptor>()
|
||||||
addDataClassMethods(declarations, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
|
addDataClassMethods(declarations, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
|
||||||
@@ -134,6 +162,11 @@ open class LazyClassMemberScope(
|
|||||||
|
|
||||||
override fun getVariableNames() = _variableNames
|
override fun getVariableNames() = _variableNames
|
||||||
override fun getFunctionNames() = _functionNames
|
override fun getFunctionNames() = _functionNames
|
||||||
|
override fun getClassifierNames() = _classifierNames
|
||||||
|
|
||||||
|
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||||
|
return _allNames?.let { name !in it } ?: false
|
||||||
|
}
|
||||||
|
|
||||||
private interface MemberExtractor<out T : CallableMemberDescriptor> {
|
private interface MemberExtractor<out T : CallableMemberDescriptor> {
|
||||||
fun extract(extractFrom: KotlinType, name: Name): Collection<T>
|
fun extract(extractFrom: KotlinType, name: Name): Collection<T>
|
||||||
|
|||||||
@@ -90,4 +90,7 @@ class LexicalChainedScope @JvmOverloads constructor(
|
|||||||
p.println("}")
|
p.println("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||||
|
return memberScopes.all { it.definitelyDoesNotContainName(name) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ interface MemberScope : ResolutionScope {
|
|||||||
p.println("Empty member scope")
|
p.println("Empty member scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun definitelyDoesNotContainName(name: Name): Boolean = true
|
||||||
|
|
||||||
override fun getFunctionNames() = emptySet<Name>()
|
override fun getFunctionNames() = emptySet<Name>()
|
||||||
override fun getVariableNames() = emptySet<Name>()
|
override fun getVariableNames() = emptySet<Name>()
|
||||||
override fun getClassifierNames() = emptySet<Name>()
|
override fun getClassifierNames() = emptySet<Name>()
|
||||||
|
|||||||
Reference in New Issue
Block a user