[Wasm] Do not erase interfaces down to Any type in Wasm signature.
This enables overloading virtual methods with different interface types
This commit is contained in:
+2
-2
@@ -255,7 +255,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
// Processing it separately
|
||||
if (call.symbol == wasmSymbols.boxIntrinsic) {
|
||||
val toType = call.getTypeArgument(0)!!
|
||||
val klass = toType.erasedUpperBound!!
|
||||
val klass = toType.getRuntimeClass!!
|
||||
val structTypeName = context.referenceGcType(klass.symbol)
|
||||
val klassId = context.referenceClassId(klass.symbol)
|
||||
|
||||
@@ -332,7 +332,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
}
|
||||
|
||||
private fun generateTypeRTT(type: IrType) {
|
||||
val rtClass = type.erasedUpperBound?.symbol ?: context.backendContext.irBuiltIns.anyClass
|
||||
val rtClass = type.getRuntimeClass?.symbol ?: context.backendContext.irBuiltIns.anyClass
|
||||
body.buildGetGlobal(context.referenceClassRTT(rtClass))
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -47,7 +47,7 @@ class WasmTypeTransformer(
|
||||
}
|
||||
|
||||
fun IrType.toWasmGcRefType(): WasmType =
|
||||
WasmRefNullType(WasmHeapType.Type(context.referenceGcType(erasedUpperBound?.symbol ?: builtIns.anyClass)))
|
||||
WasmRefNullType(WasmHeapType.Type(context.referenceGcType(getRuntimeClass?.symbol ?: builtIns.anyClass)))
|
||||
|
||||
fun IrType.toBoxedInlineClassType(): WasmType =
|
||||
toWasmGcRefType()
|
||||
@@ -111,7 +111,7 @@ class WasmTypeTransformer(
|
||||
|
||||
|
||||
// Return null if upper bound is Any
|
||||
val IrTypeParameter.erasedUpperBound: IrClass?
|
||||
private val IrTypeParameter.erasedUpperBound: IrClass?
|
||||
get() {
|
||||
// Pick the (necessarily unique) non-interface upper bound if it exists
|
||||
for (type in superTypes) {
|
||||
@@ -126,7 +126,10 @@ val IrType.erasedUpperBound: IrClass?
|
||||
is IrClassSymbol -> classifier.owner
|
||||
is IrTypeParameterSymbol -> classifier.owner.erasedUpperBound
|
||||
else -> throw IllegalStateException()
|
||||
}.let {
|
||||
}
|
||||
|
||||
val IrType.getRuntimeClass: IrClass?
|
||||
get() = erasedUpperBound.let {
|
||||
if (it?.isInterface == true) null
|
||||
else it
|
||||
}
|
||||
|
||||
+2
-3
@@ -13,9 +13,8 @@ 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.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.findUnitGetInstanceFunction
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
@@ -100,7 +99,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
context.inlineClassesUtils.isTypeInlined(this)
|
||||
|
||||
private val IrType.erasedType: IrType
|
||||
get() = this.erasedUpperBound?.defaultType ?: builtIns.anyType
|
||||
get() = this.getRuntimeClass?.defaultType ?: builtIns.anyType
|
||||
|
||||
private fun generateTypeCheck(
|
||||
valueProvider: () -> IrExpression,
|
||||
|
||||
Reference in New Issue
Block a user