Drop all usages of inlineFunctionSymbol in IrReturnableBlock

This commit is contained in:
Ivan Kylchik
2022-12-15 17:49:47 +01:00
committed by Space Team
parent 095c7c5930
commit ab2c3572ab
9 changed files with 28 additions and 33 deletions
@@ -10,7 +10,6 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
/**
@@ -19,6 +18,4 @@ import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
*/
abstract class IrReturnableBlock : IrBlock(), IrSymbolOwner, IrReturnTarget {
abstract override val symbol: IrReturnableBlockSymbol
abstract var inlineFunctionSymbol: IrFunctionSymbol?
}
@@ -60,7 +60,6 @@ class IrReturnableBlockImpl(
override var type: IrType,
override val symbol: IrReturnableBlockSymbol,
override var origin: IrStatementOrigin? = null,
override var inlineFunctionSymbol: IrFunctionSymbol? = null
) : IrReturnableBlock() {
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
@@ -73,8 +72,7 @@ class IrReturnableBlockImpl(
symbol: IrReturnableBlockSymbol,
origin: IrStatementOrigin?,
statements: List<IrStatement>,
inlineFunctionSymbol: IrFunctionSymbol? = null
) : this(startOffset, endOffset, type, symbol, origin, inlineFunctionSymbol) {
) : this(startOffset, endOffset, type, symbol, origin) {
this.statements.addAll(statements)
}
@@ -457,8 +457,7 @@ open class DeepCopyIrTreeWithSymbols(
expression.type.remapType(),
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
mapStatementOrigin(expression.origin),
expression.statements.map { it.transform() },
expression.inlineFunctionSymbol
expression.statements.map { it.transform() }
).copyAttributes(expression)
else if (expression is IrInlinedFunctionBlock)
IrInlinedFunctionBlockImpl(
@@ -1391,27 +1391,6 @@ val IrFunction.isValueClassTypedEquals: Boolean
&& (parentClass.isValue)
}
// This code is partially duplicated in jvm FunctionReferenceLowering::adapteeCall
// The difference is jvm version doesn't support ReturnableBlock, but returns call node instead of called function.
fun IrFunction.getAdapteeFromAdaptedForReferenceFunction() : IrFunction? {
if (origin != IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) return null
// The body of a callable reference adapter contains either only a call, or an IMPLICIT_COERCION_TO_UNIT type operator
// applied to a either a call or ReturnableBlock produced from that call inlining.
// That call's target is the original function which we need to get.
fun unknownStructure(): Nothing = throw UnsupportedOperationException("Unknown structure of ADAPTER_FOR_CALLABLE_REFERENCE: ${dump()}")
val call = when (val statement = body?.statements?.singleOrNull() ?: unknownStructure()) {
is IrTypeOperatorCall -> {
if (statement.operator != IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) unknownStructure()
statement.argument
}
is IrReturn -> statement.value
else -> statement
}
if (call is IrReturnableBlock) return (call.inlineFunctionSymbol ?: unknownStructure()).owner
if (call !is IrFunctionAccessExpression) { unknownStructure() }
return call.symbol.owner
}
/**
* The method is used to calculate the previous offset from the current one to prevent situations when it can calculate
* [UNDEFINED_OFFSET] from 0 offset and -2 offset from the [UNDEFINED OFFSET]
@@ -1422,4 +1401,4 @@ val Int.previousOffset
0 -> 0
-1 -> UNDEFINED_OFFSET
else -> minus(1)
}
}
@@ -645,7 +645,6 @@ object IrTree : AbstractTreeBuilder() {
parent(returnTarget)
+symbol(returnableBlockSymbolType)
+field("inlineFunctionSymbol", functionSymbolType, nullable = true)
}
val inlinedFunctionBlock: ElementConfig by element(Expression) {
parent(block)