[Wasm] Disable range checks for arrays. Add cli argument to enable them back.
This commit is contained in:
+3
@@ -253,6 +253,9 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xwasm-kclass-fqn", description = "Enable support for FQ names in KClass")
|
||||
var wasmKClassFqn: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xwasm-enable-array-range-checks", description = "Turn on range checks for the array access functions")
|
||||
var wasmEnableArrayRangeChecks: Boolean by FreezableVar(false)
|
||||
|
||||
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return super.configureAnalysisFlags(collector, languageVersion).also {
|
||||
it[allowFullyQualifiedNameInKClass] = wasm && wasmKClassFqn //Only enabled WASM BE supports this flag
|
||||
|
||||
@@ -135,6 +135,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
|
||||
configuration.put(JSConfigurationKeys.PARTIAL_LINKAGE, arguments.partialLinkage)
|
||||
|
||||
configuration.put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, arguments.wasmEnableArrayRangeChecks)
|
||||
|
||||
val commonSourcesArray = arguments.commonSources
|
||||
val commonSources = commonSourcesArray?.toSet() ?: emptySet()
|
||||
for (arg in arguments.freeArgs) {
|
||||
|
||||
@@ -156,6 +156,8 @@ class WasmSymbols(
|
||||
|
||||
val wasmRefCast = getInternalFunction("wasm_ref_cast")
|
||||
|
||||
val rangeCheck = getInternalFunction("rangeCheck")
|
||||
|
||||
val boxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("boxIntrinsic")
|
||||
val unboxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("unboxIntrinsic")
|
||||
|
||||
|
||||
+8
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.wasm.ir.*
|
||||
|
||||
class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorVoid {
|
||||
@@ -258,6 +259,13 @@ 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) {
|
||||
body.buildGetUnit()
|
||||
return
|
||||
}
|
||||
|
||||
val function: IrFunction = call.symbol.owner.realOverrideTarget
|
||||
|
||||
call.dispatchReceiver?.let { generateExpression(it) }
|
||||
|
||||
+2
@@ -39,6 +39,8 @@ where advanced options include:
|
||||
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
||||
-Xwasm Use experimental WebAssembly compiler backend
|
||||
-Xwasm-debug-info Add debug info to WebAssembly compiled module
|
||||
-Xwasm-enable-array-range-checks
|
||||
Turn on range checks for the array access functions
|
||||
-Xwasm-kclass-fqn Enable support for FQ names in KClass
|
||||
-Xwasm-launcher=esm|nodejs|d8 Picks flavor for the wasm launcher. Default is ESM.
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
|
||||
@@ -99,4 +99,7 @@ public class JSConfigurationKeys {
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> PROPERTY_LAZY_INITIALIZATION =
|
||||
CompilerConfigurationKey.create("perform lazy initialization for properties");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> WASM_ENABLE_ARRAY_RANGE_CHECKS =
|
||||
CompilerConfigurationKey.create("enable array range checks");
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.js.config.JsConfig
|
||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||
import org.jetbrains.kotlin.js.testOld.engines.ExternalTool
|
||||
@@ -235,6 +236,7 @@ abstract class BasicWasmBoxTest(
|
||||
private fun createConfig(languageVersionSettings: LanguageVersionSettings?): JsConfig {
|
||||
val configuration = environment.configuration.copy()
|
||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, TEST_MODULE)
|
||||
configuration.put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, false)
|
||||
configuration.languageVersionSettings = languageVersionSettings
|
||||
?: LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE)
|
||||
return JsConfig(project, configuration, CompilerEnvironment, null, null)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
|
||||
plugins {
|
||||
`maven-publish`
|
||||
@@ -139,6 +140,10 @@ val compileTestKotlinWasm by tasks.existing(KotlinCompile::class) {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<KotlinJsIrLink>("compileTestDevelopmentExecutableKotlinWasm") {
|
||||
(this as KotlinCompile<*>).kotlinOptions.freeCompilerArgs += "-Xwasm-enable-array-range-checks"
|
||||
}
|
||||
|
||||
val runtimeElements by configurations.creating {}
|
||||
val apiElements by configurations.creating {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user