Remove special casing for Unit in kotlinx.serialization

Unignore test since it is in muted list and auto-generated
This commit is contained in:
Leonid Startsev
2020-02-05 17:42:35 +03:00
parent 59cdf3c52e
commit bdf1441c80
6 changed files with 9 additions and 27 deletions
@@ -41,8 +41,7 @@ import org.jetbrains.kotlinx.serialization.compiler.resolve.SerializationPackage
open class SerialTypeInfo( open class SerialTypeInfo(
val property: SerializableProperty, val property: SerializableProperty,
val elementMethodPrefix: String, val elementMethodPrefix: String,
val serializer: ClassDescriptor? = null, val serializer: ClassDescriptor? = null
val unit: Boolean = false
) )
fun AbstractSerialGenerator.findAddOnSerializer(propertyType: KotlinType, module: ModuleDescriptor): ClassDescriptor? { fun AbstractSerialGenerator.findAddOnSerializer(propertyType: KotlinType, module: ModuleDescriptor): ClassDescriptor? {
@@ -75,7 +74,6 @@ fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty): S
// alternative: KotlinBuiltIns.getPrimitiveType(T)!!.typeName.identifier // alternative: KotlinBuiltIns.getPrimitiveType(T)!!.typeName.identifier
) )
KotlinBuiltIns.isString(T) -> SerialTypeInfo(property, "String") KotlinBuiltIns.isString(T) -> SerialTypeInfo(property, "String")
KotlinBuiltIns.isUnit(T) -> SerialTypeInfo(property, "Unit", unit = true)
KotlinBuiltIns.isNonPrimitiveArray(T.toClassDescriptor!!) -> { KotlinBuiltIns.isNonPrimitiveArray(T.toClassDescriptor!!) -> {
val serializer = property.serializableWith?.toClassDescriptor ?: property.module.findClassAcrossModuleDependencies( val serializer = property.serializableWith?.toClassDescriptor ?: property.module.findClassAcrossModuleDependencies(
referenceArraySerializerId referenceArraySerializerId
@@ -335,13 +335,6 @@ open class SerializerJsTranslator(
localProps[i], localProps[i],
call call
).makeStmt() ).makeStmt()
// need explicit unit instance
if (sti.unit) {
+JsAstUtils.assignment(
localProps[i],
context.getQualifiedReference(property.type.builtIns.unit)
).makeStmt()
}
// char unboxing crutch // char unboxing crutch
if (KotlinBuiltIns.isCharOrNullableChar(property.type)) { if (KotlinBuiltIns.isCharOrNullableChar(property.type)) {
val coerceTo = TranslationUtils.getReturnTypeForCoercion(property.descriptor) val coerceTo = TranslationUtils.getReturnTypeForCoercion(property.descriptor)
@@ -101,21 +101,21 @@ fun InstructionAdapter.genKOutputMethodCall(
val sti = generator.getSerialTypeInfo(property, propertyType) val sti = generator.getSerialTypeInfo(property, propertyType)
val useSerializer = if (fromClassStartVar == null) stackValueSerializerInstanceFromSerializer(classCodegen, sti, generator) val useSerializer = if (fromClassStartVar == null) stackValueSerializerInstanceFromSerializer(classCodegen, sti, generator)
else stackValueSerializerInstanceFromClass(classCodegen, sti, fromClassStartVar, generator) else stackValueSerializerInstanceFromClass(classCodegen, sti, fromClassStartVar, generator)
val actualType = if (!sti.unit) ImplementationBodyCodegen.genPropertyOnStack( val actualType = ImplementationBodyCodegen.genPropertyOnStack(
this, this,
expressionCodegen.context, expressionCodegen.context,
property.descriptor, property.descriptor,
propertyOwnerType, propertyOwnerType,
ownerVar, ownerVar,
classCodegen.state classCodegen.state
) else null )
actualType?.type?.let { type -> StackValue.coerce(type, sti.type, this) } actualType?.type?.let { type -> StackValue.coerce(type, sti.type, this) }
invokeinterface( invokeinterface(
kOutputType.internalName, kOutputType.internalName,
CallingConventions.encode + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix, CallingConventions.encode + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix,
"(" + descType.descriptor + "I" + "(" + descType.descriptor + "I" +
(if (useSerializer) kSerialSaverType.descriptor else "") + (if (useSerializer) kSerialSaverType.descriptor else "") +
(if (sti.unit) "" else sti.type.descriptor) + ")V" (sti.type.descriptor) + ")V"
) )
} }
@@ -394,9 +394,8 @@ class JVMSerialTypeInfo(
property: SerializableProperty, property: SerializableProperty,
val type: Type, val type: Type,
nn: String, nn: String,
serializer: ClassDescriptor? = null, serializer: ClassDescriptor? = null
unit: Boolean = false ) : SerialTypeInfo(property, nn, serializer)
) : SerialTypeInfo(property, nn, serializer, unit)
fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty, type: Type): JVMSerialTypeInfo { fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty, type: Type): JVMSerialTypeInfo {
fun SerializableInfo(serializer: ClassDescriptor?) = fun SerializableInfo(serializer: ClassDescriptor?) =
@@ -451,8 +450,6 @@ fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty, ty
// no explicit serializer for this property. Check other built in types // no explicit serializer for this property. Check other built in types
if (KotlinBuiltIns.isString(property.type)) if (KotlinBuiltIns.isString(property.type))
return JVMSerialTypeInfo(property, Type.getType("Ljava/lang/String;"), "String") return JVMSerialTypeInfo(property, Type.getType("Ljava/lang/String;"), "String")
if (KotlinBuiltIns.isUnit(property.type))
return JVMSerialTypeInfo(property, Type.getType("Lkotlin/Unit;"), "Unit", unit = true)
// todo: more efficient enum support here, but only for enums that don't define custom serializer // todo: more efficient enum support here, but only for enums that don't define custom serializer
// otherwise, it is a serializer for some other type // otherwise, it is a serializer for some other type
val serializer = property.serializableWith?.toClassDescriptor val serializer = property.serializableWith?.toClassDescriptor
@@ -486,7 +486,7 @@ open class SerializerCodegenImpl(
(if (useSerializer) kSerialLoaderType.descriptor else "") (if (useSerializer) kSerialLoaderType.descriptor else "")
+ (if (unknownSer) AsmTypes.K_CLASS_TYPE.descriptor else "") + (if (unknownSer) AsmTypes.K_CLASS_TYPE.descriptor else "")
+ (if (update) sti.type.descriptor else "") + (if (update) sti.type.descriptor else "")
+ ")" + (if (sti.unit) "V" else sti.type.descriptor) + ")" + (sti.type.descriptor)
) )
} }
@@ -508,11 +508,7 @@ open class SerializerCodegenImpl(
produceCall(false) produceCall(false)
} }
if (sti.unit) { StackValue.coerce(sti.type, propertyType, this)
StackValue.putUnitInstance(this)
} else {
StackValue.coerce(sti.type, propertyType, this)
}
store(propertyVar, propertyType) store(propertyVar, propertyType)
} }
@@ -9,7 +9,6 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.Ignore;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.io.File; import java.io.File;
@@ -20,7 +19,6 @@ import java.util.regex.Pattern;
@TestMetadata("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/codegen") @TestMetadata("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/codegen")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@Ignore // todo: unignore when new serialziation version will be publicly available & update it in build.gradle.kts
public class SerializationIrBytecodeListingTestGenerated extends AbstractSerializationIrBytecodeListingTest { public class SerializationIrBytecodeListingTestGenerated extends AbstractSerializationIrBytecodeListingTest {
private void runTest(String testDataFilePath) throws Exception { private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+1 -1
View File
@@ -54,6 +54,6 @@ org.jetbrains.kotlin.psi.injection.StringInterpolationInjectionTest.testInterpol
org.jetbrains.kotlin.nj2k.NewJavaToKotlinConverterSingleFileTestGenerated.Issues.testKt_8170, KT-36459 org.jetbrains.kotlin.nj2k.NewJavaToKotlinConverterSingleFileTestGenerated.Issues.testKt_8170, KT-36459
org.jetbrains.kotlin.shortenRefs.ShortenRefsTestGenerated.testExtensionForObject2, Always red org.jetbrains.kotlin.shortenRefs.ShortenRefsTestGenerated.testExtensionForObject2, Always red
org.jetbrains.kotlin.util.KotlinVersionsTest.testVersionsAreConsistent, KT-35567 org.jetbrains.kotlin.util.KotlinVersionsTest.testVersionsAreConsistent, KT-35567
org.jetbrains.kotlinx.serialization.SerializationIrBytecodeListingTestGenerated.testBasic, Broken between 20 nov and 10 dec org.jetbrains.kotlinx.serialization.SerializationIrBytecodeListingTestGenerated.testBasic, wait until new serialziation runtime version will be publicly available
org.jetbrains.kotlin.jvm.compiler.CompileKotlinAgainstJavaTestGenerated.WithAPT.testClassWithTypeParameter, KT-36448 org.jetbrains.kotlin.jvm.compiler.CompileKotlinAgainstJavaTestGenerated.WithAPT.testClassWithTypeParameter, KT-36448
org.jetbrains.kotlin.jvm.compiler.CompileKotlinAgainstJavaTestGenerated.WithoutAPT.testClassWithTypeParameter, KT-36448 org.jetbrains.kotlin.jvm.compiler.CompileKotlinAgainstJavaTestGenerated.WithoutAPT.testClassWithTypeParameter, KT-36448
Can't render this file because it contains an unexpected character in line 12 and column 132.