Optimize signature propagation

Do not collect super function with trivial signature
This commit is contained in:
Denis Zharkov
2016-02-24 11:53:45 +03:00
parent d66b9a08dd
commit 7bd8fa0b48
2 changed files with 44 additions and 3 deletions
@@ -72,7 +72,9 @@ public class SignaturesPropagationData {
createAutoMethodDescriptor(containingClass, method, autoReturnType, autoValueParameters, autoTypeParameters);
superFunctions = getSuperFunctionsForMethod(method, autoMethodDescriptor, containingClass);
modifiedValueParameters = modifyValueParametersAccordingToSuperMethods(autoValueParameters);
modifiedValueParameters = superFunctions.isEmpty()
? new ValueParameters(null, autoValueParameters, /* stableParameterNames = */false)
: modifyValueParametersAccordingToSuperMethods(autoValueParameters);
}
@NotNull
@@ -198,9 +200,18 @@ public class SignaturesPropagationData {
// TODO: Add propagation for other kotlin descriptors (KT-3621)
Name name = method.getName();
Method autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
Method autoSignature = null;
boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
Collection<FunctionDescriptor> superFunctionCandidates =
supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates)) continue;
if (autoSignature == null) {
autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
}
for (FunctionDescriptor candidate : superFunctionCandidates) {
Method candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
if (KotlinToJvmSignatureMapperKt.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
@@ -0,0 +1,30 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.jvm.kotlinSignature
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
internal fun FunctionDescriptor.containsVarargs() = valueParameters.any { it.varargElementType != null }
internal fun Collection<FunctionDescriptor>.containsAnyNotTrivialSignature() = any { it.hasNotTrivialSignature() }
private fun FunctionDescriptor.hasNotTrivialSignature(): Boolean {
if (extensionReceiverParameter != null) return true
if (hasStableParameterNames()) return true
return containsVarargs()
}