[IR] Support if and when for MFVC, fix several bugs, refactor
#KT-1179
This commit is contained in:
committed by
teamcity
parent
e76041bb3b
commit
ca789607ba
@@ -0,0 +1,53 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
@JvmInline
|
||||
value class DPoint(val x: Double, val y: Double) {
|
||||
init {
|
||||
counter++
|
||||
}
|
||||
companion object {
|
||||
@JvmStatic
|
||||
var counter: Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun ifExpr() = if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
|
||||
fun whenExpr() = when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
|
||||
fun ifBody() {
|
||||
if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
val x = if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
require(x == DPoint(4.0, 5.0))
|
||||
}
|
||||
|
||||
fun whenBody() {
|
||||
when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
val x = when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
require(x == DPoint(8.0, 9.0))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
ifBody()
|
||||
whenBody()
|
||||
require(ifExpr() == DPoint(4.0, 5.0))
|
||||
require(whenExpr() == DPoint(8.0, 9.0))
|
||||
require(DPoint.counter == 5 + 5 + 2 + 1 + 2 + 1)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
@kotlin.Metadata
|
||||
public final class ConditionalExpressionsKt {
|
||||
// source: 'conditionalExpressions.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method ifBody(): void
|
||||
public final static @org.jetbrains.annotations.NotNull method ifExpr(): DPoint
|
||||
public final static method whenBody(): void
|
||||
public final static @org.jetbrains.annotations.NotNull method whenExpr(): DPoint
|
||||
public final inner class DPoint$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class DPoint$Companion {
|
||||
// source: 'conditionalExpressions.kt'
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public synthetic deprecated static @kotlin.jvm.JvmStatic method getCounter$annotations(): void
|
||||
public final method getCounter(): int
|
||||
public final method setCounter(p0: int): void
|
||||
public final inner class DPoint$Companion
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline
|
||||
@kotlin.Metadata
|
||||
public final class DPoint {
|
||||
// source: 'conditionalExpressions.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: DPoint$Companion
|
||||
private static field counter: int
|
||||
private final field field-0: double
|
||||
private final field field-1: double
|
||||
static method <clinit>(): void
|
||||
private synthetic method <init>(p0: double, p1: double): void
|
||||
public synthetic final static method access$getCounter$cp(): int
|
||||
public synthetic final static method access$setCounter$cp(p0: int): void
|
||||
public synthetic final static method box-impl(p0: double, p1: double): DPoint
|
||||
public final static method constructor-impl(p0: double, p1: double): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: double, p1: double, p2: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: double, p1: double, p2: double, p3: double): boolean
|
||||
public final static method getCounter(): int
|
||||
public final static method getX-impl(p0: double, p1: double): double
|
||||
public final static method getY-impl(p0: double, p1: double): double
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: double, p1: double): int
|
||||
public final static method setCounter(p0: int): void
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static method toString-impl(p0: double, p1: double): java.lang.String
|
||||
public synthetic final method unbox-impl-0(): double
|
||||
public synthetic final method unbox-impl-1(): double
|
||||
public final inner class DPoint$Companion
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public final class Internal {
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: Internal$Companion
|
||||
private final field field-0: int
|
||||
private final field field-1: int
|
||||
private static field x: int
|
||||
static method <clinit>(): void
|
||||
private synthetic method <init>(p0: int, p1: int): void
|
||||
public synthetic final static method access$getX$cp(): int
|
||||
@@ -228,6 +229,7 @@ public final class Public {
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: Public$Companion
|
||||
private final field field-0: int
|
||||
private final field field-1: int
|
||||
private static field x: int
|
||||
static method <clinit>(): void
|
||||
private synthetic method <init>(p0: int, p1: int): void
|
||||
public synthetic final static method access$getX$cp(): int
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
@JvmInline
|
||||
value class DPoint(val x: Double, val y: Double)
|
||||
|
||||
fun ifExpr() = if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
|
||||
fun whenExpr() = when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
|
||||
fun ifBody() {
|
||||
if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
val x = if (DPoint(0.0, 1.0).x > 0.0) DPoint(2.0, 3.0) else DPoint(4.0, 5.0)
|
||||
}
|
||||
|
||||
fun whenBody() {
|
||||
when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
val x = when {
|
||||
DPoint(6.0, 7.0).x > 0.0 -> DPoint(8.0, 9.0)
|
||||
DPoint(10.0, 11.0).x > 0.0 -> DPoint(12.0, 13.0)
|
||||
else -> DPoint(14.0, 15.0)
|
||||
}
|
||||
}
|
||||
|
||||
// 1 ifExpr.*(\n .*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)
|
||||
// 0 ifExpr.*(\n .*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)
|
||||
// 1 whenExpr.*(\n .*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)
|
||||
// 0 whenExpr.*(\n .*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)(\n .*)*(\n .*box-impl.*)
|
||||
// 0 ifBody.*(\n .*)*(\n .*box-impl.*)
|
||||
// 0 whenBody.*(\n .*)*(\n .*box-impl.*)
|
||||
Reference in New Issue
Block a user