Generate stub for specialized equals inside inline class

This commit is contained in:
Mikhail Zarechenskiy
2018-09-05 17:11:23 +03:00
parent b4674a172e
commit 83975bd6ac
14 changed files with 137 additions and 2 deletions
@@ -77,6 +77,7 @@ class ErasedInlineClassBodyCodegen(
generateUnboxMethod()
generateFunctionsFromAny()
generateSpecializedEqualsStub()
}
private fun generateFunctionsFromAny() {
@@ -116,6 +117,31 @@ class ErasedInlineClassBodyCodegen(
)
}
private fun generateSpecializedEqualsStub() {
val specializedEqualsDescriptor = InlineClassDescriptorResolver.createSpecializedEqualsDescriptor(descriptor) ?: return
functionCodegen.generateMethod(
Synthetic(null, specializedEqualsDescriptor), specializedEqualsDescriptor, object : FunctionGenerationStrategy.CodegenBased(state) {
override fun mapMethodSignature(
functionDescriptor: FunctionDescriptor,
typeMapper: KotlinTypeMapper,
contextKind: OwnerKind,
hasSpecialBridge: Boolean
): JvmMethodGenericSignature {
// we shouldn't use default mapping here to avoid adding parameter that relates to carrier type
return typeMapper.mapSignatureForSpecializedEqualsOfInlineClass(functionDescriptor)
}
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
val iv = codegen.v
iv.aconst(null)
iv.athrow()
}
}
)
}
override fun generateKotlinMetadataAnnotation() {
writeSyntheticClassMetadata(v, state)
}
@@ -1162,6 +1162,11 @@ public class KotlinTypeMapper {
return mapSignature(f, OwnerKind.IMPLEMENTATION, true);
}
@NotNull
public JvmMethodGenericSignature mapSignatureForSpecializedEqualsOfInlineClass(@NotNull FunctionDescriptor f) {
return mapSignature(f, OwnerKind.IMPLEMENTATION, true);
}
@NotNull
public JvmMethodSignature mapSignatureSkipGeneric(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
return mapSignature(f, kind, true);