[IR] [JS_IR] Supported fun interfaces in JS
This commit is contained in:
@@ -415,7 +415,7 @@ fun IrClass.createImplicitParameterDeclarationWithWrappedDescriptor() {
|
|||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
IrDeclarationOrigin.INSTANCE_RECEIVER,
|
IrDeclarationOrigin.INSTANCE_RECEIVER,
|
||||||
IrValueParameterSymbolImpl(thisReceiverDescriptor),
|
IrValueParameterSymbolImpl(thisReceiverDescriptor),
|
||||||
Name.identifier("<this>"),
|
Name.special("<this>"),
|
||||||
index = -1,
|
index = -1,
|
||||||
type = symbol.typeWithParameters(typeParameters),
|
type = symbol.typeWithParameters(typeParameters),
|
||||||
varargElementType = null,
|
varargElementType = null,
|
||||||
|
|||||||
+2
@@ -65,6 +65,8 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
abstract fun getSuperTypeForWrapper(typeOperand: IrType): IrType
|
abstract fun getSuperTypeForWrapper(typeOperand: IrType): IrType
|
||||||
|
|
||||||
override fun lower(irFile: IrFile) {
|
override fun lower(irFile: IrFile) {
|
||||||
|
cachedImplementations.clear()
|
||||||
|
inlineCachedImplementations.clear()
|
||||||
enclosingContainer = irFile.declarations.filterIsInstance<IrClass>().find { it.isFileClass }
|
enclosingContainer = irFile.declarations.filterIsInstance<IrClass>().find { it.isFileClass }
|
||||||
?: irFile
|
?: irFile
|
||||||
irFile.transformChildrenVoid()
|
irFile.transformChildrenVoid()
|
||||||
|
|||||||
@@ -475,11 +475,21 @@ private val bridgesConstructionPhase = makeDeclarationTransformerPhase(
|
|||||||
prerequisite = setOf(suspendFunctionsLoweringPhase)
|
prerequisite = setOf(suspendFunctionsLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val singleAbstractMethodPhase = makeIrModulePhase(
|
||||||
|
::JsSingleAbstractMethodLowering,
|
||||||
|
name = "SingleAbstractMethod",
|
||||||
|
description = "Replace SAM conversions with instances of interface-implementing classes"
|
||||||
|
).toModuleLowering()
|
||||||
|
|
||||||
private val typeOperatorLoweringPhase = makeBodyLoweringPhase(
|
private val typeOperatorLoweringPhase = makeBodyLoweringPhase(
|
||||||
::TypeOperatorLowering,
|
::TypeOperatorLowering,
|
||||||
name = "TypeOperatorLowering",
|
name = "TypeOperatorLowering",
|
||||||
description = "Lower IrTypeOperator with corresponding logic",
|
description = "Lower IrTypeOperator with corresponding logic",
|
||||||
prerequisite = setOf(bridgesConstructionPhase, removeInlineFunctionsWithReifiedTypeParametersLoweringPhase)
|
prerequisite = setOf(
|
||||||
|
bridgesConstructionPhase,
|
||||||
|
removeInlineFunctionsWithReifiedTypeParametersLoweringPhase,
|
||||||
|
singleAbstractMethodPhase
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val secondaryConstructorLoweringPhase = makeDeclarationTransformerPhase(
|
private val secondaryConstructorLoweringPhase = makeDeclarationTransformerPhase(
|
||||||
@@ -580,6 +590,7 @@ val loweringList = listOf<Lowering>(
|
|||||||
copyInlineFunctionBodyLoweringPhase,
|
copyInlineFunctionBodyLoweringPhase,
|
||||||
createScriptFunctionsPhase,
|
createScriptFunctionsPhase,
|
||||||
provisionalFunctionExpressionPhase,
|
provisionalFunctionExpressionPhase,
|
||||||
|
singleAbstractMethodPhase,
|
||||||
lateinitNullableFieldsPhase,
|
lateinitNullableFieldsPhase,
|
||||||
lateinitDeclarationLoweringPhase,
|
lateinitDeclarationLoweringPhase,
|
||||||
lateinitUsageLoweringPhase,
|
lateinitUsageLoweringPhase,
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.SingleAbstractMethodLowering
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||||
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||||
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
|
|
||||||
|
class JsSingleAbstractMethodLowering(context: JsIrBackendContext) : SingleAbstractMethodLowering(context) {
|
||||||
|
override fun getSuperTypeForWrapper(typeOperand: IrType): IrType {
|
||||||
|
// FE doesn't allow type parameters for now.
|
||||||
|
// And since there is a to-do in common SingleAbstractMethodLowering (at function visitTypeOperator),
|
||||||
|
// we don't have to be more saint than a pope here.
|
||||||
|
return typeOperand.classOrNull?.defaultType ?: error("Unsupported SAM conversion: ${typeOperand.render()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
// IGNORE_BACKEND: JS, JS_IR
|
// IGNORE_BACKEND: JS
|
||||||
|
// SKIP_DCE_DRIVEN
|
||||||
|
|
||||||
fun interface Foo {
|
fun interface Foo {
|
||||||
fun invoke(): String
|
fun invoke(): String
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
// IGNORE_BACKEND: JS, JS_IR
|
// IGNORE_BACKEND: JS
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// SKIP_DCE_DRIVEN
|
||||||
|
|
||||||
fun interface KRunnable {
|
fun interface KRunnable {
|
||||||
fun invoke()
|
fun invoke()
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
// IGNORE_BACKEND: JS, JS_IR
|
// IGNORE_BACKEND: JS
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// SKIP_DCE_DRIVEN
|
||||||
|
|
||||||
fun interface Fn<T, R> {
|
fun interface Fn<T, R> {
|
||||||
fun run(s: String, i: Int, t: T): R
|
fun run(s: String, i: Int, t: T): R
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
// IGNORE_BACKEND: JS, JS_IR
|
// IGNORE_BACKEND: JS
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// SKIP_DCE_DRIVEN
|
||||||
|
|
||||||
fun interface KRunnable {
|
fun interface KRunnable {
|
||||||
fun invoke()
|
fun invoke()
|
||||||
|
|||||||
Reference in New Issue
Block a user