[IR] Add IrClass.invokeFun helper and use it throughout
This commit is contained in:
+2
-5
@@ -246,8 +246,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createInvokeMethod(clazz: IrClass): IrSimpleFunction {
|
private fun createInvokeMethod(clazz: IrClass): IrSimpleFunction {
|
||||||
val superMethods = superFunctionInterface.declarations.filterIsInstance<IrSimpleFunction>()
|
val superMethod = superFunctionInterface.invokeFun!!
|
||||||
val superMethod = superMethods.single { it.name.asString() == "invoke" }
|
|
||||||
return clazz.addFunction {
|
return clazz.addFunction {
|
||||||
setSourceRange(if (isLambda) function else reference)
|
setSourceRange(if (isLambda) function else reference)
|
||||||
name = superMethod.name
|
name = superMethod.name
|
||||||
@@ -255,9 +254,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
isSuspend = superMethod.isSuspend
|
isSuspend = superMethod.isSuspend
|
||||||
isOperator = superMethod.isOperator
|
isOperator = superMethod.isOperator
|
||||||
}.apply {
|
}.apply {
|
||||||
val secondSuperMethods: List<IrSimpleFunction>? =
|
val secondSuperMethod = secondFunctionInterface?.let { it.invokeFun!! }
|
||||||
secondFunctionInterface?.declarations?.filterIsInstance<IrSimpleFunction>()
|
|
||||||
val secondSuperMethod = secondSuperMethods?.single { it.name.asString() == "invoke" }
|
|
||||||
|
|
||||||
overriddenSymbols = listOfNotNull(
|
overriddenSymbols = listOfNotNull(
|
||||||
superMethod.symbol,
|
superMethod.symbol,
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
|
|||||||
lambdaClass: IrClass,
|
lambdaClass: IrClass,
|
||||||
newDeclarations: MutableList<IrDeclaration>
|
newDeclarations: MutableList<IrDeclaration>
|
||||||
): IrBlockBody {
|
): IrBlockBody {
|
||||||
val invokeFun = lambdaClass.declarations.filterIsInstance<IrSimpleFunction>().single { it.name.asString() == "invoke" }
|
val invokeFun = lambdaClass.invokeFun!!
|
||||||
val superInvokeFun = invokeFun.overriddenSymbols.first { it.owner.isSuspend == invokeFun.isSuspend }.owner
|
val superInvokeFun = invokeFun.overriddenSymbols.first { it.owner.isSuspend == invokeFun.isSuspend }.owner
|
||||||
val lambdaName = Name.identifier("${lambdaClass.name.asString()}\$lambda")
|
val lambdaName = Name.identifier("${lambdaClass.name.asString()}\$lambda")
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.types.getClass
|
import org.jetbrains.kotlin.ir.types.getClass
|
||||||
import org.jetbrains.kotlin.ir.types.isNullableAny
|
import org.jetbrains.kotlin.ir.types.isNullableAny
|
||||||
|
import org.jetbrains.kotlin.ir.util.invokeFun
|
||||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||||
import org.jetbrains.kotlin.ir.util.isTopLevelDeclaration
|
import org.jetbrains.kotlin.ir.util.isTopLevelDeclaration
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -116,8 +117,6 @@ fun invokeFunForLambda(call: IrCall) =
|
|||||||
call.extensionReceiver!!
|
call.extensionReceiver!!
|
||||||
.type
|
.type
|
||||||
.getClass()!!
|
.getClass()!!
|
||||||
.declarations
|
.invokeFun!!
|
||||||
.filterIsInstance<IrSimpleFunction>()
|
|
||||||
.single { it.name.asString() == "invoke" }
|
|
||||||
|
|
||||||
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }
|
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }
|
||||||
|
|||||||
@@ -197,6 +197,9 @@ val IrClassSymbol.fields: Sequence<IrFieldSymbol>
|
|||||||
val IrClass.primaryConstructor: IrConstructor?
|
val IrClass.primaryConstructor: IrConstructor?
|
||||||
get() = this.declarations.singleOrNull { it is IrConstructor && it.isPrimary } as IrConstructor?
|
get() = this.declarations.singleOrNull { it is IrConstructor && it.isPrimary } as IrConstructor?
|
||||||
|
|
||||||
|
val IrClass.invokeFun: IrSimpleFunction?
|
||||||
|
get() = declarations.filterIsInstance<IrSimpleFunction>().singleOrNull { it.name.asString() == "invoke" }
|
||||||
|
|
||||||
val IrDeclarationContainer.properties: Sequence<IrProperty>
|
val IrDeclarationContainer.properties: Sequence<IrProperty>
|
||||||
get() = declarations.asSequence().filterIsInstance<IrProperty>()
|
get() = declarations.asSequence().filterIsInstance<IrProperty>()
|
||||||
|
|
||||||
@@ -623,4 +626,4 @@ val IrDeclarationParent.isFacadeClass: Boolean
|
|||||||
get() = this is IrClass &&
|
get() = this is IrClass &&
|
||||||
(origin == IrDeclarationOrigin.JVM_MULTIFILE_CLASS ||
|
(origin == IrDeclarationOrigin.JVM_MULTIFILE_CLASS ||
|
||||||
origin == IrDeclarationOrigin.FILE_CLASS ||
|
origin == IrDeclarationOrigin.FILE_CLASS ||
|
||||||
origin == IrDeclarationOrigin.SYNTHETIC_FILE_CLASS)
|
origin == IrDeclarationOrigin.SYNTHETIC_FILE_CLASS)
|
||||||
|
|||||||
Reference in New Issue
Block a user