Removed generic hell from tower resolver
This commit is contained in:
+34
-34
@@ -78,14 +78,14 @@ class NewResolutionOldInference(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
explicitReceiver: DetailedReceiver?,
|
||||
context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<D>>
|
||||
): ScopeTowerProcessor<MyCandidate>
|
||||
|
||||
object Function : ResolutionKind<FunctionDescriptor>() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<FunctionDescriptor>> {
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
): ScopeTowerProcessor<MyCandidate> {
|
||||
val functionFactory = outer.CandidateFactoryImpl(name, context, tracing)
|
||||
return createFunctionProcessor(scopeTower, name, functionFactory, outer.CandidateFactoryProviderForInvokeImpl(functionFactory), explicitReceiver)
|
||||
}
|
||||
}
|
||||
@@ -94,8 +94,8 @@ class NewResolutionOldInference(
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<VariableDescriptor>> {
|
||||
val variableFactory = outer.CandidateFactoryImpl<VariableDescriptor>(name, context, tracing)
|
||||
): ScopeTowerProcessor<MyCandidate> {
|
||||
val variableFactory = outer.CandidateFactoryImpl(name, context, tracing)
|
||||
return createVariableAndObjectProcessor(scopeTower, name, variableFactory, explicitReceiver)
|
||||
}
|
||||
}
|
||||
@@ -104,9 +104,9 @@ class NewResolutionOldInference(
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<CallableDescriptor>> {
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
val variableFactory = outer.CandidateFactoryImpl<VariableDescriptor>(name, context, tracing)
|
||||
): ScopeTowerProcessor<MyCandidate> {
|
||||
val functionFactory = outer.CandidateFactoryImpl(name, context, tracing)
|
||||
val variableFactory = outer.CandidateFactoryImpl(name, context, tracing)
|
||||
return CompositeScopeTowerProcessor(
|
||||
createSimpleFunctionProcessor(scopeTower, name, functionFactory, explicitReceiver, classValueReceiver = false),
|
||||
createVariableProcessor(scopeTower, name, variableFactory, explicitReceiver, classValueReceiver = false)
|
||||
@@ -118,8 +118,8 @@ class NewResolutionOldInference(
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<FunctionDescriptor>> {
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
): ScopeTowerProcessor<MyCandidate> {
|
||||
val functionFactory = outer.CandidateFactoryImpl(name, context, tracing)
|
||||
// todo
|
||||
val call = (context.call as? CallTransformer.CallForImplicitInvoke).sure {
|
||||
"Call should be CallForImplicitInvoke, but it is: ${context.call}"
|
||||
@@ -135,7 +135,7 @@ class NewResolutionOldInference(
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<D>> {
|
||||
): ScopeTowerProcessor<MyCandidate> {
|
||||
throw IllegalStateException("Should be not called")
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
val overloadResults = convertToOverloadResults(candidates, tracing, context, languageVersionSettings)
|
||||
val overloadResults = convertToOverloadResults<D>(candidates, tracing, context, languageVersionSettings)
|
||||
coroutineInferenceSupport.checkCoroutineCalls(context, tracing, overloadResults)
|
||||
return overloadResults
|
||||
}
|
||||
@@ -229,13 +229,13 @@ class NewResolutionOldInference(
|
||||
return convertToOverloadResults(processedCandidates, tracing, basicCallContext, languageVersionSettings)
|
||||
}
|
||||
|
||||
private fun <D: CallableDescriptor> allCandidatesResult(allCandidates: Collection<MyCandidate<D>>)
|
||||
private fun <D: CallableDescriptor> allCandidatesResult(allCandidates: Collection<MyCandidate>)
|
||||
= OverloadResolutionResultsImpl.nameNotFound<D>().apply {
|
||||
this.allCandidates = allCandidates.map { it.resolvedCall }
|
||||
this.allCandidates = allCandidates.map { it.resolvedCall as MutableResolvedCall<D> }
|
||||
}
|
||||
|
||||
private fun <D : CallableDescriptor> convertToOverloadResults(
|
||||
candidates: Collection<MyCandidate<D>>,
|
||||
candidates: Collection<MyCandidate>,
|
||||
tracing: TracingStrategy,
|
||||
basicCallContext: BasicCallResolutionContext,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
@@ -269,7 +269,7 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
resolvedCall
|
||||
resolvedCall as MutableResolvedCall<D>
|
||||
}
|
||||
|
||||
return resolutionResultsHandler.computeResultAndReportErrors(basicCallContext, tracing, resolvedCalls, languageVersionSettings)
|
||||
@@ -318,9 +318,9 @@ class NewResolutionOldInference(
|
||||
override val isDebuggerContext: Boolean get() = resolutionContext.isDebuggerContext
|
||||
}
|
||||
|
||||
internal data class MyCandidate<out D: CallableDescriptor>(
|
||||
internal data class MyCandidate(
|
||||
val candidateStatus: ResolutionCandidateStatus,
|
||||
val resolvedCall: MutableResolvedCall<@UnsafeVariance D>
|
||||
val resolvedCall: MutableResolvedCall<*>
|
||||
) : Candidate {
|
||||
override val isSuccessful: Boolean
|
||||
get() = candidateStatus.resultingApplicability.isSuccess
|
||||
@@ -328,16 +328,16 @@ class NewResolutionOldInference(
|
||||
get() = candidateStatus
|
||||
}
|
||||
|
||||
private inner class CandidateFactoryImpl<D : CallableDescriptor>(
|
||||
private inner class CandidateFactoryImpl(
|
||||
val name: Name,
|
||||
val basicCallContext: BasicCallResolutionContext,
|
||||
val tracing: TracingStrategy
|
||||
) : CandidateFactory<D, MyCandidate<D>> {
|
||||
) : CandidateFactory<MyCandidate> {
|
||||
override fun createCandidate(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver<D>,
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): MyCandidate<D> {
|
||||
): MyCandidate {
|
||||
|
||||
val candidateTrace = TemporaryBindingTrace.create(basicCallContext.trace, "Context for resolve candidate")
|
||||
val candidateCall = ResolvedCallImpl(
|
||||
@@ -394,16 +394,16 @@ class NewResolutionOldInference(
|
||||
}
|
||||
|
||||
private inner class CandidateFactoryProviderForInvokeImpl(
|
||||
val functionContext: CandidateFactoryImpl<FunctionDescriptor>
|
||||
) : CandidateFactoryProviderForInvoke<MyCandidate<FunctionDescriptor>, MyCandidate<VariableDescriptor>> {
|
||||
val functionContext: CandidateFactoryImpl
|
||||
) : CandidateFactoryProviderForInvoke<MyCandidate> {
|
||||
|
||||
override fun transformCandidate(
|
||||
variable: MyCandidate<VariableDescriptor>,
|
||||
invoke: MyCandidate<FunctionDescriptor>
|
||||
): MyCandidate<FunctionDescriptor> {
|
||||
variable: MyCandidate,
|
||||
invoke: MyCandidate
|
||||
): MyCandidate {
|
||||
val resolvedCallImpl = VariableAsFunctionResolvedCallImpl(
|
||||
invoke.resolvedCall,
|
||||
variable.resolvedCall
|
||||
invoke.resolvedCall as MutableResolvedCall<FunctionDescriptor>,
|
||||
variable.resolvedCall as MutableResolvedCall<VariableDescriptor>
|
||||
)
|
||||
assert(variable.candidateStatus.resultingApplicability.isSuccess) {
|
||||
"Variable call must be success: $variable"
|
||||
@@ -412,7 +412,7 @@ class NewResolutionOldInference(
|
||||
return MyCandidate(ResolutionCandidateStatus(variable.candidateStatus.diagnostics + invoke.candidateStatus.diagnostics), resolvedCallImpl)
|
||||
}
|
||||
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<VariableDescriptor, MyCandidate<VariableDescriptor>> {
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<MyCandidate> {
|
||||
val newCall = CallTransformer.stripCallArguments(functionContext.basicCallContext.call).let {
|
||||
if (stripExplicitReceiver) CallTransformer.stripReceiver(it) else it
|
||||
}
|
||||
@@ -420,15 +420,15 @@ class NewResolutionOldInference(
|
||||
}
|
||||
|
||||
override fun factoryForInvoke(
|
||||
variable: MyCandidate<VariableDescriptor>,
|
||||
variable: MyCandidate,
|
||||
useExplicitReceiver: Boolean
|
||||
): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<FunctionDescriptor, MyCandidate<FunctionDescriptor>>>? {
|
||||
): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<MyCandidate>>? {
|
||||
assert(variable.resolvedCall.status.possibleTransformToSuccess()) {
|
||||
"Incorrect status: ${variable.resolvedCall.status} for variable call: ${variable.resolvedCall} " +
|
||||
"and descriptor: ${variable.resolvedCall.candidateDescriptor}"
|
||||
}
|
||||
val calleeExpression = variable.resolvedCall.call.calleeExpression
|
||||
val variableDescriptor = variable.resolvedCall.resultingDescriptor
|
||||
val variableDescriptor = variable.resolvedCall.resultingDescriptor as VariableDescriptor
|
||||
assert(variable.resolvedCall.status.possibleTransformToSuccess() && calleeExpression != null) {
|
||||
"Unexpected variable candidate: $variable"
|
||||
}
|
||||
@@ -452,7 +452,7 @@ class NewResolutionOldInference(
|
||||
.replaceCall(functionCall)
|
||||
.replaceContextDependency(ContextDependency.DEPENDENT) // todo
|
||||
|
||||
val newContext = CandidateFactoryImpl<FunctionDescriptor>(OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
|
||||
val newContext = CandidateFactoryImpl(OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
|
||||
|
||||
return basicCallResolutionContext.transformToReceiverWithSmartCastInfo(variableReceiver) to newContext
|
||||
}
|
||||
|
||||
+6
-6
@@ -43,21 +43,21 @@ interface ImplicitScopeTower {
|
||||
}
|
||||
|
||||
interface ScopeTowerLevel {
|
||||
fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
||||
fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
|
||||
fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
||||
fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
|
||||
fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>>
|
||||
fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
}
|
||||
|
||||
interface CandidateWithBoundDispatchReceiver<out D : CallableDescriptor> {
|
||||
val descriptor: D
|
||||
interface CandidateWithBoundDispatchReceiver {
|
||||
val descriptor: CallableDescriptor
|
||||
|
||||
val diagnostics: List<ResolutionDiagnostic>
|
||||
|
||||
val dispatchReceiver: ReceiverValueWithSmartCastInfo?
|
||||
|
||||
fun copy(newDescriptor: @UnsafeVariance D): CandidateWithBoundDispatchReceiver<D>
|
||||
fun copy(newDescriptor: CallableDescriptor): CandidateWithBoundDispatchReceiver
|
||||
}
|
||||
|
||||
data class ResolutionCandidateStatus(val diagnostics: List<ResolutionDiagnostic>) {
|
||||
|
||||
+25
-25
@@ -27,16 +27,16 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastI
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractInvokeTowerProcessor<F : Candidate, V : Candidate>(
|
||||
protected val factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
private val variableProcessor: ScopeTowerProcessor<V>
|
||||
) : ScopeTowerProcessor<F> {
|
||||
abstract class AbstractInvokeTowerProcessor<C : Candidate>(
|
||||
protected val factoryProviderForInvoke: CandidateFactoryProviderForInvoke<C>,
|
||||
private val variableProcessor: ScopeTowerProcessor<C>
|
||||
) : ScopeTowerProcessor<C> {
|
||||
// todo optimize it
|
||||
private val previousData = ArrayList<TowerData>()
|
||||
private val invokeProcessors: MutableList<Collection<VariableInvokeProcessor>> = ArrayList()
|
||||
|
||||
private inner class VariableInvokeProcessor(val variableCandidate: V): ScopeTowerProcessor<F> {
|
||||
val invokeProcessor: ScopeTowerProcessor<F> = createInvokeProcessor(variableCandidate)
|
||||
private inner class VariableInvokeProcessor(val variableCandidate: C): ScopeTowerProcessor<C> {
|
||||
val invokeProcessor: ScopeTowerProcessor<C> = createInvokeProcessor(variableCandidate)
|
||||
|
||||
override fun process(data: TowerData)
|
||||
= invokeProcessor.process(data).map { candidateGroup ->
|
||||
@@ -44,12 +44,12 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate, V : Candidate>(
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F>
|
||||
protected abstract fun createInvokeProcessor(variableCandidate: C): ScopeTowerProcessor<C>
|
||||
|
||||
override fun process(data: TowerData): List<Collection<F>> {
|
||||
override fun process(data: TowerData): List<Collection<C>> {
|
||||
previousData.add(data)
|
||||
|
||||
val candidateGroups = ArrayList<Collection<F>>(0)
|
||||
val candidateGroups = ArrayList<Collection<C>>(0)
|
||||
|
||||
for (processorsGroup in invokeProcessors) {
|
||||
candidateGroups.addAll(processorsGroup.processVariableGroup(data))
|
||||
@@ -73,7 +73,7 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate, V : Candidate>(
|
||||
return candidateGroups
|
||||
}
|
||||
|
||||
private fun Collection<VariableInvokeProcessor>.processVariableGroup(data: TowerData): List<Collection<F>> {
|
||||
private fun Collection<VariableInvokeProcessor>.processVariableGroup(data: TowerData): List<Collection<C>> {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> single().process(data)
|
||||
@@ -86,35 +86,35 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate, V : Candidate>(
|
||||
}
|
||||
|
||||
// todo KT-9522 Allow invoke convention for synthetic property
|
||||
class InvokeTowerProcessor<F : Candidate, V : Candidate>(
|
||||
class InvokeTowerProcessor<C : Candidate>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val name: Name,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<C>,
|
||||
explicitReceiver: DetailedReceiver?
|
||||
) : AbstractInvokeTowerProcessor<F, V>(
|
||||
) : AbstractInvokeTowerProcessor<C>(
|
||||
factoryProviderForInvoke,
|
||||
createVariableAndObjectProcessor(scopeTower, name, factoryProviderForInvoke.factoryForVariable(stripExplicitReceiver = false), explicitReceiver)
|
||||
) {
|
||||
|
||||
// todo filter by operator
|
||||
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
||||
override fun createInvokeProcessor(variableCandidate: C): ScopeTowerProcessor<C> {
|
||||
val (variableReceiver, invokeContext) = factoryProviderForInvoke.factoryForInvoke(variableCandidate, useExplicitReceiver = false)
|
||||
?: return KnownResultProcessor(emptyList())
|
||||
return ExplicitReceiverScopeTowerProcessor(scopeTower, invokeContext, variableReceiver) { getFunctions(OperatorNameConventions.INVOKE, it) }
|
||||
}
|
||||
}
|
||||
|
||||
class InvokeExtensionTowerProcessor<F : Candidate, V : Candidate>(
|
||||
class InvokeExtensionTowerProcessor<C : Candidate>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val name: Name,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<C>,
|
||||
private val explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
) : AbstractInvokeTowerProcessor<F, V>(
|
||||
) : AbstractInvokeTowerProcessor<C>(
|
||||
factoryProviderForInvoke,
|
||||
createVariableAndObjectProcessor(scopeTower, name, factoryProviderForInvoke.factoryForVariable(stripExplicitReceiver = true), explicitReceiver = null)
|
||||
) {
|
||||
|
||||
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
||||
override fun createInvokeProcessor(variableCandidate: C): ScopeTowerProcessor<C> {
|
||||
val (variableReceiver, invokeContext) = factoryProviderForInvoke.factoryForInvoke(variableCandidate, useExplicitReceiver = true)
|
||||
?: return KnownResultProcessor(emptyList())
|
||||
val invokeDescriptor = scopeTower.getExtensionInvokeCandidateDescriptor(variableReceiver)
|
||||
@@ -124,10 +124,10 @@ class InvokeExtensionTowerProcessor<F : Candidate, V : Candidate>(
|
||||
}
|
||||
|
||||
private class InvokeExtensionScopeTowerProcessor<C : Candidate>(
|
||||
context: CandidateFactory<FunctionDescriptor, C>,
|
||||
private val invokeCandidateDescriptor: CandidateWithBoundDispatchReceiver<FunctionDescriptor>,
|
||||
context: CandidateFactory<C>,
|
||||
private val invokeCandidateDescriptor: CandidateWithBoundDispatchReceiver,
|
||||
private val explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
) : AbstractSimpleScopeTowerProcessor<FunctionDescriptor, C>(context) {
|
||||
) : AbstractSimpleScopeTowerProcessor<C>(context) {
|
||||
|
||||
override fun simpleProcess(data: TowerData): Collection<C> {
|
||||
if (explicitReceiver != null && data == TowerData.Empty) {
|
||||
@@ -145,7 +145,7 @@ private class InvokeExtensionScopeTowerProcessor<C : Candidate>(
|
||||
// todo debug info
|
||||
private fun ImplicitScopeTower.getExtensionInvokeCandidateDescriptor(
|
||||
extensionFunctionReceiver: ReceiverValueWithSmartCastInfo
|
||||
): CandidateWithBoundDispatchReceiver<FunctionDescriptor>? {
|
||||
): CandidateWithBoundDispatchReceiver? {
|
||||
val type = extensionFunctionReceiver.receiverValue.type
|
||||
if (!type.isBuiltinExtensionFunctionalType) return null // todo: missing smart cast?
|
||||
|
||||
@@ -159,12 +159,12 @@ private fun ImplicitScopeTower.getExtensionInvokeCandidateDescriptor(
|
||||
}
|
||||
|
||||
// case 1.(foo())() or (foo())()
|
||||
fun <F : Candidate> createCallTowerProcessorForExplicitInvoke(
|
||||
fun <C : Candidate> createCallTowerProcessorForExplicitInvoke(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
functionContext: CandidateFactory<FunctionDescriptor, F>,
|
||||
functionContext: CandidateFactory<C>,
|
||||
expressionForInvoke: ReceiverValueWithSmartCastInfo,
|
||||
explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): ScopeTowerProcessor<F> {
|
||||
): ScopeTowerProcessor<C> {
|
||||
val invokeExtensionDescriptor = scopeTower.getExtensionInvokeCandidateDescriptor(expressionForInvoke)
|
||||
if (explicitReceiver != null) {
|
||||
if (invokeExtensionDescriptor == null) {
|
||||
|
||||
+28
-30
@@ -17,8 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
|
||||
@@ -39,8 +37,8 @@ class CompositeScopeTowerProcessor<out C>(
|
||||
override fun process(data: TowerData): List<Collection<C>> = processors.flatMap { it.process(data) }
|
||||
}
|
||||
|
||||
internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
|
||||
val candidateFactory: CandidateFactory<D, C>
|
||||
internal abstract class AbstractSimpleScopeTowerProcessor<C: Candidate>(
|
||||
val candidateFactory: CandidateFactory<C>
|
||||
) : ScopeTowerProcessor<C> {
|
||||
|
||||
protected abstract fun simpleProcess(data: TowerData): Collection<C>
|
||||
@@ -48,15 +46,15 @@ internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor
|
||||
override fun process(data: TowerData): List<Collection<C>> = listOfNotNull(simpleProcess(data).takeIf { it.isNotEmpty() })
|
||||
}
|
||||
|
||||
private typealias CandidatesCollector<D> =
|
||||
ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
|
||||
private typealias CandidatesCollector =
|
||||
ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver>
|
||||
|
||||
internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
|
||||
internal class ExplicitReceiverScopeTowerProcessor<C: Candidate>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
context: CandidateFactory<D, C>,
|
||||
context: CandidateFactory<C>,
|
||||
val explicitReceiver: ReceiverValueWithSmartCastInfo,
|
||||
val collectCandidates: CandidatesCollector<D>
|
||||
): AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
val collectCandidates: CandidatesCollector
|
||||
): AbstractSimpleScopeTowerProcessor<C>(context) {
|
||||
override fun simpleProcess(data: TowerData): Collection<C> {
|
||||
return when (data) {
|
||||
TowerData.Empty -> resolveAsMember()
|
||||
@@ -78,12 +76,12 @@ internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Ca
|
||||
}
|
||||
}
|
||||
|
||||
private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
|
||||
private class QualifierScopeTowerProcessor<C: Candidate>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
context: CandidateFactory<D, C>,
|
||||
context: CandidateFactory<C>,
|
||||
val qualifier: QualifierReceiver,
|
||||
val collectCandidates: CandidatesCollector<D>
|
||||
): AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
val collectCandidates: CandidatesCollector
|
||||
): AbstractSimpleScopeTowerProcessor<C>(context) {
|
||||
override fun simpleProcess(data: TowerData): Collection<C> {
|
||||
if (data != TowerData.Empty) return emptyList()
|
||||
|
||||
@@ -94,10 +92,10 @@ private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate>
|
||||
}
|
||||
}
|
||||
|
||||
private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
|
||||
context: CandidateFactory<D, C>,
|
||||
val collectCandidates: CandidatesCollector<D>
|
||||
) : AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
private class NoExplicitReceiverScopeTowerProcessor<C: Candidate>(
|
||||
context: CandidateFactory<C>,
|
||||
val collectCandidates: CandidatesCollector
|
||||
) : AbstractSimpleScopeTowerProcessor<C>(context) {
|
||||
override fun simpleProcess(data: TowerData): Collection<C>
|
||||
= when(data) {
|
||||
is TowerData.TowerLevel -> {
|
||||
@@ -124,8 +122,8 @@ private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: C
|
||||
private fun <D : CallableDescriptor, C : Candidate> processCommonAndSyntheticMembers(
|
||||
receiverForMember: ReceiverValueWithSmartCastInfo,
|
||||
scopeTowerLevel: ScopeTowerLevel,
|
||||
collectCandidates: CandidatesCollector<D>,
|
||||
candidateFactory: CandidateFactory<D, C>,
|
||||
collectCandidates: CandidatesCollector,
|
||||
candidateFactory: CandidateFactory<C>,
|
||||
isExplicitReceiver: Boolean
|
||||
): List<C> {
|
||||
val (members, syntheticExtension) =
|
||||
@@ -150,12 +148,12 @@ private fun <D : CallableDescriptor, C : Candidate> processCommonAndSyntheticMem
|
||||
}
|
||||
}
|
||||
|
||||
private fun <D : CallableDescriptor, C: Candidate> createSimpleProcessor(
|
||||
private fun <C : Candidate> createSimpleProcessor(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
context: CandidateFactory<D, C>,
|
||||
context: CandidateFactory<C>,
|
||||
explicitReceiver: DetailedReceiver?,
|
||||
classValueReceiver: Boolean,
|
||||
collectCandidates: CandidatesCollector<D>
|
||||
collectCandidates: CandidatesCollector
|
||||
) : ScopeTowerProcessor<C> {
|
||||
if (explicitReceiver is ReceiverValueWithSmartCastInfo) {
|
||||
return ExplicitReceiverScopeTowerProcessor(scopeTower, context, explicitReceiver, collectCandidates)
|
||||
@@ -180,28 +178,28 @@ private fun <D : CallableDescriptor, C: Candidate> createSimpleProcessor(
|
||||
}
|
||||
|
||||
fun <C : Candidate> createVariableProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getVariables(name, it) }
|
||||
|
||||
fun <C : Candidate> createVariableAndObjectProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = CompositeScopeTowerProcessor(
|
||||
createVariableProcessor(scopeTower, name, context, explicitReceiver),
|
||||
createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getObjects(name, it) }
|
||||
)
|
||||
|
||||
fun <C : Candidate> createSimpleFunctionProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: CandidateFactory<FunctionDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getFunctions(name, it) }
|
||||
|
||||
|
||||
fun <F: Candidate, V: Candidate> createFunctionProcessor(
|
||||
fun <С: Candidate> createFunctionProcessor(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
name: Name,
|
||||
simpleContext: CandidateFactory<FunctionDescriptor, F>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
simpleContext: CandidateFactory<С>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<С>,
|
||||
explicitReceiver: DetailedReceiver?
|
||||
): CompositeScopeTowerProcessor<F> {
|
||||
): CompositeScopeTowerProcessor<С> {
|
||||
|
||||
// a.foo() -- simple function call
|
||||
val simpleFunction = createSimpleFunctionProcessor(scopeTower, name, simpleContext, explicitReceiver)
|
||||
|
||||
@@ -47,12 +47,12 @@ internal abstract class AbstractScopeTowerLevel(
|
||||
): ScopeTowerLevel {
|
||||
protected val location: LookupLocation get() = scopeTower.location
|
||||
|
||||
protected fun <D : CallableDescriptor> createCandidateDescriptor(
|
||||
descriptor: D,
|
||||
protected fun createCandidateDescriptor(
|
||||
descriptor: CallableDescriptor,
|
||||
dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
||||
specialError: ResolutionDiagnostic? = null,
|
||||
dispatchReceiverSmartCastType: KotlinType? = null
|
||||
): CandidateWithBoundDispatchReceiver<D> {
|
||||
): CandidateWithBoundDispatchReceiver {
|
||||
val diagnostics = SmartList<ResolutionDiagnostic>()
|
||||
diagnostics.addIfNotNull(specialError)
|
||||
|
||||
@@ -86,17 +86,17 @@ internal class MemberScopeTowerLevel(
|
||||
|
||||
private val syntheticScopes = scopeTower.syntheticScopes
|
||||
|
||||
private fun <D : CallableDescriptor> collectMembers(
|
||||
getMembers: ResolutionScope.(KotlinType?) -> Collection<D>
|
||||
): Collection<CandidateWithBoundDispatchReceiver<D>> {
|
||||
val result = ArrayList<CandidateWithBoundDispatchReceiver<D>>(0)
|
||||
private fun collectMembers(
|
||||
getMembers: ResolutionScope.(KotlinType?) -> Collection<CallableDescriptor>
|
||||
): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
val result = ArrayList<CandidateWithBoundDispatchReceiver>(0)
|
||||
val receiverValue = dispatchReceiver.receiverValue
|
||||
receiverValue.type.memberScope.getMembers(receiverValue.type).mapTo(result) {
|
||||
createCandidateDescriptor(it, dispatchReceiver)
|
||||
}
|
||||
|
||||
val unstableError = if (dispatchReceiver.isStable) null else UnstableSmartCastDiagnostic
|
||||
val unstableCandidates = if (unstableError != null) ArrayList<CandidateWithBoundDispatchReceiver<D>>(0) else null
|
||||
val unstableCandidates = if (unstableError != null) ArrayList<CandidateWithBoundDispatchReceiver>(0) else null
|
||||
|
||||
for (possibleType in dispatchReceiver.possibleTypes) {
|
||||
possibleType.memberScope.getMembers(possibleType).mapTo(unstableCandidates ?: result) {
|
||||
@@ -133,15 +133,15 @@ internal class MemberScopeTowerLevel(
|
||||
return ReceiverValueWithSmartCastInfo(newReceiverValue, possibleTypes, isStable)
|
||||
}
|
||||
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
return collectMembers { getContributedVariables(name, location) }
|
||||
}
|
||||
|
||||
override fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
|
||||
override fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> {
|
||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
return collectMembers {
|
||||
getContributedFunctions(name, location) + it.getInnerConstructors(name, location) +
|
||||
syntheticScopes.collectSyntheticMemberFunctions(listOfNotNull(it), name, location)
|
||||
@@ -174,17 +174,17 @@ internal open class ScopeBasedTowerLevel protected constructor(
|
||||
|
||||
internal constructor(scopeTower: ImplicitScopeTower, lexicalScope: LexicalScope) : this(scopeTower, lexicalScope as ResolutionScope)
|
||||
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
= resolutionScope.getContributedVariables(name, location).map {
|
||||
createCandidateDescriptor(it, dispatchReceiver = null)
|
||||
}
|
||||
|
||||
override fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
||||
override fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
= resolutionScope.getContributedObjectVariables(name, location).map {
|
||||
createCandidateDescriptor(it, dispatchReceiver = null)
|
||||
}
|
||||
|
||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>>
|
||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver>
|
||||
= resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticConstructorsProvider).map {
|
||||
createCandidateDescriptor(it, dispatchReceiver = null)
|
||||
}
|
||||
@@ -201,7 +201,7 @@ internal class SyntheticScopeBasedTowerLevel(
|
||||
private val ReceiverValueWithSmartCastInfo.allTypes: Set<KotlinType>
|
||||
get() = possibleTypes + receiverValue.type
|
||||
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
|
||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
if (extensionReceiver == null) return emptyList()
|
||||
|
||||
return syntheticScopes.collectSyntheticExtensionProperties(extensionReceiver.allTypes, name, location).map {
|
||||
@@ -211,15 +211,14 @@ internal class SyntheticScopeBasedTowerLevel(
|
||||
|
||||
override fun getObjects(
|
||||
name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> =
|
||||
): Collection<CandidateWithBoundDispatchReceiver> =
|
||||
emptyList()
|
||||
|
||||
override fun getFunctions(
|
||||
name: Name,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> =
|
||||
): Collection<CandidateWithBoundDispatchReceiver> =
|
||||
emptyList()
|
||||
|
||||
}
|
||||
|
||||
internal class HidesMembersTowerLevel(scopeTower: ImplicitScopeTower): AbstractScopeTowerLevel(scopeTower) {
|
||||
@@ -227,16 +226,16 @@ internal class HidesMembersTowerLevel(scopeTower: ImplicitScopeTower): AbstractS
|
||||
= getCandidates(name, extensionReceiver, LexicalScope::collectVariables)
|
||||
|
||||
override fun getObjects(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?)
|
||||
= emptyList<CandidateWithBoundDispatchReceiver<VariableDescriptor>>()
|
||||
= emptyList<CandidateWithBoundDispatchReceiver>()
|
||||
|
||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?)
|
||||
= getCandidates(name, extensionReceiver, LexicalScope::collectFunctions)
|
||||
|
||||
private fun <T: CallableDescriptor> getCandidates(
|
||||
private fun getCandidates(
|
||||
name: Name,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?,
|
||||
collectCandidates: LexicalScope.(Name, LookupLocation) -> Collection<T>
|
||||
): Collection<CandidateWithBoundDispatchReceiver<T>> {
|
||||
collectCandidates: LexicalScope.(Name, LookupLocation) -> Collection<CallableDescriptor>
|
||||
): Collection<CandidateWithBoundDispatchReceiver> {
|
||||
if (extensionReceiver == null || name !in HIDES_MEMBERS_NAME_LIST) return emptyList()
|
||||
|
||||
return scopeTower.lexicalScope.collectCandidates(name, location).filter {
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
@@ -34,23 +31,23 @@ interface Candidate {
|
||||
val status: ResolutionCandidateStatus
|
||||
}
|
||||
|
||||
interface CandidateFactory<in D : CallableDescriptor, out C: Candidate> {
|
||||
interface CandidateFactory<out C: Candidate> {
|
||||
fun createCandidate(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver<D>,
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): C
|
||||
}
|
||||
|
||||
interface CandidateFactoryProviderForInvoke<F : Candidate, V : Candidate> {
|
||||
interface CandidateFactoryProviderForInvoke<C : Candidate> {
|
||||
|
||||
fun transformCandidate(variable: V, invoke: F): F
|
||||
fun transformCandidate(variable: C, invoke: C): C
|
||||
|
||||
fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<VariableDescriptor, V>
|
||||
fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<C>
|
||||
|
||||
// foo() -> ReceiverValue(foo), context for invoke
|
||||
// null means that there is no invoke on variable
|
||||
fun factoryForInvoke(variable: V, useExplicitReceiver: Boolean): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<FunctionDescriptor, F>>?
|
||||
fun factoryForInvoke(variable: C, useExplicitReceiver: Boolean): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<C>>?
|
||||
}
|
||||
|
||||
sealed class TowerData {
|
||||
|
||||
@@ -26,14 +26,14 @@ val ResolutionCandidateApplicability.isSuccess: Boolean
|
||||
val CallableDescriptor.isSynthesized: Boolean
|
||||
get() = (this is CallableMemberDescriptor && kind == CallableMemberDescriptor.Kind.SYNTHESIZED)
|
||||
|
||||
val CandidateWithBoundDispatchReceiver<*>.requiresExtensionReceiver: Boolean
|
||||
val CandidateWithBoundDispatchReceiver.requiresExtensionReceiver: Boolean
|
||||
get() = descriptor.extensionReceiverParameter != null
|
||||
|
||||
internal class CandidateWithBoundDispatchReceiverImpl<out D : CallableDescriptor>(
|
||||
internal class CandidateWithBoundDispatchReceiverImpl(
|
||||
override val dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
||||
override val descriptor: D,
|
||||
override val descriptor: CallableDescriptor,
|
||||
override val diagnostics: List<ResolutionDiagnostic>
|
||||
) : CandidateWithBoundDispatchReceiver<D> {
|
||||
override fun copy(newDescriptor: @UnsafeVariance D) =
|
||||
) : CandidateWithBoundDispatchReceiver {
|
||||
override fun copy(newDescriptor: CallableDescriptor) =
|
||||
CandidateWithBoundDispatchReceiverImpl(dispatchReceiver, newDescriptor, diagnostics)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user