rra/ilgonmic/exported-bridges-2

[JS IR] Use js name for signature

[JS] bridgeSavingExport only for JS IR

[JS IR] Fix test

[JS IR] Stable and non stable signatures

[JS IR] Consider return type in js signature and erase for JS name signature

[JS IR] Copy signature from wasm to JS and export bridge, not original

Merge-request: KT-MR-5174
This commit is contained in:
Ilya Goncharov
2021-12-08 08:30:14 +00:00
committed by Space
parent 0c74376cc4
commit 00289d3514
11 changed files with 127 additions and 61 deletions
@@ -6,14 +6,10 @@
package org.jetbrains.kotlin.backend.wasm.ir2wasm
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.backend.js.utils.erasedUpperBound
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.packageFqName
import org.jetbrains.kotlin.name.FqName
@@ -126,24 +122,6 @@ fun isBuiltInWasmRefType(type: IrType): Boolean {
fun isExternalType(type: IrType): Boolean =
type.erasedUpperBound?.isExternal ?: false
// Return null if upper bound is Any
private val IrTypeParameter.erasedUpperBound: IrClass?
get() {
// Pick the (necessarily unique) non-interface upper bound if it exists
for (type in superTypes) {
return type.erasedUpperBound ?: continue
}
return null
}
val IrType.erasedUpperBound: IrClass?
get() = when (val classifier = classifierOrNull) {
is IrClassSymbol -> classifier.owner
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
else -> throw IllegalStateException()
}
val IrType.getRuntimeClass: IrClass?
get() = erasedUpperBound.let {
if (it?.isInterface == true) null
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
import org.jetbrains.kotlin.backend.common.lower.irComposite
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound
import org.jetbrains.kotlin.ir.backend.js.utils.erasedUpperBound
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
import org.jetbrains.kotlin.ir.builders.irImplicitCast
import org.jetbrains.kotlin.ir.declarations.IrFile
@@ -6,16 +6,13 @@
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
import org.jetbrains.kotlin.ir.backend.js.lower.BridgesConstruction
import org.jetbrains.kotlin.ir.backend.js.utils.eraseGenerics
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.isNullable
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.name.Name
@@ -44,7 +41,7 @@ data class WasmSignature(
override fun toString(): String {
val er = extensionReceiverType?.let { "(er: ${it.render()}) " } ?: ""
val parameters = valueParametersType.joinToString(", ") { it.render() }
val nonVirtual = if (!isVirtual) "(non-virtual) " else ""
val nonVirtual = if (!isVirtual) "(non-virtual) " else ""
return "[$nonVirtual$er$name($parameters) -> ${returnType.render()}]"
}
}
@@ -56,11 +53,4 @@ fun IrSimpleFunction.wasmSignature(irBuiltIns: IrBuiltIns): WasmSignature =
valueParameters.map { it.type.eraseGenerics(irBuiltIns) },
returnType.eraseGenerics(irBuiltIns),
isOverridableOrOverrides
)
private fun IrType.eraseGenerics(irBuiltIns: IrBuiltIns): IrType {
val defaultType = this.erasedUpperBound?.defaultType ?: irBuiltIns.anyType
if (!this.isNullable()) return defaultType
return defaultType.makeNullable()
}
)
@@ -13,10 +13,10 @@ import org.jetbrains.kotlin.backend.common.lower.at
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
import org.jetbrains.kotlin.backend.common.lower.irNot
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound
import org.jetbrains.kotlin.backend.wasm.ir2wasm.getRuntimeClass
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.backend.js.utils.erasedUpperBound
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFile