Optimize scopes handling inside LexicalChainedScope

This commit is contained in:
Ilya Chernikov
2020-06-02 23:12:20 +02:00
parent bf97323301
commit 3da6ff7ec3
4 changed files with 31 additions and 12 deletions
@@ -25,10 +25,11 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
import org.jetbrains.kotlin.util.collectionUtils.getFirstClassifierDiscriminateHeaders
import org.jetbrains.kotlin.util.collectionUtils.getFromAllScopes
import org.jetbrains.kotlin.util.collectionUtils.listOfNonEmptyScopes
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
class LexicalChainedScope @JvmOverloads constructor(
class LexicalChainedScope private constructor(
parent: LexicalScope,
override val ownerDescriptor: DeclarationDescriptor,
override val isOwnerDescriptorAccessibleByLabel: Boolean,
@@ -36,7 +37,7 @@ class LexicalChainedScope @JvmOverloads constructor(
override val kind: LexicalScopeKind,
// NB. Here can be very special subtypes of MemberScope (e.g., DeprecatedMemberScope).
// Please, do not leak them outside of LexicalChainedScope, because other parts of compiler are not ready to work with them
private val memberScopes: List<MemberScope>,
private val memberScopes: Array<MemberScope>,
@Deprecated("This value is temporary hack for resolve -- don't use it!")
val isStaticScope: Boolean = false
) : LexicalScope {
@@ -93,4 +94,23 @@ class LexicalChainedScope @JvmOverloads constructor(
override fun definitelyDoesNotContainName(name: Name): Boolean {
return memberScopes.all { it.definitelyDoesNotContainName(name) }
}
companion object {
@JvmOverloads
fun create(
parent: LexicalScope,
ownerDescriptor: DeclarationDescriptor,
isOwnerDescriptorAccessibleByLabel: Boolean,
implicitReceiver: ReceiverParameterDescriptor?,
kind: LexicalScopeKind,
vararg memberScopes: MemberScope?,
isStaticScope: Boolean = false
): LexicalScope =
LexicalChainedScope(
parent, ownerDescriptor, isOwnerDescriptorAccessibleByLabel, implicitReceiver, kind,
listOfNonEmptyScopes(*memberScopes).toTypedArray(),
isStaticScope
)
}
}