[Wasm] Build bridges for non-virtual functions that implement interfaces

This commit is contained in:
Svyatoslav Kuzmich
2021-09-20 16:31:51 +03:00
parent 1eb9a5a86d
commit 6db7154876
4 changed files with 22 additions and 9 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.backend.wasm.lower
import org.jetbrains.kotlin.backend.common.ir.isOverridableOrOverrides
import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
@@ -32,12 +33,19 @@ data class WasmSignature(
val name: Name,
val extensionReceiverType: IrType?,
val valueParametersType: List<IrType>,
val returnType: IrType
val returnType: IrType,
// Needed for bridges to final non-override methods
// that indirectly implement interfaces. For example:
// interface I { fun foo() }
// class C1 { fun foo() {} }
// class C2 : C1(), I
val isVirtual: Boolean,
) {
override fun toString(): String {
val er = extensionReceiverType?.let { "(er: ${it.render()}) " } ?: ""
val parameters = valueParametersType.joinToString(", ") { it.render() }
return "[$er$name($parameters) -> ${returnType.render()}]"
val nonVirtual = if (!isVirtual) "(non-virtual) " else ""
return "[$nonVirtual$er$name($parameters) -> ${returnType.render()}]"
}
}
@@ -46,7 +54,8 @@ fun IrSimpleFunction.wasmSignature(irBuiltIns: IrBuiltIns): WasmSignature =
name,
extensionReceiverParameter?.type?.eraseGenerics(irBuiltIns),
valueParameters.map { it.type.eraseGenerics(irBuiltIns) },
returnType.eraseGenerics(irBuiltIns)
returnType.eraseGenerics(irBuiltIns),
isOverridableOrOverrides
)
private fun IrType.eraseGenerics(irBuiltIns: IrBuiltIns): IrType {
@@ -1,6 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: IMPLICIT_INTERFACE_METHOD_IMPL
interface Named {
val name: String
}
-3
View File
@@ -1,6 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: IMPLICIT_INTERFACE_METHOD_IMPL
open class B {
val name: String
get() = "OK"
@@ -1960,6 +1960,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/callableReference/function/local/constructorWithInitializer.kt");
}
@TestMetadata("enumExtendsTrait.kt")
public void testEnumExtendsTrait() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt");
}
@TestMetadata("extension.kt")
public void testExtension() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/local/extension.kt");
@@ -14981,6 +14986,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/regressions/kt39088.kt");
}
@TestMetadata("kt4142.kt")
public void testKt4142() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt4142.kt");
}
@TestMetadata("kt4281.kt")
public void testKt4281() throws Exception {
runTest("compiler/testData/codegen/box/regressions/kt4281.kt");