From d865202bd5bd012ed536394b1b3dc5bc39d38841 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Thu, 22 Jun 2023 13:56:47 +0000 Subject: [PATCH] [Wasm] Inline _importModule ^KT-59556 fixed --- .../src/org/jetbrains/kotlin/backend/wasm/compiler.kt | 8 ++------ compiler/testData/codegen/box/size/add.kt | 2 +- compiler/testData/codegen/box/size/helloWorld.kt | 2 +- compiler/testData/codegen/box/size/helloWorldDOM.kt | 2 +- compiler/testData/codegen/box/size/objectsOptimization.kt | 2 +- compiler/testData/codegen/box/size/ok.kt | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt index 3ce363c74e4..2a39bd1da34 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt @@ -193,7 +193,7 @@ fun WasmCompiledModuleFragment.generateAsyncJsWrapper( .sorted() .joinToString("") { val moduleSpecifier = it.toJsStringLiteral() - " $moduleSpecifier: await _importModule($moduleSpecifier),\n" + " $moduleSpecifier: imports[$moduleSpecifier] ?? await import($moduleSpecifier),\n" } val referencesToQualifiedAndImportedDeclarations = jsModuleAndQualifierReferences @@ -205,7 +205,7 @@ fun WasmCompiledModuleFragment.generateAsyncJsWrapper( append(it.jsVariableName) append(" = ") if (module != null) { - append("(await _importModule(${module.toJsStringLiteral()}))") + append("(imports[${module.toJsStringLiteral()}] ?? await import(${module.toJsStringLiteral()}))") if (qualifier != null) append(".") } @@ -231,10 +231,6 @@ export async function instantiate(imports={}, runInitializer=true) { externrefBoxes.set(ref, ifNotCached); return ifNotCached; } - - async function _importModule(x) { - return imports[x] ?? await import(x); - } $referencesToQualifiedAndImportedDeclarations diff --git a/compiler/testData/codegen/box/size/add.kt b/compiler/testData/codegen/box/size/add.kt index 7b40d94964d..99875d3e180 100644 --- a/compiler/testData/codegen/box/size/add.kt +++ b/compiler/testData/codegen/box/size/add.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_946 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_456 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/helloWorld.kt b/compiler/testData/codegen/box/size/helloWorld.kt index 02aae10f792..93699f3ec02 100644 --- a/compiler/testData/codegen/box/size/helloWorld.kt +++ b/compiler/testData/codegen/box/size/helloWorld.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 47_948 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_482 fun box(): String { println("Hello, World!") diff --git a/compiler/testData/codegen/box/size/helloWorldDOM.kt b/compiler/testData/codegen/box/size/helloWorldDOM.kt index 772a8c944dd..381a9fb5cad 100644 --- a/compiler/testData/codegen/box/size/helloWorldDOM.kt +++ b/compiler/testData/codegen/box/size/helloWorldDOM.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_307 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_011 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/objectsOptimization.kt b/compiler/testData/codegen/box/size/objectsOptimization.kt index 3b9aab61ac2..76b716428c1 100644 --- a/compiler/testData/codegen/box/size/objectsOptimization.kt +++ b/compiler/testData/codegen/box/size/objectsOptimization.kt @@ -1,7 +1,7 @@ // TARGET_BACKEND: WASM // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 18_621 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_328 object Simple diff --git a/compiler/testData/codegen/box/size/ok.kt b/compiler/testData/codegen/box/size/ok.kt index 2b036c023de..71f7e74f1c8 100644 --- a/compiler/testData/codegen/box/size/ok.kt +++ b/compiler/testData/codegen/box/size/ok.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_988 -// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_328 fun box() = "OK" \ No newline at end of file