Optimize scopes handling inside LexicalChainedScope
This commit is contained in:
+4
-2
@@ -99,12 +99,14 @@ class ClassResolutionScopesSupport(
|
|||||||
|
|
||||||
val parentForNewScope = companionObjectDescriptor?.packScopesOfCompanionSupertypes(parent, ownerDescriptor) ?: parent
|
val parentForNewScope = companionObjectDescriptor?.packScopesOfCompanionSupertypes(parent, ownerDescriptor) ?: parent
|
||||||
|
|
||||||
val lexicalChainedScope = LexicalChainedScope(
|
val lexicalChainedScope = LexicalChainedScope.create(
|
||||||
parentForNewScope, ownerDescriptor,
|
parentForNewScope, ownerDescriptor,
|
||||||
isOwnerDescriptorAccessibleByLabel = false,
|
isOwnerDescriptorAccessibleByLabel = false,
|
||||||
implicitReceiver = companionObjectDescriptor?.thisAsReceiverParameter,
|
implicitReceiver = companionObjectDescriptor?.thisAsReceiverParameter,
|
||||||
kind = LexicalScopeKind.CLASS_INHERITANCE,
|
kind = LexicalScopeKind.CLASS_INHERITANCE,
|
||||||
memberScopes = staticScopes,
|
classDescriptor.staticScope,
|
||||||
|
classDescriptor.unsubstitutedInnerClassesScope,
|
||||||
|
companionObjectDescriptor?.getStaticScopeOfCompanionObject(classDescriptor),
|
||||||
isStaticScope = true
|
isStaticScope = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||||
import org.jetbrains.kotlin.util.collectionUtils.getFirstClassifierDiscriminateHeaders
|
import org.jetbrains.kotlin.util.collectionUtils.getFirstClassifierDiscriminateHeaders
|
||||||
import org.jetbrains.kotlin.util.collectionUtils.getFromAllScopes
|
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.Printer
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
|
|
||||||
class LexicalChainedScope @JvmOverloads constructor(
|
class LexicalChainedScope private constructor(
|
||||||
parent: LexicalScope,
|
parent: LexicalScope,
|
||||||
override val ownerDescriptor: DeclarationDescriptor,
|
override val ownerDescriptor: DeclarationDescriptor,
|
||||||
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
||||||
@@ -36,7 +37,7 @@ class LexicalChainedScope @JvmOverloads constructor(
|
|||||||
override val kind: LexicalScopeKind,
|
override val kind: LexicalScopeKind,
|
||||||
// NB. Here can be very special subtypes of MemberScope (e.g., DeprecatedMemberScope).
|
// 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
|
// 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!")
|
@Deprecated("This value is temporary hack for resolve -- don't use it!")
|
||||||
val isStaticScope: Boolean = false
|
val isStaticScope: Boolean = false
|
||||||
) : LexicalScope {
|
) : LexicalScope {
|
||||||
@@ -93,4 +94,23 @@ class LexicalChainedScope @JvmOverloads constructor(
|
|||||||
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||||
return memberScopes.all { it.definitelyDoesNotContainName(name) }
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -100,12 +99,10 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return new LexicalChainedScope(
|
return LexicalChainedScope.Companion.create(
|
||||||
typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC,
|
typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||||
Arrays.asList(
|
contextClass.getDefaultType().getMemberScope(),
|
||||||
contextClass.getDefaultType().getMemberScope(),
|
module.getBuiltIns().getBuiltInsPackageScope()
|
||||||
module.getBuiltIns().getBuiltInsPackageScope()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,12 +156,12 @@ private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescri
|
|||||||
descriptor.constructors.forEach { addFunctionDescriptor(it) }
|
descriptor.constructors.forEach { addFunctionDescriptor(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val scopeChain = listOfNotNull(
|
return LexicalChainedScope.create(
|
||||||
|
headerScope, descriptor, false, null, LexicalScopeKind.SYNTHETIC,
|
||||||
descriptor.defaultType.memberScope,
|
descriptor.defaultType.memberScope,
|
||||||
descriptor.staticScope,
|
descriptor.staticScope,
|
||||||
descriptor.companionObjectDescriptor?.defaultType?.memberScope
|
descriptor.companionObjectDescriptor?.defaultType?.memberScope
|
||||||
)
|
)
|
||||||
return LexicalChainedScope(headerScope, descriptor, false, null, LexicalScopeKind.SYNTHETIC, scopeChain)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKDocLinkResolutionScope(resolutionFacade: ResolutionFacade, contextDescriptor: DeclarationDescriptor): LexicalScope {
|
fun getKDocLinkResolutionScope(resolutionFacade: ResolutionFacade, contextDescriptor: DeclarationDescriptor): LexicalScope {
|
||||||
|
|||||||
Reference in New Issue
Block a user