Replace POP with ARETURN if it pops Unit and ARETURN shall return Unit

#KT-16880: Fixed
This commit is contained in:
Ilmir Usmanov
2017-11-10 15:46:11 +03:00
parent 2cdc246a27
commit c8904b1c7c
7 changed files with 354 additions and 2 deletions
@@ -0,0 +1,61 @@
suspend fun empty() {}
suspend fun withoutReturn() { empty() }
suspend fun withReturn() { return empty() }
suspend fun notTailCall() { empty(); empty() }
suspend fun lambdaAsParameter(c: suspend ()->Unit) { c() }
suspend fun lambdaAsParameterNotTailCall(c: suspend ()->Unit) { c(); c() }
suspend fun lambdaAsParameterReturn(c: suspend ()->Unit) { return c() }
suspend fun returnsInt() = 42
// This should not be tail-call, since the caller should push Unit.INSTANCE on stack
suspend fun callsIntNotTailCall() { returnsInt() }
suspend fun multipleExitPoints(b: Boolean) { if (b) empty() else withoutReturn() }
suspend fun multipleExitPointsNotTailCall(b: Boolean) { if (b) empty() else returnsInt() }
fun ordinary() = 1
inline fun ordinaryInline() { ordinary() }
suspend fun multipleExitPointsWithOrdinaryInline(b: Boolean) { if (b) empty() else ordinaryInline() }
suspend fun multipleExitPointsWhen(i: Int) {
when(i) {
1 -> empty()
2 -> withReturn()
3 -> withoutReturn()
else -> lambdaAsParameter {}
}
}
suspend fun <T> generic(): T = TODO()
suspend fun useGenericReturningUnit() {
generic<Unit>()
}
class Generic<T> {
suspend fun foo(): T = TODO()
}
suspend fun useGenericClass(g: Generic<Unit>) {
g.foo()
}
suspend fun <T> genericInferType(c: () -> T): T = TODO()
suspend fun useGenericIngerType() {
genericInferType {}
}
suspend fun nullableUnit(): Unit? = null
suspend fun useNullableUnit() {
nullableUnit()
}
suspend fun useRunRunRunRunRun() {
run {
run {
run {
run {
run {
empty()
}
}
}
}
}
}
@@ -0,0 +1,115 @@
@kotlin.Metadata
public final class Generic {
public method <init>(): void
public final @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$callsIntNotTailCall$1 {
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class TailSuspendUnitFunKt$callsIntNotTailCall$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$lambdaAsParameterNotTailCall$1 {
field L$0: java.lang.Object
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class TailSuspendUnitFunKt$lambdaAsParameterNotTailCall$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$multipleExitPointsNotTailCall$1 {
field Z$0: boolean
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class TailSuspendUnitFunKt$multipleExitPointsNotTailCall$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$multipleExitPointsWhen$2 {
inner class TailSuspendUnitFunKt$multipleExitPointsWhen$2
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$notTailCall$1 {
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class TailSuspendUnitFunKt$notTailCall$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$useGenericIngerType$2 {
public final static field INSTANCE: TailSuspendUnitFunKt$useGenericIngerType$2
inner class TailSuspendUnitFunKt$useGenericIngerType$2
static method <clinit>(): void
method <init>(): void
public synthetic method invoke(): java.lang.Object
public final method invoke(): void
}
@kotlin.Metadata
final class TailSuspendUnitFunKt$useNullableUnit$1 {
synthetic field data: java.lang.Object
synthetic field exception: java.lang.Throwable
inner class TailSuspendUnitFunKt$useNullableUnit$1
method <init>(p0: kotlin.coroutines.experimental.Continuation): void
public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object
synthetic final method getLabel(): int
synthetic final method setLabel(p0: int): void
}
@kotlin.Metadata
public final class TailSuspendUnitFunKt {
inner class TailSuspendUnitFunKt$callsIntNotTailCall$1
inner class TailSuspendUnitFunKt$lambdaAsParameterNotTailCall$1
inner class TailSuspendUnitFunKt$multipleExitPointsNotTailCall$1
inner class TailSuspendUnitFunKt$multipleExitPointsWhen$2
inner class TailSuspendUnitFunKt$notTailCall$1
inner class TailSuspendUnitFunKt$useGenericIngerType$2
inner class TailSuspendUnitFunKt$useNullableUnit$1
public final static @org.jetbrains.annotations.Nullable method callsIntNotTailCall(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method empty(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method generic(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method genericInferType(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method lambdaAsParameter(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method lambdaAsParameterNotTailCall(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method lambdaAsParameterReturn(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method multipleExitPoints(p0: boolean, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method multipleExitPointsNotTailCall(p0: boolean, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method multipleExitPointsWhen(p0: int, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method multipleExitPointsWithOrdinaryInline(p0: boolean, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method notTailCall(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method nullableUnit(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static method ordinary(): int
public final static method ordinaryInline(): void
public final static @org.jetbrains.annotations.Nullable method returnsInt(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method useGenericClass(@org.jetbrains.annotations.NotNull p0: Generic, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method useGenericIngerType(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method useGenericReturningUnit(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method useNullableUnit(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method useRunRunRunRunRun(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method withReturn(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
public final static @org.jetbrains.annotations.Nullable method withoutReturn(@org.jetbrains.annotations.Nullable p0: java.lang.Object): java.lang.Object
}