[WASM] Add command line option to enable/disable assertions
This commit is contained in:
@@ -31,6 +31,8 @@ class WasmSymbols(
|
||||
private val symbolTable: SymbolTable
|
||||
) : Symbols<WasmBackendContext>(context, context.irBuiltIns, symbolTable) {
|
||||
|
||||
private val kotlinTopLevelPackage: PackageViewDescriptor =
|
||||
context.module.getPackage(FqName("kotlin"))
|
||||
private val wasmInternalPackage: PackageViewDescriptor =
|
||||
context.module.getPackage(FqName("kotlin.wasm.internal"))
|
||||
private val collectionsPackage: PackageViewDescriptor =
|
||||
@@ -157,6 +159,7 @@ class WasmSymbols(
|
||||
val wasmRefCast = getInternalFunction("wasm_ref_cast")
|
||||
|
||||
val rangeCheck = getInternalFunction("rangeCheck")
|
||||
val assertFuncs = findFunctions(kotlinTopLevelPackage.memberScope, Name.identifier("assert"))
|
||||
|
||||
val boxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("boxIntrinsic")
|
||||
val unboxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("unboxIntrinsic")
|
||||
|
||||
+9
-3
@@ -259,9 +259,15 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
||||
return
|
||||
}
|
||||
|
||||
// Range check intrinsic is a special case because it doesn't require arguments on the stack.
|
||||
if (call.symbol == wasmSymbols.rangeCheck &&
|
||||
backendContext.configuration.getNotNull(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS) == false) {
|
||||
// Some intrinsics are a special case because we want to remove them completely, including their arguments.
|
||||
val removableIntrinsics = buildList {
|
||||
if (backendContext.configuration.getNotNull(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS) == false)
|
||||
add(wasmSymbols.rangeCheck)
|
||||
if (backendContext.configuration.getNotNull(JSConfigurationKeys.WASM_ENABLE_ASSERTS) == false)
|
||||
addAll(wasmSymbols.assertFuncs)
|
||||
}
|
||||
|
||||
if (call.symbol in removableIntrinsics) {
|
||||
body.buildGetUnit()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user