From b695f5edd9102e71da454965506d3ba59574757b Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 23 Aug 2016 16:18:17 +0300 Subject: [PATCH] Refactoring. Some simplifications in OverloadingConflictResolver. --- .../kotlin/resolve/OverloadChecker.kt | 1 + .../results/OverloadingConflictResolver.kt | 65 ++++++++----------- .../kotlin/resolve/DescriptorUtils.kt | 8 ++- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt index ef3a1c65909..760b9394b42 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverloadChecker.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.results.* import org.jetbrains.kotlin.resolve.calls.tower.getTypeAliasConstructors import org.jetbrains.kotlin.resolve.descriptorUtil.hasLowPriorityInOverloadResolution +import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index 95d5fbb6fe8..0cfd6a33baa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -24,11 +24,11 @@ import org.jetbrains.kotlin.descriptors.ScriptDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode -import org.jetbrains.kotlin.resolve.calls.inference.toHandle import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionMutableResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils @@ -160,7 +160,7 @@ class OverloadingConflictResolver( if (isGeneric1 && isGeneric2) return false } - return isSignatureNotLessSpecific(call1, call2, SpecificityComparisonWithNumerics, specificityComparator, call1.callHandle()) + return isSignatureNotLessSpecific(call1, call2, SpecificityComparisonWithNumerics, specificityComparator) } private val SpecificityComparisonWithNumerics = object : SpecificityComparisonCallbacks { @@ -254,43 +254,34 @@ class OverloadingConflictResolver( tryCompareDescriptorsFromScripts(f, g) ?: isNotLessSpecificCallableReferenceDescriptor(f, g) - companion object { - // Different smartcasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects - private fun uniquifyCandidatesSet(candidates: Collection>): Set> = - THashSet>(candidates.size, getCallHashingStrategy>()).apply { addAll(candidates) } + // Different smartcasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects + private fun uniquifyCandidatesSet(candidates: Collection>): Set> = + THashSet>(candidates.size, getCallHashingStrategy>()).apply { addAll(candidates) } - private fun newResolvedCallSet(expectedSize: Int): MutableSet = - THashSet(expectedSize, getCallHashingStrategy()) + private fun newResolvedCallSet(expectedSize: Int): MutableSet = + THashSet(expectedSize, getCallHashingStrategy()) - private object ResolvedCallHashingStrategy : TObjectHashingStrategy> { - override fun equals(call1: ResolvedCall<*>?, call2: ResolvedCall<*>?): Boolean = - if (call1 != null && call2 != null) - call1.resultingDescriptor == call2.resultingDescriptor - else - call1 == call2 - - override fun computeHashCode(call: ResolvedCall<*>?): Int = - call?.resultingDescriptor?.hashCode() ?: 0 - } - - private val MutableResolvedCall<*>.resultingVariableDescriptor: VariableDescriptor - get() = (this as VariableAsFunctionResolvedCall).variableCall.resultingDescriptor - - @Suppress("UNCHECKED_CAST") - private fun getCallHashingStrategy() = - ResolvedCallHashingStrategy as TObjectHashingStrategy + private object ResolvedCallHashingStrategy : TObjectHashingStrategy> { + override fun equals(call1: ResolvedCall<*>?, call2: ResolvedCall<*>?): Boolean = + if (call1 != null && call2 != null) + call1.resultingDescriptor == call2.resultingDescriptor + else + call1 == call2 + override fun computeHashCode(call: ResolvedCall<*>?): Int = + call?.resultingDescriptor?.hashCode() ?: 0 } + + private val MutableResolvedCall<*>.resultingVariableDescriptor: VariableDescriptor + get() = (this as VariableAsFunctionResolvedCall).variableCall.resultingDescriptor + + @Suppress("UNCHECKED_CAST") + private fun getCallHashingStrategy() = + ResolvedCallHashingStrategy as TObjectHashingStrategy + + private fun FlatSignature>.candidateDescriptor() = + origin.resultingDescriptor.original + + private fun FlatSignature>.descriptorVisibility() = + candidateDescriptor().visibility } - -internal fun FlatSignature>.candidateDescriptor() = - origin.candidateDescriptor.original - -internal fun FlatSignature>.callHandle() = - origin.call.toHandle() - -internal fun FlatSignature>.descriptorVisibility() = - candidateDescriptor().visibility - -internal fun CallableDescriptor.varargParameterPosition() = - valueParameters.indexOfFirst { it.varargElementType != null } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt index 3791ebc4d99..c6a6574702a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -259,4 +259,8 @@ fun ClassDescriptor.getConstructorByParams(params: List): Constructo // TODO: inline and remove as soon as all usage sies are converted to kotlin fun getConstructorByParamsMap(classDescriptor: ClassDescriptor, params: List>): ConstructorDescriptor? = - classDescriptor.getConstructorByParams(params.map { it.second }) \ No newline at end of file + classDescriptor.getConstructorByParams(params.map { it.second }) + + +fun CallableDescriptor.varargParameterPosition() = + valueParameters.indexOfFirst { it.varargElementType != null }