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(
val property: SerializableProperty,
val elementMethodPrefix: String,
val serializer: ClassDescriptor? = null,
val unit: Boolean = false
val serializer: ClassDescriptor? = null
)
fun AbstractSerialGenerator.findAddOnSerializer(propertyType: KotlinType, module: ModuleDescriptor): ClassDescriptor? {
@@ -75,7 +74,6 @@ fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty): S
// alternative: KotlinBuiltIns.getPrimitiveType(T)!!.typeName.identifier
)
KotlinBuiltIns.isString(T) -> SerialTypeInfo(property, "String")
KotlinBuiltIns.isUnit(T) -> SerialTypeInfo(property, "Unit", unit = true)
KotlinBuiltIns.isNonPrimitiveArray(T.toClassDescriptor!!) -> {
val serializer = property.serializableWith?.toClassDescriptor ?: property.module.findClassAcrossModuleDependencies(
referenceArraySerializerId
@@ -335,13 +335,6 @@ open class SerializerJsTranslator(
localProps[i],
call
).makeStmt()
// need explicit unit instance
if (sti.unit) {
+JsAstUtils.assignment(
localProps[i],
context.getQualifiedReference(property.type.builtIns.unit)
).makeStmt()
}
// char unboxing crutch
if (KotlinBuiltIns.isCharOrNullableChar(property.type)) {
val coerceTo = TranslationUtils.getReturnTypeForCoercion(property.descriptor)
@@ -101,21 +101,21 @@ fun InstructionAdapter.genKOutputMethodCall(
val sti = generator.getSerialTypeInfo(property, propertyType)
val useSerializer = if (fromClassStartVar == null) stackValueSerializerInstanceFromSerializer(classCodegen, sti, generator)
else stackValueSerializerInstanceFromClass(classCodegen, sti, fromClassStartVar, generator)
val actualType = if (!sti.unit) ImplementationBodyCodegen.genPropertyOnStack(
val actualType = ImplementationBodyCodegen.genPropertyOnStack(
this,
expressionCodegen.context,
property.descriptor,
propertyOwnerType,
ownerVar,
classCodegen.state
) else null
)
actualType?.type?.let { type -> StackValue.coerce(type, sti.type, this) }
invokeinterface(
kOutputType.internalName,
CallingConventions.encode + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix,
"(" + descType.descriptor + "I" +
(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,
val type: Type,
nn: String,
serializer: ClassDescriptor? = null,
unit: Boolean = false
) : SerialTypeInfo(property, nn, serializer, unit)
serializer: ClassDescriptor? = null
) : SerialTypeInfo(property, nn, serializer)
fun AbstractSerialGenerator.getSerialTypeInfo(property: SerializableProperty, type: Type): JVMSerialTypeInfo {
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
if (KotlinBuiltIns.isString(property.type))
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
// otherwise, it is a serializer for some other type
val serializer = property.serializableWith?.toClassDescriptor
@@ -486,7 +486,7 @@ open class SerializerCodegenImpl(
(if (useSerializer) kSerialLoaderType.descriptor else "")
+ (if (unknownSer) AsmTypes.K_CLASS_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)
}
if (sti.unit) {
StackValue.putUnitInstance(this)
} else {
StackValue.coerce(sti.type, propertyType, this)
}
StackValue.coerce(sti.type, propertyType, this)
store(propertyVar, propertyType)
}
@@ -9,7 +9,6 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import java.io.File;
@@ -20,7 +19,6 @@ import java.util.regex.Pattern;
@TestMetadata("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/codegen")
@TestDataPath("$PROJECT_ROOT")
@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 {
private void runTest(String testDataFilePath) throws Exception {
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.shortenRefs.ShortenRefsTestGenerated.testExtensionForObject2, Always red
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.WithoutAPT.testClassWithTypeParameter, KT-36448
Can't render this file because it contains an unexpected character in line 12 and column 132.