Raw FIR: generate more trivial tree for lambdas (no explicit return)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
aaf4645cef
commit
a0de50307a
@@ -668,14 +668,14 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
) { toFirOrImplicitType() }
|
||||
multiParameter
|
||||
} else {
|
||||
valueParameter.convert<FirValueParameter>()
|
||||
valueParameter.toFirValueParameter(FirImplicitTypeRefImpl(session, psi))
|
||||
}
|
||||
}
|
||||
label = firLabels.pop() ?: firFunctionCalls.lastOrNull()?.calleeReference?.name?.let {
|
||||
FirLabelImpl(this@RawFirBuilder.session, expression, it.asString())
|
||||
}
|
||||
val bodyExpression = literal.bodyExpression.toFirExpression("Lambda has no body")
|
||||
if (bodyExpression is FirBlockImpl) {
|
||||
body = if (bodyExpression is FirBlockImpl) {
|
||||
if (bodyExpression.statements.isEmpty()) {
|
||||
bodyExpression.statements.add(FirUnitExpression(this@RawFirBuilder.session, expression))
|
||||
}
|
||||
@@ -684,8 +684,10 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
|
||||
bodyExpression.statements.add(index, statement)
|
||||
}
|
||||
}
|
||||
bodyExpression
|
||||
} else {
|
||||
FirSingleExpressionBlock(this@RawFirBuilder.session, bodyExpression.toReturn())
|
||||
}
|
||||
body = FirSingleExpressionBlock(this@RawFirBuilder.session, bodyExpression.toReturn())
|
||||
|
||||
firFunctions.removeLast()
|
||||
}
|
||||
|
||||
+24
-48
@@ -16,86 +16,62 @@ FILE: lambda.kt
|
||||
}
|
||||
public? final? fun foo(): Int {
|
||||
lval l1: <implicit> = fun <implicit>.<anonymous>(t: Tuple): <implicit> {
|
||||
^ {
|
||||
lval x: <implicit> = t#.x#
|
||||
lval y: <implicit> = t#.y#
|
||||
x#.plus#(y#)
|
||||
}
|
||||
|
||||
lval x: <implicit> = t#.x#
|
||||
lval y: <implicit> = t#.y#
|
||||
x#.plus#(y#)
|
||||
}
|
||||
|
||||
use#(<L> = use@fun <implicit>.<anonymous>(<destruct>: <implicit>): <implicit> {
|
||||
^ {
|
||||
lval x: <implicit> = <destruct>#.component1()
|
||||
lval y: <implicit> = <destruct>#.component2()
|
||||
x#.plus#(y#)
|
||||
}
|
||||
|
||||
lval x: <implicit> = <destruct>#.component1()
|
||||
lval y: <implicit> = <destruct>#.component2()
|
||||
x#.plus#(y#)
|
||||
}
|
||||
)
|
||||
^foo use#(<L> = use@fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
when () {
|
||||
==(it#.x#, Int(0)) -> {
|
||||
^foo Int(0)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
when () {
|
||||
==(it#.x#, Int(0)) -> {
|
||||
^foo Int(0)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
|
||||
^@use it#.y#
|
||||
}
|
||||
|
||||
^@use it#.y#
|
||||
}
|
||||
)
|
||||
}
|
||||
public? final? fun bar(): Int {
|
||||
^bar use#(<L> = lambda@fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
when () {
|
||||
==(it#.x#, Int(0)) -> {
|
||||
^bar Int(0)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
when () {
|
||||
==(it#.x#, Int(0)) -> {
|
||||
^bar Int(0)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
|
||||
^@lambda it#.y#
|
||||
}
|
||||
|
||||
^@lambda it#.y#
|
||||
}
|
||||
)
|
||||
}
|
||||
public? final? fun test(list: List<Int>): kotlin/Unit {
|
||||
lval map: <implicit> = mutableMapOf#<Int, String>()
|
||||
list#.forEach#(<L> = forEach@fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
lval <complex-set>: <implicit> = map#.getOrPut#(it#, getOrPut@fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
mutableListOf#()
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
<complex-set># += String()
|
||||
lval <complex-set>: <implicit> = map#.getOrPut#(it#, getOrPut@fun <implicit>.<anonymous>(): <implicit> {
|
||||
mutableListOf#()
|
||||
}
|
||||
|
||||
)
|
||||
<complex-set># += String()
|
||||
}
|
||||
)
|
||||
}
|
||||
public? final? val simple: <implicit> = fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
Unit
|
||||
}
|
||||
|
||||
Unit
|
||||
}
|
||||
|
||||
public? get(): <implicit>
|
||||
public? final? val another: <implicit> = fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
Int(42)
|
||||
}
|
||||
|
||||
Int(42)
|
||||
}
|
||||
|
||||
public? get(): <implicit>
|
||||
|
||||
@@ -27,10 +27,7 @@ FILE: these.kt
|
||||
}
|
||||
public? final? fun test(some: Some): Int {
|
||||
^test with#(some#, <L> = with@fun <implicit>.<anonymous>(): <implicit> {
|
||||
^ {
|
||||
this#.foo#().plus#(this@with.extension#())
|
||||
}
|
||||
|
||||
this#.foo#().plus#(this@with.extension#())
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user