Revert back visibility in deserialization ctor to public so inheritors can access it from other modules.

Fix instantiating of polymorphic serializer with generics.
Move context creation below as asked.
This commit is contained in:
Leonid Startsev
2019-04-30 12:55:00 +03:00
parent 3610c99163
commit 0ecf20bd62
3 changed files with 26 additions and 20 deletions
@@ -127,12 +127,12 @@ public class ConstructorCodegen {
) { ) {
if (!canHaveDeclaredConstructors(descriptor)) return; if (!canHaveDeclaredConstructors(descriptor)) return;
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor, typeMapper);
KtSecondaryConstructor constructor = (KtSecondaryConstructor) descriptorToDeclaration(constructorDescriptor); KtSecondaryConstructor constructor = (KtSecondaryConstructor) descriptorToDeclaration(constructorDescriptor);
// Synthetic constructors don't have corresponding declarations // Synthetic constructors don't have corresponding declarations
if (constructor == null) return; if (constructor == null) return;
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor, typeMapper);
functionCodegen.generateMethod( functionCodegen.generateMethod(
JvmDeclarationOriginKt.OtherOrigin(constructor, constructorDescriptor), JvmDeclarationOriginKt.OtherOrigin(constructor, constructorDescriptor),
constructorDescriptor, constructorContext, constructorDescriptor, constructorContext,
@@ -263,23 +263,9 @@ internal fun AbstractSerialGenerator.stackValueSerializerInstance(codegen: Class
dup() dup()
// instantiate all arg serializers on stack // instantiate all arg serializers on stack
val signature = StringBuilder("(") val signature = StringBuilder("(")
when (serializer.classId) {
enumSerializerId, contextSerializerId, polymorphicSerializerId -> { fun instantiate(typeArgument: Pair<KotlinType, ClassDescriptor?>) {
// a special way to instantiate enum -- need a enum KClass reference val (argType, argSerializer) = typeArgument
// GENERIC_ARGUMENT forces boxing in order to obtain KClass
aconst(codegen.typeMapper.mapType(kType, null, TypeMappingMode.GENERIC_ARGUMENT))
AsmUtil.wrapJavaClassIntoKClass(this)
signature.append(AsmTypes.K_CLASS_TYPE.descriptor)
}
referenceArraySerializerId -> {
// a special way to instantiate reference array serializer -- need an element KClass reference
aconst(codegen.typeMapper.mapType(kType.arguments[0].type, null, TypeMappingMode.GENERIC_ARGUMENT))
AsmUtil.wrapJavaClassIntoKClass(this)
signature.append(AsmTypes.K_CLASS_TYPE.descriptor)
}
}
// all serializers get arguments with serializers of their generic types
argSerializers.forEach { (argType, argSerializer) ->
assert( assert(
stackValueSerializerInstance( stackValueSerializerInstance(
codegen, codegen,
@@ -295,6 +281,26 @@ internal fun AbstractSerialGenerator.stackValueSerializerInstance(codegen: Class
if (argType.isMarkedNullable) wrapStackValueIntoNullableSerializer() if (argType.isMarkedNullable) wrapStackValueIntoNullableSerializer()
signature.append(kSerializerType.descriptor) signature.append(kSerializerType.descriptor)
} }
when (serializer.classId) {
enumSerializerId, contextSerializerId, polymorphicSerializerId -> {
// a special way to instantiate enum -- need a enum KClass reference
// GENERIC_ARGUMENT forces boxing in order to obtain KClass
aconst(codegen.typeMapper.mapType(kType, null, TypeMappingMode.GENERIC_ARGUMENT))
AsmUtil.wrapJavaClassIntoKClass(this)
signature.append(AsmTypes.K_CLASS_TYPE.descriptor)
}
referenceArraySerializerId -> {
// a special way to instantiate reference array serializer -- need an element KClass reference
aconst(codegen.typeMapper.mapType(kType.arguments[0].type, null, TypeMappingMode.GENERIC_ARGUMENT))
AsmUtil.wrapJavaClassIntoKClass(this)
signature.append(AsmTypes.K_CLASS_TYPE.descriptor)
// Reference array serializer still needs serializer for its argument type
instantiate(argSerializers[0])
}
// all serializers get arguments with serializers of their generic types
else -> argSerializers.forEach(::instantiate)
}
signature.append(")V") signature.append(")V")
// invoke constructor // invoke constructor
invokespecial(serializerType.internalName, "<init>", signature.toString(), false) invokespecial(serializerType.internalName, "<init>", signature.toString(), false)
@@ -323,7 +323,7 @@ object KSerializerDescriptorResolver {
functionDescriptor.initialize( functionDescriptor.initialize(
consParams, consParams,
Visibilities.INTERNAL Visibilities.PUBLIC
) )
functionDescriptor.returnType = classDescriptor.defaultType functionDescriptor.returnType = classDescriptor.defaultType