JVM: Generate equals-impl0 method for inline classes
This commit is contained in:
committed by
Alexander Udalov
parent
2c7da67600
commit
f53b28e8a3
@@ -861,6 +861,33 @@ public class AsmUtil {
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BranchedValue genTotalOrderEqualsForExpressionOnStack(
|
||||
@NotNull StackValue left,
|
||||
@NotNull StackValue right,
|
||||
@NotNull Type asmType
|
||||
) {
|
||||
return new BranchedValue(left, right, asmType, Opcodes.IFEQ) {
|
||||
@Override
|
||||
public void condJump(@NotNull Label jumpLabel, @NotNull InstructionAdapter iv, boolean jumpIfFalse) {
|
||||
if (asmType.getSort() == Type.FLOAT) {
|
||||
left.put(asmType, kotlinType, iv);
|
||||
right.put(asmType, kotlinType, iv);
|
||||
iv.invokestatic("java/lang/Float", "compare", "(FF)I", false);
|
||||
iv.visitJumpInsn(patchOpcode(jumpIfFalse ? Opcodes.IFNE : Opcodes.IFEQ, iv), jumpLabel);
|
||||
} else if (asmType.getSort() == Type.DOUBLE) {
|
||||
left.put(asmType, kotlinType, iv);
|
||||
right.put(asmType, kotlinType, iv);
|
||||
iv.invokestatic("java/lang/Double", "compare", "(DD)I", false);
|
||||
iv.visitJumpInsn(patchOpcode(jumpIfFalse ? Opcodes.IFNE : Opcodes.IFEQ, iv), jumpLabel);
|
||||
} else {
|
||||
StackValue value = genEqualsForExpressionsOnStack(KtTokens.EQEQ, left, right);
|
||||
BranchedValue.Companion.condJump(value, jumpLabel, jumpIfFalse, iv);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StackValue genEqualsBoxedOnStack(@NotNull IElementType opToken) {
|
||||
return StackValue.operation(Type.BOOLEAN_TYPE, v -> genAreEqualCall(v, opToken));
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.genTotalOrderEqualsForExpressionOnStack
|
||||
import org.jetbrains.kotlin.codegen.context.ClassContext
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.Synthetic
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
class ErasedInlineClassBodyCodegen(
|
||||
aClass: KtClass,
|
||||
@@ -109,11 +111,17 @@ class ErasedInlineClassBodyCodegen(
|
||||
|
||||
|
||||
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
||||
val iv = codegen.v
|
||||
iv.aconst(null)
|
||||
iv.athrow()
|
||||
val firstIndex = codegen.frameMap.getIndex(specializedEqualsDescriptor.valueParameters[0])
|
||||
val secondIndex = codegen.frameMap.getIndex(specializedEqualsDescriptor.valueParameters[1])
|
||||
val asmType = signature.valueParameters[0].asmType
|
||||
val left = StackValue.local(firstIndex, asmType)
|
||||
val right = StackValue.local(secondIndex, asmType)
|
||||
genTotalOrderEqualsForExpressionOnStack(left, right, asmType).put(Type.BOOLEAN_TYPE, codegen.v)
|
||||
codegen.v.areturn(Type.BOOLEAN_TYPE)
|
||||
}
|
||||
|
||||
override fun skipNotNullAssertionsForParameters(): Boolean = true
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-19
@@ -251,25 +251,7 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
if (asmType.getSort() == Type.FLOAT) {
|
||||
thisPropertyValue.put(asmType, kotlinType, iv);
|
||||
otherPropertyValue.put(asmType, kotlinType, iv);
|
||||
iv.invokestatic("java/lang/Float", "compare", "(FF)I", false);
|
||||
iv.ifne(ne);
|
||||
}
|
||||
else if (asmType.getSort() == Type.DOUBLE) {
|
||||
thisPropertyValue.put(asmType, kotlinType, iv);
|
||||
otherPropertyValue.put(asmType, kotlinType, iv);
|
||||
iv.invokestatic("java/lang/Double", "compare", "(DD)I", false);
|
||||
iv.ifne(ne);
|
||||
}
|
||||
else {
|
||||
StackValue value = genEqualsForExpressionsOnStack(
|
||||
KtTokens.EQEQ, thisPropertyValue, otherPropertyValue
|
||||
);
|
||||
value.put(Type.BOOLEAN_TYPE, iv);
|
||||
iv.ifeq(ne);
|
||||
}
|
||||
genTotalOrderEqualsForExpressionOnStack(thisPropertyValue, otherPropertyValue, asmType).condJump(ne, iv, true);
|
||||
}
|
||||
|
||||
iv.mark(eq);
|
||||
|
||||
Reference in New Issue
Block a user