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) {
|
if (kind == JvmMethodParameterKind.VALUE) {
|
||||||
ValueParameterDescriptor parameter = iterator.next();
|
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);
|
AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, typeMapper);
|
||||||
|
|
||||||
if (functionDescriptor instanceof PropertySetterDescriptor) {
|
if (functionDescriptor instanceof PropertySetterDescriptor) {
|
||||||
|
|||||||
+4
-1
@@ -284,7 +284,10 @@ public class DescriptorSerializer {
|
|||||||
private ProtoBuf.Callable.ValueParameter.Builder valueParameter(@NotNull ValueParameterDescriptor descriptor) {
|
private ProtoBuf.Callable.ValueParameter.Builder valueParameter(@NotNull ValueParameterDescriptor descriptor) {
|
||||||
ProtoBuf.Callable.ValueParameter.Builder builder = ProtoBuf.Callable.ValueParameter.newBuilder();
|
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()));
|
builder.setName(getSimpleNameIndex(descriptor.getName()));
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -137,14 +137,14 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
|||||||
callable: ProtoBuf.Callable,
|
callable: ProtoBuf.Callable,
|
||||||
nameResolver: NameResolver,
|
nameResolver: NameResolver,
|
||||||
kind: AnnotatedCallableKind,
|
kind: AnnotatedCallableKind,
|
||||||
|
parameterIndex: Int,
|
||||||
proto: ProtoBuf.Callable.ValueParameter
|
proto: ProtoBuf.Callable.ValueParameter
|
||||||
): List<A> {
|
): List<A> {
|
||||||
val methodSignature = getCallableSignature(callable, nameResolver, kind)
|
val methodSignature = getCallableSignature(callable, nameResolver, kind)
|
||||||
if (methodSignature != null) {
|
if (methodSignature != null) {
|
||||||
if (proto.hasExtension(index)) {
|
val index = if (proto.hasExtension(index)) proto.getExtension(index) else parameterIndex
|
||||||
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, proto.getExtension(index))
|
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index)
|
||||||
return findClassAndLoadMemberAnnotations(container, callable, nameResolver, kind, paramSignature)
|
return findClassAndLoadMemberAnnotations(container, callable, nameResolver, kind, paramSignature)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return listOf()
|
return listOf()
|
||||||
|
|||||||
+1
@@ -53,6 +53,7 @@ class BuiltInsAnnotationAndConstantLoader(
|
|||||||
callable: ProtoBuf.Callable,
|
callable: ProtoBuf.Callable,
|
||||||
nameResolver: NameResolver,
|
nameResolver: NameResolver,
|
||||||
kind: AnnotatedCallableKind,
|
kind: AnnotatedCallableKind,
|
||||||
|
parameterIndex: Int,
|
||||||
proto: ProtoBuf.Callable.ValueParameter
|
proto: ProtoBuf.Callable.ValueParameter
|
||||||
): List<AnnotationDescriptor> {
|
): List<AnnotationDescriptor> {
|
||||||
val annotations = proto.getExtension(BuiltInsProtoBuf.parameterAnnotation).orEmpty()
|
val annotations = proto.getExtension(BuiltInsProtoBuf.parameterAnnotation).orEmpty()
|
||||||
|
|||||||
+1
@@ -44,6 +44,7 @@ public interface AnnotationAndConstantLoader<A, C, T> {
|
|||||||
@NotNull ProtoBuf.Callable callable,
|
@NotNull ProtoBuf.Callable callable,
|
||||||
@NotNull NameResolver nameResolver,
|
@NotNull NameResolver nameResolver,
|
||||||
@NotNull AnnotatedCallableKind kind,
|
@NotNull AnnotatedCallableKind kind,
|
||||||
|
int parameterIndex,
|
||||||
@NotNull ProtoBuf.Callable.ValueParameter proto
|
@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> {
|
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
|
||||||
val callableDescriptor = c.containingDeclaration as CallableDescriptor
|
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(
|
ValueParameterDescriptorImpl(
|
||||||
callableDescriptor, null, i,
|
callableDescriptor, null, i,
|
||||||
containerOfCallable?.let { getParameterAnnotations(it, callable, kind, proto) } ?: Annotations.EMPTY,
|
containerOfCallable?.let { getParameterAnnotations(it, callable, kind, i, proto) } ?: Annotations.EMPTY,
|
||||||
c.nameResolver.getName(proto.getName()),
|
c.nameResolver.getName(proto.name),
|
||||||
c.typeDeserializer.type(proto.getType()),
|
c.typeDeserializer.type(proto.type),
|
||||||
Flags.DECLARES_DEFAULT_VALUE.get(proto.getFlags()),
|
Flags.DECLARES_DEFAULT_VALUE.get(flags),
|
||||||
if (proto.hasVarargElementType()) c.typeDeserializer.type(proto.getVarargElementType()) else null,
|
if (proto.hasVarargElementType()) c.typeDeserializer.type(proto.varargElementType) else null,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
)
|
)
|
||||||
}.toReadOnlyList()
|
}.toReadOnlyList()
|
||||||
@@ -227,10 +228,13 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
|||||||
container: ProtoContainer,
|
container: ProtoContainer,
|
||||||
callable: Callable,
|
callable: Callable,
|
||||||
kind: AnnotatedCallableKind,
|
kind: AnnotatedCallableKind,
|
||||||
|
index: Int,
|
||||||
valueParameter: Callable.ValueParameter
|
valueParameter: Callable.ValueParameter
|
||||||
): Annotations {
|
): Annotations {
|
||||||
return DeserializedAnnotations(c.storageManager) {
|
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(
|
override fun loadClassAnnotations(
|
||||||
classProto: ProtoBuf.Class, nameResolver: NameResolver
|
classProto: ProtoBuf.Class, nameResolver: NameResolver
|
||||||
): List<ClassId> =
|
): 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(
|
override fun loadCallableAnnotations(
|
||||||
container: ProtoContainer,
|
container: ProtoContainer,
|
||||||
@@ -47,9 +47,10 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
|||||||
callable: ProtoBuf.Callable,
|
callable: ProtoBuf.Callable,
|
||||||
nameResolver: NameResolver,
|
nameResolver: NameResolver,
|
||||||
kind: AnnotatedCallableKind,
|
kind: AnnotatedCallableKind,
|
||||||
|
parameterIndex: Int,
|
||||||
proto: ProtoBuf.Callable.ValueParameter
|
proto: ProtoBuf.Callable.ValueParameter
|
||||||
): List<ClassId> =
|
): 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(
|
override fun loadExtensionReceiverParameterAnnotations(
|
||||||
container: ProtoContainer,
|
container: ProtoContainer,
|
||||||
@@ -62,7 +63,7 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
|||||||
proto: ProtoBuf.Type,
|
proto: ProtoBuf.Type,
|
||||||
nameResolver: NameResolver
|
nameResolver: NameResolver
|
||||||
): List<ClassId> =
|
): 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(
|
override fun loadPropertyConstant(
|
||||||
container: ProtoContainer,
|
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) {
|
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) {
|
if (callableKind == CallableKind.VAL || callableKind == CallableKind.VAR) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val parameterListStub = KotlinPlaceHolderStubImpl<JetParameterList>(parent, JetStubElementTypes.VALUE_PARAMETER_LIST)
|
val parameterListStub = KotlinPlaceHolderStubImpl<JetParameterList>(parent, JetStubElementTypes.VALUE_PARAMETER_LIST)
|
||||||
for (valueParameterProto in callableProto.getValueParameterList()) {
|
for ((index, valueParameterProto) in callableProto.valueParameterList.withIndex()) {
|
||||||
val name = c.nameResolver.getName(valueParameterProto.getName())
|
val name = c.nameResolver.getName(valueParameterProto.name)
|
||||||
val parameterStub = KotlinParameterStubImpl(
|
val parameterStub = KotlinParameterStubImpl(
|
||||||
parameterListStub,
|
parameterListStub,
|
||||||
name = name.ref(),
|
name = name.ref(),
|
||||||
@@ -157,13 +157,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
|||||||
val isVararg = valueParameterProto.hasVarargElementType()
|
val isVararg = valueParameterProto.hasVarargElementType()
|
||||||
val modifierList = if (isVararg) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null
|
val modifierList = if (isVararg) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null
|
||||||
val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations(
|
val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations(
|
||||||
container, callableProto, c.nameResolver, callableProto.annotatedCallableKind, valueParameterProto
|
container, callableProto, c.nameResolver, callableProto.annotatedCallableKind, index, valueParameterProto
|
||||||
)
|
)
|
||||||
if (parameterAnnotations.isNotEmpty()) {
|
if (parameterAnnotations.isNotEmpty()) {
|
||||||
createAnnotationStubs(parameterAnnotations, modifierList ?: createEmptyModifierList(parameterStub))
|
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)
|
createTypeReferenceStub(parameterStub, typeProto)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -52,6 +52,7 @@ class KotlinJavascriptAnnotationAndConstantLoader(
|
|||||||
callable: ProtoBuf.Callable,
|
callable: ProtoBuf.Callable,
|
||||||
nameResolver: NameResolver,
|
nameResolver: NameResolver,
|
||||||
kind: AnnotatedCallableKind,
|
kind: AnnotatedCallableKind,
|
||||||
|
parameterIndex: Int,
|
||||||
proto: ProtoBuf.Callable.ValueParameter
|
proto: ProtoBuf.Callable.ValueParameter
|
||||||
): List<AnnotationDescriptor> {
|
): List<AnnotationDescriptor> {
|
||||||
val annotations = proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty()
|
val annotations = proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty()
|
||||||
|
|||||||
Reference in New Issue
Block a user