From e7dc443c18329faae7f7fa3a9d48a5838b25c3ae Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 13 Dec 2022 19:16:23 +0100 Subject: [PATCH] [Wasm] Require location for `buildStructGet` and fix all usages --- .../backend/wasm/ir2wasm/BodyGenerator.kt | 20 +++++++++---------- .../kotlin/wasm/ir/WasmExpressionBuilder.kt | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) 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 34c39bf0857..c3378ad1657 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 @@ -361,6 +361,8 @@ class BodyGenerator( } private fun generateCall(call: IrFunctionAccessExpression) { + val location = call.getSourceLocation() + // Box intrinsic has an additional klass ID argument. // Processing it separately if (call.symbol == wasmSymbols.boxIntrinsic) { @@ -427,8 +429,8 @@ class BodyGenerator( //TODO: check why it could be needed generateRefNullCast(receiver.type, klass.defaultType) - body.buildStructGet(context.referenceGcType(klass.symbol), WasmSymbol(0)) - body.buildStructGet(context.referenceVTableGcType(klass.symbol), WasmSymbol(vfSlot)) + body.buildStructGet(context.referenceGcType(klass.symbol), WasmSymbol(0), location) + body.buildStructGet(context.referenceVTableGcType(klass.symbol), WasmSymbol(vfSlot), location) body.buildInstr(WasmOp.CALL_REF, WasmImmediate.TypeIdx(context.referenceFunctionType(function.symbol))) body.commentGroupEnd() } else { @@ -437,16 +439,16 @@ class BodyGenerator( generateExpression(call.dispatchReceiver!!) body.commentGroupStart { "interface call: ${function.fqNameWhenAvailable}" } - body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1)) + body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1), location) val classITableReference = context.referenceClassITableGcType(symbol) body.buildRefCastNullStatic(classITableReference) - body.buildStructGet(classITableReference, context.referenceClassITableInterfaceSlot(symbol)) + body.buildStructGet(classITableReference, context.referenceClassITableInterfaceSlot(symbol), location) val vfSlot = context.getInterfaceMetadata(symbol).methods .indexOfFirst { it.function == function } - body.buildStructGet(context.referenceVTableGcType(symbol), WasmSymbol(vfSlot)) + body.buildStructGet(context.referenceVTableGcType(symbol), WasmSymbol(vfSlot), location) body.buildInstr(WasmOp.CALL_REF, WasmImmediate.TypeIdx(context.referenceFunctionType(function.symbol))) body.commentGroupEnd() } else { @@ -459,9 +461,7 @@ class BodyGenerator( } else { // Static function call - withLocation(call.getSourceLocation()) { - body.buildCall(context.referenceFunction(function.symbol), location) - } + body.buildCall(context.referenceFunction(function.symbol), location) } // Unit types don't cross function boundaries @@ -533,9 +533,9 @@ class BodyGenerator( body.buildBlock("isInterface", WasmI32) { outerLabel -> body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel -> body.buildGetLocal(parameterLocal, location) - body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1)) + body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1), location) body.buildBrInstr(WasmOp.BR_ON_CAST_FAIL_DEPRECATED, innerLabel, classITable) - body.buildStructGet(classITable, context.referenceClassITableInterfaceSlot(irInterface.symbol)) + body.buildStructGet(classITable, context.referenceClassITableInterfaceSlot(irInterface.symbol), location) body.buildInstr(WasmOp.REF_IS_NULL) body.buildInstr(WasmOp.I32_EQZ) body.buildBr(outerLabel) 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 5d0e4093861..267b30ca17a 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 @@ -145,9 +145,10 @@ abstract class WasmExpressionBuilder { buildInstr(WasmOp.GLOBAL_SET, location, WasmImmediate.GlobalIdx(global)) } - fun buildStructGet(struct: WasmSymbol, fieldId: WasmSymbol) { + fun buildStructGet(struct: WasmSymbol, fieldId: WasmSymbol, location: SourceLocation) { buildInstr( WasmOp.STRUCT_GET, + location, WasmImmediate.GcType(struct), WasmImmediate.StructFieldIdx(fieldId) )