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
@@ -99,12 +99,14 @@ class ClassResolutionScopesSupport(
val parentForNewScope = companionObjectDescriptor?.packScopesOfCompanionSupertypes(parent, ownerDescriptor) ?: parent
val lexicalChainedScope = LexicalChainedScope(
val lexicalChainedScope = LexicalChainedScope.create(
parentForNewScope, ownerDescriptor,
isOwnerDescriptorAccessibleByLabel = false,
implicitReceiver = companionObjectDescriptor?.thisAsReceiverParameter,
kind = LexicalScopeKind.CLASS_INHERITANCE,
memberScopes = staticScopes,
classDescriptor.staticScope,
classDescriptor.unsubstitutedInnerClassesScope,
companionObjectDescriptor?.getStaticScopeOfCompanionObject(classDescriptor),
isStaticScope = true
)
@@ -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
)
}
}
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.tests.di.InjectionKt;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -100,12 +99,10 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
return Unit.INSTANCE;
}
);
return new LexicalChainedScope(
return LexicalChainedScope.Companion.create(
typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC,
Arrays.asList(
contextClass.getDefaultType().getMemberScope(),
module.getBuiltIns().getBuiltInsPackageScope()
)
contextClass.getDefaultType().getMemberScope(),
module.getBuiltIns().getBuiltInsPackageScope()
);
}
@@ -156,12 +156,12 @@ private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescri
descriptor.constructors.forEach { addFunctionDescriptor(it) }
}
val scopeChain = listOfNotNull(
return LexicalChainedScope.create(
headerScope, descriptor, false, null, LexicalScopeKind.SYNTHETIC,
descriptor.defaultType.memberScope,
descriptor.staticScope,
descriptor.companionObjectDescriptor?.defaultType?.memberScope
)
return LexicalChainedScope(headerScope, descriptor, false, null, LexicalScopeKind.SYNTHETIC, scopeChain)
}
fun getKDocLinkResolutionScope(resolutionFacade: ResolutionFacade, contextDescriptor: DeclarationDescriptor): LexicalScope {