From 542bfab96ff645bbdb98a6b0d4c6fd2bdca50271 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 24 Sep 2015 12:37:45 +0300 Subject: [PATCH] Don't write unnecessary information to ValueParameter proto Flags can have a default value and the index can be trivially computed almost all the time --- .../kotlin/codegen/FunctionCodegen.java | 4 +++- .../serialization/DescriptorSerializer.java | 5 ++++- ...tBinaryClassAnnotationAndConstantLoader.kt | 8 ++++---- .../BuiltInsAnnotationAndConstantLoader.kt | 1 + .../AnnotationAndConstantLoader.java | 1 + .../deserialization/MemberDeserializer.kt | 20 +++++++++++-------- ...ionLoaderForKotlinJavaScriptStubBuilder.kt | 7 ++++--- .../stubBuilder/TypeClsStubBuilder.kt | 10 +++++----- ...inJavascriptAnnotationAndConstantLoader.kt | 1 + 9 files changed, 35 insertions(+), 22 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index a0d3c93835b..f2311d24cdf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -268,7 +268,9 @@ public class FunctionCodegen { if (kind == JvmMethodParameterKind.VALUE) { ValueParameterDescriptor parameter = iterator.next(); - v.getSerializationBindings().put(INDEX_FOR_VALUE_PARAMETER, parameter, i); + if (parameter.getIndex() != i) { + v.getSerializationBindings().put(INDEX_FOR_VALUE_PARAMETER, parameter, i); + } AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, typeMapper); if (functionDescriptor instanceof PropertySetterDescriptor) { diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java index 032813640a8..378c0eb8cab 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java @@ -284,7 +284,10 @@ public class DescriptorSerializer { private ProtoBuf.Callable.ValueParameter.Builder valueParameter(@NotNull ValueParameterDescriptor descriptor) { ProtoBuf.Callable.ValueParameter.Builder builder = ProtoBuf.Callable.ValueParameter.newBuilder(); - builder.setFlags(Flags.getValueParameterFlags(hasAnnotations(descriptor), descriptor.declaresDefaultValue())); + int flags = Flags.getValueParameterFlags(hasAnnotations(descriptor), descriptor.declaresDefaultValue()); + if (flags != 0) { + builder.setFlags(flags); + } builder.setName(getSimpleNameIndex(descriptor.getName())); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt index 1a586228722..b25a8b189a6 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt @@ -137,14 +137,14 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { val methodSignature = getCallableSignature(callable, nameResolver, kind) if (methodSignature != null) { - if (proto.hasExtension(index)) { - val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, proto.getExtension(index)) - return findClassAndLoadMemberAnnotations(container, callable, nameResolver, kind, paramSignature) - } + val index = if (proto.hasExtension(index)) proto.getExtension(index) else parameterIndex + val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index) + return findClassAndLoadMemberAnnotations(container, callable, nameResolver, kind, paramSignature) } return listOf() diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt index 0a92aa51e8a..fdc36916bd6 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt @@ -53,6 +53,7 @@ class BuiltInsAnnotationAndConstantLoader( callable: ProtoBuf.Callable, nameResolver: NameResolver, kind: AnnotatedCallableKind, + parameterIndex: Int, proto: ProtoBuf.Callable.ValueParameter ): List { val annotations = proto.getExtension(BuiltInsProtoBuf.parameterAnnotation).orEmpty() diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java index 5a435297950..f089850aed7 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java @@ -44,6 +44,7 @@ public interface AnnotationAndConstantLoader { @NotNull ProtoBuf.Callable callable, @NotNull NameResolver nameResolver, @NotNull AnnotatedCallableKind kind, + int parameterIndex, @NotNull ProtoBuf.Callable.ValueParameter proto ); diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index 53181276d43..5cfed041421 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -208,16 +208,17 @@ public class MemberDeserializer(private val c: DeserializationContext) { private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List { val callableDescriptor = c.containingDeclaration as CallableDescriptor - val containerOfCallable = callableDescriptor.getContainingDeclaration().asProtoContainer() + val containerOfCallable = callableDescriptor.containingDeclaration.asProtoContainer() - return callable.getValueParameterList().mapIndexed { i, proto -> + return callable.valueParameterList.mapIndexed { i, proto -> + val flags = if (proto.hasFlags()) proto.flags else 0 ValueParameterDescriptorImpl( callableDescriptor, null, i, - containerOfCallable?.let { getParameterAnnotations(it, callable, kind, proto) } ?: Annotations.EMPTY, - c.nameResolver.getName(proto.getName()), - c.typeDeserializer.type(proto.getType()), - Flags.DECLARES_DEFAULT_VALUE.get(proto.getFlags()), - if (proto.hasVarargElementType()) c.typeDeserializer.type(proto.getVarargElementType()) else null, + containerOfCallable?.let { getParameterAnnotations(it, callable, kind, i, proto) } ?: Annotations.EMPTY, + c.nameResolver.getName(proto.name), + c.typeDeserializer.type(proto.type), + Flags.DECLARES_DEFAULT_VALUE.get(flags), + if (proto.hasVarargElementType()) c.typeDeserializer.type(proto.varargElementType) else null, SourceElement.NO_SOURCE ) }.toReadOnlyList() @@ -227,10 +228,13 @@ public class MemberDeserializer(private val c: DeserializationContext) { container: ProtoContainer, callable: Callable, kind: AnnotatedCallableKind, + index: Int, valueParameter: Callable.ValueParameter ): Annotations { return DeserializedAnnotations(c.storageManager) { - c.components.annotationAndConstantLoader.loadValueParameterAnnotations(container, callable, c.nameResolver, kind, valueParameter) + c.components.annotationAndConstantLoader.loadValueParameterAnnotations( + container, callable, c.nameResolver, kind, index, valueParameter + ) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt index 51ff14159f2..a770b9c1153 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt @@ -31,7 +31,7 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon override fun loadClassAnnotations( classProto: ProtoBuf.Class, nameResolver: NameResolver ): List = - classProto.getExtension(JsProtoBuf.classAnnotation).orEmpty().map { nameResolver.getClassId(it.getId()) } + classProto.getExtension(JsProtoBuf.classAnnotation).orEmpty().map { nameResolver.getClassId(it.id) } override fun loadCallableAnnotations( container: ProtoContainer, @@ -47,9 +47,10 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon callable: ProtoBuf.Callable, nameResolver: NameResolver, kind: AnnotatedCallableKind, + parameterIndex: Int, proto: ProtoBuf.Callable.ValueParameter ): List = - proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty().map { nameResolver.getClassId(it.getId()) } + proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty().map { nameResolver.getClassId(it.id) } override fun loadExtensionReceiverParameterAnnotations( container: ProtoContainer, @@ -62,7 +63,7 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon proto: ProtoBuf.Type, nameResolver: NameResolver ): List = - proto.getExtension(JsProtoBuf.typeAnnotation).orEmpty().map { nameResolver.getClassId(it.getId()) } + proto.getExtension(JsProtoBuf.typeAnnotation).orEmpty().map { nameResolver.getClassId(it.id) } override fun loadPropertyConstant( container: ProtoContainer, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index 8bc965a2475..de84ef8b950 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -139,13 +139,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { } fun createValueParameterListStub(parent: StubElement, callableProto: ProtoBuf.Callable, container: ProtoContainer) { - val callableKind = Flags.CALLABLE_KIND[callableProto.getFlags()] + val callableKind = Flags.CALLABLE_KIND[callableProto.flags] if (callableKind == CallableKind.VAL || callableKind == CallableKind.VAR) { return } val parameterListStub = KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.VALUE_PARAMETER_LIST) - for (valueParameterProto in callableProto.getValueParameterList()) { - val name = c.nameResolver.getName(valueParameterProto.getName()) + for ((index, valueParameterProto) in callableProto.valueParameterList.withIndex()) { + val name = c.nameResolver.getName(valueParameterProto.name) val parameterStub = KotlinParameterStubImpl( parameterListStub, name = name.ref(), @@ -157,13 +157,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { val isVararg = valueParameterProto.hasVarargElementType() val modifierList = if (isVararg) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations( - container, callableProto, c.nameResolver, callableProto.annotatedCallableKind, valueParameterProto + container, callableProto, c.nameResolver, callableProto.annotatedCallableKind, index, valueParameterProto ) if (parameterAnnotations.isNotEmpty()) { createAnnotationStubs(parameterAnnotations, modifierList ?: createEmptyModifierList(parameterStub)) } - val typeProto = if (isVararg) valueParameterProto.getVarargElementType() else valueParameterProto.getType() + val typeProto = if (isVararg) valueParameterProto.varargElementType else valueParameterProto.type createTypeReferenceStub(parameterStub, typeProto) } } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt index 13618cba014..20961048de1 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt @@ -52,6 +52,7 @@ class KotlinJavascriptAnnotationAndConstantLoader( callable: ProtoBuf.Callable, nameResolver: NameResolver, kind: AnnotatedCallableKind, + parameterIndex: Int, proto: ProtoBuf.Callable.ValueParameter ): List { val annotations = proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty()