[Wasm] export __callFunction_* only when a respective closure/lambda converter is used
This commit is contained in:
committed by
Space Team
parent
699ad87be2
commit
c114afb55d
@@ -53,6 +53,9 @@ private fun buildRoots(modules: List<IrModuleFragment>, context: WasmBackendCont
|
|||||||
add(context.irBuiltIns.throwableClass.owner)
|
add(context.irBuiltIns.throwableClass.owner)
|
||||||
add(context.mainCallsWrapperFunction)
|
add(context.mainCallsWrapperFunction)
|
||||||
add(context.fieldInitFunction)
|
add(context.fieldInitFunction)
|
||||||
|
|
||||||
|
// Remove all functions used to call a kotlin closure from JS side, reachable ones will be added back later.
|
||||||
|
removeAll(context.closureCallExports.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun List<IrModuleFragment>.onAllFiles(body: IrFile.() -> Unit) {
|
private inline fun List<IrModuleFragment>.onAllFiles(body: IrFile.() -> Unit) {
|
||||||
|
|||||||
+6
@@ -23,6 +23,10 @@ internal class WasmUsefulDeclarationProcessor(
|
|||||||
|
|
||||||
private val unitGetInstance: IrSimpleFunction = context.findUnitGetInstanceFunction()
|
private val unitGetInstance: IrSimpleFunction = context.findUnitGetInstanceFunction()
|
||||||
|
|
||||||
|
// The mapping from function for wrapping a kotlin closure/lambda with JS closure to function used to call a kotlin closure from JS side.
|
||||||
|
private val kotlinClosureToJsClosureConvertFunToKotlinClosureCallFun =
|
||||||
|
context.kotlinClosureToJsConverters.entries.associate { (k, v) -> v to context.closureCallExports[k] }
|
||||||
|
|
||||||
override val bodyVisitor: BodyVisitorBase = object : BodyVisitorBase() {
|
override val bodyVisitor: BodyVisitorBase = object : BodyVisitorBase() {
|
||||||
override fun visitConst(expression: IrConst<*>, data: IrDeclaration) = when (expression.kind) {
|
override fun visitConst(expression: IrConst<*>, data: IrDeclaration) = when (expression.kind) {
|
||||||
is IrConstKind.Null -> expression.type.enqueueType(data, "expression type")
|
is IrConstKind.Null -> expression.type.enqueueType(data, "expression type")
|
||||||
@@ -160,6 +164,8 @@ internal class WasmUsefulDeclarationProcessor(
|
|||||||
|
|
||||||
irFunction.getEffectiveValueParameters().forEach { it.enqueueValueParameterType(irFunction) }
|
irFunction.getEffectiveValueParameters().forEach { it.enqueueValueParameterType(irFunction) }
|
||||||
irFunction.returnType.enqueueType(irFunction, "function return type")
|
irFunction.returnType.enqueueType(irFunction, "function return type")
|
||||||
|
|
||||||
|
kotlinClosureToJsClosureConvertFunToKotlinClosureCallFun[irFunction]?.enqueue(irFunction, "kotlin closure to JS closure conversion", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processSimpleFunction(irFunction: IrSimpleFunction) {
|
override fun processSimpleFunction(irFunction: IrSimpleFunction) {
|
||||||
|
|||||||
+2
@@ -458,6 +458,8 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT
|
|||||||
}
|
}
|
||||||
+irReturn(info.resultAdapter.adaptIfNeeded(callInvoke, builder))
|
+irReturn(info.resultAdapter.adaptIfNeeded(callInvoke, builder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO find out a better way to export the such declarations only when it's required. Also, fix building roots for DCE, then.
|
||||||
result.annotations += builder.irCallConstructor(context.wasmSymbols.jsExportConstructor, typeArguments = emptyList())
|
result.annotations += builder.irCallConstructor(context.wasmSymbols.jsExportConstructor, typeArguments = emptyList())
|
||||||
additionalDeclarations += result
|
additionalDeclarations += result
|
||||||
return result
|
return result
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 34_869
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 29_800
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_359
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_104
|
||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 65_687
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 60_691
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_458
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_130
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
println("Hello, World!")
|
println("Hello, World!")
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 38_128
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 31_232
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_798
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_659
|
||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 34_917
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 29_848
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_231
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_976
|
||||||
|
|
||||||
fun box() = "OK"
|
fun box() = "OK"
|
||||||
Reference in New Issue
Block a user