Optimize resolution scope queries from the synthetic scopes
now required descriptors are queried in advance and passed to the methods, to avoid multiple same name queries in a row
This commit is contained in:
+16
-12
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitutio
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.sam.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -168,19 +167,24 @@ class SamAdapterFunctionsScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticStaticFunctions(
|
||||
contributedFunctions: Collection<FunctionDescriptor>,
|
||||
location: LookupLocation
|
||||
): Collection<FunctionDescriptor> {
|
||||
if (!shouldGenerateAdditionalSamCandidate) return emptyList()
|
||||
|
||||
return getSamFunctions(scope.getContributedFunctions(name, location), location)
|
||||
return getSamFunctions(contributedFunctions, location)
|
||||
}
|
||||
|
||||
override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
val classifier = scope.getContributedClassifier(name, location) ?: return emptyList()
|
||||
recordSamLookupsToClassifier(classifier, location)
|
||||
override fun getSyntheticConstructors(
|
||||
contributedClassifier: ClassifierDescriptor,
|
||||
location: LookupLocation
|
||||
): Collection<FunctionDescriptor> {
|
||||
recordSamLookupsToClassifier(contributedClassifier, location)
|
||||
|
||||
if (!shouldGenerateAdditionalSamCandidate) return listOfNotNull(getSamConstructor(classifier))
|
||||
if (!shouldGenerateAdditionalSamCandidate) return listOfNotNull(getSamConstructor(contributedClassifier))
|
||||
|
||||
return getAllSamConstructors(classifier)
|
||||
return getAllSamConstructors(contributedClassifier)
|
||||
}
|
||||
|
||||
private fun recordSamLookupsToClassifier(classifier: ClassifierDescriptor, location: LookupLocation) {
|
||||
@@ -191,14 +195,14 @@ class SamAdapterFunctionsScope(
|
||||
lookupTracker.record(location, classifier, SAM_LOOKUP_NAME)
|
||||
}
|
||||
|
||||
override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor> {
|
||||
override fun getSyntheticStaticFunctions(functionDescriptors: Collection<DeclarationDescriptor>): Collection<FunctionDescriptor> {
|
||||
if (!shouldGenerateAdditionalSamCandidate) return emptyList()
|
||||
|
||||
return getSamFunctions(scope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS), location = null)
|
||||
return getSamFunctions(functionDescriptors, location = null)
|
||||
}
|
||||
|
||||
override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor> {
|
||||
val classifiers = scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance<ClassifierDescriptor>()
|
||||
override fun getSyntheticConstructors(classifierDescriptors: Collection<DeclarationDescriptor>): Collection<FunctionDescriptor> {
|
||||
val classifiers = classifierDescriptors.filterIsInstance<ClassifierDescriptor>()
|
||||
|
||||
if (!shouldGenerateAdditionalSamCandidate) return classifiers.mapNotNull { getSamConstructor(it) }
|
||||
|
||||
|
||||
@@ -23,7 +23,10 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCa
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAliasObject
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isLowPriorityFromStdlibJre7Or8
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasHidesMembersAnnotation
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasLowPriorityInOverloadResolution
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.CastImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||
@@ -36,7 +39,6 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.getImmediateSuperclassNotAny
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
internal abstract class AbstractScopeTowerLevel(
|
||||
protected val scopeTower: ImplicitScopeTower
|
||||
@@ -382,14 +384,18 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors(
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?,
|
||||
scopeTower: ImplicitScopeTower
|
||||
): Collection<FunctionDescriptor> {
|
||||
val result = ArrayList<FunctionDescriptor>(getContributedFunctions(name, location))
|
||||
val contributedFunctions = getContributedFunctions(name, location)
|
||||
|
||||
val result = ArrayList<FunctionDescriptor>(contributedFunctions)
|
||||
|
||||
getContributedClassifier(name, location)?.let {
|
||||
result.addAll(getConstructorsOfClassifier(it))
|
||||
result.addAll(scopeTower.syntheticScopes.collectSyntheticConstructors(it, location))
|
||||
}
|
||||
|
||||
result.addAll(scopeTower.syntheticScopes.collectSyntheticStaticFunctions(this, name, location))
|
||||
result.addAll(scopeTower.syntheticScopes.collectSyntheticConstructors(this, name, location))
|
||||
if (contributedFunctions.isNotEmpty()) {
|
||||
result.addAll(scopeTower.syntheticScopes.collectSyntheticStaticFunctions(contributedFunctions, location))
|
||||
}
|
||||
|
||||
return scopeTower.interceptFunctionCandidates(this, name, result, location, dispatchReceiver, extensionReceiver)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user