diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt index a3cb2f90ce7..5b3c084764f 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt @@ -287,8 +287,9 @@ class BodyGenerator( return } + val location = expression.getSourceLocation() + if (expression.symbol.owner.hasWasmPrimitiveConstructorAnnotation()) { - val location = expression.getSourceLocation() generateAnyParameters(klassSymbol, location) for (i in 0 until expression.valueArgumentsCount) { generateExpression(expression.getValueArgument(i)!!) @@ -298,7 +299,7 @@ class BodyGenerator( return } - body.buildRefNull(WasmHeapType.Simple.NullNone) // this = null + body.buildRefNull(WasmHeapType.Simple.NullNone, location) // this = null generateCall(expression) } @@ -309,7 +310,7 @@ class BodyGenerator( if (klassSymbol.owner.hasInterfaceSuperClass()) { body.buildGetGlobal(context.referenceGlobalClassITable(klassSymbol), location) } else { - body.buildRefNull(WasmHeapType.Simple.Data) + body.buildRefNull(WasmHeapType.Simple.Data, location) } body.buildConstI32Symbol(context.referenceClassId(klassSymbol), location) @@ -721,7 +722,7 @@ class BodyGenerator( if (actualType.isNullableNothing() && expectedType.isNullable()) { if (expectedType.getClass()?.isExternal == true) { body.buildDrop() - body.buildRefNull(WasmHeapType.Simple.NullNoExtern) + body.buildRefNull(WasmHeapType.Simple.NullNoExtern, location) } return } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt index 377c283f608..4581c23bfa1 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt @@ -258,6 +258,7 @@ class DeclarationGenerator( val vTableRefGcType = WasmRefType(WasmHeapType.Type(vTableTypeReference)) val initVTableGlobal = buildWasmExpression { + val location = SourceLocation.NoLocation("Create instance of vtable struct") metadata.virtualMethods.forEachIndexed { i, method -> if (method.function.modality != Modality.ABSTRACT) { buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(context.referenceFunction(method.function.symbol))) @@ -266,10 +267,10 @@ class DeclarationGenerator( "Cannot find class implementation of method ${method.signature} in class ${klass.fqNameWhenAvailable}" } //This erased by DCE so abstract version appeared in non-abstract class - buildRefNull(vtableStruct.fields[i].type.getHeapType()) + buildRefNull(vtableStruct.fields[i].type.getHeapType(), location) } } - buildStructNew(vTableTypeReference, SourceLocation.NoLocation("Create instance of vtable struct")) + buildStructNew(vTableTypeReference, location) } context.defineGlobalVTable( irClass = symbol, @@ -294,7 +295,7 @@ class DeclarationGenerator( val iFaceVTableGcNullHeapType = WasmHeapType.Type(iFaceVTableGcType) if (!metadata.interfaces.contains(iFace.owner)) { - buildRefNull(iFaceVTableGcNullHeapType) + buildRefNull(iFaceVTableGcNullHeapType, location) continue } @@ -311,7 +312,7 @@ class DeclarationGenerator( buildInstr(WasmOp.REF_FUNC, WasmImmediate.FuncIdx(functionTypeReference)) } else { //This erased by DCE so abstract version appeared in non-abstract class - buildRefNull(WasmHeapType.Type(context.referenceFunctionType(method.function.symbol))) + buildRefNull(WasmHeapType.Type(context.referenceFunctionType(method.function.symbol)), location) } } buildStructNew(iFaceVTableGcType, location) @@ -482,11 +483,11 @@ fun generateDefaultInitializerForType(type: WasmType, g: WasmExpressionBuilder) WasmI64 -> g.buildConstI64(0, location) WasmF32 -> g.buildConstF32(0f, location) WasmF64 -> g.buildConstF64(0.0, location) - is WasmRefNullType -> g.buildRefNull(type.heapType) - is WasmRefNullNoneType -> g.buildRefNull(WasmHeapType.Simple.NullNone) - is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NullNoExtern) - is WasmAnyRef -> g.buildRefNull(WasmHeapType.Simple.Any) - is WasmExternRef -> g.buildRefNull(WasmHeapType.Simple.Extern) + is WasmRefNullType -> g.buildRefNull(type.heapType, location) + is WasmRefNullNoneType -> g.buildRefNull(WasmHeapType.Simple.NullNone, location) + is WasmRefNullExternrefType -> g.buildRefNull(WasmHeapType.Simple.NullNoExtern, location) + is WasmAnyRef -> g.buildRefNull(WasmHeapType.Simple.Any, location) + is WasmExternRef -> g.buildRefNull(WasmHeapType.Simple.Extern, location) WasmUnreachableType -> error("Unreachable type can't be initialized") else -> error("Unknown value type ${type.name}") } diff --git a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/WasmExpressionBuilder.kt b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/WasmExpressionBuilder.kt index c9d0269696d..da19e157b4c 100644 --- a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/WasmExpressionBuilder.kt +++ b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/WasmExpressionBuilder.kt @@ -175,8 +175,8 @@ abstract class WasmExpressionBuilder { buildInstr(WasmOp.REF_TEST_DEPRECATED, location, WasmImmediate.TypeIdx(toType)) } - fun buildRefNull(type: WasmHeapType) { - buildInstr(WasmOp.REF_NULL, WasmImmediate.HeapType(WasmRefType(type))) + fun buildRefNull(type: WasmHeapType, location: SourceLocation) { + buildInstr(WasmOp.REF_NULL, location, WasmImmediate.HeapType(WasmRefType(type))) } fun buildDrop() {