JVM IR: Avoid parameter null-checks in inline class impl methods
This commit is contained in:
committed by
Alexander Udalov
parent
cdd3f82396
commit
475079611d
@@ -39,5 +39,6 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin {
|
||||
object GENERATED_SAM_IMPLEMENTATION : IrDeclarationOriginImpl("GENERATED_SAM_IMPLEMENTATION", isSynthetic = true)
|
||||
object ENUM_MAPPINGS_FOR_WHEN : IrDeclarationOriginImpl("ENUM_MAPPINGS_FOR_WHEN", isSynthetic = true)
|
||||
object SYNTHETIC_INLINE_CLASS_MEMBER : IrDeclarationOriginImpl("SYNTHETIC_INLINE_CLASS_MEMBER", isSynthetic = true)
|
||||
object INLINE_CLASS_GENERATED_IMPL_METHOD : IrDeclarationOriginImpl("INLINE_CLASS_GENERATED_IMPL_METHOD")
|
||||
object GENERATED_ASSERTION_ENABLED_FIELD : IrDeclarationOriginImpl("GENERATED_ASSERTION_ENABLED_FIELD", isSynthetic = true)
|
||||
}
|
||||
|
||||
+2
@@ -193,6 +193,8 @@ class ExpressionCodegen(
|
||||
return
|
||||
|
||||
val isSyntheticOrBridge = irFunction.origin.isSynthetic ||
|
||||
// TODO: Implement this as a lowering, so that we can more easily exclude generated methods.
|
||||
irFunction.origin == JvmLoweredDeclarationOrigin.INLINE_CLASS_GENERATED_IMPL_METHOD ||
|
||||
// Although these are accessible from Java, the functions they bridge to already have the assertions.
|
||||
irFunction.origin == IrDeclarationOrigin.BRIDGE_SPECIAL ||
|
||||
irFunction.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE ||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
@@ -32,7 +33,7 @@ object HashCode : IntrinsicMethod() {
|
||||
val result = receiver.accept(this, data).materialized
|
||||
val target = context.state.target
|
||||
when {
|
||||
irFunction.origin == IrDeclarationOrigin.GENERATED_INLINE_CLASS_MEMBER || irFunction.origin == IrDeclarationOrigin.GENERATED_DATA_CLASS_MEMBER ->
|
||||
irFunction.origin == JvmLoweredDeclarationOrigin.INLINE_CLASS_GENERATED_IMPL_METHOD || irFunction.origin == IrDeclarationOrigin.GENERATED_DATA_CLASS_MEMBER ->
|
||||
AsmUtil.genHashCode(mv, mv, result.type, target)
|
||||
target == JvmTarget.JVM_1_6 -> {
|
||||
result.coerceToBoxed(receiver.type).materialize()
|
||||
|
||||
+1
-1
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
@@ -29,6 +28,7 @@ object InlineClassAbi {
|
||||
val klass = type.classOrNull?.owner ?: return null
|
||||
if (!klass.isInline) return null
|
||||
|
||||
// TODO: Apply type substitutions
|
||||
val underlyingType = getUnderlyingType(klass).unboxInlineClass()
|
||||
if (!type.isNullable())
|
||||
return underlyingType
|
||||
|
||||
+3
@@ -157,6 +157,9 @@ class MemoizedInlineClassReplacements {
|
||||
private fun buildReplacement(function: IrFunction, body: IrFunctionImpl.() -> Unit) =
|
||||
buildFunWithDescriptorForInlining(function.descriptor) {
|
||||
updateFrom(function)
|
||||
if (function.origin == IrDeclarationOrigin.GENERATED_INLINE_CLASS_MEMBER) {
|
||||
origin = JvmLoweredDeclarationOrigin.INLINE_CLASS_GENERATED_IMPL_METHOD
|
||||
}
|
||||
name = mangledNameFor(function)
|
||||
returnType = function.returnType
|
||||
}.apply {
|
||||
|
||||
Vendored
+7
-2
@@ -1,9 +1,9 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class AsNonNullPrimitive(val i: Int)
|
||||
inline class AsNonNullReference(val s: String)
|
||||
// ^ 5 assertions (constructor, box method, erased constructor, 2 assertions in equals--impl)
|
||||
// ^ JVM: 5 assertions (constructor, box method, erased constructor, 2 assertions in equals--impl)
|
||||
// JVM IR: 1 assertion (erased constructor)
|
||||
|
||||
fun nonNullPrimitive(a: AsNonNullPrimitive) {}
|
||||
|
||||
@@ -13,5 +13,10 @@ fun AsNonNullReference.nonNullReferenceExtension(b1: AsNonNullReference) {} // 2
|
||||
fun asNullablePrimitive(c: AsNonNullPrimitive?) {}
|
||||
fun asNullableReference(c: AsNonNullReference?) {}
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 8 checkParameterIsNotNull
|
||||
// 0 checkNotNullParameter
|
||||
|
||||
// JVM_IR_TEMPLATES
|
||||
// 4 checkParameterIsNotNull
|
||||
// 0 checkNotNullParameter
|
||||
|
||||
Reference in New Issue
Block a user