Optimizations

This commit is contained in:
Valentin Kipyatkov
2016-09-13 22:22:50 +03:00
parent 6b94e5fd34
commit d8759fcbcc
5 changed files with 23 additions and 17 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.resolve.calls;
import com.google.common.collect.Lists;
import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -52,6 +51,7 @@ import org.jetbrains.kotlin.types.expressions.*;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -272,7 +272,7 @@ public class ArgumentTypeResolver {
}
return FunctionTypeResolveUtilsKt.createFunctionType(
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), TypeUtils.DONT_CARE
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), null, TypeUtils.DONT_CARE
);
}
@@ -303,14 +303,14 @@ public class ArgumentTypeResolver {
? functionPlaceholders
.createFunctionPlaceholderType(Collections.<KotlinType>emptyList(), /* hasDeclaredArguments = */ false)
: FunctionTypeResolveUtilsKt.createFunctionType(
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), DONT_CARE
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), null, DONT_CARE
);
}
List<KtParameter> valueParameters = function.getValueParameters();
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
trace, "trace to resolve function literal parameter types");
List<KotlinType> parameterTypes = Lists.newArrayList();
List<Name> parameterNames = Lists.newArrayList();
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(valueParameters.size());
List<Name> parameterNames = new ArrayList<Name>(valueParameters.size());
for (KtParameter parameter : valueParameters) {
parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE));
Name name = parameter.getNameAsName();
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
@@ -291,13 +290,11 @@ public class CallResolver {
if (calleeExpression instanceof KtLambdaExpression) {
int parameterNumber = ((KtLambdaExpression) calleeExpression).getValueParameters().size();
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(parameterNumber);
List<Name> parameterNames = new ArrayList<Name>(parameterNumber);
for (int i = 0; i < parameterNumber; i++) {
parameterTypes.add(NO_EXPECTED_TYPE);
parameterNames.add(SpecialNames.NO_NAME_PROVIDED);
}
expectedType = FunctionTypeResolveUtilsKt.createFunctionType(
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, parameterNames, context.expectedType
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, null, context.expectedType
);
}
KotlinType calleeType = expressionTypingServices.safeGetType(
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.inference
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.EQUAL
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.SUB_TYPE
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
@@ -449,6 +448,5 @@ internal fun createTypeForFunctionPlaceholder(
functionPlaceholderTypeConstructor.argumentTypes
}
val receiverType = if (isExtension) DONT_CARE else null
val parameterNames = newArgumentTypes.map { SpecialNames.NO_NAME_PROVIDED }
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, parameterNames, DONT_CARE)
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, null, DONT_CARE)
}
@@ -28,7 +28,10 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeProjection
fun createValueParametersForInvokeInFunctionType(
functionDescriptor: FunctionDescriptor, parameterTypes: List<TypeProjection>
@@ -51,9 +54,9 @@ fun createFunctionType(
annotations: Annotations,
receiverType: KotlinType?,
parameterTypes: List<KotlinType>,
parameterNames: List<Name>,
parameterNames: List<Name>?,
returnType: KotlinType
): FunctionType {
): SimpleType {
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
val size = parameterTypes.size
val classDescriptor = builtIns.getFunction(if (receiverType == null) size else size + 1)
@@ -56,8 +56,16 @@ object KotlinTypeFactory {
annotations: Annotations,
descriptor: ClassDescriptor,
arguments: List<TypeProjection>,
parameterNames: List<Name>
): FunctionType = FunctionType(simpleNotNullType(annotations, descriptor, arguments), parameterNames)
parameterNames: List<Name>?
): SimpleType {
val simpleType = simpleNotNullType(annotations, descriptor, arguments)
if (parameterNames == null || parameterNames.all { it.isSpecial }) {
return simpleType
}
else {
return FunctionType(simpleType, parameterNames)
}
}
@JvmStatic
fun simpleType(