[Wasm] Don't generate wat format by default in box tests

Gives ~15% tests speedup
Use kotlin.wasm.debugMode=1 to enable old behaviour
This commit is contained in:
Svyatoslav Kuzmich
2022-05-20 14:52:24 +03:00
committed by Space
parent 706a0d287a
commit 84ed3ff5b0
3 changed files with 16 additions and 7 deletions
@@ -358,6 +358,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
backendContext = backendContext, backendContext = backendContext,
emitNameSection = arguments.wasmDebug, emitNameSection = arguments.wasmDebug,
allowIncompleteImplementations = arguments.irDce, allowIncompleteImplementations = arguments.irDce,
generateWat = true,
) )
val launcherKind = when (arguments.wasmLauncher) { val launcherKind = when (arguments.wasmLauncher) {
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToText
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File
class WasmCompilerResult(val wat: String, val js: String, val wasm: ByteArray) class WasmCompilerResult(val wat: String?, val js: String, val wasm: ByteArray)
fun compileToLoweredIr( fun compileToLoweredIr(
depsDescriptors: ModulesStructure, depsDescriptors: ModulesStructure,
@@ -76,15 +76,20 @@ fun compileWasm(
backendContext: WasmBackendContext, backendContext: WasmBackendContext,
emitNameSection: Boolean = false, emitNameSection: Boolean = false,
allowIncompleteImplementations: Boolean = false, allowIncompleteImplementations: Boolean = false,
generateWat: Boolean = false,
): WasmCompilerResult { ): WasmCompilerResult {
val compiledWasmModule = WasmCompiledModuleFragment(backendContext.irBuiltIns) val compiledWasmModule = WasmCompiledModuleFragment(backendContext.irBuiltIns)
val codeGenerator = WasmModuleFragmentGenerator(backendContext, compiledWasmModule, allowIncompleteImplementations = allowIncompleteImplementations) val codeGenerator = WasmModuleFragmentGenerator(backendContext, compiledWasmModule, allowIncompleteImplementations = allowIncompleteImplementations)
allModules.forEach { codeGenerator.generateModule(it) } allModules.forEach { codeGenerator.generateModule(it) }
val linkedModule = compiledWasmModule.linkWasmCompiledFragments() val linkedModule = compiledWasmModule.linkWasmCompiledFragments()
val watGenerator = WasmIrToText() val wat = if (generateWat) {
watGenerator.appendWasmModule(linkedModule) val watGenerator = WasmIrToText()
val wat = watGenerator.toString() watGenerator.appendWasmModule(linkedModule)
watGenerator.toString()
} else {
null
}
val js = compiledWasmModule.generateJs() val js = compiledWasmModule.generateJs()
@@ -168,10 +173,9 @@ fun writeCompilationResult(
dir: File, dir: File,
loaderKind: WasmLoaderKind, loaderKind: WasmLoaderKind,
fileNameBase: String = "index", fileNameBase: String = "index",
writeWat: Boolean = true,
) { ) {
dir.mkdirs() dir.mkdirs()
if (writeWat) { if (result.wat != null) {
File(dir, "$fileNameBase.wat").writeText(result.wat) File(dir, "$fileNameBase.wat").writeText(result.wat)
} }
File(dir, "$fileNameBase.wasm").writeBytes(result.wasm) File(dir, "$fileNameBase.wasm").writeBytes(result.wasm)
@@ -127,11 +127,14 @@ abstract class BasicWasmBoxTest(
propertyLazyInitialization = true, propertyLazyInitialization = true,
) )
val generateWat = debugMode >= DebugMode.DEBUG
val compilerResult = compileWasm( val compilerResult = compileWasm(
allModules = allModules, allModules = allModules,
backendContext = backendContext, backendContext = backendContext,
emitNameSection = true, emitNameSection = true,
allowIncompleteImplementations = false, allowIncompleteImplementations = false,
generateWat = generateWat,
) )
eliminateDeadDeclarations(allModules, backendContext) eliminateDeadDeclarations(allModules, backendContext)
@@ -141,6 +144,7 @@ abstract class BasicWasmBoxTest(
backendContext = backendContext, backendContext = backendContext,
emitNameSection = true, emitNameSection = true,
allowIncompleteImplementations = true, allowIncompleteImplementations = true,
generateWat = generateWat,
) )
val testJsQuiet = """ val testJsQuiet = """
@@ -176,7 +180,7 @@ abstract class BasicWasmBoxTest(
println(" ------ $name Test file://$path/test.js") println(" ------ $name Test file://$path/test.js")
} }
writeCompilationResult(res, dir, WasmLoaderKind.D8, writeWat = debugMode >= DebugMode.DEBUG) writeCompilationResult(res, dir, WasmLoaderKind.D8)
File(dir, "test.js").writeText(testJs) File(dir, "test.js").writeText(testJs)
ExternalTool(System.getProperty("javascript.engine.path.V8")) ExternalTool(System.getProperty("javascript.engine.path.V8"))
.run( .run(