FIR2IR: pick return target based on matched IrFunction

This commit is contained in:
Jinseong Jeon
2020-09-11 14:53:10 -07:00
committed by Mikhail Glukhikh
parent 6ebad9589a
commit 680dd64211
8 changed files with 6 additions and 11 deletions
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.fir.backend
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.expressions.FirReturnExpression
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.parentClassOrNull
@@ -95,11 +95,11 @@ class Fir2IrConversionScope {
return result
}
fun returnTarget(expression: FirReturnExpression): IrFunction {
fun returnTarget(expression: FirReturnExpression, declarationStorage: Fir2IrDeclarationStorage): IrFunction {
val firTarget = expression.target.labeledElement
val irTarget = (firTarget as? FirFunction)?.let { declarationStorage.getCachedIrFunction(it) }
for (potentialTarget in functionStack.asReversed()) {
// TODO: remove comparison by name
if (potentialTarget.name == (firTarget as? FirSimpleFunction)?.name) {
if (potentialTarget == irTarget) {
return potentialTarget
}
}
@@ -293,7 +293,7 @@ class Fir2IrVisitor(
// ==================================================================================
override fun visitReturnExpression(returnExpression: FirReturnExpression, data: Any?): IrElement {
val irTarget = conversionScope.returnTarget(returnExpression)
val irTarget = conversionScope.returnTarget(returnExpression, declarationStorage)
return returnExpression.convertWithOffsets { startOffset, endOffset ->
val result = returnExpression.result
IrReturnImpl(
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// COMMON_COROUTINES_TEST
// WITH_COROUTINES
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// COMMON_COROUTINES_TEST
// WITH_COROUTINES
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T> outer(command: () -> T) : T = command()
inline fun <K> inner(action: () -> K): K = action()
+1 -1
View File
@@ -39,7 +39,7 @@ FILE fqName:<root> fileName:/nonLocalReturn.kt
block: FUN_EXPR type=kotlin.Function0<kotlin.Nothing> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Nothing
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Nothing declared in <root>.test3.<anonymous>'
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Unit declared in <root>.test3'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
FUN name:testLrmFoo1 visibility:public modality:FINAL <> (ints:kotlin.collections.List<kotlin.Int>) returnType:kotlin.Unit
VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List<kotlin.Int>