From 95c84d5d3f0d2c6a88ee9012556237c50de4167e Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 13 Dec 2022 19:31:49 +0100 Subject: [PATCH] [Wasm] Require location for `buildDrop` and fix all usages --- .../kotlin/backend/wasm/ir2wasm/BodyGenerator.kt | 11 +++++------ .../backend/wasm/ir2wasm/OptimisedWhenGenerator.kt | 4 ++-- .../jetbrains/kotlin/wasm/ir/WasmExpressionBuilder.kt | 4 ++-- 3 files changed, 9 insertions(+), 10 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 5b3c084764f..44341ae5e2d 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 @@ -68,7 +68,7 @@ class BodyGenerator( private fun generateAsStatement(statement: IrExpression) { generateExpression(statement) if (statement.type != wasmSymbols.voidType) { - body.buildDrop() + body.buildDrop(statement.getSourceLocation()) } } @@ -489,7 +489,7 @@ class BodyGenerator( location ) } else { - body.buildDrop() + body.buildDrop(location) body.buildConstI32(1, location) } } @@ -546,11 +546,11 @@ class BodyGenerator( body.buildInstr(WasmOp.I32_EQZ) body.buildBr(outerLabel) } - body.buildDrop() + body.buildDrop(location) body.buildConstI32(0, location) } } else { - body.buildDrop() + body.buildDrop(location) body.buildConstI32(0, location) } } @@ -589,7 +589,6 @@ class BodyGenerator( } wasmSymbols.unsafeGetScratchRawMemory -> { - body.buildConstI32Symbol(context.scratchMemAddr, location) } @@ -721,7 +720,7 @@ class BodyGenerator( // NOTHING? -> TYPE? -> (NOTHING?)NULL if (actualType.isNullableNothing() && expectedType.isNullable()) { if (expectedType.getClass()?.isExternal == true) { - body.buildDrop() + body.buildDrop(location) body.buildRefNull(WasmHeapType.Simple.NullNoExtern, location) } return diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/OptimisedWhenGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/OptimisedWhenGenerator.kt index 53189d4adeb..4debd537eb6 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/OptimisedWhenGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/OptimisedWhenGenerator.kt @@ -333,7 +333,7 @@ private fun BodyGenerator.genTableIntSwitch( for (expression in branches) { if (resultType != null) { - body.buildDrop() + body.buildDrop(location) } generateWithExpectedType(expression.expression, expectedType) @@ -343,7 +343,7 @@ private fun BodyGenerator.genTableIntSwitch( if (elseExpression != null) { if (resultType != null) { - body.buildDrop() + body.buildDrop(location) } generateWithExpectedType(elseExpression, expectedType) } 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 da19e157b4c..133050766f2 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 @@ -179,8 +179,8 @@ abstract class WasmExpressionBuilder { buildInstr(WasmOp.REF_NULL, location, WasmImmediate.HeapType(WasmRefType(type))) } - fun buildDrop() { - buildInstr(WasmOp.DROP) + fun buildDrop(location: SourceLocation) { + buildInstr(WasmOp.DROP, location) } inline fun commentPreviousInstr(text: () -> String) {