[Wasm] Add compiler flag to disable exception handling proposal
Fail with unreachable instead of throwing an exception Merge-request: KT-MR-11481 Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
ec73815f80
commit
47ade4530c
+1
-1
@@ -24,11 +24,11 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.addChild
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
|
||||
@@ -97,7 +97,10 @@ fun compileWasm(
|
||||
generateWat: Boolean = false,
|
||||
generateSourceMaps: Boolean = false,
|
||||
): WasmCompilerResult {
|
||||
val compiledWasmModule = WasmCompiledModuleFragment(backendContext.irBuiltIns)
|
||||
val compiledWasmModule = WasmCompiledModuleFragment(
|
||||
backendContext.irBuiltIns,
|
||||
backendContext.configuration.getBoolean(JSConfigurationKeys.WASM_USE_TRAPS_INSTEAD_OF_EXCEPTIONS)
|
||||
)
|
||||
val codeGenerator = WasmModuleFragmentGenerator(backendContext, compiledWasmModule, allowIncompleteImplementations = allowIncompleteImplementations)
|
||||
allModules.forEach { codeGenerator.collectInterfaceTables(it) }
|
||||
allModules.forEach { codeGenerator.generateModule(it) }
|
||||
|
||||
+10
@@ -137,12 +137,22 @@ class BodyGenerator(
|
||||
|
||||
override fun visitThrow(expression: IrThrow) {
|
||||
generateExpression(expression.value)
|
||||
if (context.backendContext.configuration.getBoolean(JSConfigurationKeys.WASM_USE_TRAPS_INSTEAD_OF_EXCEPTIONS)) {
|
||||
body.buildUnreachable(SourceLocation.NoLocation("Unreachable is inserted instead of a `throw` instruction"))
|
||||
return
|
||||
}
|
||||
|
||||
body.buildThrow(functionContext.tagIdx, expression.getSourceLocation())
|
||||
}
|
||||
|
||||
override fun visitTry(aTry: IrTry) {
|
||||
assert(aTry.isCanonical(irBuiltIns)) { "expected canonical try/catch" }
|
||||
|
||||
if (context.backendContext.configuration.getBoolean(JSConfigurationKeys.WASM_USE_TRAPS_INSTEAD_OF_EXCEPTIONS)) {
|
||||
generateExpression(aTry.tryResult)
|
||||
return
|
||||
}
|
||||
|
||||
val resultType = context.transformBlockResultType(aTry.type)
|
||||
body.buildTry(null, resultType)
|
||||
generateExpression(aTry.tryResult)
|
||||
|
||||
+6
-3
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.wasm.ir.*
|
||||
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
|
||||
|
||||
class WasmCompiledModuleFragment(val irBuiltIns: IrBuiltIns) {
|
||||
class WasmCompiledModuleFragment(
|
||||
val irBuiltIns: IrBuiltIns,
|
||||
generateTrapsInsteadOfExceptions: Boolean,
|
||||
) {
|
||||
val functions =
|
||||
ReferencableAndDefinable<IrFunctionSymbol, WasmFunction>()
|
||||
val globalFields =
|
||||
@@ -49,7 +52,7 @@ class WasmCompiledModuleFragment(val irBuiltIns: IrBuiltIns) {
|
||||
),
|
||||
emptyList()
|
||||
)
|
||||
val tag = WasmTag(tagFuncType)
|
||||
val tags = if (generateTrapsInsteadOfExceptions) emptyList() else listOf(WasmTag(tagFuncType))
|
||||
|
||||
val typeInfo = ReferencableAndDefinable<IrClassSymbol, ConstantDataElement>()
|
||||
|
||||
@@ -238,7 +241,7 @@ class WasmCompiledModuleFragment(val irBuiltIns: IrBuiltIns) {
|
||||
elements = emptyList(),
|
||||
data = data,
|
||||
dataCount = true,
|
||||
tags = listOf(tag)
|
||||
tags = tags
|
||||
)
|
||||
module.calculateIds()
|
||||
return module
|
||||
|
||||
Reference in New Issue
Block a user