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
This commit is contained in:
@@ -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) {
|
||||
|
||||
+4
-1
@@ -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()));
|
||||
|
||||
|
||||
+4
-4
@@ -137,14 +137,14 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
callable: ProtoBuf.Callable,
|
||||
nameResolver: NameResolver,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.Callable.ValueParameter
|
||||
): List<A> {
|
||||
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()
|
||||
|
||||
+1
@@ -53,6 +53,7 @@ class BuiltInsAnnotationAndConstantLoader(
|
||||
callable: ProtoBuf.Callable,
|
||||
nameResolver: NameResolver,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.Callable.ValueParameter
|
||||
): List<AnnotationDescriptor> {
|
||||
val annotations = proto.getExtension(BuiltInsProtoBuf.parameterAnnotation).orEmpty()
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public interface AnnotationAndConstantLoader<A, C, T> {
|
||||
@NotNull ProtoBuf.Callable callable,
|
||||
@NotNull NameResolver nameResolver,
|
||||
@NotNull AnnotatedCallableKind kind,
|
||||
int parameterIndex,
|
||||
@NotNull ProtoBuf.Callable.ValueParameter proto
|
||||
);
|
||||
|
||||
|
||||
+12
-8
@@ -208,16 +208,17 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
|
||||
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -31,7 +31,7 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
||||
override fun loadClassAnnotations(
|
||||
classProto: ProtoBuf.Class, nameResolver: NameResolver
|
||||
): List<ClassId> =
|
||||
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<ClassId> =
|
||||
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<ClassId> =
|
||||
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,
|
||||
|
||||
+5
-5
@@ -139,13 +139,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
}
|
||||
|
||||
fun createValueParameterListStub(parent: StubElement<out PsiElement>, 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<JetParameterList>(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)
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -52,6 +52,7 @@ class KotlinJavascriptAnnotationAndConstantLoader(
|
||||
callable: ProtoBuf.Callable,
|
||||
nameResolver: NameResolver,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.Callable.ValueParameter
|
||||
): List<AnnotationDescriptor> {
|
||||
val annotations = proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty()
|
||||
|
||||
Reference in New Issue
Block a user