From 9d099348ba6c0ba086866d029e56d0fe2140c61e Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Wed, 28 Dec 2022 17:33:51 +0000 Subject: [PATCH] [Wasm] Disable interop adapters for WasmImport Merge-request: KT-MR-8152 --- .../wasm/lower/JsInteropFunctionsLowering.kt | 2 ++ .../imperativeWrapperInitialised.kt | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/JsInteropFunctionsLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/JsInteropFunctionsLowering.kt index 6bf58063182..ef9b8e408fb 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/JsInteropFunctionsLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/JsInteropFunctionsLowering.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.wasm.WasmBackendContext import org.jetbrains.kotlin.backend.wasm.ir2wasm.isBuiltInWasmRefType import org.jetbrains.kotlin.backend.wasm.ir2wasm.isExported import org.jetbrains.kotlin.backend.wasm.ir2wasm.isExternalType +import org.jetbrains.kotlin.backend.wasm.utils.getWasmImportDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.ir.backend.js.utils.getJsNameOrKotlinName import org.jetbrains.kotlin.ir.builders.* @@ -49,6 +50,7 @@ class JsInteropFunctionsLowering(val context: WasmBackendContext) : DeclarationT if (declaration.isPropertyAccessor) return null if (declaration.parent !is IrPackageFragment) return null if (!isExported && !isExternal) return null + if (declaration.getWasmImportDescriptor() != null) return null check(!(isExported && isExternal)) { "Exported external declarations are not supported: ${declaration.fqNameWhenAvailable}" } check(declaration.parent !is IrClass) { "Interop members are not supported: ${declaration.fqNameWhenAvailable}" } diff --git a/compiler/testData/codegen/boxWasmJsInterop/imperativeWrapperInitialised.kt b/compiler/testData/codegen/boxWasmJsInterop/imperativeWrapperInitialised.kt index 6d5bdb18b0b..b182bb4f060 100644 --- a/compiler/testData/codegen/boxWasmJsInterop/imperativeWrapperInitialised.kt +++ b/compiler/testData/codegen/boxWasmJsInterop/imperativeWrapperInitialised.kt @@ -12,11 +12,19 @@ external fun inc2(x: Int): Int @WasmImport("./bar.mjs", "inc3") external fun inc3(x: Int): Int +@WasmImport("./bar.mjs", "giveMeNumber") +external fun giveMeNumber(x: Boolean) + @JsExport fun myBox(): String { if (inc1(5) != 6) return "KFail1" if (inc2(5) != 6) return "KFail2" if (inc3(5) != 6) return "KFail3" + + // Test that booleans are translated as i32 + giveMeNumber(true) + giveMeNumber(false) + return "OK" } @@ -37,7 +45,14 @@ let inc = x => x + 1; let imports = { "foo": { inc1 : inc }, "~!@#\$%^&*()_+\`-={}|[]\\\\:\\\";'<>?,./" : { inc2 : inc }, - "./bar.mjs" : { inc3 : inc }, + "./bar.mjs" : { + inc3 : inc, + giveMeNumber(x) { + if (typeof x !== 'number') { + throw "Not a number!"; + } + }, + }, } let { exports } = await instantiate(imports);